from fractions import Fraction n = int(input()) f = [[Fraction(1, 1)], [Fraction(1, 1)], [Fraction(1, 1)]] for _ in range(n): p, a, b = map(int, input().split()) f[p].append(Fraction(a, a + b)) f[1].sort() f[2].sort() ans = 0 for i in range(len(f[0])): k0 = len(f[2]) while k0 > 0 and f[0][i] + f[2][k0 - 1] >= Fraction(1, 1): k0 -= 1 k1 = len(f[2]) k2 = len(f[2]) for j in range(len(f[1])): while k1 > 0 and f[1][j] + f[2][k1 - 1] >= Fraction(1, 1): k1 -= 1 while k2 > 0 and f[0][i] + f[1][j] + f[2][k2 - 1] >= Fraction(2, 1): k2 -= 1 if f[0][i] + f[1][j] < Fraction(1, 1): continue if k2 < len(f[2]) and f[0][i] + f[1][j] + f[2][k2] == Fraction(2, 1): ans -= 1 ans += len(f[2]) - max(k0, k1) print(ans)