Given segments on a triangular grid, choose the largest subset so that no two share an endpoint at an acute angle.
Medium6GraphDynamic programmingGeometryBit manipulationNo attempts yetTime limit1sMemory limit512 MBIn one tilted city the paths and the streets do not meet at right angles. They always meet at an angle that is a multiple of 60 degrees. More precisely, the city sits on a triangular grid, a coordinate system in which the x axis and the y axis enclose an angle of 60 degrees. Two points A and B with integer coordinates are neighbors when their Euclidean distance equals 1. Every point has exactly 6 neighbors. The neighbors of the point (x,y) are (x+1,y), (x−1,y), (x,y+1), (x,y−1), (x+1,y−1), and (x−1,y+1).
The city has n paths. Each path connects a point to one of its neighbors. The city has secured the money to cover paths with asphalt and turn them into modern roads. Sharp turns on those new roads are not allowed. Precisely, two paved paths must not touch at a point and enclose an acute angle there.
Determine the largest number of paths that can be paved so that no sharp turn appears.
The first line contains the number of paths n (1≤n≤1000).
Each of the next n lines contains four positive integers xA, yA, xB, yB (1≤xA,yA,xB,yB≤100), in that order the coordinates of the points A and B that the path connects. A and B are always neighbors, and no path appears more than once in the input.
Print the largest number of paths that can be paved.

The figure shows the two coordinate axes meeting at 60 degrees and the triangular grid. The orange segments are the 17 paths of the first example, and the 10 segments outlined in gray are the paved ones.