import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdio; class Fraction { long n, m; this(long n, long m) { if (m < 0) { n *= -1; m *= -1; } long g = gcd(n, m); this.n = n / g; this.m = m / g; } long gcd(long a, long b) { a = abs(a); b = abs(b); long c; while (b) { c = a % b; a = b; b = c; } return a; } Fraction opBinary(string op)(Fraction f) { long a = this.n; long b = this.m; long x = op == "-" ? -f.n : f.n; long y = f.m; static if (op == "+" || op == "-") { long g = gcd(b, y); auto ret = new Fraction(y/g*a + b/g*x , b*y/g); return ret; } else static assert(0, "Operator "~op~" not implemented"); } override bool opEquals(Object o) { auto f = cast(Fraction) o; if (f is null) return false; return n == f.n && m == f.m; } override int opCmp(Object o) { auto f = cast(Fraction) o; auto ret = (this - f).n; if (ret > 0) return 1; else if (ret == 0) return 0; else return -1; } override string toString() { return n.to!string ~ "/" ~ m.to!string; } } void main() { auto N = readln.chomp.to!int; auto V = new Fraction[][](3); auto ONE = new Fraction(1, 1); foreach (i; 0..N) { auto s = readln.split.map!(to!long); int p = s[0].to!int; V[p] ~= new Fraction(s[2], s[1] + s[2]); } long ans = N + 1; foreach (i; 0..3) foreach (v1; V[i]) foreach (v2; V[(i+1)%3]) if (v1 + v2 < ONE) ans++; auto W = V[2].sort().assumeSorted; int Wn = W.length.to!int; foreach (v1; V[0]) { foreach (v2; V[1]) { if (v1 + v2 > ONE) continue; ans += Wn - W.upperBound(ONE-max(v1, v2)).length.to!int; ans -= Wn - W.lowerBound(ONE-v1-v2).length - W.upperBound(ONE-v1-v2).length; } } ans.writeln; }