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.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;


public class algorithms{

    public static void main(String[] args) throws IOException {
    	MyScanner in = new MyScanner();
    	Task284C task = new Task284C();
    	task.slove(in);
    }
    
    public static class Task284A {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		int x = in.nextInt();
    		int l, r, count = 0, current = 1, b2;
    		for (int i = 0; i < n;i++) {
    			l = in.nextInt();
    			r = in.nextInt();
    			b2 = (l - current)/x;
    			if (b2 >= 1) {
    				current += x*b2; 
    			}
    			count += r - current + 1;
    			current = r+1;
    		}
    		System.out.println(count);
    	}
    	
    }
    
    public static class Task284B {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		int m = in.nextInt();
    		Map<String, String> map = new HashMap<String, String>();
    		String s, answer = "";
    		for (int i = 0; i < m;i++) {
    			s = in.nextLine();
    			String arr [] = s.split(" ");
    			if (arr[1].length() < arr[0].length()) {
    				map.put(arr[0], arr[1]);
    			} else {
    				map.put(arr[0], arr[0]);
    			}
    		}
    		s = in.nextLine();
    		for (String retval: s.split(" ")){
    			answer += map.get(retval) + " ";
    		}
    		System.out.println(answer);
    	}
    	
    }
    
    public static class Task284C {
    	public void slove(MyScanner in) {
    		long x = in.nextInt();
    		long y = in.nextInt();
    		Point pa = new Point(x, y);
    		x = in.nextInt();
     		y = in.nextInt();
    		Point pb = new Point(x, y);
    		int count = 0;
    		int n = in.nextInt();
    		long a, b, c;
    		for (int i = 0; i < n;i++) {
        		a = in.nextInt();
         		b = in.nextInt();
         		c = in.nextInt();
         		if (pa.onOneSide(pb, a, b, c) == false) {
         			count++;
         		}
    		}
    		System.out.println(count);
    	}
    	
    }
    
    public static class Point {
    		   
    	public long x;
    	public long y;
    	
    	public Point(long x, long y) {
    		this.x = x;
    		this.y = y;
    	}
    	
    	public boolean onOneSide(Point p, long a, long b, long c) {
    		long d2 = a*p.x + b*p.y + c;
    		long d1 = a*this.x + b*this.y + c;
//    		if (d2 == 0 || d1 == 0) {
//    			System.out.println(d2);
//    		}
//    		System.out.println(d1);
//    		System.out.println(d2);
    		if ((d2 > 0 && d1 < 0) || (d1 > 0 && d2 < 0)) {
    			return false;
    		}
    		return true;
    	}
    }
    
    public static class TaskA {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		int prev = 0, prevprev = 0, diff, answer;
    		int min = 1000, max = 0;
    		int imin = 1;
    		int arr [] = new int [n];
    		for (int i = 0; i < n;i++) {
    			arr[i] = in.nextInt();
    			if (i != 0) {
    				if (i > 1) {
		    			diff = arr[i] - prevprev;
		    			if (diff < min) {
		    				min = diff;
		    				imin = i;
		    			}
    				}
	    			if ((arr[i] - prev) > max) {
	    				max = arr[i] - prev;
	    			}
    			}
    			prevprev = prev;
    			prev = arr[i];
    		}
    		diff = arr[imin] - arr[imin-2];
    		if (diff > max) {
    			answer = diff;
    		} else {
    			answer = max;
    		}
    		
    		System.out.println(answer);
    	}
    	
    }
    
    public static class TaskB {
    	public int arr [];
    	public int n;
    	public void slove(MyScanner in) {
    		n = in.nextInt();
    		arr = new int [n];
    		int count[] = new int [10];
    		String s = in.nextLine();
    		String min = s, num;
    		for (int i = 0; i < n;i++) {
    			arr[i] = Character.getNumericValue(s.charAt(i));
    			count[arr[i]] += 1;
    		}
    		for (int i = 0; i < 10;i++) {
    			if (count[i] == 0) {
    				continue;
    			}
    			num = getSmallestInt(10 - i);
    			for (int j = 0; j < num.length();j++) {
	    			if (num.charAt(j) < min.charAt(j)) {
	    				min = num;
	    			}
	    			if (num.charAt(j) != min.charAt(j)) {
	    				break;
	    			}
    			}
    			
    		}
    		String answer = "";
    		answer += min;
    		System.out.println(answer);
    	}
    	
    	public String getSmallestInt(int offset) {
    		StringBuffer tmp = new StringBuffer();
    		long newvalue;
    		ArrayList<Integer> al = new ArrayList<Integer>();
			for (int i = 0; i < n;i++) {
				newvalue = arr[i] + offset;
				if (newvalue >= 10) {
					newvalue -= 10;
					if (newvalue == 0) {
						al.add(i);
					}
				}
				tmp.append((int)newvalue);
    		}
			String str = tmp.toString();
			String newstr;
			String min = String.format("%0" + n + "d", 0).replace("0","9");
			for(int i = 0; i < al.size(); i++) {
				newstr = str.substring(al.get(i)) + str.substring(0, al.get(i));
	    		for (int j = 0; j < newstr.length();j++) {
	    			if (newstr.charAt(j) < min.charAt(j)) {
	    				min = newstr;
	    			}
	    			if (newstr.charAt(j) != min.charAt(j)) {
	    				break;
	    			}
	    		}
			}
    		return min;
    	}
    	
    }
    
    public static class TaskC {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		int m = in.nextInt();
    		String arr [] = new String [n];
    		char prev = ' ';
    		int count = 0;
    		for (int i = 0; i < n;i++) {
    			arr[i] = in.nextLine();
    		}
    		char c;
    		ArrayList<Integer> ignore = new ArrayList<Integer>();
    		ArrayList<Integer> ignorenext = new ArrayList<Integer>();
    		for (int i = 0; i < m;i++) {
    			prev = ' ';
    			for (int j = 0; j < n;j++) {
    				c = arr[j].charAt(i);
        			if (ignore.contains(j)) {
        				prev = c;
        				continue;
        			}
    				if (c > prev && prev != ' ') {
    					if (ignorenext.contains(j) == false) {
    						ignorenext.add(j);
    					}
    				}
    				if (c < prev) {
    					count++;
    					ignorenext.clear();
    					break;
    				}
    				prev = c;
    			}
    			ignore.addAll(ignorenext);
    			ignorenext.clear();
    		}
    		System.out.println(count);
    	}
    	
    }
    
    
    public static class TaskD {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		int s = 0, t = 0;
    		int count1 = 0, count2 = 0;
    		int max = 0;
    		int arr[] = new int [n];
    		for (int i = 0; i < n; i++) {
    			arr[i] = in.nextInt();
    			if (arr[i] == 1) {
    				count1++;
    			} else {
    				count2++;
    			}
    		}
    		if (count1 != count2) {
    			if (count1 > count2) {
    				max = count1;
    			} else {
    				max = count2;
    			}
    			int x = 1, y = max;
    			while (max/x >= 1) {
    				if (max%x == 0) {
    					y = max/x;
    					System.out.println(x + " " + y);
    				}
    				x++;
    			}
    		}

    		System.out.println(s + " " + t);
    	}
    	
    }
    
    public static class Pair implements Comparable<Pair> {
	  public final Comparator<Pair> SLOPE_ORDER = new Comparator<Pair>() {
		   // compare points by slope to this point
		       public int compare(Pair p1, Pair p2) {
		    	   return p1.compareTo(p2);
		       }
		};
    		   
    	private long min;
    	private long max;
    	private int count;
    	private int num;
    	
    	public Pair(long min, long max, int count, int num) {
    		this.min = min;
    		this.max = max;
    		this.count = count;
    		this.num = num;
    	}
    	
    	public void decrease() {
    		count--;
    	}
    	
    	public int count() {
    		return count;
    	}
    	
    	public int num() {
    		return num;
    	}
    	
		public int compareTo(Pair that) {
	       if ((this.min == that.min) && (this.max == that.max)) {
	           return 0;
	       }
	       if ((this.min < that.min) || (this.min == that.min && this.max < that.max)) {
	           return -1;
	       } 
	       return 1;
		}
		
		public int contain(Pair that) {
//			System.out.println(this.min);
//			System.out.println(this.max);
//			System.out.println(that.min);
//			System.out.println(that.max);
		       if ((this.min <= that.min) && (this.max >= that.max)) {
		           return 1;
		       }
		       if (this.min <= that.min) {
		    	   return 0;
		       }
		       return -1;
			}
    }
    
    public static class TaskE {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		Pair parties[] = new Pair [n];
    		int p_a[] = new int [n];
    		long min, max;
    		int count;
    		for (int i = 0; i< n;i++) {
    			min = in.nextLong();
    			max = in.nextLong();
    			parties[i] = new Pair(min, max, 0, i+1);
    		}
    		Arrays.sort(parties);
//    		for (int i = 0; i< n;i++) {
//    			System.out.println(parties[i].num());
//    		}
    		int m = in.nextInt();
    		Pair actors[] = new Pair [m];
    		for (int i = 0; i< m;i++) {
    			min = in.nextLong();
    			max = in.nextLong();
    			count = in.nextInt();
    			actors[i] = new Pair(min, max, count, i+1);
    		}
    		Arrays.sort(actors);
//    		for (int i = 0; i< m;i++) {
//    			System.out.println(actors[i].num());
//    		}
    		int j = 0;
    		Pair partie;
    		String answer = "YES\n";
    		for (int i = 0; i< n;i++) {
    			partie = parties[i];
//    			actor = actors[j];
//    			System.out.println(actor.count());
    			if (actors[j].count() <= 0) {
    				if (j == (m)) {
    					answer = "NO";
    					break;
    				}
    				j++;
//    				actor = actors[j];
    			}
//    			System.out.println(actor.contain(partie));
    			for(int k = j; k< m; k++) {
    				if (actors[k].count() <= 0) {
    					continue;
    				}
	    			int contain = actors[k].contain(partie);
	    			if (contain == 1) {
	    				actors[k].decrease();
//	    				System.out.println(actors[k].count());
//	    				System.out.println(partie.num());
//	    				System.out.println(actors[k].num());
	    				p_a[partie.num()-1] = actors[k].num();
	    				break;
	    			} else if (contain == -1){
	    				answer = "NO";
						break;
	    			}
    			}
    			if (answer == "NO") {
    				break;
    			}
    			
    		}
    		if (answer != "NO") {
    			for (int i = 0; i< n;i++) {
    				if (p_a[i] == 0) {
    					answer = "NO";
    					break;
    				}
    				answer += p_a[i] + " ";
    			}
    		}
    		System.out.println(answer);
    	}
    	
    }
    public static class TaskDold {
    	public void slove(MyScanner in) {
    		int n = in.nextInt();
    		Boolean ok = true;
    		int arr [][] = new int [n][n];
    		int minj [] = new int [n];
    		int min = 1000000000;
    		int min_j = 0;
    		for (int i =0; i< n;i++) {
    			min = 1000000001;
    			min_j = 0;
    			for (int j=0; j< n; j++) {
    				arr[i][j] = in.nextInt();
    				if (arr[i][j] < min && (i != j)) {
    					min = arr[i][j];
    					min_j = j;
    				}
    				if ((i == j) && (arr[i][j] != 0)) {
    					ok = false;
    				}
    				if ((i > j) && (arr[i][j] != arr[j][i])) {
    					ok = false;
    				}
    				if ((i != j) && (arr[i][j] == 0)) {
    					ok = false;
    				}
    			}
    			minj[i] = min_j;
    			for (int j =0; j< i;j++) {
    				if ((j == min_j) && (minj[j] == i))
    				{
    					
    				}
    			}
    		}
    		if (!ok) {
    			System.out.println("NO");
    			return;
    		}
    		int j;
    		for (int i =0; i< n;i++) {
    			min_j = minj[i];
//    			System.out.println(min_j);
    			for (j =0; j< i;j++) {
					if ((j == min_j) && (minj[j] == i))
					{
						
					}
    				if (minj[j] == min_j) {
//    					System.out.println(arr[i][j]);
//    					System.out.println(arr[j][minj[j]]);
//    					System.out.println(arr[i][min_j]);
    					if (arr[i][j] != (arr[j][minj[j]] + arr[i][min_j])) {
    						System.out.println("NO");
    		    			return;
    					}
    				}
    			}
    			
    		}
    		
    		System.out.println("YES");
    	}
    	
    }
    
    
    public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			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;
		}

	}

}