#P11185. Best Possible Ranking

    ID: 13251 Type: Default 1000ms 256MiB

Best Possible Ranking

Best Possible Ranking

There are \(n\) children competing in several contests. The \(i\)-th child has obtained \(g_i\) gold medals, \(s_i\) silver medals, and \(b_i\) bronze medals. Each child is required to create a ranking list of all children.

Since each child wants to appear as high as possible in their own ranking, they can choose the ordering criteria as follows:

  • Sort by gold medals in descending order.
  • Sort by silver medals in descending order.
  • Sort by bronze medals in descending order.

In each self-made ranking, if a child is tied with others, they can list themselves at the top of that tie group.

For each child \(i\), determine the best ranking position they can achieve (i.e. the smallest possible rank) by choosing the optimal sorting criteria.

Hint: Under a given medal type, the ranking position of child \(i\) is \(\text{rank}_i = (\#\text{ children with strictly more medals than } i) + 1\) because in case of a tie, \(i\) can be placed at the top among those tied.

inputFormat

The first line contains an integer \(n\) representing the number of children.

Each of the next \(n\) lines contains three integers \(g_i\), \(s_i\), and \(b_i\), separated by spaces, representing the number of gold, silver, and bronze medals obtained by the \(i\)-th child.

outputFormat

Output a single line containing \(n\) integers separated by a space, where the \(i\)-th integer is the best (smallest) ranking position that the \(i\)-th child can achieve on their customized ranking list.

sample

3
1 2 3
3 2 1
2 1 2
1 1 2