Automatic Friends
InterviewTime limit2sMemory limit1024 MB
Count pairs of triples that agree in exactly one coordinate and differ in the other two.
- Level
Medium5 of 10
- Topics
- Hash map, Combinatorics, Math, Array
- Solved
- No attempts yet
Problem
A school for young programmers decided to build its own social network that automatically suggests potential friends to each user. When registering, every user takes a psychological test, and the results determine the values of three psychological characteristics for that user. Each characteristic value is a positive integer.
If two users differ in all three psychological characteristics, they will constantly quarrel, and if they match in two or three characteristics, they will be bored. So the only pairs of users who are potential friends are those that match in exactly one characteristic and differ in the other two.
Given triples of characteristic values for the users, write a program that finds the number of pairs of potential friends, that is, the number of index pairs for which exactly one of the three equalities , , holds.
Input
The first line of the input contains the number of users. Each of the next lines contains three positive integers , , and , the characteristic values of the -th user.
Output
The output must contain the required number of pairs of potential friends.
Hint
In the first example, the pairs of potential friends are users 1 and 2, and users 2 and 3. In both cases the users match in the first characteristic and differ in the second and third. Users 1 and 3 match in the first two characteristics, so they do not form a pair of potential friends.