Flip the number

0

0 votes
Data Structures
Problem

Someone provides you a binary number N and asked you to process the Q queries. In each query, you have been given a number K and want you to flip the first K bits of the number from left to right.

Input

 

  • First-line contains a number X as input denoting the length of the binary number. The next line contains a binary number as input.
  • The next line contains a number Q as input that denotes a total number of queries.
  • Next, Q lines contain an integer K each.

Output


In each query, print the decimal representation of X mod 10+ 7 after the flip.

Constraints

 

  • 1 ≤ |N| ≤ 105 where |N|=X is the length of a binary number
  • 1 ≤ Q ≤ 105
  • 1 ≤ K ≤ |N|

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Initially, the binary number is 011 so the value is 3 but if you will flip the first 2 bits then the number changes to 101 whose value is 5 so the output for the query 1 is 5

Editor Image

?