Build the String

시간 제한2초메모리 제한1024 MB

요약
a와 b로 이루어진 목표 문자열이 주어질 때, 초기 스택 'a b'에서 시작해 copy, swap, roll, fuse만으로 충돌 없이 문자열을 만드는 3n 이하 길이의 프로그램을 출력한다.
난이도

보통10점 중 7점

유형
그리디, 구현, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Let us have some virtual machine. The machine has a memory stack that can infinitely widen and can contain strings of any finite non-zero length.

The machine supports four operations:

  • copy --- copy a string at the stack's end and place it in the stack's end;
  • swap --- swap the last string in the stack and the one before the last;
  • roll --- cyclically shift three last strings in the stack away from the stack's end;
  • fuse --- extract two strings from the stack's end and then place their concatenation at the stack's end.

More formally it looks like that: ([...] stands for some sequence of strings at the beginning of the stack, perhaps of zero length):

  • copy: [...] x →\to [...] x x;
  • swap: [...] x y →\to [...] y x;
  • roll: [...] x y z →\to [...] y z x;
  • fuse: [...] x y →\to [...] xy.

Program for a given virtual machine is represented by a command sequence; the machine performs the commands one after another. If the stack doesn't have enough strings to perform the program's current command, then an event CRASH occurs and the machine stops functioning. The machine also stops if the program runs out of commands (in this case the CRASH event never occurs).

Initially the virtual machine's stack contains two strings and has the form of "a b". You have to write a program for the given machine; the program's progress should result in an ss string located at the stack's end (at the end of the program's progress the stack can have more than one string left). The program should contain no more than 3×∣s∣3 \times |s| commands (∣s∣|s| --- is the ss string's length). Of course, the program's progress shouldn't lead to the CRASH event.

입력

The first line contains the ss string. It only consists of lowercase Latin letters "a" and "b" and has the length from 11 to 10510^5 characters.

출력

Print on the first output line number kk the number of commands in the program (0≤k≤3×∣s∣0 \le k \le 3 \times |s|). Print on the next kk lines kk commands, one command per line. The acceptable commands are "copy", "swap", "roll" and "fuse". As the result of the program's progress the last element in the stack should be string ss (the stack can have more than one string left). The program shouldn't lead to the CRASH event. If there are several acceptable decisions, print any of them. See the samples for clarifications.

힌트

During the sample program's progress the virtual machine's stack changes in the following manner:

a b →\to b a →\to b a a →\to a a b →\to a ab →\to a ab ab →\to a abab →\to a abab abab →\to abab abab a →\to abab ababa

예제1

  1. 예제 1

    입력
    ababa
    
    예상 출력
    9
    swap
    copy
    roll
    fuse
    copy
    fuse
    copy
    roll
    fuse