#include <bits/stdc++.h>
using namespace std;
const int N = 500005, M = 998244353;
int n, x, y, nh, nw, ans;
long long sh[N], sw[N], h[N], w[N];
struct str {
  long long w, h, c;
} a[200005];
bool cmp(str a, str b) {
  if (a.w == b.w) return a.h < b.h;
  return a.w < b.w;
}
int id(int x, int y) { return (x - 1) * nh + y; }
bool check(long long y) {
  sw[1] = y;
  sh[1] = a[1].c / y;
  for (register int i = 1; i <= nh; ++i) {
    if (a[id(1, i)].c % y != 0) return false;
    sh[i] = a[id(1, i)].c / y;
  }
  for (register int i = 1; i <= nw; ++i) {
    if (a[id(i, 1)].c % sh[1] != 0) return false;
    sw[i] = a[id(i, 1)].c / sh[1];
  }
  for (register int i = 1; i <= nw; ++i)
    for (register int j = 1; j <= nh; ++j)
      if (1ll * sw[i] * sh[j] != a[id(i, j)].c) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%lld %lld %lld", &a[i].w, &a[i].h, &a[i].c);
    w[i] = a[i].w, h[i] = a[i].h;
  }
  sort(w + 1, w + 1 + n);
  sort(h + 1, h + 1 + n);
  for (register int i = 1; i <= n; ++i)
    if (h[i] != h[nh]) h[++nh] = h[i];
  for (register int i = 1; i <= n; ++i)
    if (w[i] != w[nw]) w[++nw] = w[i];
  sort(a + 1, a + 1 + n, cmp);
  if (1ll * nw * nh != n) {
    printf("0");
    return 0;
  }
  x = y = 1;
  for (register int i = 1; i <= n; ++i) {
    if (a[i].w != w[x] || a[i].h != h[y]) {
      printf("0");
      return 0;
    }
    ++y;
    if (y > nh) {
      ++x;
      y = 1;
    }
  }
  for (register int i = 1; 1ll * i * i <= a[1].c; ++i)
    if (a[1].c % i == 0) {
      if (check(i)) ++ans;
      if (1ll * i * i != a[1].c && check(a[1].c / i)) ++ans;
    }
  cout << ans;
}
