P5759 [NOI1997] Contest Ranking

Description

A city organized an all-round science and technology contest for middle school students. Each participant takes part in eight contests: Mathematics, Physics, Chemistry, Astronomy, Geography, Biology, Computer Science, and English. In the end, the overall ranking is determined based on the combined results of these eight contests. The contestant IDs are $1,2,\dots,N$ ($N$ is the total number of participants). Let $x_{i, j}$ ($1 \le i \le N, 1 \le j \le 8$) denote the score of contestant $i$ in contest $j$. Other indicators are defined as follows: - The average score of contest $j$ ($1 \le j \le 8$): $avg_j = \frac{1}{N} \sum_{i=1}^N x_{i, j}$ - The total score of contestant $i$ ($1 \le i \le N$): $sumx_i = \sum_{j=1}^8 x_{i, j}$ - The positional score of contestant $i$ ($1 \le i \le N$) in contest $j$ ($1 \le j \le 8$): $$ y_{i, j}= \begin{cases} 0 & \left(\sum_{i = 1} ^ N |x_{i, j} - avg_j| = 0\right) \\ \frac{x_{i, j} - avg_j}{\frac{1}{N} \sum_{i = 1} ^ N |x_{i ,j} - agv_j|} & \left(\sum_{i = 1} ^ N |x_{i, j} - avg_j| \ne 0\right)\end{cases} $$ - The total positional score of contestant $i$ ($1 \le i \le N$): $sumy_i = \sum_{j=1}^3 y_{i, j} + 0.8 \sum_{j=4}^8 y_{i, j}$ The ranking rules are as follows: 1. Contestants with higher total positional scores rank earlier. 2. If two or more contestants have the same total positional score, the one with the higher total score ranks earlier. 3. If two or more contestants have the same total positional score and the same total score, the one with the smaller ID ranks earlier. Please write a program for the contest committee to compute the overall ranking for this all-round contest.

Input Format

The first line contains the total number of participants $N$. From the second line to the $N$-th line, the scores of contestants with IDs from $1$ to $N$ are given in order. Each line contains $8$ integers between $0$ and $100$, representing the contestant’s scores in the 8 contests. Adjacent numbers on the same line are separated by one space.

Output Format

Output $N$ lines. From line 1 to line $N$, output the ID of the contestant ranked 1st, the ID of the contestant ranked 2nd, $\dots$, and the ID of the contestant ranked $N$-th.

Explanation/Hint

#### Constraints For all testdata, $1 \le N \le 1000$. Translated by ChatGPT 5