#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
struct Rectangle {
  long long w, h, c;
} rec[MAXN + 5];
long long R, C, ans, gr, gc;
vector<long long> rev;
vector<pair<long long, long long> > row[MAXN + 5];
map<long long, long long> trans;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
bool not_equal(long long c1, long long c2, long long c3, long long c4) {
  long long g = gcd(c1, c4);
  c1 /= g;
  c4 /= g;
  if (c2 % c4 != 0) return true;
  c2 /= c4;
  if (c1 > c3 / c2) return true;
  return c1 * c2 != c3;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> rec[i].w >> rec[i].h >> rec[i].c;
    rev.push_back(rec[i].h);
  }
  sort((rev).begin(), (rev).end());
  rev.resize(unique((rev).begin(), (rev).end()) - rev.begin());
  for (int i = 0; i < rev.size(); i++) {
    trans[rev[i]] = i;
  }
  for (int i = 0; i < N; i++) {
    rec[i].h = trans[rec[i].h];
  }
  for (int i = 0; i < N; i++) {
    row[rec[i].h].push_back({rec[i].w, rec[i].c});
  }
  bool ok = true;
  R = rev.size(), C = row[0].size();
  for (int i = 0; i < R; i++) {
    sort((row[i]).begin(), (row[i]).end());
    if (row[i].size() != C) {
      ok = false;
      break;
    }
    for (int j = 0; j < C; j++) {
      if (row[i][j].first != row[0][j].first) {
        ok = false;
        break;
      }
      if (not_equal(row[i][0].second, row[0][j].second, row[0][0].second,
                    row[i][j].second)) {
        ok = false;
        break;
      }
    }
  }
  if (!ok) {
    cout << 0 << '\n';
    return 0;
  }
  gr = gc = row[0][0].second;
  for (int i = 0; i < R; i++) gc = gcd(gc, row[i][0].second);
  for (int i = 0; i < C; i++) gr = gcd(gr, row[0][i].second);
  long long x = row[0][0].second;
  for (long long i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      long long r = i, n = x / i;
      if (gr % r == 0 && gc % n == 0) ans++;
      if (r != n) {
        if (gr % n == 0 && gc % r == 0) ans++;
      }
    }
  }
  cout << ans << '\n';
}
