Add or Multiply
문제
Your younger sister is playing with a wooden math toy consisting of number and operator blocks. Each number block is printed with a single digit from to , and operator blocks are double-sided; and are printed on each side.
She has just built a math expression by alternating number and operator blocks. The first block is a number, the second is an operator, the third is a number, and so on. She asks, "can you answer the value of the expression?"
Further, she repeatedly makes one of the following moves.
s(swap): Swaps the th and th number blocks.f(flip): Flips the th operator block. Its operator alternates between and .a(all flip): Flips all the operator blocks in the entire math expression.
After her move, you have to quickly answer the updated value (possibly the same as the previous one). Remember that you must perform multiplications earlier than additions.
입력
The first line of input contains two integers () and (), where is the number of integers and is the number of queries.
The second line represents the initial input of characters. Single digits between and are at odd positions, and operators ("+") or ("*") are at even positions.
Each of the next lines represents your sister's move.
The swap move is described as "s " with , where and are the 1-indexed positions to swap. If , then no blocks are swapped.
The flip move is described as "f " with , meaning your sister flips the th operator.
Finally, the all-flip move is described as "a", without additional parameters.
출력
The first line of output should be the value of the initial expression. Then, output more lines, one for each move. Since values can be large, print the value modulo ().
예제
예제 1
3 4 2+3*4 s 1 2 a f 2 a
14 11 10 24 9