#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector VI; typedef vector VL; typedef pair PI; const ll mod = 1e9 + 7; int main(void){ int n; cin >> n; vector pool[3]; REP(i, 0, 3) { pool[i].push_back(PI(0, 1)); } REP(i, 0, n) { int p, a, b; cin >> p >> a >> b; int g = __gcd(a, b); a /= g; b /= g; pool[p].push_back(PI(b, a + b)); } ll tot = (ll)(pool[0].size() * pool[1].size()) * pool[2].size(); set pool2(pool[2].begin(), pool[2].end()); REP(i, 0, pool[0].size()) { REP(j, 0, pool[1].size()) { PI u = pool[0][i]; PI v = pool[1][j]; PI w = PI(u.second * v.second - u.first * v.second - u.second * v.first, u.second * v.second); int g = __gcd(w.first, w.second); w.first /= g; w.second /= g; if (pool2.count(w)) { tot--; } } } cout << tot << endl; }