spoj#ADACABAA. Ada and Species
Ada and Species
As you might know, Ada the Ladybug is a farmer. She needs to choose some species of vegetables. Each vegetable disposes with four important attributes. We say that a vegetable is worse than another vegetable, if all of its four attributes are greater.
She wants to eliminate the list of vegetables, so only vegetables, which are not worse than any other vegetables remains.
Input
The first line contains integer 1 ≤ N ≤ 2*105
Each of the next N lines contains four integers 1 ≤ X, Y, Z, W ≤ N. It is guaranteed, that all X attributes are distinct for all vegetables. The same is true for Y, Z and W (so in fact, there are four permutations of numbers from 1 to N).
Output
Print the number of vegetables, which are not worse than any other vegetable.
Example Input 1
3 1 1 1 1 2 2 2 2 3 3 3 3
Example Output 1
1
Example Input 2
10 8 9 9 2 3 7 2 4 5 5 10 10 9 3 5 9 4 6 8 6 2 8 1 7 1 2 6 1 7 4 7 5 6 1 3 8 10 10 4 3
Example Output 2
5