#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct point {
  long long x, y, z;
  point() {}
  point(int x, int y, int z) : x(x), y(y), z(z) {}
  friend bool operator<(const point &p, const point &q) {
    if (p.x != q.x) return p.x < q.x;
    return p.y < q.y;
  }
} a[N];
vector<pair<long long, long long> > v[N];
long long c[N];
int cnt = 0;
void init(int n) {
  int i = 1;
  while (i <= n) {
    int j = i;
    while (j <= n && a[j].x == a[i].x) j++;
    cnt++;
    for (int k = i; k < j; k++) {
      v[cnt].push_back(make_pair(a[k].y, a[k].z));
      c[cnt] += a[k].z;
    }
    i = j;
  }
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long c = gcd(a, b);
  a /= c;
  return a * b;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].z;
  sort(a + 1, a + n + 1);
  init(n);
  long long mx = c[1];
  for (int i = 2; i <= cnt; i++) mx = gcd(mx, c[i]);
  long long mi = 1;
  for (int i = 1; i <= cnt; i++) {
    long long first = v[i][0].second;
    for (int j = 0; j < v[i].size(); j++) {
      first = gcd(first, v[i][j].second);
    }
    mi = lcm(mi, c[i] / first);
    if (mx % mi) {
      cout << 0 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (long long i = 1; i * i <= mx; i++) {
    if (mx % i) continue;
    if (i % mi == 0) ans++;
    long long first = mx / i;
    if (first % mi) continue;
    if (first != i) ans++;
  }
  for (int i = 2; i <= cnt; i++) {
    if (v[i].size() != v[1].size()) {
      cout << 0 << endl;
      return 0;
    }
    for (int j = 0; j < v[1].size(); j++) {
      if (v[1][j].first != v[i][j].first) {
        cout << 0 << endl;
        return 0;
      }
      if (fabs((long double)c[i] / v[i][j].second -
               (long double)c[1] / v[1][j].second) > 1e-8) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
