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.io.PrintWriter;
import java.util.StringTokenizer;

public class fff {
	PrintWriter pw = new PrintWriter(System.out);

	public static void main(String[] args) {
		sc sc = new sc();
		Point home = new Point(sc.nextInt(), sc.nextInt());
		Point uni = new Point(sc.nextInt(), sc.nextInt());
		Line homeToUni = new Line(home, uni);
		int n = sc.nextInt();
		Line[] roads = new Line[n];
		int ans = 0;

		for (int i = 0; i < n; i++) {

			roads[i] = new Line(sc.nextDouble(), sc.nextDouble(), sc.nextDouble());
			Point intersect = roads[i].intersect(homeToUni);

			if (intersect != null && intersect.between(home, uni)) {
				ans++;
			}
			// System.out.println(intersect.x + " " + intersect.y);
		}
		System.out.println(ans);

	}

}

class Line {

	static final double INF = 1e9, EPS = 1e-9;

	double a, b, c;

	Line(Point p, Point q) {
		if (Math.abs(p.x - q.x) < EPS) {
			a = 1;
			b = 0;
			c = -p.x;
		} else {
			a = (p.y - q.y) / (q.x - p.x);
			b = 1.0;
			c = -(a * p.x + p.y);
		}

	}

	Line(Point p, double m) {
		a = -m;
		b = 1;
		c = -(a * p.x + p.y);
	}

	Line(double a, double b, double c) {
		if (b != 0) {
			this.a = a / b;
			this.c = c/b;

			this.b = 1;
		} else {
			this.c = c / a;
			this.a = 1;

			this.b = 0;
		}
	}

	boolean parallel(Line l) {
		return Math.abs(a - l.a) < EPS && Math.abs(b - l.b) < EPS;
	}

	boolean same(Line l) {
		return parallel(l) && Math.abs(c - l.c) < EPS;
	}

	Point intersect(Line l) {
		if (parallel(l))
			return null;
		double x = (b * l.c - c * l.b) / (a * l.b - b * l.a);
		double y;
		if (Math.abs(b) < EPS)
			y = -l.a * x - l.c;
		else
			y = -a * x - c;

		return new Point(x, y);
	}

	Point closestPoint(Point p) {
		if (Math.abs(b) < EPS)
			return new Point(-c, p.y);
		if (Math.abs(a) < EPS)
			return new Point(p.x, -c);
		return intersect(new Line(p, 1 / a));
	}

}

class Point implements Comparable<Point> {

	static final double EPS = 1e-9;

	double x, y;

	Point(double a, double b) {
		x = a;
		y = b;
	}

	public int compareTo(Point p) {
		if (Math.abs(x - p.x) > EPS)
			return x > p.x ? 1 : -1;
		if (Math.abs(y - p.y) > EPS)
			return y > p.y ? 1 : -1;
		return 0;
	}

	public double dist(Point p) {
		return Math.sqrt(sq(x - p.x) + sq(y - p.y));
	}

	static double sq(double x) {
		return x * x;
	}

	Point rotate(double angle) {
		double c = Math.cos(angle), s = Math.sin(angle);
		return new Point(x * c - y * s, x * s + y * c);
	}
	// for integer points and rotation by 90 (counterclockwise) : swap x and y,
	// negate x

	Point rotate(double theta, Point p) // rotate around p
	{
		Vector v = new Vector(p, new Point(0, 0));
		return translate(v).rotate(theta).translate(v.reverse());
	}

	Point translate(Vector v) {
		return new Point(x + v.x, y + v.y);
	}

	Point reflectionPoint(Line l) // reflection point of p on line l
	{
		Point p = l.closestPoint(this);
		Vector v = new Vector(this, p);
		return this.translate(v).translate(v);
	}

	boolean between(Point p, Point q) {
		return x < Math.max(p.x, q.x) + EPS && x + EPS > Math.min(p.x, q.x) && y < Math.max(p.y, q.y) + EPS
				&& y + EPS > Math.min(p.y, q.y);
	}

	// returns true if it is on the line defined by a and b
	boolean onLine(Point a, Point b) {
		if (a.compareTo(b) == 0)
			return compareTo(a) == 0;
		return Math.abs(new Vector(a, b).cross(new Vector(a, this))) < EPS;
	}

	boolean onSegment(Point a, Point b) {
		if (a.compareTo(b) == 0)
			return compareTo(a) == 0;
		return onRay(a, b) && onRay(b, a);
	}

	// returns true if it is on the ray whose start point is a and passes through b
	boolean onRay(Point a, Point b) {
		if (a.compareTo(b) == 0)
			return compareTo(a) == 0;
		return new Vector(a, b).normalize().equals(new Vector(a, this).normalize()); // implement equals()
	}

	// returns true if it is on the left side of Line pq
	// add EPS to LHS if on-line points are accepted
	static boolean ccw(Point p, Point q, Point r) {
		return new Vector(p, q).cross(new Vector(p, r)) > 0;
	}

	static boolean collinear(Point p, Point q, Point r) {
		return Math.abs(new Vector(p, q).cross(new Vector(p, r))) < EPS;
	}

	static double angle(Point a, Point o, Point b) // angle AOB
	{
		Vector oa = new Vector(o, a), ob = new Vector(o, b);
		return Math.acos(oa.dot(ob) / Math.sqrt(oa.norm2() * ob.norm2()));
	}

	static double distToLine(Point p, Point a, Point b) // distance between point p and a line defined by points a, b (a
														// != b)
	{
		if (a.compareTo(b) == 0)
			return p.dist(a);
		// formula: c = a + u * ab
		Vector ap = new Vector(a, p), ab = new Vector(a, b);
		double u = ap.dot(ab) / ab.norm2();
		Point c = a.translate(ab.scale(u));
		return p.dist(c);
	}
	// Another way: find closest point and calculate the distance between it and p

	static double distToLineSegment(Point p, Point a, Point b) {
		Vector ap = new Vector(a, p), ab = new Vector(a, b);
		double u = ap.dot(ab) / ab.norm2();
		if (u < 0.0)
			return p.dist(a);
		if (u > 1.0)
			return p.dist(b);
		return distToLine(p, a, b);
	}
	// Another way: find closest point and calculate the distance between it and p
}

class Vector {

	double x, y;

	Vector(double a, double b) {
		x = a;
		y = b;
	}

	Vector(Point a, Point b) {
		this(b.x - a.x, b.y - a.y);
	}

	Vector scale(double s) {
		return new Vector(x * s, y * s);
	} // s is a non-negative value

	double dot(Vector v) {
		return (x * v.x + y * v.y);
	}

	double cross(Vector v) {
		return x * v.y - y * v.x;
	}

	double norm2() {
		return x * x + y * y;
	}

	Vector reverse() {
		return new Vector(-x, -y);
	}

	Vector normalize() {
		double d = Math.sqrt(norm2());
		return scale(1 / d);
	}
}

class sc {
	BufferedReader br;
	StringTokenizer st;

	public sc() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}
}
