#include <bits/stdc++.h>
using namespace std;
const int maxN = 200011;
long long n, i, j, cntx, cnty, x, y, z;
long long vx[maxN];
map<long long, long long> Mx, My;
map<pair<long long, long long>, long long> M;
pair<long long, pair<long long, long long> > low;
vector<vector<long long> > data;
vector<long long> le, ri;
vector<long long> vals;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
bool check_rat() {
  int i, j;
  for (i = 1; i + 1 <= cntx; i++) {
    for (j = 1; j + 1 <= cnty; j++) {
      if (data[i][j] * data[i + 1][j + 1] != data[i + 1][j] * data[i][j + 1])
        return false;
    }
  }
  return true;
}
void check(long long d) {
  long long i, j;
  le[low.second.first] = d;
  for (i = 1; i <= cnty; i++) {
    if (data[low.second.first][i] % d) return;
    ri[i] = data[low.second.first][i] / d;
  }
  for (i = 1; i <= cntx; i++) {
    if (data[i][1] % ri[1]) return;
    le[i] = data[i][1] / ri[1];
  }
  long long aux = 0;
  for (i = 1; i <= cntx; i++) aux += le[i] * vx[i];
  vals.push_back(aux);
}
int main() {
  low = make_pair(1LL << 60, make_pair(0, 0));
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &x, &y, &z);
    if (Mx[x] == 0) Mx[x] = ++cntx, vx[cntx] = x;
    if (My[y] == 0) My[y] = ++cnty;
    M[make_pair(Mx[x], My[y])] = z;
    low = min(low, make_pair(z, make_pair(Mx[x], My[y])));
  }
  if (cntx * cnty != n) {
    printf("0");
    return 0;
  }
  le.resize(cntx + 1);
  ri.resize(cnty + 1);
  data = vector<vector<long long> >(cntx + 1, vector<long long>(cnty + 1, 0));
  for (i = 1; i <= cntx; i++)
    for (j = 1; j <= cnty; j++) data[i][j] = M[make_pair(i, j)];
  if (!check_rat()) {
    printf("0");
    return 0;
  }
  for (i = 1; i <= cnty; i++)
    low.first = gcd(low.first, data[low.second.first][i]);
  for (long long d = 1; d * d <= low.first; d++) {
    if (low.first % d) continue;
    check(d);
    if (d * d != low.first) check(low.first / d);
  }
  sort(vals.begin(), vals.end());
  vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
  printf("%d", vals.size());
  return 0;
}
