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.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.util.Collections;
import java.io.InputStream;

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

    static class TaskD_SimonsLine {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int zero = 0;
            List<Point> points = new ArrayList<Point>();
            for (int i = 0; i < n; ++i) {
                int a = in.nextInt();
                int b = in.nextInt();
                int c = in.nextInt();

                if (c == 0) {
                    ++zero;
                } else {
                    Line l = new Line(a, b, c);
                    double dst = l.value(Point.ORIGIN);
                    Point v = new Point(a, b).norm(dst);
                    v = v.mul(-1);
                    points.add(v);
                }
            }
            long res = zero * 1L * (zero - 1) * points.size() / 2;

            List<Line> list = new ArrayList<Line>();
//        TreeMap<Line, Integer> count = new TreeMap<Line, Integer>(new Comparator<Line>() {
//            @Override
//            public int compare(Line o1, Line o2) {
//                if (DoubleUtils.compareTo(o1.a, o2.a) < 0) {
//                    return -1;
//                }
//                if (DoubleUtils.compareTo(o1.a, o2.a) > 0) {
//                    return 1;
//                }
//                if (DoubleUtils.compareTo(o1.b, o2.b) < 0) {
//                    return -1;
//                }
//                if (DoubleUtils.compareTo(o1.b, o2.b) > 0) {
//                    return 1;
//                }
//                return DoubleUtils.compareTo(o1.c, o2.c);
//            }
//        });

            for (int i = 0; i < points.size(); ++i) {
                for (int j = 0; j < i; ++j) {
                    Line l = new Line(points.get(i), points.get(j));
                    if (DoubleUtils.compareTo(l.a, 0) < 0) {
                        l = new Line(-l.a, -l.b, -l.c);
                    } else if (DoubleUtils.compareTo(l.a, 0) == 0) {
                        if (DoubleUtils.compareTo(l.b, 0) < 0) {
                            l = new Line(0, -l.b, -l.c);
                        }
                    }
                    list.add(l);
//                if (count.containsKey(l)) {
//                    count.put(l, count.get(l) + 1);
//                } else {
//                    count.put(l, 1);
//                }
                }
            }

            Collections.sort(list, new Comparator<Line>() {

                public int compare(Line o1, Line o2) {
                    int c = DoubleUtils.compareTo(o1.a, o2.a);
                    if (c != 0) return c;
                    c = DoubleUtils.compareTo(o1.b, o2.b);
                    if (c != 0) return c;
                    return DoubleUtils.compareTo(o1.c, o2.c);
                }
            });

            int start = 0;

            int[] preSqrt = new int[1000000];
            for (int i = 0; i * i < 1000000; ++i) {
                preSqrt[i * i] = i;
            }

            for (int i = 1; i < list.size(); ++i) {
                if (compare(list.get(i), list.get(start)) != 0) {
                    int c = i - start;
                    int value;
                    if (1 + 8 * c < 1000000) {
                        value = preSqrt[1 + 8 * c];
                    } else {
                        value = (int) (Math.sqrt(1. + 8 * c) + 0.1);
                    }
                    value = (1 + value) / 2;
                    res += value * 1L * (value - 1) * (value - 2) / 6;
                    start = i;
                }
            }
//
            int c = list.size() - start;
            int value;
            if (1 + 8 * c < 1000000) {
                value = preSqrt[1 + 8 * c];
            } else {
                value = (int) (Math.sqrt(1. + 8 * c) + 0.1);
            }
            value = (1 + value) / 2;
            res += value * 1L * (value - 1) * (value - 2) / 6;

//        for (Line l : count.keySet()) {
//            int c = count.get(l);
//            if (c < 3) continue;
//            int value;
//                if (1 + 4 * c < 1000000) {
//                    value = preSqrt[1 + 8 * c];
//                } else {
//                    value = (int) (Math.sqrt(1. + 8 * c) + 0.1);
//                }
//            value = (1 + value) / 2;
//            // x * (x - 1) == 2c
//            // x2 - x - 2c => 1 + 4c
////            int value = (int) (Math.sqrt(1. + 4 * c) + 0.1);
//            res += value * 1L * (value - 1) * (value - 2) / 6;
//        }
            out.println(res);
        }

        int compare(Line o1, Line o2) {
            int c = DoubleUtils.compareTo(o1.a, o2.a);
            if (c != 0) return c;
            c = DoubleUtils.compareTo(o1.b, o2.b);
            if (c != 0) return c;
            return DoubleUtils.compareTo(o1.c, o2.c);
        }

    }

    static class DoubleUtils {
        public static final double EPS = 1e-11;

        public static double sqr(double x) {
            return x * x;
        }

        public static int compareTo(double a, double b) {
            if (doubleEqual(a, b)) {
                return 0;
            }
            if (a < b) {
                return -1;
            }
            return 1;
        }

        private static boolean doubleEqual(double a, double b) {
            return Math.abs(a - b) < EPS;
        }

        public static double sqrt(double a) {
            if (compareTo(a, 0) < 0) {
                System.exit(1);
            }
            if (a < 0) return 0;
            return Math.sqrt(a);
        }

        public static double hypot(double a, double b) {
            return sqrt(sqr(a) + sqr(b));
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String nextString() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

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

        public double nextDouble() {
            return Double.parseDouble(nextString());
        }

    }

    static class Line {
        public final double a;
        public final double b;
        public final double c;
        public Point p1;
        public Point p2;
        boolean hasPoints;


        public int hashCode() {
            double res = a * 1e50 + b * 1e25 + c;
            return (int) res;
        }

        public Line(Point p, double angle) {
            a = Math.sin(angle);
            b = -Math.cos(angle);
            c = -p.x * a - p.y * b;
            p1 = p2 = null;
            hasPoints = false;
        }

        public Line(double a, double b, double c) {
            double h = DoubleUtils.hypot(a, b);
            this.a = a / h;
            this.b = b / h;
            this.c = c / h;
            hasPoints = false;
        }

        public Line(Point p1, Point p2) {
            double a = p2.y - p1.y;
            double b = p1.x - p2.x;
            double c = -(p1.x * a + p1.y * b);
            double h = DoubleUtils.hypot(a, b);
            this.a = a / h;
            this.b = b / h;
            this.c = c / h;
            hasPoints = true;
        }

        public boolean parallel(Line other) {
            return DoubleUtils.compareTo(Math.abs(a * other.b - b * other.a), 0) == 0;
        }

        public double value(Point point) {
            return a * point.x + b * point.y + c;
        }


        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Line line = (Line) o;

            if (!parallel(line)) return false;
            if (Math.abs(a * line.c - c * line.a) > DoubleUtils.EPS || Math.abs(b * line.c - c * line.b) > DoubleUtils.EPS)
                return false;

            return true;
        }

    }

    static class Point implements Comparable<Point> {
        public double x;
        public double y;
        public static final Point ORIGIN = new Point(0, 0);

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

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

        public Point(InputReader in) {
            this.x = in.nextDouble();
            this.y = in.nextDouble();
        }


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


        public boolean equals(Object o) {
            Point p = (Point) o;
            return DoubleUtils.compareTo(x, p.x) == 0 && DoubleUtils.compareTo(y, p.y) == 0;
        }


        public int hashCode() {
            int result;
            long temp;
            temp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;
            result = (int) (temp ^ (temp >>> 32));
            temp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;
            result = 31 * result + (int) (temp ^ (temp >>> 32));
            return result;
        }

        public Point mul(double k) {
            return new Point(x * k, y * k);
        }

        public double dotProduct(Point p) {
            return x * p.x + y * p.y;
        }

        public Point norm(double k) {
            double len = length();
            if (DoubleUtils.compareTo(len, 0) == 0) {
                if (DoubleUtils.compareTo(k, 0) == 0) return new Point();
                //throw new Exception("zero-size vector");
                System.exit(1);
            }
            return mul(k / len);
        }

        public double length() {
            return DoubleUtils.sqrt(dotProduct(this));
        }


        public int compareTo(Point o) {
            int temp = DoubleUtils.compareTo(x, o.x);
            if (temp == 0) {
                return DoubleUtils.compareTo(y, o.y);
            }
            return temp;
        }

    }
}

