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).
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
struct line {
  double k, b;
  inline bool operator<(const line t) const {
    if (fabs(k - t.k) > eps)
      return k < t.k;
    else
      return b < t.b;
  }
};
line l[5000000];
double px[3000], py[3000];
int i, j, k, n, t, x, y, z;
long long s;
bool b;
inline void calc(int x) {
  for (int i = 1;; i++)
    if (i * (i - 1) / 2 == x) {
      s = s + 1LL * i * (i - 1) * (i - 2) / 6;
      return;
    }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    px[i] = -1.0 * x * z / (x * x + y * y);
    py[i] = -1.0 * y * z / (x * x + y * y);
    if (fabs(px[i]) + fabs(py[i]) < eps)
      if (!b)
        b = true;
      else
        s = s + n - 2, i--, n--;
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j < i; j++)
      if (fabs(px[i] - px[j]) < eps)
        k++, l[k] = (line){-1e10, px[i]};
      else
        k++, l[k].k = 1.0 * (py[i] - py[j]) / (px[i] - px[j]),
             l[k].b = py[i] - l[k].k * px[i];
  sort(l + 1, l + k + 1);
  l[k + 1].k = 1e10;
  for (i = 1; i <= k + 1; i++)
    if ((fabs(l[i].k - l[i - 1].k) < eps) && (fabs(l[i].b - l[i - 1].b) < eps))
      t++;
    else
      calc(t), t = 1;
  calc(t);
  printf("%I64d", s);
  return 0;
}
