Under construction

Still being built. Things may change

Triangles

Time limit2sMemory limit1024 MB

Summary
Each step replaces every triangle with its medial-triangle expansion, and the task is to find the first step where some pair of triangles intersects.
Level

Medium7 of 10

Topics
Geometry, Implementation, Math
Solved
No attempts yet

Statement

Recently Vasya explained the basics of compass and straightedge constructions to his younger brother Petya. As an example, he showed how to build, from a given triangle, a triangle whose side midpoints coincide with the vertices of the first one. He called this action the "expansion" of a triangle.

In the picture, triangle DEFDEF is an expansion of triangle ABCABC.

For practice, Vasya drew nn triangles on a sheet of paper. He called one expansion of all triangles at once a "step". Then he asked Petya to find after how many steps a pair of intersecting triangles appears.

Two triangles intersect if there is a point that lies inside or on the boundary of each triangle. In particular, if one triangle lies inside another, they intersect.

Vasya wants a program that answers this question for the given triangles, so Petya can check his work.

Input

The first line contains a positive integer nn (2≤n≤502 \le n \le 50), the number of triangles. Each of the next nn lines contains six integers x1,y1,x2,y2,x3,y3x_1, y_1, x_2, y_2, x_3, y_3 separated by spaces. They define the triangle with vertices (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), and (x3,y3)(x_3, y_3). All numbers in the input are at most 10810^8 in absolute value.

Output

Print one integer: the number of steps after which a pair of intersecting triangles appears.

Hint

This explains the last example. The solid lines show the expansions of the first triangle, and the dashed lines show the expansions of the second one.

Examples3

  1. Example 1

    Input
    2
    0 0 1 0 0 1
    0 0 -1 0 0 -1
    
    Expected output
    0
    
  2. Example 2

    Input
    2
    0 0 1 0 0 1
    -1 -1 -1 3 3 -1
    
    Expected output
    0
    
  3. Example 3

    Input
    2
    10 2 5 9 3 5
    -9 0 0 -9 -9 -5
    
    Expected output
    3