Bang! Bang!

Given lines and circles all passing through the origin, count how many regions the plane is divided into, treating duplicates as one shape.

Hard8GeometryCombinatoricsMathImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Donggyu has a habit of banging his mouse on the desk while he plays. One day the desk finally cracked. Looking at the broken desk, he saw that every crack ran through the point he had hit last. Some cracks were straight lines, and some were circles through that point. He took a photo of the pattern.

Right after the photo, he nudged the desk and it fell apart along the cracks. Donggyu wants to check that he picked up every piece. Use the cracks in the photo to count how many pieces the desk broke into.

Put the point he hit last at the origin (0,0)(0, 0). Every crack is then a line through the origin or a circle through the origin. Count the regions that these lines and circles cut the plane into.

Input

The first line contains the total number of circles and lines NN (1N30001 \le N \le 3\,000). Each of the next NN lines contains three integers describing one circle or one line, with this meaning.

  • 1 a b : the line through the two points (0,0)(0, 0) and (a,b)(a, b)
  • 2 a b : the circle whose diameter is the segment joining (0,0)(0, 0) and (a,b)(a, b)

In both cases a,b106|a|, |b| \le 10^{6}, and aa and bb are never both 00. The same line or the same circle can be given several times, and shapes that coincide count as one shape.

Output

Print the number of regions that the lines and circles cut the desk into.

The desk is large enough that every intersection point of the circles and lines lies inside it.