Check the String
시간 제한2초메모리 제한1024 MB
copy, swap, roll, fuse 명령을 실행하는 스택 기계를 시뮬레이션하면서 CRASH 발생 여부를 판정하고 마지막 문자열이 s와 같은지 확인한다.
문제
Suppose we have a virtual machine that is described in the statement of problem B.
Given string and a program in the form of a list of commands for the given machine (each command is one from the list "copy", "swap", "roll", "fuse").
Initially, the virtual machine stack contains two strings and looks like "a b".
All commands from the list are sequentially executed on the virtual machine.
Determine if all the commands from the list were executed correctly, or if the execution of one of them resulted with the CRASH event. If all program commands were executed correctly --- additionally determine whether the string at the end of the machine's stack after the execution of all commands is equal to the string or not.
입력
The first line contains the string . It consists only of lowercase Latin letters "a" and "b" and has a length from to characters.
The second line contains an integer ().
The next lines contain the program commands, one per line, ordered in the order of execution on the virtual machine. Each of the commands is one from the list "copy", "swap", "roll", "fuse".
출력
Print exactly one of the following messages:
CRASH--- if theCRASHevent occurred during the execution of the program.YES--- if after executing all the commands the string at the end of the machine's stack is equal to .NO--- if after executing all the commands the string at the end of the stack is not equal to .