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 ( - 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

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):

<image> <image>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;


public class S2P10 {
	final static double EPS = 1e-9;
	// In Java, we can use Math.PI instead of using Math.acos(-1.0)

	double DEG_to_RAD(double d) { return d * Math.PI / 180.0; }
	double RAD_to_DEG(double r) { return r * 180.0 / Math.PI; }

	static class point implements Comparable<point>{
		double x, y;                   // only used if more precision is needed
		point() { x = y = 0.0; }                         // default constructor
		point(double _x, double _y) { x = _x; y = _y; }         // user-defined
		// use EPS (1e-9) when testing equality of two floating points
		public int compareTo(point other) {      // override less than operator
			if (Math.abs(x - other.x) > EPS)                // useful for sorting
				return (int)Math.ceil(x - other.x);       // first: by x-coordinate
			else if (Math.abs(y - other.y) > EPS)
				return (int)Math.ceil(y - other.y);      // second: by y-coordinate
			else
				return 0; } };                                    // they are equal

				static class vec { double x, y;     // name: `vec' is different from Java Vector
				vec(double _x, double _y) { x = _x; y = _y; } };

				static vec toVec(point a, point b) {               // convert 2 points to vector
					return new vec(b.x - a.x, b.y - a.y); }

				static double dist(point p1, point p2) {                   // Euclidean distance
					return Math.hypot(p1.x - p2.x, p1.y - p2.y); }         // return double

				// returns the perimeter, which is the sum of Euclidian distances
				// of consecutive line segments (polygon edges)
				double perimeter(List<point> P) {
					double result = 0.0;
					for (int i = 0; i < (int)P.size()-1; i++)  // remember that P[0] = P[n-1]
						result += dist(P.get(i), P.get(i+1));
					return result; }

				// returns the area, which is half the determinant
				// works for both convex and concave polygons
				static double area(List<point> P) {
					double result = 0.0, x1, y1, x2, y2;
					for (int i = 0; i < (int)P.size()-1; i++) {
						x1 = P.get(i).x; x2 = P.get(i+1).x;
						y1 = P.get(i).y; y2 = P.get(i+1).y;
						result += (x1 * y2 - x2 * y1);
					}
					return Math.abs(result) / 2.0; }

				static double dot(vec a, vec b) { return (a.x * b.x + a.y * b.y); }

				static double norm_sq(vec v) { return v.x * v.x + v.y * v.y; }

				static double angle(point a, point o, point b) {     // returns angle aob in rad
					vec oa = toVec(o, a), ob = toVec(o, b);
					return Math.acos(dot(oa, ob) / Math.sqrt(norm_sq(oa) * norm_sq(ob))); }

				static double cross(vec a, vec b) { return a.x * b.y - a.y * b.x; }

				// note: to accept collinear points, we have to change the `> 0'
				// returns true if point r is on the left side of line pq
				static boolean ccw(point p, point q, point r) {
					return cross(toVec(p, q), toVec(p, r)) > 0; }

				// returns true if point r is on the same line as the line pq
				static boolean collinear(point p, point q, point r) {
					return Math.abs(cross(toVec(p, q), toVec(p, r))) < EPS; }

				// returns true if we always make the same turn while examining
				// all the edges of the polygon one by one
				boolean isConvex(List<point> P) {
					int sz = (int)P.size();
					if (sz <= 3) return false;   // a point/sz=2 or a line/sz=3 is not convex
					boolean isLeft = ccw(P.get(0), P.get(1), P.get(2)); // remember one result
					for (int i = 1; i < sz-1; i++)            // then compare with the others
						if (ccw(P.get(i), P.get(i+1), P.get((i+2) == sz ? 1 : i+2)) != isLeft)
							return false;            // different sign -> this polygon is concave
					return true; }                                  // this polygon is convex

				// returns true if point p is in either convex/concave polygon P
				static boolean inPolygon(point pt, List<point> P) {
					if ((int)P.size() == 0) return false;
					double sum = 0; // assume first vertex = last vertex
					for (int i = 0; i < (int)P.size()-1; i++) {
						if (ccw(pt, P.get(i), P.get(i+1)))
							sum += angle(P.get(i), pt, P.get(i+1));   // left turn/ccw
						else sum -= angle(P.get(i), pt, P.get(i+1)); } // right turn/cw
					return Math.abs(Math.abs(sum) - 2*Math.PI) < EPS; }

				static // line segment p-q intersect with line A-B.
				point lineIntersectSeg(point p, point q, point A, point B) {
					double a = B.y - A.y;
					double b = A.x - B.x;
					double c = B.x * A.y - A.x * B.y;
					double u = Math.abs(a * p.x + b * p.y + c);
					double v = Math.abs(a * q.x + b * q.y + c);
					return new point((p.x * v + q.x * u) / (u+v), (p.y * v + q.y * u) / (u+v)); }

				// cuts polygon Q along the line formed by point a -> point b
				// (note: the last point must be the same as the first point)
				static List<point> cutPolygon(point a, point b, List<point> Q) {
					List<point> P = new ArrayList<point>();
					for (int i = 0; i < (int)Q.size(); i++) {
						double left1 = cross(toVec(a, b), toVec(a, Q.get(i))), left2 = 0;
						if (i != (int)Q.size()-1) left2 = cross(toVec(a, b), toVec(a, Q.get(i+1)));
						if (left1 > -EPS) P.add(Q.get(i)); // Q[i] is on the left of ab
						if (left1 * left2 < -EPS) // edge (Q[i], Q[i+1]) crosses line ab
							P.add(lineIntersectSeg(Q.get(i), Q.get(i+1), a, b));
					}
					if (!P.isEmpty() && P.get(P.size()-1).compareTo(P.get(0)) != 0)
						P.add(P.get(0)); // make P's first point = P's last point
					return P; }
				static class line { double a, b, c;
				line(double a,double b,double c){
					this.a=a;this.b=b;this.c=c;
				}; 
				}

				public static void main(String[] args) throws IOException {
					BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
					String in = br.readLine();
					StringTokenizer st =new StringTokenizer(in);
					int x1 = Integer.parseInt(st.nextToken());
					int y1 = Integer.parseInt(st.nextToken());
					point p1 = new point(x1,y1);
					in = br.readLine();
					st =new StringTokenizer(in);
					x1 = Integer.parseInt(st.nextToken());
					y1 = Integer.parseInt(st.nextToken());
					point p2 = new point(x1,y1);
					in = br.readLine();
					int lines = Integer.parseInt(in);
					int result = 0;
					for (int i = 0; i <lines; i++) {
						in = br.readLine();
						st =new StringTokenizer(in);
						int a = Integer.parseInt(st.nextToken());
						int b = Integer.parseInt(st.nextToken());
						int c = Integer.parseInt(st.nextToken());
						if(b == 0){
							double bla = (-c)/(double)a;
							point s =new point(bla,0);
							point e =new point(bla,1);
							if(ccw(p1,s,e)!=ccw(p2,s,e))
								result++;
						}else{
							double bla = (-1*a-c)/(double)b;
							double blabla = (-c)/(double)b;
							point s =new point(1,bla);
							point e =new point(0,blabla);
							if(ccw(p1,s,e)!=ccw(p2,s,e))
								result++;
						}
					}
					System.out.println(result);
				}
}
