#include #include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) typedef long long ll; typedef boost::rational ratio; using namespace std; int main() { int n; cin >> n; array, 3> qs = {}; repeat (i,n) { int p, a, b; cin >> p >> a >> b; qs[p].emplace_back(a, a + b); } repeat (i,3) { qs[i].emplace_back(1); whole(sort, qs[i]); } int cnt = 0; repeat (i,3) { for (ratio q1 : qs[(i + 1) % 3]) { for (ratio q2 : qs[(i + 2) % 3]) { ratio qm = max(1 - q1, 1 - q2); ratio qc = (1 - q1) + (1 - q2); if (qc <= 1) { int lm = whole(lower_bound, qs[i], qm) - qs[i].begin(); int lc = whole(lower_bound, qs[i], qc) - qs[i].begin(); cnt += qs[i].size() - lm - (qs[i][lc] == qc); } } } } assert (cnt % 3 == 0); cout << cnt / 3 << endl; return 0; }