Bil-176 FINAL 2017-2018 Bahar |
Start: May.18.2018 at 09:00:00 AM
Finish: May.24.2018 at 11:00:00 AM
The contest is finished!
• Contest scoreboard
|
Feedback | | If you notice incorrect translations in Contester, please let author know.
|
|
Time limit 1000/1000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Problem description
It's known fact that all railway stations have special turnout system to rearrange wagons of train (see the figure). Train with N wagons numbered from 1 to N in increasing order comes to turnout from the right side. Railway station workers want to rearrange wagons so that at the left side of turnout they appear in a given order p1, p2, ..., pn. Employees can perform exactly 3 operations:
A. Put wagon into turnout;
B. Take wagon from the left side of turnout;
C. Take wagon from the right side of turnout, see figure and example.
Write a program which will help railway station workers!
Input
There is one number N on the first line (1 <= N <= 250). On the second line there are N positive integers p1, p2, ..., pn, which form a permutation of numbers from 1 to N .
Output
Write NO in the first line of output if it's impossible to rearrange wagons in given order. Otherwise write YES on the first line and sequence of operations which must be performed on the second line encoded with letters A, B and C. If there are several solutions output any of them.
Example
| stdin |
stdout |
3
1 3 2 |
YES
ABAACC |
4
4 2 1 3 |
NO |
 Для отправки решений необходимо выполнить вход.
|