#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct node {
  long long x, y, s;
} v[N], V[N];
long long S, G, X, H, Z, D, ZS;
int i, j, k, n, m, d, g, an;
char c;
inline char getc() {
  static char s[10000000], *l = s, *r = s;
  if (l == r) l = s, r = s + fread(s, 1, 10000000, stdin);
  return l == r ? 0 : *l++;
}
long long read() {
  long long z = 0;
  do c = getc();
  while (c < '0' || c > '9');
  while (c >= '0' && c <= '9') z *= 10, z += c - '0', c = getc();
  return z;
}
bool cmp(node a, node b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int solve() {
  n = read();
  for (i = 1; i <= n; ++i) v[i] = (node){read(), read(), read()}, ZS += v[i].s;
  sort(v + 1, v + n + 1, cmp);
  for (H = S = v[1].s, i = 2; v[i - 1].x == v[i].x; ++i)
    S += v[i].s, H = gcd(H, v[i].s);
  X = gcd(S, ZS), Z = S / gcd(S, H);
  if (X % Z) return 0;
  for (j = 1; j < i; ++j)
    G = gcd(v[j].s, S), V[++g] = (node){v[j].s / G, S / G, v[j].y};
  for (; i <= n; i = j + 1) {
    for (S = H = v[j = i].s; v[j].x == v[j + 1].x;)
      S += v[++j].s, H = gcd(H, v[j].s);
    for (k = i; k <= j; ++k) {
      G = gcd(v[k].s, S);
      if (!(V[k - i + 1].x == v[k].s / G && V[k - i + 1].y == S / G &&
            V[k - i + 1].s == v[k].y))
        return 0;
    }
    X = gcd(X, S), D = S / gcd(S, H), G = gcd(Z, D);
    if (Z / G > X / D) return 0;
    Z *= D / G;
    if (X % Z) return 0;
  }
  for (D = 1; D * D < X; ++D)
    if (!(X % D)) an += (!(D % Z)) + (!(X / D % Z));
  if (D * D == X && !(D % Z)) ++an;
  return an;
}
int main() {
  printf("%d\n", solve());
  return 0;
}
