And Then, How Many Are There?

No attempts yetTime limit5sMemory limit128 MB

Problem

Mr. Solitarius, a famous creator of solo-play games, comes up with a new idea almost every day. His latest game uses discs of various colors and sizes.

At the start, all the discs are randomly scattered around the center of a table. During play you may remove a pair of discs of the same color, provided that neither of them has any disc lying on top of it. Note that a disc is not considered to lie on top of another when the two are only externally tangent.

Seven discs on the table

For example, in the figure above you can first remove the two black discs; doing so then makes it possible to remove the two white discs. The two gray discs, on the other hand, can never be removed.

Given the colors, sizes, and initial positions of the discs, compute the maximum number of discs that can be removed.

Input

The input consists of several datasets. Each dataset describes the state of a game immediately after all the discs have been scattered, in the following format:

n
x1 y1 r1 c1
x2 y2 r2 c2
...
xn yn rn cn

The first line contains a positive integer $n$, the number of discs. Each of the next $n$ lines contains four space-separated integers describing one disc:

  • $(x_i, y_i)$ is the center, $r_i$ the radius, and $c_i$ the color index of the $i$-th disc.
  • Whenever the $i$-th disc lies on top of the $j$-th disc, $i < j$ holds.

Every color index is an integer between $1$ and $4$ inclusive, and at most $6$ discs in a dataset share the same color. Every center coordinate is between $0$ and $100$ inclusive, and every radius is between $1$ and $100$ inclusive.

The end of the input is indicated by a line containing a single zero.

Output

For each dataset, print a single line containing one integer: the maximum number of discs that can be removed.