Hubtown

Assign citizens to one of their two angularly nearest train rays, respecting each ray's capacity, and maximize the number assigned.

Hard8GreedySortingGeometryTwo pointersNo attempts yetTime limit10sMemory limit512 MB

Problem

Hubtown is a large Nordic city that is home to nn citizens. Every morning each citizen wants to travel to the central hub the city is named after, using one of the mm commuter trains that pass through the city. Each train line is a ray, a line segment that extends infinitely far in one direction, and it ends at the central hub at coordinates (0,0)(0, 0). A train line carries a limited number of people, and that limit may differ between lines, so a line can fill up and the citizens who do not fit drive instead. The city council wants as few people as possible to go by car. To arrange that, the council issues instructions stating which citizens may take which train.

A citizen always takes the train line of least angular distance from their house. A citizen who sits exactly in the middle between two train lines is willing to take either of them, and the council decides which of the two that citizen uses.

The figure below illustrates the first sample. The dashed arrows point at the train line each citizen is closest to. The quantity measured here is angular distance, not Euclidean distance.

Find the largest number of citizens who can reach the central hub by train in the morning, where each of those citizens takes one of the lines of least angular distance from their house and no line carries more citizens than its limit.

Input

The first line contains two integers nn and mm. Here nn is the number of citizens with 0n2000000 \le n \le 200000, and mm is the number of train lines with 1m2000001 \le m \le 200000.

Each of the next nn lines contains two integers xx and yy, the Cartesian coordinates of one citizen's home. No citizen lives at the central hub.

Each of the following mm lines contains three integers xx, yy and cc describing one train line. The point (x,y)(x, y) is different from the central hub and the line passes through it. The capacity of the line is cc with 0cn0 \le c \le n. The train line is the ray that starts at (0,0)(0, 0) and passes through (x,y)(x, y).

Every coordinate xx and yy, for both the homes and the points that define the train lines, is at most 1000 in absolute value. No two train lines overlap. Several citizens may live at the same coordinates.

Output

Print one integer, the largest number of citizens who can reach the central hub by train.