403663: GYM101234 J Zero Game

Memory Limit:0 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Zero Gametime limit per test1 secondmemory limit per test512 mebibytesinputstandard inputoutputstandard output

You are given one string S consisting of only '0' and '1'. You are bored, so you start to play with the string. In each operation, you can move any character of this string to some other position in the string. For example, suppose . Then you can move the first zero to the tail, and S will become '0100'.

Additionally, you have Q numbers K1, K2, ..., KQ. For each i, you wonder what can be the maximum number of consecutive zeroes in the string if you start with S and use at most Ki operations. In order to satisfy your curiosity, please write a program which will find the answers for you.

Input

The first line of input contains one string S. The second line of input contains one integer Q. Each of the following Q lines contains one integer Ki indicating the maximum number of operations in i-th query.

  • 2 ≤ N ≤ 106
  • the length of S is exactly N characters
  • S consists of only '0' and '1'
  • 1 ≤ Q ≤ 105
  • N × Q ≤ 2 × 107
  • 1 ≤ Ki ≤ 106
Output

For each query, output one line containing one number: the answer for this query.

ExampleInput
0000110000111110
5
1
2
3
4
5
Output
5
8
9
9
9

加入题单

算法标签: