QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 100

#9511. Shift

統計

Byteasar bought his son Bytie a set of blocks numbered from $1$ to $n$ and arranged them in a row in a certain order. Bytie's goal is to rearrange the blocks so that they are ordered naturally, from the smallest number to the largest. However, the only moves Bytie is allowed to make are:

  • putting the last block at the very beginning (move a), and
  • putting the third block at the very beginning (move b).

Help Bytie by writing a program that tells whether a given arrangement of blocks can be properly reordered, and tells the right sequence of moves if it is.

Input

In the first line of the standard input there is a single integer $n$, $1 \le n \le 2\,000$. In the second line there are $n$ integers from the range $1$ to $n$, separated by single spaces. No number appears twice, and thus they represent the initial arrangement of the blocks.

Output

If there is no sequence of moves leading to an arrangement with increasing blocks' numbers, your program should print out "NIE DA SIE" (there is no way in Polish), without the quotation marks.

Otherwise there should be a single integer $m$ ($m \leq n^2$), denoting the number of operations, in the first line. An operation is a $k$-fold execution of either a or b move.

If $m > 0$, then there should be a sequence of $m$ integers with either a or b appended in the second line. Thus $k$a (for $0 < k < n$) denotes the $k$-fold execution of the move $a$. Analogously, $k$b (for $0 < k < n$) denotes the $k$-fold execution of the move b.

Furthermore, the characters appended to the numbers in the second line have to alternate.

Should there be more than one solution, your program is free to pick one arbitrarily.

Example

For the input data:

4
1 3 2 4

the correct result is:

4
3a 2b 2a 2b

For the input data:

7
1 3 2 4 5 6 7

the correct result is:

NIE DA SIE

For the input data:

3
1 2 3

the correct result is:

0
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.