Chika is playing a game!
Chika got her
The game is to figure out who has which card. However, if you ask someone what card they have, they will instead reply with the minimum label of their neighbours' cards (for some reason). You have asked everyone for their answers and have recorded them in your array
Chika already knows the answers—because she cheated. You, however, must figure out the answer. It occurs to you that the answer is not always unique; that is, even if you ask everyone, there may be multiple valid configurations that are consistent with the answers.
As such, you decide to only declare a card's value when you are convinced of it, formally, when across all configurations consistent with the answers given, the person always has the same card.
In order to have the most fun, Chika has decreed that you will play
Constraints
It is guaranteed that there is a valid arrangement of the integers from
The sum of
Subtask 1 [10%]
The sum of
Subtask 2 [30%]
The sum of
Subtask 3 [60%]
No additional constraints.
Input Specification
The first line contains the integer
The next
Output Specification
For each game, output an array of length
Sample Input
2
5
1 3 1 4 2
4
1 3 1 3
Sample Output
3 1 0 2 0
0 0 0 0
Explanation
It can be proven that the only two valid configurations for the first game are 3 1 4 2 5
and 3 1 5 2 4
.
Comments