Codeforces Global Round 18
G
Maximum Adjacent Pairs
Codeforces
3300
原题
← FH →
翻译中…

You are given an array $a$ consisting of $n$ non-negative integers.

翻译中…

You have to replace each $0$ in $a$ with an integer from $1$ to $n$ (different elements equal to $0$ can be replaced by different integers).

翻译中…

The value of the array you obtain is the number of integers $k$ from $1$ to $n$ such that the following condition holds: there exist a pair of adjacent elements equal to $k$ (i. e. there exists some $i \in [1, n - 1]$ such that $a_i = a_{i + 1} = k$). If there are multiple such pairs for some integer $k$, this integer is counted in the value only once.

翻译中…

Your task is to obtain the array with the maximum possible value.

翻译中…

Input

翻译中…

The first line contains one integer $n$ ($2 \le n \le 3 \cdot 10^5$) — the number of elements in the array.

翻译中…

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le \min(n, 600)$) — the elements of the array.

翻译中…

Output

翻译中…

Print $n$ integers not less than $1$ and not greater than $n$ — the array with the maximum possible value you can obtain.

翻译中…

If there are multiple answers, print any of them.

翻译中…

样例

Input #1
4
1 1 0 2
Output #1
1 1 2 2
InputCopy OutputCopy
Input #2
5
0 0 0 0 0
Output #2
3 1 1 3 3
InputCopy OutputCopy
Input #3
5
1 2 3 4 5
Output #3
1 2 3 4 5
InputCopy OutputCopy
Input #4
6
1 0 0 0 0 1
Output #4
1 2 3 3 1 1
InputCopy OutputCopy
Input #5
3
3 0 2
Output #5
3 2 2
InputCopy OutputCopy
Input #6
5
1 0 2 0 1
Output #6
1 2 2 1 1
InputCopy OutputCopy
Input #7
7
1 0 2 3 1 0 2
Output #7
1 2 2 3 1 1 2
InputCopy OutputCopy
题目信息
题号
1615G
时间限制
3 s
内存限制
512 MB
标签
构造
图匹配

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。