from fractions import Fraction from bisect import bisect_left n = int(input()) ps = [[Fraction(1)], [Fraction(1)], [Fraction(1)]] for _ in range(n): p, a, b = map(int, input().split()) ps[p].append(Fraction(a, a + b)) ps = list(map(sorted, ps)) ans = 0 for x in ps[0]: t = bisect_left(ps[1], Fraction(1) - x) for c in range(t, len(ps[1])): y = ps[1][c] mn, mx = (x, y) if x < y else (y, x) k = Fraction(1) - mn i = bisect_left(ps[2], k) ans += len(ps[2]) - i if mn > Fraction(1, 2): r = (Fraction(1) - mn) + (Fraction(1) - mx) j = bisect_left(ps[2], r) if ps[2][j] == r: ans -= 1 elif mn == Fraction(1) - mx: ans -= 1 elif mn != mx: r = mn - (Fraction(1) - mx) j = bisect_left(ps[2], r) if ps[2][j] == r: ans -= 1 else: ans -= 1 print(ans)