400789: GYM100247 K Three Contests

Memory Limit:256 MB Time Limit:4 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Three Conteststime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

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?

Input

The 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.

Output

Output the only integer — number of pairs of teams where each team considers itself stronger than the other.

ExamplesInput
4
1 3 1
2 2 4
4 1 2
3 4 3
Output
5

加入题单

上一题 下一题 算法标签: