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.
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, 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 ( - 106 ≤ ai, 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 the answer to the problem.
1 1 -1 -1 2 0 1 0 1 0 0
2
1 1 -1 -1 3 1 0 0 0 1 0 1 1 -3
2
//Tmp = (y1 – y2) * x + (x2 – x1) * y + x1 * y2 – x2 * y1
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
double x1,y1,x2,y2;
double a,b,c;
int n;
while(~scanf("%lf%lf",&x1,&y1)){
int s = 0;
scanf("%lf%lf",&x2,&y2);
scanf("%d",&n);
while(n--){
scanf("%lf%lf%lf",&a,&b,&c);
/*判断是否在直线的同一侧*/
if(b) {
double y01 = (-a/b * x1) - (c/b) - y1;
double y02 = (-a/b * x2) - (c/b) - y2;
if(y01*y02<0)s++;
}
else {
double x01 = (-b/a * y1) - (c/a) - x1;
double x02 = (-b/a * y2) - (c/a) - x2;
if(x01*x02<0)s++;
}
}
printf("%d\n",s);
}
}