Zing Zhu's Oyster Farm

No attempts yetTime limit1sMemory limit128 MB

Problem

Zing Zhu owns an island that is a piece of flat land. Every day, when the tide rises, the island is flooded by sea water. After much thinking and asking advice from members of his family, Zing Zhu decided to set up an oyster farm on the island.

Zing Zhu uses a sophisticated system of watertight plastic modular fences to control which areas are flooded and which are not while the tide rises. Each fence is either horizontal or vertical and comes as a strip with its own length and height. Any two fences intersect in at most one point, not necessarily at their endpoints.

Given the height the tide will reach and the position and height of every fence strip, compute the total area of land that will not be flooded at high tide.

Oyster farm fences

You may assume that the fence strips are so thin compared with the size of the land that, for the purpose of computing area, they may be considered to have zero width.

Sea water enters from outside the island (from infinitely far away) and floods every region it can reach. A fence strip holds the water back along its segment only when its height $H$ is at least the tide height $W$ (that is, $H \ge W$); if $H < W$ the tide flows over it. A region stays dry exactly when it is completely surrounded by fence segments that all hold the water back.

Input

The input contains several test cases.

The first line of a test case contains an integer $N$, the number of fence strips on the island ($1 \le N \le 2000$). Each of the next $N$ lines contains five integers $X_1$, $Y_1$, $X_2$, $Y_2$ and $H$: the start point $(X_1, Y_1)$ and end point $(X_2, Y_2)$ of the strip, and its height $H$. The last line of a test case contains an integer $W$, the tide height.

Coordinates are given in meters and heights in centimeters. Moreover $X_1 = X_2$ or $Y_1 = Y_2$ (but not both); $-500 \le X_1, Y_1, X_2, Y_2 \le 500$; and $1 \le W, H \le 1000$.

The end of the input is indicated by $N = 0$.

Output

For each test case, output one line containing a single integer: the total area, in square meters (m²), of the land that will not be flooded.