#P5728. Evenly Matched Opponents
Evenly Matched Opponents
Evenly Matched Opponents
There are n students taking the final exam. Each student has three scores in Chinese, Mathematics, and English, each being a natural number not exceeding 150. Define the total score of a student as \( S = \text{Chinese} + \text{Mathematics} + \text{English} \).
Two students \( i \) and \( j \) are considered evenly matched opponents if, for each subject, the absolute difference in scores satisfies \[ |a_i - a_j| \le 5, \quad |b_i - b_j| \le 5, \quad |c_i - c_j| \le 5, \] and the absolute difference in total scores satisfies \[ |S_i - S_j| \le 10. \]
Your task is to count the number of distinct pairs of evenly matched opponents. Note that one student may form a pair with multiple other students.
inputFormat
The first line contains an integer n
denoting the number of students.
Each of the following n
lines contains three space-separated integers representing the scores in Chinese, Mathematics, and English respectively.
outputFormat
Output a single integer — the total number of pairs of evenly matched opponents.
sample
4
80 90 100
85 95 105
80 90 100
100 100 100
1