50155. Iron Block in Tank

I'm a slow walker, but I never walk backwards.

We have a water tank and an iron block. The tank is a cuboid whose width, length and height are $a$, $b$ and $c$ respectively. The depth of water inside the tank is $d$. The width, length and height of the iron block are $e$, $f$ and $g$ respectively.

We now place the iron block into the water tank. We assume that the iron block will always sink to the bottom of the tank because iron is heavier than water. This assumption is true even when the length and width of the iron block are equal to those of the water tank. Also, water in the tank will spill out if there is not enough space left in the tank because of the iron block.

Write a program to compute the depth of water, which is defined as the distance from the surface of the water, to the bottom of the tank. If there is no water in the tank, the depth of water is 0.

Input Format

The input has seven lines for integers $a$, $b$, $c$, $d$, $e$, $f$, and $g$.

  • $a, b, c, e, f, g \geq 1$
  • $d \geq 0$
  • $a \geq e$
  • $b \geq f$
  • $c \geq d$

Output Format

The output is an integer, which is the depth of water after placing the iron block into the tank. We assume that the answer is always a non-negative integer.

Sample Input

2
3
6
4
2
2
3

Sample Output

6

Discussion