Carnival General
면접 대비시간 제한1초메모리 제한1024 MB
어떤 인접한 두 장군도 나이 많은 쪽의 순위에서 나이 어린 쪽이 정확히 후반부에 오지 않도록 장군 N명을 한 줄로 배열한다.
문제
Every four years, the students of Lund come together to organize the Lund Carnival. For a few days, a park fills with tents where all kinds of festive activities take place. The person in charge of making this happen is the carnival general.
In total, there have been carnivals, each with a different general. The generals are numbered from to in chronological order. Every general has given their opinion on how good their predecessors were, by publishing a ranking of the generals in order from best to worst.
The next Lund Carnival will be in 2026. In the meantime, all past carnival generals have gathered to take a group photo. However, it would be awkward if generals and (where end up next to each other if is strictly in the second half of 's ranking.
For example:
- If general has given the ranking
3 2 1 0, then can stand next to , or , but not or . - If general has given the ranking
4 3 2 1 0, then can stand next to or , but not or .
Note that it is fine if one general is exactly in the middle of another's ranking.
The following figure illustrates sample 1. Here, general stands next to generals and , and general stands next to general only.

You are given the rankings that the generals published. Your task is to arrange the generals in a row, so that if and are adjacent (where ) then is not strictly in the second half of 's ranking.
입력
The first line contains the positive integer , the number of generals.
The following lines contain the rankings. The first of these lines contains general 's ranking, the second line contains general 's ranking, and so on until general . General is absent since general didn't have any predecessors to rank.
The ranking of general is a list with integers in which every integer from to occurs exactly once. Specifically, is the best and is the worst general according to general .
출력
Print a list of integers, an ordering of the numbers , such that for each pair of adjacent numbers, neither is strictly in the second half of the other's ranking.
It can be proven that a solution always exists. If there are multiple solutions, you may print any of them.
제한
- .
- for .
힌트
The first sample matches the condition of test group . In this sample, neither general nor can stand next to general , and neither general nor can stand next to generals and . The sample output was illustrated in the figure above.
The second sample matches the condition of test group . In this sample, general can't stand next to general , general can't stand next to general , and general can't stand next to generals and .
The third sample matches the condition of test group . In this sample, the only pairs of generals that can't stand next to each other are and . Hence, there are no conflicts if they are arranged 3 0 1 2. Another possible answer is 0 1 2 3.