Crossing Wires

Program

WIRES.PAS, WIRES.C, WIRES.CPP


A firm, producing chips, NELIT, suffered from lack of profit. So they decided to cut down producing costs. Their new design would be as simple as possible. With uninsolated wires they would connect components on the chip and afterwards they will isolate the wires only on part of segments where two wires have a common point. Help NELIT designers and write a program which counts pairs of wires which have at least one common point.

Input:

Input (WIRES.IN) consists of blocks of lines, describing sample chip. In the first line of each block, there is number N (<= 1000), which describes the number of wires. The following N lines consist of 4 nonnegative whole numbers, giving coordinates of the starting and ending point of each wire. After each block there is a blank line. The end of input is denoted by a block with 0 in the first line.

Output:

For each block, WIRES.OUT has a single line with number of wire pairs, which have at least one common point. There is no line corresponding to the last null block.

Sample input/output:

3
0 0 1 1
0 1 1 0
2 0 2 1

2
0 0 1 1
2 0 3 1

3
0 0 2 2
0 2 2 0
1 0 1 2

0

Output:

1
0
1