AtCoder Regular Contest 177
B
Puzzle of Lamps
AtCoder
⌀ 93
原题
← AC →
翻译中…

Problem Statement

翻译中…

Mr. AtCoder has created a device consisting of $N$ small light bulbs arranged in a row from left to right, and two switches A and B. Each light bulb can be in one of two states: 0 (OFF) and 1 (ON). Pressing each switch causes the following:

翻译中…
  • Pressing switch A turns the leftmost light bulb in the 0 state into 1.
  • Pressing switch B turns the leftmost light bulb in the 1 state into 0.
翻译中…

If there is no applicable light bulb, you cannot press the switch.

翻译中…

Initially, all light bulbs are in the 0 state. He wants the states of the light bulbs to be $S_1, S_2, \dots, S_N$ from left to right. Determine the order and number of times the switches should be pressed to achieve this. It is not necessary to minimize the number of presses, but it should be at most $10^6$ so that the operations can finish in a realistic time. It can be proved that a solution exists under the constraints of this problem.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 30$
  • Each of $S_1, S_2, \dots, S_N$ is 0 or 1.
  • Not all of $S_1, S_2, \dots, S_N$ are 0.
  • $N$ is an integer.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
S_1 S_2 \dots S_N

翻译中…

Note that the second line is given as a string of length $N$.

翻译中…

Output

翻译中…

If your solution presses the switches $m$ times $(1 \leq m \leq 10^6)$ in the order $t_1, t_2, \dots, t_m$ (each being A or B), print those in the following format:

翻译中…

m
t_1 t_2 \dots t_m

翻译中…

The second line should be printed as a string of length $m$.

翻译中…

样例

Input #1
5
01100
Output #1
4
AAAB
This sample output presents a solution that presses the switches in the order A, A, A, B. This sets the light bulbs to the desired states, as shown in the figure below: ![ ](https://img.atcoder.jp/arc177/76af43b23a9e1158288d5f3162174c42.png) Alternatively, pressing switches in the order A, A, B, A, A, B also sets the light bulbs to the desired states. The following output corresponding to this solution would also be accepted:
题目信息
题号
arc177_b
时间限制
2 s
内存限制
1024 MB

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