Under construction

Still being built. Things may change

Check the String

Time limit2sMemory limit1024 MB

Summary
Given a string s of a and b and a list of stack commands (copy, swap, roll, fuse), report CRASH if a command fails, otherwise whether the final top string equals s.
Level

Medium6 of 10

Topics
String, Simulation, Implementation
Solved
No attempts yet

Problem

Suppose we have a virtual machine that is described in the statement of problem B.

Given a string ss and a program of nn commands for this machine. Each command is one of copy, swap, roll, or fuse. Initially, the stack of the virtual machine contains two strings and looks like "a b". Execute all commands in the list in order.

Determine whether every command executed correctly or whether one of them caused a CRASH event. If every command executed correctly, also determine whether the string at the top of the stack after all commands have run is equal to ss.

Input

The first line contains the string ss. It consists only of the lowercase Latin letters a and b, and its length is between 1 and 10510^5 characters.

The second line contains an integer nn (0≤n≤1050 \le n \le 10^5). The next nn lines contain the commands, one per line, in the order they are executed. Each command is one of copy, swap, roll, or fuse.

Output

Print exactly one of the following messages.

  • CRASH: a CRASH event occurred while the program ran.
  • YES: after all commands run, the string at the top of the stack is equal to ss.
  • NO: after all commands run, the string at the top of the stack is not equal to ss.

Examples3

  1. Example 1

    Input
    ababa
    9
    swap
    copy
    roll
    fuse
    copy
    fuse
    copy
    roll
    fuse
    
    Expected output
    YES
    
  2. Example 2

    Input
    a
    0
    
    Expected output
    NO
    
  3. Example 3

    Input
    aaba
    1
    roll
    
    Expected output
    CRASH