#K4476. Chain Call Functions

    ID: 27603 Type: Default 1000ms 256MiB

Chain Call Functions

Chain Call Functions

You are given a sequence of operations and an initial input. Each operation represents a function that transforms its argument. The available operations are as follows:

  • ADD_ONE or INCREMENT: Increase the integer value by 1.
  • SQUARE: Square the integer value.
  • DOUBLE: Multiply the integer value by 2.
  • TO_STR: Convert the current integer value into its string representation.
  • IDENTITY: Return the value unchanged.
  • REVERSE: Reverse the string. (If the current value is an integer, it is first converted to a string.)

Starting with an initial value, apply each operation in order. The input guarantees that if an operation expects an integer, then the value will be in integer form, and similarly operations on strings will have a string value.

The final result after applying all operations should be printed to stdout.

Note: The input is to be read from stdin and the output should be written to stdout.

inputFormat

The first line contains a single integer n representing the number of operations.

The second line contains the initial value. This value can be either an integer (which may be negative) or a string.

Each of the next n lines contains one operation. The operation is one of the following strings: ADD_ONE, INCREMENT, SQUARE, DOUBLE, TO_STR, IDENTITY, or REVERSE.

outputFormat

Print the final result obtained after applying the sequence of operations on the initial value. The output should be printed to stdout (if the result is a number, print it as a number; if it is a string, print the string).

## sample
3
3
ADD_ONE
SQUARE
TO_STR
16