#C8033. Team Ranking in a Round Robin Tournament

    ID: 51971 Type: Default 1000ms 256MiB

Team Ranking in a Round Robin Tournament

Team Ranking in a Round Robin Tournament

Sophia is organizing a competition where n teams participate in a round robin tournament. In this tournament, each team plays exactly one match against every other team.

The results are given in an n × n matrix A, where:

  • A[i][j] = 1 indicates that team i won against team j,
  • A[i][j] = -1 indicates that team i lost to team j, and
  • A[i][j] = 0 indicates that team i did not play against team j.

The ranking criteria are as follows:

  1. A team with a higher number of wins is ranked higher. That is, if team i has w_i wins and team j has w_j wins, then team i is ranked higher if $$w_i > w_j$$.
  2. If two teams have the same number of wins, the team with fewer losses is ranked higher. In other words, if team i has l_i losses and team j has l_j losses, then team i is ranked higher if $$l_i < l_j$$.
  3. If two teams have the same number of wins and losses, they are considered to have the same rank. In such cases, list the teams in increasing order of their team numbers.

Your task is to write a program that reads the tournament results from standard input, computes the ranking according to the above criteria, and prints each team’s number along with its number of wins in order from the top-ranked team to the lowest.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains an integer n (1 ≤ n ≤ 1000), the number of teams.
  2. The next n lines each contain n space-separated integers. The j-th integer in the i-th line represents the result of the match between team i and team j (1 for a win, -1 for a loss, and 0 if they did not play).

outputFormat

For each team, print a line with two integers: the team number and the number of wins it achieved. The teams must be printed in descending order of their ranking, based on the criteria provided. If two teams have the same ranking, list them by increasing team number.

## sample
1
0
1 0

</p>