{"problem":{"name":"J. Zero Game","description":{"content":"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 ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":524288},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10123J"},"statements":[{"statement_type":"Markdown","content":"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_'.\n\nAdditionally, 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.\n\nThe 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.\n\nFor each query, output one line containing one number: the answer for this query.\n\n## Input\n\nThe 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 \n\n## Output\n\nFor each query, output one line containing one number: the answer for this query.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ S \\in \\{0,1\\}^* $ be the input binary string.  \nLet $ z = |S|_0 $ be the total number of '0's in $ S $.  \nLet $ Q \\in \\mathbb{Z}^+ $ be the number of queries.  \nFor each query $ i \\in \\{1, \\dots, Q\\} $, let $ K_i \\in \\mathbb{Z}_{\\geq 0} $ be the maximum allowed operations.\n\n**Constraints**  \nEach operation consists of moving one character to any other position in $ S $.  \nThe total number of '0's $ z $ is invariant under operations.\n\n**Objective**  \nFor each query $ i $, find the maximum possible length $ L_i $ of a contiguous substring of '0's achievable in $ S $ using at most $ K_i $ operations.  \n\nThat is,  \n$$\nL_i = \\max \\left\\{ \\ell \\in \\mathbb{Z} \\mid 0 \\leq \\ell \\leq z \\text{ and } \\ell \\text{ consecutive '0's can be formed with } \\leq K_i \\text{ moves} \\right\\}\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10123J","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}