#K38872. Reorder Problems

    ID: 26295 Type: Default 1000ms 256MiB

Reorder Problems

Reorder Problems

You are given a set of problems, each identified by an integer identifier and a difficulty level. Your task is to reorder these problems so that their difficulty levels are in strictly increasing order. In mathematical terms, if the sorted difficulties are represented as \(d_1, d_2, \ldots, d_n\), then they must satisfy \(d_1 < d_2 < \cdots < d_n\). If such a reordering is impossible because at least two problems share the same difficulty or the difficulties do not allow a strictly increasing order, output impossible.

If the input list is empty, output an empty line.

Note: The problems must be reordered by sorting according to their difficulty levels. The order of the problem identifiers in the output should correspond to the sorted order.

inputFormat

The input is given via standard input and consists of:

  • The first line contains a single integer \(n\) representing the number of problems.
  • The next \(n\) lines each contain two space-separated integers: the first is the problem's identifier and the second is its difficulty level.

outputFormat

Output the problem identifiers in the order of strictly increasing difficulty, separated by spaces. If it is impossible to reorder the problems so that their difficulty levels become strictly increasing, output impossible instead. For an input of \(n = 0\), output an empty line.

## sample
3
3 20
1 10
2 30
1 3 2