#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np eps = 1e-11 N = int(readline()) X = [[0] for _ in range(3)] m = map(int, read().split()) for p, a, b in zip(m, m, m): x = b / (a + b) X[p].append(x) X.sort(key=len) def solve_naive(): import itertools ret = 0 for x1, x2, x3 in itertools.product(*X): if 1 - eps < x1 + x2 + x3 < 1 + eps: continue if x1 + x3 > 1 + eps: continue if x1 + x2 > 1 + eps: continue if x2 + x3 > 1 + eps: continue ret += 1 return ret def solve(X, Y, Z): X.sort() Y.sort() Z.sort() add_XY = np.add.outer(X, Y).ravel() max_XY = np.maximum.outer(X, Y).ravel() cnt_Z = np.searchsorted(Z, 1 - max_XY + eps) ret = (cnt_Z * (add_XY < 1 + eps)).sum() # 1点で交わるものを除く ret -= (np.searchsorted(Z, 1 - add_XY + eps) - np.searchsorted(Z, 1 - add_XY - eps)).sum() return ret X, Y, Z = map(np.array, X) print(solve(X, Y, Z))