#C3890. Team Median Sorting

    ID: 47367 Type: Default 1000ms 256MiB

Team Median Sorting

Team Median Sorting

You are given the scores of several teams. Each team has the same number of members and each member has a score. The goal is to compute the median score for each team and then sort the teams in increasing order based on their medians. If two teams have the same median score, their order should remain as in the input (i.e., stable sorting using 1-indexed team ids).

For a sorted list of scores, the median is defined as:

  • If the number of scores, \(N\), is odd, the median is the middle score.
  • If \(N\) is even, the median is the average of the two middle scores, i.e. \(\frac{a_{\frac{N}{2}} + a_{\frac{N}{2}+1}}{2}\).

Your program should read input from stdin and output the sorted team indices (one per line) to stdout.

inputFormat

The first line of input contains two integers \(T\) and \(N\), where \(T\) represents the number of teams and \(N\) represents the number of members in each team.

This is followed by \(T\) lines, each containing \(N\) integers representing the scores of the team's members.

All input should be read from stdin.

outputFormat

Output the sorted team indices based on the median scores, one index per line, to stdout.

## sample
3 4
50 80 90 70
60 40 100 50
30 20 60 10
3

2 1

</p>