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.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class CF_284C {
    
    static Reader sc = new Reader();
    
    public static void main(String[] args) throws IOException {
        
        Point a = new Point(sc.nextDouble(), sc.nextDouble());
        Point b = new Point(sc.nextDouble(), sc.nextDouble());
        if(a.eq(b)){
            System.out.println(0);
            return;
        }
        
        int count = 0;
        
        int n = sc.nextInt();
        
        for (int i = 0; i < n; i++) {
            Line act = new Line(sc.nextDouble(), sc.nextDouble(), sc.nextDouble());
            Point p = intersect(a, b, act);
            if(p != null) {
                count++;
            }
        }
        
        System.out.println(count);
    }
    
    static final double EPS = 1e-8;
    
    static double deg2rad(double deg){
        return deg * Math.PI / 180.0;
    }

    static double rad2deg(double rad){
        return rad * 180.0 / Math.PI;
    }

    static int cmp(double a, double b) {
        if (eqZero(a - b))
            return 0;
        return Double.compare(a, b);
    }
    
    static boolean eqZero(double d) {
        return Math.abs(d) < EPS;
    }
    
    // Intersection of 2 segments
    static Point intersect(Point a, Point b, Line B) {              
        Line A = new Line(a, b);
        Point res = A.intersect(B);             
        if (res == null) return null;
        if (isInside(res.x, a.x, b.x) && isInside(res.y, a.y, b.y)) return res;     
        return null;
    }
    static boolean isInside(double val, double x, double y) {
        if (x > y) {
            double tmp = x;
            x = y;
            y = tmp;
        }
        return cmp(val, x) >= 0 && cmp(val, y) <= 0;
    }
    
    static class Point implements Comparable<Point>{
        double x, y;

        public static Point readPoint(Scanner in) {
            double x = in.nextDouble();
            double y = in.nextDouble();
            return new Point(x, y);
        }
        
        public boolean eq(Point p) {
            return Math.abs(x - p.x) < EPS && Math.abs(y - p.y) < EPS;
        }

        public Point(double x, double y) {
            this.x = x;
            this.y = y;
        }

        public double dist(Point b){
            double dx = b.x - this.x;
            double dy = b.y - this.y;
            return Math.sqrt(dx*dx + dy*dy);
        }

        @Override
        public int compareTo(Point o) {
            if (cmp(y, o.y) != 0)
                return cmp(y, o.y);
            return cmp(x, o.x);
        }

        public Point sub(Point a){
            return new Point(x - a.x,y - a.y);
        }

        public Point add(Point a){
            return new Point(x + a.x,y + a.y);
        }

        public double cross(Point a){
            return x*a.y - y*a.x;
        }

        public Point multbyscalar(double ua) {
            return  new Point(ua*x,ua*y);
        }

        public Line line(Point other) {
            if (equals(other))
                return null;
            double a = other.y - y;
            double b = x - other.x;
            double c = -a * x - b * y;
            return new Line(a, b, c);
        }

        @Override
        public String toString() {
            return "(" + x + ", " + y + ")";
        }       
    }

    static class Line {
        double A, B, C;
        boolean normed = false;

        public Line(Point P, Point Q) {
            A = Q.y - P.y;
            B = P.x - Q.x;
            C = -A * P.x - B * P.y;
        }

        public Line(double a, double b, double c) {
            double h = Math.sqrt(a * a + b * b);

            /*if (a < -GeometryUtils.epsilon) {
                    a = -a;
                    b = -b;
                    c = -c;
            } else if (a < GeometryUtils.epsilon && b < -GeometryUtils.epsilon) {
                    b = -b;
                    c = -c;
            }*/
            this.A = a / h;
            this.B = b / h;
            this.C = c / h;
        }

        Point intersect(Line p) {
            double D = A * p.B - B * p.A;
            if (eqZero(D))
                return null;
            double x = C * p.B - B * p.C;
            double y = A * p.C - C * p.A;
            return new Point(-x / D, -y / D);
        }

        void norm() {
            double z = Math.sqrt(A * A + B * B);
            A /= z;
            B /= z;
            C /= z;
            normed = true;
        }

        double dist(Point p) {
            if (!normed)
                norm();
            return Math.abs(A * p.x + B * p.y + C);
        }

        public boolean parallel(Line other) {
            return Math.abs(A * other.B - B * other.A) <
                    EPS;
        }

        public Line perpendicular(Point point) {
            return new Line(-B, B, B * point.x - A * point.y);
        }


    }
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;private byte[] buffer;private int bufferPointer, bytesRead;
        public Reader(){buffer=new byte[BUFFER_SIZE];bufferPointer=bytesRead=0;
        }private void fillBuffer() throws IOException{bytesRead=System.in.read(buffer,bufferPointer=0,BUFFER_SIZE);if(bytesRead==-1)buffer[0]=-1;
        }private byte read() throws IOException{if(bufferPointer==bytesRead)fillBuffer();return buffer[bufferPointer++];
        }public String next() throws IOException{StringBuilder sb = new StringBuilder();byte c;while((c=read())<=' '){if(c==-1) return null;};do{sb.append((char)c);}while((c=read())>' ');if (sb.length()==0) return null;return sb.toString();
        }public String nextLine() throws IOException{StringBuilder sb = new StringBuilder();byte c;boolean read = false;while((c=read())!=-1){if(c=='\n') {read = true;break;}if(c>=' ')sb.append((char)c);}if (!read) return null;return sb.toString();
        }public int nextInt() throws IOException{int ret=0;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c=read();do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(neg)return -ret;return ret;
        }public long nextLong() throws IOException{long ret=0;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c=read();do{ret=ret*10L+c-'0';}while((c=read())>='0'&&c<='9');if(neg)return -ret;return ret;
        }public double nextDouble() throws IOException{double ret=0,div=1;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c = read();do {ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(c=='.')while((c=read())>='0'&&c<='9')ret+=(c-'0')/(div*=10);if(neg)return -ret;return ret;
        }public int[] na(int n) throws IOException{int[] a = new int[n];for(int i = 0;i < n;i++)a[i] = nextInt();return a;
        }public int[][] nm(int n, int m) throws IOException{int[][] map = new int[n][m];for(int i = 0;i < n;i++)map[i] = na(m);return map;
        }public void close() throws IOException{if(System.in==null) return;System.in.close();}
    }
    
        
    /*
    long s = System.currentTimeMillis();
    debug(System.currentTimeMillis()-s+"ms");
     */
}
