package yukicoder; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Q461 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList[] f = new ArrayList[3]; for (int i = 0; i < 3; ++i) { f[i] = new ArrayList<>(); f[i].add(new Fraction(1, 1)); } for (int i = 0; i < n; ++i) { int p = sc.nextInt(); long a = sc.nextLong(); long b = sc.nextLong(); f[p].add(new Fraction(a, a + b)); } Collections.sort(f[1]); Collections.sort(f[2]); long ans = 0; for (Fraction f0 : f[0]) { out: for (Fraction f1 : f[1]) { if (f0.add(f1).compareTo(ONE) == -1) continue; for (Fraction f2 : f[2]) { if (f1.add(f2).compareTo(ONE) == -1) continue; if (f0.add(f2).compareTo(ONE) == -1) continue; if (f0.add(f1).add(f2).equiv(TWO)) { continue; } ++ans; } } } System.out.println(ans); } static Fraction ONE = new Fraction(1, 1); static Fraction TWO = new Fraction(2, 1); static class Fraction implements Comparable { long x; long y; public Fraction(long x, long y) { this.x = x; this.y = y; } Fraction add(Fraction o) { return new Fraction(x * o.y + o.x * y, y * o.y); } Fraction subtruct(Fraction o) { return new Fraction(x * o.y - o.x * y, y * o.y); } Fraction mul(Fraction o) { return new Fraction(x * o.x, y * o.y); } boolean equiv(Fraction o) { return x * o.y == y * o.x; } @Override public int compareTo(Fraction o) { if (o.y < 0 || y < 0) throw new AssertionError(); return Long.compare(x * o.y, o.x * y); } } }