P5728 [Deep Basics 5.Example 5] Evenly Matched Opponents

Description

There are $N$ students who took the final exam, and we are given each student’s information: Chinese, Math, and English scores (all natural numbers not exceeding $150$). If for a pair of students $\lang i,j\rang$, the score difference in each subject is no more than $5$, and the difference in total score is no more than $10$, then this pair of students are “evenly matched opponents”. Now, find how many pairs of “evenly matched opponents” there are among these students. The same student may be paired with multiple other students.

Input Format

The first line contains a positive integer $N$. The next $N$ lines each contain three integers. The $i$-th line gives the Chinese, Math, and English scores of the $i$-th student. The first student read in is numbered $1$.

Output Format

Output one integer, representing the number of pairs of “evenly matched opponents”.

Explanation/Hint

Constraints: $2 \le N\le 1000$, and each subject score is a natural number not exceeding $150$. Translated by ChatGPT 5