Under construction

Still being built. Things may change

Add or Multiply

Time limit7sMemory limit1024 MB

Summary
Given a digit expression with + and × operators, report its value modulo 1e9+7 after each swap of digits, single operator flip, or flip of all operators.
Level

Medium6 of 10

Topics
Segment tree, Math
Solved
No attempts yet

Problem

Your younger sister is playing with a wooden math toy made of number blocks and operator blocks. Each number block shows a single digit from 1 to 9. Each operator block is double-sided, and each side shows + or ×.

She has 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 whether you can find the value of the expression.

She then repeatedly makes one of the following moves.

  • s ii jj (swap): Swaps the iith and jjth number blocks.
  • f ii (flip): Flips the iith operator block. Its operator alternates between + and ×.
  • a (all flip): Flips all the operator blocks in the expression.

After each move, you must quickly answer the updated value, which may be the same as the previous one. Remember that multiplication is performed before addition.

Input

The first line contains two integers NN (2≤N≤2×1052 \leq N \leq 2 \times 10^5) and MM (1≤M≤2×1051 \leq M \leq 2 \times 10^5), where NN is the number of integers and MM is the number of queries.

The second line contains the initial expression of 2N−12N - 1 characters. Single digits from 1 to 9 are at odd positions, and operators + or * are at even positions.

Each of the next MM lines describes one move.

  • The swap move is given as s ii jj, with 1≤i,j≤N1 \leq i, j \leq N. If i=ji = j, no blocks are swapped.
  • The flip move is given as f ii, with 1≤i≤N−11 \leq i \leq N-1, meaning the iith operator is flipped.
  • The all-flip move is given as a, with no other parameters.

Output

On the first line, print the value of the initial expression. Then print MM more lines, one for each move, containing the value after that move. Print each value modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    3 4
    2+3*4
    s 1 2
    a
    f 2
    a
    
    Expected output
    14
    11
    10
    24
    9