Triangles
Time limit2sMemory limit1024 MB
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 is an expansion of triangle .
For practice, Vasya drew 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 (), the number of triangles. Each of the next lines contains six integers separated by spaces. They define the triangle with vertices , , and . All numbers in the input are at most 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.
