Empty Triangles

No attempts yetTime limit2sMemory limit512 MB

Problem

It is surprisingly easy to turn a very simple question into a brutally hard one. Here is an example.

How many triangles can you form with NN lines in the plane? If the lines have pairwise different slopes and no three of them pass through a single point, they form (N3)\binom{N}{3} triangles, which is the largest number possible.

That was not so hard. But now count only the empty triangles — those whose interior is not crossed by any of the lines. Suddenly the number becomes very small. For example, with 44 lines you can form at most 22 empty triangles, even though the total number of triangles can be as large as 44 (see the figure).

No general formula is known for the maximum number of empty triangles that NN lines can form; the hard part is choosing the right arrangement of the lines. Your task is easier: given NN lines in the plane, count how many empty triangles they form.

Four lines forming two empty triangles (shaded).

Figure 1: Four lines forming two empty triangles (shaded).

Input

The input consists of several test cases. Each test case begins with a line containing an integer NN (1N5001 \le N \le 500), the number of lines. Each of the next NN lines contains four integers x1x_1, y1y_1, x2x_2, y2y_2 (each between 1000-1000 and 10001000), describing a line that passes through the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). No three lines meet at a single point, and all lines are distinct. The input ends with a line containing N=0N = 0, which is not processed.

Output

For each test case, print a single line containing the number of empty triangles formed by the given lines.