EXAM
문제
Martin is a beastly kid, who likes destroying his mother's flower pots. His mother owns N flower pots set up in a line and each pot has three integers written on it. When Martin crashes one of those pots, every pot right of that pot and shares at least on number with it also falls. Moreover, this rule is applied recursively, thus can result in crashing of whole lotta pots from just one direct pot crash from Martin. Beastly kids are known to be lazy and so is Martin, and he wants to know the minimal number of pots he has to crash directly so that all pots end up destroyed.
[이미지 1]
On the picture above the second sample is shown. If Domagoj crashes pot 2, it will also crash pot 3 and pot 4 because of number 2 and additionaly pot 5 because of number 9 (found on pot 4). He needs to crash pot 1, which will cause the crashing of pot 3. This amounts to two direct crashes from Martin and is the solution to the sample.
입력
First line contains one integer N (1 ≤ N ≤ 300 000).
Each of the following N lines contains three integer Ai, Bi, Ci (1 ≤ Ai, Bi, Ci ≤ 1 000 000), three numbers written on the i-th pot from the left.
출력
In the first and only line write the minimal number of pots Martin has to crash himself to crash all the pots.
예제
예제 1
3 1 2 3 2 3 4 4 5 6
1
예제 2
5 3 4 1 2 5 6 7 2 8 2 1 9 11 10 9
2