QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 100

#11591. Transformation Sequence

Estadísticas

For $N$ integers $0, 1, \dots, N-1$, a transformation sequence $T$ maps $i$ to $T_i$, where $T_i \in \{0, 1, \dots, N-1\}$ and $\bigcup_{i=0}^{N-1} \{T_i\} = \{0, 1, \dots, N-1\}$. For any $x, y \in \{0, 1, \dots, N-1\}$, the distance between $x$ and $y$ is defined as $D(x, y) = \min\{|x-y|, N-|x-y|\}$. Given the distance $D(i, T_i)$ for each $i$, you need to find a transformation sequence $T$ that satisfies the requirements. If there are multiple such sequences, output the one that is lexicographically smallest.

Note: For two transformation sequences $S$ and $T$, we say $S$ is lexicographically smaller than $T$ if there exists $p < N$ such that for all $i = 0, 1, \dots, p-1$, $S_i = T_i$ and $S_p < T_p$.

Input

The first line contains an integer $N$, representing the length of the sequence. The next line contains $N$ integers $D_i$, where $D_i$ represents the distance between $i$ and $T_i$.

Output

If at least one valid transformation sequence $T$ exists, output a single line containing $N$ integers, representing the lexicographically smallest $T$ you calculated; otherwise, output "No Answer" (without quotes). Note: Adjacent numbers in the output should be separated by a single space, and there should be no trailing spaces at the end of the line.

Constraints

20% of the data: $N \le 50$; 60% of the data: $N \le 500$; 100% of the data: $N \le 10000$.

Examples

Input 1

5
1 1 2 2 1

Output 1

1 2 4 0 3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.