#include #define int ll #define fi first #define endl '\n' #define il inline #define se second #define pb push_back #define INF 0x3f3f3f3f using namespace std; typedef long long ll; typedef pair pii; #ifdef ONLINE_JUDGE #define debug(...) 0 #else #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #endif const int N = 4e3 + 10; int n, ans, cnt, C[N]; vector a[2]; map c; signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; a[0].pb({1, 0}), a[1].pb({1, 0}), C[c[{1, 0}] = cnt = 1] = 1e18; for (int i = 1, opt, x, y; i <= n; i++) { cin >> opt >> x >> y; if (opt < 2) a[opt].pb({x / __gcd(x, y), y / __gcd(x, y)}); else c[{x / __gcd(x, y), y / __gcd(x, y)}]++, C[++cnt] = x * 1e9 / y; } sort(C + 1, C + cnt + 1); for (auto x : a[0]) for (auto y : a[1]) { int a = x.fi * y.se + x.se * y.fi + 2 * x.se * y.se, b = x.fi * y.fi - x.se * y.se; int p = a / __gcd(a, b), q = b / __gcd(a, b); if (p < 0 || q < 0) continue; ans += cnt - (prev(lower_bound(C + 1, C + cnt + 1, max(x.se * 1e9 / x.fi, y.se * 1e9 / y.fi))) - C); if (c.count({p, q})) ans -= c[{p, q}]; // cout << x.fi << ' ' << x.se << ' ' << y.fi << ' ' << y.se << ' ' << p << ' ' << q << endl; } cout << ans << endl; return 0; }