#K51917. Process Operations

    ID: 29194 Type: Default 1000ms 256MiB

Process Operations

Process Operations

You are given an initial integer value and a string of operations. Each character in the string represents an arithmetic operation to be performed sequentially on the initial value. The operations are defined as follows:

  • A: Add 1 to the current value.
  • S: Subtract 1 from the current value.
  • M: Multiply the current value by 2.
  • D: Perform an integer division of the current value by 2 (i.e. floor division).

Your task is to apply each operation in order and output the final resulting value.

For example, if the initial value is 10 and the operations string is AMSD, the sequence of operations will be:

\(10 \xrightarrow{A} 11 \xrightarrow{M} 22 \xrightarrow{S} 21 \xrightarrow{D} 10\)

Thus, the final output is 10.

Note: The operations are applied from left to right.

inputFormat

The input consists of two lines:

  1. The first line contains a single integer, the initial value.
  2. The second line contains a string of characters where each character is one of 'A', 'S', 'M', or 'D', representing the operations.

outputFormat

Output a single integer — the final value obtained after processing all the given operations.

## sample
10
AMSD
10