#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 > v(3, vector(1, 1)); for(int i=0; i> p >> a >> b; v[p].push_back(Fraction(a, a + b)); } long long ans = 0; sort(v[0].begin(), v[0].end()); for(Fraction a : v[1]){ for(Fraction b : v[2]){ if(a + b < 1) continue; Fraction c = Fraction(1) - min(a, b); ans += v[0].end() - lower_bound(v[0].begin(), v[0].end(), c); Fraction d = Fraction(2) - a - b; if(binary_search(v[0].begin(), v[0].end(), d)) -- ans; } } cout << ans << endl; return 0; }