Rasterization

Count the pixel centers inside or on a triangle with integer-coordinate corners, handling the collinear case as a segment.

Medium4GeometryImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

One of the basic operations in computer graphics is rasterizing a triangle. Given the pixel coordinates of the corners of a triangle, a rasterization algorithm decides which pixels to colour.

The image above shows a screen of 12 rows by 10 columns of pixels. In the coordinate system used for the corners, integer values sit on the pixel boundaries and pixel centres sit at half integral coordinates. The coordinates of the three corners are printed at the top left of the image, x first and y second. The y coordinate increases downward. The corners follow the standard graphics convention and are listed in clockwise order, and any cyclic permutation of the three corners describes the same triangle.

The rule is this. Colour a pixel if its centre is inside the triangle or on an edge of the triangle, and leave it uncoloured otherwise. Because the corners have integer coordinates, whether a pixel centre lies exactly on an edge can be decided, and it must be decided exactly.

If the three corners are collinear, the triangle has zero area and the union of its three edges is a single segment that contains all three corners. In that case colour only the pixels whose centres lie on that segment.

Given the coordinates of the three corners, count the pixels coloured by this rule. The example in the image colours 20 pixels.

Input

The input holds several problems, one problem per line. Each line holds six space separated integers x1x_1, y1y_1, x2x_2, y2y_2, x3x_3, y3y_3. Every coordinate is between 0 and 2000 inclusive. Assume the screen is 2000 wide and 2000 high. There are at most 200 problems. A line of six zeroes ends the input and is not processed.

Output

For each problem, print the number of coloured pixels on its own line.