Kevin Sun is ruminating on the origin of cows while standing at the origin of the Cartesian plane. He notices n lines <image> on the plane, each representable by an equation of the form ax + by = c. He also observes that no two lines are parallel and that no three lines pass through the same point.

For each triple (i, j, k) such that 1 ≤ i < j < k ≤ n, Kevin considers the triangle formed by the three lines <image> . He calls a triangle original if the circumcircle of that triangle passes through the origin. Since Kevin believes that the circles of bovine life are tied directly to such triangles, he wants to know the number of original triangles formed by unordered triples of distinct lines. 

Recall that the circumcircle of a triangle is the circle which passes through all the vertices of that triangle.

Input

The first line of the input contains a single integer n (3 ≤ n ≤ 2000), the number of lines.

The next n lines describe lines <image>. The i-th of these lines contains three space-separated integers ai, bi, ci (|ai|, |bi|, |ci| ≤ 10 000, ai2 + bi2 > 0), representing the equation aix + biy = ci of line <image>.

Output

Print a single integer, the number of triples (i, j, k) with i < j < k such that lines <image> form an original triangle.

Examples

Input

4
1 0 0
0 1 0
1 1 -1
1 -1 2


Output

2


Input

3
0 1 1
1 1 2
1 -1 -2


Output

1

Note

Note that in the first sample, some of the lines pass through the origin.

In the second sample, there is exactly one triple of lines: y = 1, x + y = 2, x - y = - 2. The triangle they form has vertices (0, 2), (1, 1), ( - 1, 1). The circumcircle of this triangle has equation x2 + (y - 1)2 = 1. This indeed passes through (0, 0).
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.BufferedInputStream;
import java.util.concurrent.Callable;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		BufferedInputStream in = new BufferedInputStream(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		public void solve(int testNumber, BufferedInputStream _in, PrintWriter out) {
			InputReader in = new InputReader(_in);
			long startTime = System.currentTimeMillis();
			int nt = 1;
			Task t = new Task(1);
			t.readInput(in);
			t.call();
			t.writeOutput(out);
			in.close();
			System.err.println("Time: " + (System.currentTimeMillis() - startTime) + " miliseconds");
		}

	}

	static class Task implements Callable<Task> {
		long[] X = null;
		long[] Y = null;
		long[] Z = null;
		long RE = 0;
		int testNumber;

		public void readInput(InputReader in) {
	/* read input here */


			int n = in.nextInt();
			X = new long[n];
			Y = new long[n];
			Z = new long[n];
			int cnt = 0;
			for (int i = 0; i < n; ++i) {
				long a = in.nextInt();
				long b = in.nextInt();
				long c = in.nextInt();
				long ab = a * a + b * b;

				X[i] = (a * c);
				Y[i] = (b * c);
				Z[i] = (ab);

				if (X[(i)] == 0 && Y[(i)] == 0) {
					cnt++;
				}

			}
			if (cnt == 2) RE = n - 2;


		}

		long count(long n) {
			if (n < 3) return 0l;
			return n * (n - 1) * (n - 2) / 6l;
		}

		public Task call() {

			if (X.length < 3) return this;


			HashMap<PP, Long> mm = new HashMap<>();

			for (int i = 0; i < Y.length; ++i)
				if (X[i] != 0 || Y[i] != 0) {

					PP pa = new PP(Y[i], Z[i]);
					Long f = mm.get(pa);
					if (f == null) {
						mm.put(pa, 1l);
					} else mm.put(pa, 1l + f);
				}

			for (Long v : mm.values()) {
				RE += count(v);
			}


			mm.clear();
			for (int i = 0; i < X.length; ++i)
				if (X[i] != 0 || Y[i] != 0) {
					for (int j = i + 1; j < X.length; ++j)
						if (X[j] != 0 || Y[j] != 0) {
							long yi = Y[i];
							long zi = Z[i];
							long xi = X[i];

							long yj = Y[j];
							long zj = Z[j];
							long xj = X[j];
							long dy = yi * zj - zi * yj;
							if (dy != 0) {
								long dx = xi * zj - zi * xj;

								PP pa = new PP(dx, dy);
								Long f = mm.get(pa);
								if (f == null) {
									mm.put(pa, 1l);
								} else {
									mm.put(pa, f + 1);
								}
							}
						}

					for (Long v : mm.values()) {
						if (v >= 2) {
							RE += (v - 1) * v / 2;
						}
					}

					mm.clear();
				}


			System.err.println("Test case: " + testNumber + " done!");/**/


			return this;
		}

		public void writeOutput(PrintWriter out) {
			out.println(RE);
		}

		Task(int testNumber) {
			this.testNumber = testNumber;
		}

	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(BufferedInputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

		public void close() {
			try {
				if (reader != null)
					reader.close();
			} catch (Exception ex) {
				throw new RuntimeException(ex);
			}
		}

	}

	static class PP implements Comparable<PP> {
		Long first;
		Long second;

		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		public PP(Long first, Long second) {

			long g = gcd(Math.abs(first), Math.abs(second));
			if (second < 0) g = -g;


			this.first = first / g;
			this.second = second / g;
		}


		public int compareTo(PP o) {
			int t = first.compareTo(o.first);
			if (t != 0) return t;
			else
				return second.compareTo(o.second);
		}

		public boolean equals(Object obj) {
			if (obj instanceof PP) {
				return compareTo((PP) obj) == 0;
			}
			return false;
		}


		public int hashCode() {
			return first.hashCode() ^ second.hashCode();
		}

	}
}

