#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template class Operators { public: template const T1 operator+(const T2& right) const{ T1 ans = static_cast( *this ); ans += right; return ans; } template const T1 operator-(const T2& right) const{ T1 ans = static_cast( *this ); ans -= right; return ans; } template const T1 operator*(const T2& right) const{ T1 ans = static_cast( *this ); ans *= right; return ans; } template const T1 operator/(const T2& right) const{ T1 ans = static_cast( *this ); ans /= right; return ans; } bool operator!=(const T1& right) const{ const T1& left = static_cast( *this ); return !(left == right); } bool operator>(const T1& right) const{ const T1& left = static_cast( *this ); return right < left; } bool operator<=(const T1& right) const{ const T1& left = static_cast( *this ); return !(right < left); } bool operator>=(const T1& right) const{ const T1& left = static_cast( *this ); return !(left < right); } }; class Fraction : public Operators { private: long long n; // 分子(numerator) long long d; // 分母(denominator) // 約分 void reduce(){ if(d < 0){ n *= -1; d *= -1; } long long a = abs(n); long long b = d; while(b != 0){ long long tmp = a % b; a = b; b = tmp; } n /= a; d /= a; } public: Fraction(){ n = 0; d = 1; } Fraction(long long n0){ n = n0; d = 1; } Fraction(long long n0, long long d0){ n = n0; d = d0; reduce(); } pair getValue() const{ return make_pair(n, d); } Fraction& operator+=(const Fraction& f){ n = n * f.d + d * f.n; d *= f.d; reduce(); return *this; } Fraction& operator-=(const Fraction& f){ n = n * f.d - d * f.n; d *= f.d; reduce(); return *this; } Fraction& operator*=(const Fraction& f){ n *= f.n; d *= f.d; reduce(); return *this; } Fraction& operator/=(const Fraction& f){ n *= f.d; d *= f.n; reduce(); return *this; } bool operator==(const Fraction& f) const{ return n == f.n && d == f.d; } bool operator<(const Fraction& f) const{ return n * f.d < f.n * d; } }; int main() { int n; cin >> n; vector > seg(3); for(int i=0; i> p >> a >> b; seg[p].push_back(Fraction(a, a + b)); } vector v1, v2; v1.push_back(0); for(const Fraction& a : seg[1]){ v1.push_back(Fraction(1) - a); for(const Fraction& b : seg[2]){ v1.push_back(Fraction(1) - b); Fraction f = Fraction(2) - a - b; if(f <= 1){ v1.push_back(f); v2.push_back(f); } } } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); seg[0].push_back(1); sort(seg[0].begin(), seg[0].end()); int ans = 0; unsigned a = 0; unsigned b = 0; for(const Fraction& f : seg[0]){ while(a < v1.size() && v1[a] < f) ++ a; while(b < v2.size() && v2[b] <= f) ++ b; ans += a + (v2.size() - b); } cout << ans << endl; return 0; }