5390: 疯狂的小镇

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:6 通过:3

题目描述

疯狂小镇是一个有n条无限直线道路的平面。每条道路由方程aix+biy+ci=0定义,其中aibi不都等于零。道路将平面划分为可能具有无限空间的连接区域。让我们把每个这样的区域称为一个块。我们将交叉点定义为至少两条不同道路相交的点。

你的家位于其中一个街区。今天你需要去大学,也在某个街区。在一个步骤中,如果块的公共边界长度为非零,则可以从一个块移动到另一个块(特别是,这意味着如果块与一个交点相邻,但没有共享的非零边界线段,则不允许在一个步骤中从一个移动到另另一个)。

确定到达包含大学的街区所需的最少步骤数。保证你的家和大学都不在路上。

Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix+biy+ci=0, where ai and bi 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 x1, y1 (-106x1,y1≤106) − the coordinates of your home.
The second line contains two integers separated by a space x2, y2 (-106x2,y2≤106) − 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 (-106ai,bi,ci≤106; |ai|+|bi|>0) − the coefficients of the line aix+biy+ci=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.
Examples
Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2
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):

输入格式

第一行包含两个空格分隔的整数x1y1-106≤x1y1≤106-您家的坐标。

第二行包含两个整数,由空间x2y2-106≤x2y2≤106)分隔,即您所就读大学的坐标。

第三行包含整数n1≤n≤300)−城市中的道路数量。以下n条线包含3个空格分隔的整数(-106≤aibici≤106|ai|+|bi|>0)−线aix+biy+ci=0的系数,定义了第i条道路。保证没有两条道路是相同的。此外,你的家和大学都不在路上(即它们不属于任何一条线路)。

输出格式

输出问题的答案。

示例

Input
1 1
-1 -1
2
0 1 0
1 0 0
Output
2
Input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
Output
2

注意

样本图片如下(A是代表房子的点;B是代表大学的点,不同的块用不同的颜色填充):

输入样例 复制

1 1
-1 -1
2
0 1 0
1 0 0

输出样例 复制

2