#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); } }; 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 v; v.push_back(0); for(const Fraction& a : seg[1]){ v.push_back(Fraction(1) - a); for(const Fraction& b : seg[2]){ v.push_back(Fraction(1) - b); Fraction f = (Fraction(1) - b) / a - a + 1; if(f < 1) v.push_back(f); } } sort(v.begin(), v.end()); int ans = 0; unsigned k = 0; for(const Fraction& f : seg[0]){ while(k < v.size() && v[k] < f) ++ k; ans += k; } ans += v.size(); cout << ans << endl; return 0; }