#P5741. Equally Matched Opponents

    ID: 18969 Type: Default 1000ms 256MiB

Equally Matched Opponents

Equally Matched Opponents

There are N (\(N \le 1000\)) students who participated in the final exam. For each student, you are given the following information:

  • Name: a string with at most 8 characters (no spaces).
  • Scores in Chinese, Math, and English: each a natural number not exceeding 150.

For any pair of students \(\langle i,j \rangle\), if for each subject the absolute difference in scores is no more than 5, and the difference in their total scores is no more than 10, then the two students are considered equally matched opponents. Your task is to find all such pairs among the students and output their names.

Note:

  1. The names in the input are given in lexicographical order.
  2. When outputting a pair \(\langle name_1, name_2 \rangle\), ensure that \(name_1\) comes lexicographically before \(name_2\).
  3. The pairs should be printed in lexicographical order: first by the first name, then by the second if the first names are identical.

inputFormat

The first line contains an integer \(N\) representing the number of students. Each of the following \(N\) lines contains a student's information in the format:

name Chinese_score Math_score English_score

All tokens are separated by spaces. The names are provided in lexicographical order.

outputFormat

For each pair of equally matched opponents, output a line with the two names separated by a space. The pairs must be in lexicographical order as described in the problem statement.

sample

3
AAA 80 90 100
BBB 83 87 98
CCC 70 80 90
AAA BBB