P27169 [AtCoder] The Shrine Maiden of Nemuro
NOI
题目描述

Problem Description

It is the year 42XX, and the world is crumbling due to the various entities summoned by Takahashi. All the wise men except you have been swallowed by an endless void, and the only hope left is you and the grimoire left by the shrine maiden Abdul Irohazard. Time is running out, and any event is creeping behind you by just $0$. Through your research, you have found that Takahashi's incantation is a sequence of integers of length $N$, denoted as $B_1, B_2, \dots, B_N$. To restore the world to peace, you must recite an incantation that is a sequence of integers $A_1, A_2, \dots, A_N$ that satisfies the following conditions:

  • Each $A_i$ is an integer between $1$ and $10^6$ inclusive.
  • For each integer $i$ where $1 \leq i \leq N$, the maximum integer $0 \leq x < i$ that satisfies the following condition is $B_i$:
  • The sequence of $x$ elements from $A_1$ to $A_x$ is equal to the sequence of $x$ elements from $A_{i-x+1}$ to $A_i$.

Determine if there exists a sequence $A_1, A_2, \dots, A_N$ that satisfies the conditions, and if so, provide one such sequence.

Input Format

The input is given from the standard input in the following format:

$ N $ $ B_1 $ $ B_2 $ $\cdots$ $ B_N $

Output Format

On the first line, output Yes if there is a sequence that satisfies the conditions, otherwise output No. If such a sequence exists, output one example on the second line, separated by spaces.

If multiple answers exist, any one of them will be accepted.

Sample Input and Output

Sample Input #1

8
0 0 1 0 1 2 3 2

Sample Output #1

Yes
1 2 1 3 1 2 1 2

Sample Input #2

4
0 1 2 1

Sample Output #2

No

Notes/Hints

Constraints

  • All inputs are integers.
  • $1 \leq N \leq 10^5$
  • $0 \leq B_i < i$

Explanation

Explanation

Sample Explanation 1

For example, consider $i=6$:
- The sequence of $2$ elements from $A_1$ to $A_2$ is $(1, 2)$, and the sequence of $2$ elements from $A_{6+1-2}$ to $A_6$ is $(1, 2)$, so the condition is satisfied when $x=2$.
- The sequence of $4$ elements from $A_1$ to $A_4$ is $(1, 2, 1, 3)$, and the sequence of $4$ elements from $A_{6+1-4}$ to $A_6$ is $(1, 3, 1, 2)$, so the condition is not satisfied when $x=4$.
The maximum integer that satisfies the condition is $x=2$, which does not contradict $B_6 = 2$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
8 0 0 1 0 1 2 3 2
样例输出
Yes 1 2 1 3 1 2 1 2