#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(c) begin(c), end(c) #define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl using ld = __float128; int n; vector ls[3]; int main(){ cin >> n; rep(i, n){ int p; int a, b; cin >> p >> a >> b; ls[p].push_back((ld)a / (a + b)); } for(int i = 0; i < 3; ++i) sort(all(ls[i])); // 1本 ll ans = n + 1; for(auto &x : ls[1]){ x = 1 - x; ans += ls[0].end() - upper_bound(all(ls[0]), x); } for(auto &y : ls[2]){ y = 1 - y; ans += ls[0].end() - upper_bound(all(ls[0]), y); } for(ld x : ls[1]){ for(ld y : ls[2]){ // 2本 (1,2) if(x + y < 1) ++ans; // 3本 (0,1,2) int a = lower_bound(all(ls[0]), x + y) - lower_bound(all(ls[0]), max(x, y)); int b = upper_bound(all(ls[0]), 10000) - upper_bound(all(ls[0]), x + y); ans += a + b; } } cout << ans << endl; }