400789: GYM100247 K Three Contests
Description
Three contests have finished at the programming training camp. Now every team considers itself stronger than every other team which has been beaten by it at least at the one of these contests.
How many pairs of teams, where each team considers itself stronger than the other, exist?
InputThe first line contains the only integer n (1 ≤ n ≤ 200000) — the number of teams at the training camp.
Each of the next n lines contains three integers: ai, bi and ci (1 ≤ ai, bi, ci ≤ n) — the places taken by team i at the first, the second and the third contest correspondingly.
It's guaranteed that there is no contest where some teams share the same place, that is, all ai are distinct, all bi are distinct, and all ci are distinct.
OutputOutput the only integer — number of pairs of teams where each team considers itself stronger than the other.
ExamplesInput4Output
1 3 1
2 2 4
4 1 2
3 4 3
5