#include <bits/stdc++.h>
using namespace std;
int n;
map<long long, long long> A, B;
map<pair<long long, long long>, long long> C;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
bool checkProd(long long a, long long b, long long c, long long d) {
  long long g = gcd(a, c);
  a /= g;
  c /= g;
  g = gcd(b, c);
  b /= g;
  c /= g;
  g = gcd(a, d);
  a /= g;
  d /= g;
  g = gcd(b, d);
  b /= g;
  d /= g;
  return a == 1 && b == 1 && c == 1 && d == 1;
}
int main() {
  scanf("%d", &n);
  long long S = 0;
  for (int i = 0; i < n; i++) {
    long long x, y, w;
    scanf("%lld%lld%lld", &x, &y, &w);
    C[make_pair(x, y)] += w;
    A[x] += w;
    B[y] += w;
    S += w;
  }
  if ((long long)A.size() * (long long)B.size() != (long long)C.size()) {
    printf("0\n");
    return 0;
  }
  for (auto t1 : A)
    for (auto t2 : B) {
      if (!checkProd(t1.second, t2.second, S,
                     C[make_pair(t1.first, t2.first)])) {
        printf("0\n");
        return 0;
      }
    }
  long long P = 0, Q = 0;
  for (auto t : A) P = gcd(P, t.second);
  for (auto t : B) Q = gcd(Q, t.second);
  if (S % P != 0 || S % Q != 0) throw;
  S /= P;
  if (Q % S != 0) {
    printf("0\n");
    return 0;
  }
  S = Q / S;
  long long ans = 1;
  for (long long x = 2; x * x <= S; x++) {
    if (S % x != 0) continue;
    long long t = 1;
    while (S % x == 0) {
      S /= x;
      t++;
    }
    ans *= t;
  }
  if (S > 1) ans *= 2;
  printf("%lld\n", ans);
  return 0;
}
