Bisectors#2623

Bisectors

1 second
64 megabytes
Hard

We all know how to find the equations of bisectors in coordinate geometry. If the equations of two lines are a_i x + b_i y + c_i = 0 and a_j x + b_j y + c_j = 0, the equations of the bisectors of the four angles they form are also defined. However, one must know for which angles to choose the "+" (plus) sign and for which angles to choose the "-" (minus) sign. In this problem, you will have to make a similar choice.

Suppose there is a fixed point (C_x, C_y) and (n \leq 10000) other points around it. None of these points are collinear with (C_x, C_y). If you connect all these points to (C_x, C_y), you will get a star topology made from lines. The equations of these lines are given, and only these equations must be used when finding bisector equations. These lines form \frac{n(n-1)}{2} (acute or obtuse) angles in total, and thus there are \frac{n(n-1)}{2} bisectors. You must determine how many of these bisectors have equations formed using the "+" sign. The illustration below shows the case for n = 5, C_x = 5, and C_y = 2. This diagram corresponds to the only sample input.

Input

The input file contains at most 35 input sets. The description of each set is as follows:

The first line of each set contains three integers C_x, C_y (-10000 \leq C_x, C_y \leq 10000) and (0 \leq n \leq 10000). Each of the next lines contains two integers x_i, y_i (-20000 \leq x_i, y_i \leq 20000) and a string of the form a_i x + b_i y + c_i = 0. Here, (x_i, y_i) is a point around (C_x, C_y), and the string specifies the equation of the line joining (C_x, C_y) and (x_i, y_i). You may assume -100000 \leq a_i, b_i \leq 100000 and -2000000000 \leq c_i \leq 2000000000. This equation will be used to find the equations of the bisectors of the angles formed by these lines.

Input is terminated by a set where the value of is zero.

Output

For each input set, output a single line. This line should contain an integer — the number of bisector equations that are formed using the "+" sign in the bisector equation.

Examples

Example 1

Loading
Loading