Codeforces Round 284 (Div. 1)
A
Crazy Town
Codeforces
1700
原题
←B →
翻译中…

Crazy Town is a plane on which there are $*n*$ infinite line roads. Each road is defined by the equation $*a*_{*i*}*x* + *b*_{*i*}*y* + *c*_{*i*} = 0$, where $*a*_{*i*}$ and $*b*_{*i*}$ are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.

翻译中…

Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).

翻译中…

Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*x*_{1}$, $*y*_{1}$ ($- 10^{6} ≤ *x*_{1}, *y*_{1} ≤ 10^{6}$) — the coordinates of your home.

翻译中…

The second line contains two integers separated by a space $*x*_{2}$, $*y*_{2}$ ($- 10^{6} ≤ *x*_{2}, *y*_{2} ≤ 10^{6}$) — the coordinates of the university you are studying at.

翻译中…

The third line contains an integer $*n*$ ($1 ≤ *n* ≤ 300$) — the number of roads in the city. The following $*n*$ lines contain 3 space-separated integers ($- 10^{6} ≤ *a*_{*i*}, *b*_{*i*}, *c*_{*i*} ≤ 10^{6}$; $|*a*_{*i*}| + |*b*_{*i*}| > 0$) — the coefficients of the line $*a*_{*i*}*x* + *b*_{*i*}*y* + *c*_{*i*} = 0$, defining the $*i*$-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

翻译中…

Output

翻译中…

Output the answer to the problem.

翻译中…

Note

翻译中…

Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):

翻译中…

image

翻译中…

image

翻译中…

样例

Input #1
1 1
-1 -1
2
0 1 0
1 0 0
Output #1
2
InputCopy OutputCopy
Input #2
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output #2
2
InputCopy OutputCopy
题目信息
题号
498A
时间限制
1 s
内存限制
256 MB
标签
计算几何

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。