#B3937. Binary String Transformation

    ID: 11594 Type: Default 1000ms 256MiB

Binary String Transformation

Binary String Transformation

You are given a binary string \( s \) of length \( n \) where each character is either 0 or 1. The \( i \)-th character is denoted as \( s_i \). You need to perform \( q \) operations on the string. Each operation is one of the following types:

  • 1: Reverse the string. That is, the order of characters is reversed. For example, if \( s \) is 10010, after reversing it becomes 01001.
  • 2: Invert the string, namely, for every position \( i \) (\( 1 \leq i \leq n \)), if \( s_i = 0 \) then change it to 1, and if \( s_i = 1 \) then change it to 0.

After performing all \( q \) operations sequentially, output the final state of the binary string \( s \).

inputFormat

The first line contains two integers \( n \) and \( q \) separated by a space. The second line contains the binary string \( s \) of length \( n \). Each of the following \( q \) lines contains one integer representing the operation. The integer is either 1 or 2 corresponding to the two types of operations described above.

outputFormat

Output the final binary string after performing all the operations.

sample

5 2
10010
1
2
10110