#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct rect {
  long long x, y, k;
  void read() { scanf("%I64d %I64d %I64d", &x, &y, &k); }
} a[N];
long long gcd(long long x, long long y) {
  if ((!x) || (!y)) return x + y;
  long long r = x % y;
  while (r) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
long long lcm(long long x, long long y) {
  if ((!x) || (!y)) return x + y;
  return x / gcd(x, y) * y;
}
long long work(long long x) {
  long long t = 1;
  for (long long i = 2; i * i <= x; i++)
    if (x % i == 0) {
      long long c;
      for (c = 0; x % i == 0; c++) x /= i;
      t *= (c + 1);
    }
  if (x != 1) t *= 2;
  return t;
}
int n;
long long B, C, sum;
bool cmp(rect a, rect b) { return a.x < b.x; }
bool cmp2(rect a, rect b) { return a.y < b.y; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    a[i].read();
    sum += a[i].k;
  }
  B = 1, C = 0;
  sort(a + 1, a + n + 1, cmp);
  int i = 1, j;
  while (i <= n) {
    long long x = a[i].k, y = a[i].k;
    for (j = i + 1; a[i].x == a[j].x; j++) {
      y += a[j].k;
      x = gcd(x, a[j].k);
    }
    B = lcm(B, y / x);
    C = gcd(C, y);
    i = j;
  }
  sort(a + 1, a + n + 1, cmp2);
  i = 1;
  while (i <= n) {
    long long x = a[i].k, y = a[i].k;
    for (j = i + 1; a[i].y == a[j].y; j++) {
      x += a[j].k;
      y = gcd(y, a[j].k);
    }
    B = lcm(B, sum / gcd(sum, x));
    long long t = gcd(sum, x);
    C = gcd(C, sum / t * (y / (x / t)));
    i = j;
  }
  if (C % B == 0)
    printf("%I64d\n", work(C / B));
  else
    puts("0");
  return 0;
}
