using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using Point = System.Tuple; class Program { static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); int n = sc.Int; var lines = new List[3]; for (int i = 0; i < 3; i++) { lines[i] = new List(); lines[i].Add(new int[]{0, 1}); } for (int i = 0; i < n; i++) { var a = sc.IntArr; int g = gcd(a[1], a[2]); lines[a[0]].Add(new int[]{a[2] / g, (a[1] + a[2]) / g}); } int ans = 0; foreach (var a in lines[0]) { foreach (var b in lines[1]) { if (!ok(a, b)) continue; int s = a[0] * b[1] + a[1] * b[0], t = a[1] * b[1]; foreach (var c in lines[2]) if (ok(a, c) && ok(b, c) && s * c[1] != t * (c[1] - c[0])) ++ans; } } sw.WriteLine(ans); sw.Flush(); } static bool ok(int[] a, int[] b) { return a[0] * b[1] + a[1] * b[0] <= a[1] * b[1]; } static int gcd(int a, int b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } }