#include #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; const long double eps = 1e-17; int n; vector t[3]; ll ans; signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; t[0].pb(1), t[1].pb(1), t[2].pb(1); for(int i = 1, p, a, b; i <= n; i++) cin >> p >> a >> b, t[p].pb(a / (long double)(a + b)); sort(t[0].begin(), t[0].end()); sort(t[1].begin(), t[1].end()); sort(t[2].begin(), t[2].end()); for(auto l0 : t[0]) for(auto l1 : t[1]) { long double ma = max(1 - l0, 1 - l1); long double jd = 2 - l0 - l1; if (jd > 1 + eps) continue; int it1 = lower_bound(t[2].begin(), t[2].end(), ma - eps) - t[2].begin(); int it2 = lower_bound(t[2].begin(), t[2].end(), jd - eps) - t[2].begin(); ans += t[2].size() - it1; if (fabs(t[2][it2] - jd) < eps) ans--; } cout << ans << endl; return 0; }