시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB32266.667%

문제

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 $S = \text{'0010'}$. Then you can move the first zero to the tail, and $S$ will become '0100'.

Additionally, you have $Q$ numbers $K_1, K_2, \ldots, K_Q$. 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 $K_i$ operations. In order to satisfy your curiosity, please write a program which will find the answers for you.

입력

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 $K_i$ indicating the maximum number of operations in $i$-th query.

출력

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

제한

  • $2 \le N \le 10^6$
  • the length of $S$ is exactly $N$ characters
  • $S$ consists of only '0' and '1'
  • $1 \le Q \le 10^5$
  • $N \times Q \le 2 \times 10^7$
  • $1 \le K_i \le 10^6$

예제 입력 1

0000110000111110
5
1
2
3
4
5

예제 출력 1

5
8
9
9
9