#C4471. String Operation Manipulator

    ID: 48013 Type: Default 1000ms 256MiB

String Operation Manipulator

String Operation Manipulator

You are given an initial string s and a sequence of n operations to perform on the string. There are three types of operations:

  • R (Reverse): Reverse the substring of s from index x to y (inclusive). Indices are 0-indexed.
  • C (Concatenate): Concatenate a given string x to the end of s.
  • S (Subset): Check whether every character in string x appears in string y with at least the same frequency. If so, output YES; otherwise, output NO and terminate further operations.

If no subset operation is executed (or if a subset operation is executed only after other operations), then the operations are performed sequentially and the final string is printed at the end. Note that for a subset operation, your program should terminate immediately after printing the result (YES or NO), and not process any further operations.

Note: All indices are 0-indexed.

inputFormat

The input is given in the following format from stdin:

&s
n
operation_1
operation_2
...
operation_n

Here, &s is the initial string, n is an integer representing the number of operations, and each of the next n lines describes an operation.

  • For a reverse operation, the line will be: R x y where x and y are integers indicating the start and end indices respectively.
  • For a concatenation operation, the line will be: C string_to_append.
  • For a subset operation, the line will be: S x y where x and y are strings.

outputFormat

Output the final string s after performing all operations. However, if a subset operation is executed, output either YES or NO according to the condition and terminate the program immediately.

All outputs should be printed to stdout.

## sample
abcde
3
R 1 3
C xyz
S xyz deab
NO