atcoder#CF17FINALI. Full Tournament
Full Tournament
Score : points
Problem Statement
players competed in a tournament. Each player has a unique ID number from through . When two players play a match, the player with the smaller ID always wins.
This tournament was a little special, in which losers are not eliminated to fully rank all the players.
We will call such a tournament that involves players a full tournament of level n. In a full tournament of level , the players are ranked as follows:
- In a full tournament of level , the only player is ranked first.
- In a full tournament of level , initially all players are lined up in a row. Then:
- First, starting from the two leftmost players, the players are successively divided into pairs of two players.
- Each of the pairs plays a match. The winner enters the "Won" group, and the loser enters the "Lost" group.
- The players in the "Won" group are lined up in a row, maintaining the relative order in the previous row. Then, a full tournament of level is held to fully rank these players.
- The players in the "Lost" group are also ranked in the same manner, then the rank of each of these players increases by .
For example, the figure below shows how a full tournament of level progresses when eight players are lined up in the order . The list of the players sorted by the final ranking will be .
Takahashi has a sheet of paper with the list of the players sorted by the final ranking in the tournament, but some of it blurred and became unreadable. You are given the information on the sheet as a sequence of length . When is or greater, it means that the -th ranked player had the ID . If is , it means that the ID of the -th ranked player is lost.
Determine whether there exists a valid order in the first phase of the tournament which is consistent with the sheet. If it exists, provide one such order.
Constraints
- No integer, except , occurs more than once in .
Input
Input is given from Standard Input in the following format:
Output
If there exists a valid order in the first phase of the tournament, print YES
first, then in the subsequent line, print the IDs of the players sorted by the final ranking, with spaces in between.
If there is no such order, print NO
instead.
3
0 3 0 6 0 0 0 8
YES
3 4 8 6 2 1 7 5
This is the same order as the one in the statement.
1
2 1
NO