Problem:
 Score : 600 points    Problem Statement Takahashi is playing a board game called Sugoroku.  On the board, there are N + 1 squares numbered 0 to N . Takahashi starts at Square 0 , and he has to stop exactly at Square N to win the game.  The game uses a roulette with the M numbers from 1 to M . In each turn, Takahashi spins the roulette. If the number x comes up when he is at Square s , he moves to Square s+x . If this makes him go beyond Square N , he loses the game.  Additionally, some of the squares are Game Over Squares. He also loses the game if he stops at one of those squares. You are given a string S of length N + 1 , representing which squares are Game Over Squares. For each i  (0 \leq i \leq N) , Square i is a Game Over Square if S[i] = 1 and not if S[i] = 0 .  Find the sequence of numbers coming up in the roulette in which Takahashi can win the game in the fewest number of turns possible. If there are multiple such sequences, find the lexicographically smallest such sequence. If Takahashi cannot win the game, print -1 .      Constraints  1 \leq N \leq 10^5  1 \leq M \leq 10^5  |S| = N + 1  S consists of 0 and 1 .  S[0] =  0  S[N] =  0         Input Input is given from Standard Input in the following format:  N  M  S       Output If Takahashi can win the game, print the lexicographically smallest sequence among the shortest sequences of numbers coming up in the roulette in which Takahashi can win the game, with spaces in between.  If Takahashi cannot win the game, print -1 .        Sample Input 1 9 3
0001000100      Sample Output 1 1 3 2 3  If the numbers 1 , 3 , 2 , 3 come up in this order, Takahashi can reach Square 9 via Square 1 , 4 , and 6 . He cannot reach Square 9 in three or fewer turns, and this is the lexicographically smallest sequence in which he reaches Square 9 in four turns.       Sample Input 2 5 4
011110      Sample Output 2 -1  Takahashi cannot reach Square 5 .       Sample Input 3 6 6
0101010      Sample Output 3 6

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,m = ma()
s = input()
dp = [-1]*(n+1) 
dp[0]=0
r=0
while r<=n-1:
    l=0
    tmp=0
    while l+1<=m and r+l+1<=n:
        l+=1
        if s[r+l]=="0":
            tmp=l
            dp[r+l]=dp[r]+1
    r+=tmp
    
    if tmp==0:
        print(-1)
        exit()
d = dp[-1]
rt = []
dp = dp[::-1]
r=0
while r<=n-1:
    l=0
    tmp=0
    while l+1<=m and r+l+1<=n:
        l+=1
        if dp[r+l]==d-1:
            tmp=l
    rt.append(tmp)
    d-=1
    r+=tmp
print(*reversed(rt))

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()




class SegmentTree:

    __slots__ = ["func", "e", "original_size", "n", "data"]

    def __init__(self, length_or_list, func=max, e=-10**18):
        self.func = func
        self.e = e
        if isinstance(length_or_list, int):
            self.original_size = length_or_list
            self.n = 1 << ((length_or_list - 1).bit_length())
            self.data = [self.e] * (self.n*2)
        else:
            self.original_size = len(length_or_list)
            self.n = 1 << ((self.original_size - 1).bit_length())
            self.data = [self.e] * self.n + length_or_list + \
                [self.e] * (self.n - self.original_size)
            for i in range(self.n-1, 0, -1):
                self.data[i] = self.func(self.data[2*i], self.data[2*i+1])

    def replace(self, index, value):
        index += self.n
        self.data[index] = value
        index //= 2
        while index > 0:
            self.data[index] = self.func(
                self.data[2*index], self.data[2*index+1])
            index //= 2

    def folded(self, l, r):
        left_folded = self.e
        right_folded = self.e
        l += self.n
        r += self.n
        while l < r:
            if l % 2:
                left_folded = self.func(left_folded, self.data[l])
                l += 1
            if r % 2:
                r -= 1
                right_folded = self.func(self.data[r], right_folded)
            l //= 2
            r //= 2
        return self.func(left_folded, right_folded)

    def all_folded(self):
        return self.data[1]

    def __getitem__(self, index):
        return self.data[self.n + index]

    def max_right(self, l, f):
        
        if l >= self.original_size:
            return self.original_size
        l += self.n
        left_folded = self.e
        while True:
            
            while l % 2 == 0:
                l //= 2
            if not f(self.func(left_folded, self.data[l])):
                while l < self.n:
                    l *= 2
                    if f(self.func(left_folded, self.data[l])):
                        left_folded = self.func(left_folded, self.data[l])
                        l += 1
                return l - self.n
            left_folded = self.func(left_folded, self.data[l])
            l += 1
            if l == l & -l:
                break
        return self.original_size

    
    def min_left(self, r, f):
        
        if r == 0:
            return 0
        r += self.n
        right_folded = self.e
        while True:
            r //= r & -r
            if not f(self.func(self.data[r], right_folded)):
                while r < self.n:
                    r = 2 * r + 1
                    if f(self.func(self.data[r], right_folded)):
                        right_folded = self.func(self.data[r], right_folded)
                        r -= 1
                return r + 1 - self.n
            if r == r & -r:
                break
        return 0


def minindex(x, y):
    if x[0] <= y[0]:
        return x
    else:
        return y


def main():
    n, m = map(int, input().split())
    S = list(map(lambda x: 0 if x == '0' else 10**10, list(input())))
    roots = [10**10]*(n+1)
    for i in range(1, min(m+2, n+1)):
        if S[i] < 10**9:
            S[i] = 1
            roots[i] = 0
    S = [[s, i] for i, s in enumerate(S)]
    seg = SegmentTree(S, minindex, [10**12, 10**12])
    for i in range(m+1, n+1):
        if S[i][0] < 10**9:
            dist, masu = seg.folded(i-m, i)
            roots[i] = masu
            seg.replace(i, [dist+1, i])
    
    
    if seg.folded(n, n+1)[0] > 10**9:
        print(-1)
    else:
        ans = []
        while n > 0:
            ans.append(n-roots[n])
            n = roots[n]
        print(*ans[::-1], sep=" ")


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
S = input()[::-1]

"""
スタートから貪欲に考えようとすると
「最短で行くために大きい目を出したい」と
「辞書順最小のために小さい目を出したい」が共存してやりづらい

ゴールから貪欲に考える（出来るだけ多く戻る）と考えると
「最短で行くために大きい目を出したい」と
「辞書順最小のために、最後の手を出来るだけ小さくしたい
 -> 後ろから考えて、大きい目を出せば良い」となり
貪欲に解ける
"""

ans = []

now = 0

while True:
    
    
    if now + M >= N:
        ans.append(N - now)
        break

    
    step = M
    
    while S[now + step] == '1':
        step -= 1
        
        if step == 0:
            print(-1)
            exit()

    now += step
    ans.append(step)

print(*ans[::-1])

Solution (Python):



n, m = map(int, input().split())
s = input()
s = s[::-1]
INF = 2*n

if '1'*m in s:
    print(-1)
    exit()

dp = [-1] * (n+1)
nw = 0
st = 0
nst = 0
ret = []
while nw < (n+1):
    if s[nw]=='1':
        dp[nw] = INF
    else:
        dp[nw] = dp[st] + 1
        nst = nw
    nw += 1
    if nw == n+1:
        ret.append(nst-st)
    elif nw > st + m:
        ret.append(nst-st)
        st = nst
print(' '.join(map(str,ret[::-1])))

Solution (Python):
N, M = map(int, input().split())
S = input()
if N <= M:
  print(N)
  exit()
if '1'*M in S:
  print(-1)
  exit()

from collections import deque
count = deque([])
for k in range(M+1):
  if S[k] == '1':
    count.append(-1)
  else:
    count.append(k)
sgn = deque([])
k = 0
while k < N:
  k += 1
  if S[k] == '0':
    sgn.append(M)
  else:
    d = 0
    while k < N:
      if S[k] == '1':
        k += 1
        d += 1
        continue
      else:
        break
    while d > 0:
      sgn.append(M-d)
      d -= 1
    sgn.append(M)
now = M
while now < N:
  now += 1
  a = sgn.popleft()
  if S[now] == '1':
    count.append(-1)
  else:
    count.append(a)
count = list(count)  
c = 0
ans = ''
while c < N:
  ans = str(count[-1-c]) + ' ' + ans
  c += count[-1-c]

print(ans)

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N, M = LI()
    S = SL()

    ans = []
    tmp = 0
    checkpoint = -1

    for e in S[:-1][::-1]:
        tmp += 1
        if e == "0":
            if tmp >= M:
                ans.append(tmp)
                tmp = 0
                checkpoint = -1
            else:
                checkpoint = tmp
        else:
            if tmp >= M:
                if checkpoint == -1: break
                ans.append(checkpoint)
                tmp -= checkpoint
                checkpoint = -1
    else:
        if tmp > 0:
            ans.append(tmp)
        print(*ans[::-1])
        return
    print(-1)



if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
s=[int(s) for s in input()][::-1]
i=0
k=m
cnt=0
a=[]
while i<n:
  j=-1
  while i<n and k:
    k-=1
    i+=1
    if s[i]==0:j=i
  if j==-1:
    print(-1)
    exit()
  a+=[j]
  k=m-i+j
  cnt+=1
for i in range(len(a)-1,0,-1):
  a[i]-=a[i-1]
print(*a[::-1])

Solution (Python):
from sys import exit

n, m = map(int, input().split())
s = input()[::-1]

res = []
pos = 0
while True:
    if pos + m >= n:
        res.append(n - pos)
        break

    step = m
    while s[pos + step] == '1':
        step -= 1
        if step == 0:
            print(-1)
            exit()
    
    pos += step
    res.append(step)
    
print(*res[::-1])

Solution (Python):
from sys import exit

n, m = map(int, input().split())
s = input()[::-1]

res = []
pos = 0
while True:
    if pos + m >= n:
        res.append(n - pos)
        break

    step = m
    while s[pos + step] == '1':
        step -= 1
        if step == 0:
            print(-1)
            exit()
    
    pos += step
    res.append(step)
    
print(*res[::-1], sep=' ')

Solution (Python):
N,M = map(int,input().split())
S = input()
RS = S[::-1]

"""
ゴール側から考えれば、自然と辞書順最小になる。（気がする）
前処理で各セーフマスから最も近い前方のセーフマスの位置を求めておく。
nxSafe[i] =>　ゴールからスタートに進むとして、ゴールからiマス目の次のセーフゾーンのインデックス
"""
nxSafe = [None]*(N+1)
safe = N
for i in range(N-1,-1,-1):
    if RS[i] == "0":
        nxSafe[i] = safe
        safe = i

cur = 0
ans = []
while cur < N:
    tmp = cur
    while True:
        if tmp == N:
            break
        if nxSafe[tmp] - cur <= M:
            tmp = nxSafe[tmp]
        else:
            break
    if cur == tmp:
        print(-1)
        exit()
    ans.append(str(tmp-cur))
    cur = tmp
ans = ans[::-1]
print(" ".join(ans))

Solution (Python):
N, M = map(int, input().split())
S = input()

index = N
count = 0
history = []
while index > 0:
    start = max(0, index - M)
    for i, c in enumerate(S[start:index], start=start):
        if c == '0':
            history.append(index - i)
            index = i
            count += 1
            break
    else:
        print(-1)
        exit()

print(*history[::-1])

Solution (Python):
N, M = map(int, input().split())
S = list(map(int, list(input())))
S.reverse()

ans = []

i=0
while i < N:
  max = 0
  for j in range(1, M+1):
    if i + j < N+1:
      if S[i+j] == 0:
        max = j
  if max == 0:
    print(-1)
    exit()
  ans.insert(0, max)
  i += max
for i in ans:
  print(i,end=" ")

Solution (Python):
N,M=map(int,input().split())
A,c,dp,r=[0]*N,0,0,[]
for i, s in enumerate(reversed(input())):
    if s=="1":c+=1;A[i]=c
    else:c=0
while dp+M<=N-1:
    t = M-A[dp+M]
    if t>0: dp+=t
    else:print(-1);exit()
    r.append(t)
r.append(N-dp)
print(*reversed(r))

Solution (Python):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
    if s=="1":
        cnt += 1
        A[i] = cnt
    else:
        cnt = 0
dp = 0
res = []
while dp+M <= N-1:
    t = M - A[dp+M]
    if t>0:
        dp += t
    else:
        print(-1)
        exit()
    res.append(t)
res.append(N-dp)
res.reverse()
print(*res)

Solution (Python):
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
    if s=="1":
        cnt += 1
        A[i] = cnt
    else:
        cnt = 0
dp = 0
res = []
while dp+M <= N-1:
    t = M - A[dp+M]
    if t>0:
        dp += t
    else:
        print(-1)
        exit()
    res.append(t)
res.append(N-dp)
res.reverse()
print(*res)

Solution (Python):
import sys

N, M = map(int, input().split())
S = input()[::-1]
ans = ''
i = 0
while i < N - M:
    found = False
    for j in range(M, 0, -1):
        if S[i + j] == '0':
            ans += str(j) + ' '
            i += j
            found = True
            break
    if not found:
        print(-1)
        sys.exit()
ans += str(N-i)
print(' '.join(ans.split()[::-1]))

Solution (Python):
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter



input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)



def solve():
    n, m = getList()
    li = []
    ans = []
    for i, c in enumerate(getS()):
        if c == "0":
            li.append(i)
    cur = n
    while True:
        
        ins = cur - m
        ind = bisect_left(li, ins)
        tgt = li[ind]
        if cur == tgt:
            print(-1)
            return

        ans.append(cur - tgt)
        if tgt == 0:
            break
        cur = tgt

    ans.reverse()
    print(*ans)





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):
N,M = map(int,input().split())
S = input()[::-1]
ans = []
cur = 0
while cur < N:
    for i in range(1,min(M+1,N-cur+1))[::-1]:
        if S[cur+i] == '0':
            ans.append(i)
            cur += i
            break
    else:
        print(-1)
        exit()
print(*ans[::-1])

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, M = in_nn()
    S = in_s()

    ans = []
    now = N
    while now > 0:
        next = -1
        end = max(0, now - M)
        for i in range(now - 1, end - 1, -1):
            if S[i] == '0':
                next = i
        if next == -1:
            print(-1)
            exit()
        else:
            ans.append(now - next)
            now = next

    ans = ans[::-1]
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, M = in_nn()
    S = in_s()

    ans = []
    now = N
    while now > 0:
        next = -1
        end = max(0, now - M)
        for i in range(now - 1, end - 1, -1):
            if S[i] == '0':
                next = i
        if next == -1:
            print(-1)
            exit()
        else:
            ans.append(now - next)
            now = next

    ans = ans[::-1]
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
s=input()

ans=[]
s=s[::-1]

now=0
while now<n:
    for i in range(m,0,-1):
        if now+i<=n and s[now+i]=="0":
            ans.append(i)
            now=now+i
            break
    else:
        print(-1)
        break
else:
    ans=[str(i) for i in ans]
    print(" ".join(ans[::-1]))

Solution (Python):

class SegmentTree:
    def __init__(self, size, fn=min, default=None, initial_values=None):
        """
        :param int size:
        :param callable fn: 区間に適用する関数。引数を 2 つ取る。min, max, operator.xor など
        :param default:
        :param list initial_values:
        """
        default = default or 0

        
        n = 1
        while n < size:
            n *= 2
        self._size = n
        self._fn = fn

        self._tree = [default] * (self._size * 2 - 1)
        if initial_values:
            i = self._size - 1
            for v in initial_values:
                self._tree[i] = v
                i += 1
            i = self._size - 2
            while i >= 0:
                self._tree[i] = self._fn(self._tree[i * 2 + 1], self._tree[i * 2 + 2])
                i -= 1

    def set(self, i, value):
        """
        i 番目に value を設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self._tree[x] = value

        while x > 0:
            x = (x - 1) // 2
            self._tree[x] = self._fn(self._tree[x * 2 + 1], self._tree[x * 2 + 2])

    def update(self, i, value):
        """
        もとの i 番目と value に fn を適用したものを i 番目に設定
        :param int i:
        :param value:
        :return:
        """
        x = self._size - 1 + i
        self.set(i, self._fn(self._tree[x], value))

    def get(self, from_i, to_i=None, k=0, L=None, r=None):
        """
        [from_i, to_i) に fn を適用した結果を返す
        :param int from_i:
        :param int to_i:
        :param int k: self._tree[k] が、[L, r) に fn を適用した結果を持つ
        :param int L:
        :param int r:
        :return:
        """
        if to_i is None:
            return self._tree[self._size - 1 + from_i]

        L = 0 if L is None else L
        r = self._size if r is None else r

        if from_i <= L and r <= to_i:
            return self._tree[k]

        if to_i <= L or r <= from_i:
            return None

        ret_L = self.get(from_i, to_i, k * 2 + 1, L, (L + r) // 2)
        ret_r = self.get(from_i, to_i, k * 2 + 2, (L + r) // 2, r)
        if ret_L is None:
            return ret_r
        if ret_r is None:
            return ret_L
        return self._fn(ret_L, ret_r)

    def __len__(self):
        return self._size


def resolve():
    INF = float('inf')
    N, M = map(int, input().split())
    S = input()

    dp = [INF] * (N + 1)
    dp[0] = 0

    seg = SegmentTree(N + 1, min, INF)
    seg.update(N, 0)
    for i in range(N - 1, -1, -1):
        if S[i] == '1':
            continue
        
        dp[i] = seg.get(i, i + M + 1) + 1
        seg.update(i, dp[i])

    ans = []
    position = 0
    while position < N:
        for move in range(1, M + 1):
            if position + move > N:
                continue
            if S[position + move] == '1':
                continue

            
            if dp[position + move] == dp[position]:
                continue

            ans.append(move)
            position += move
            break

        else:
            print(-1)
            return

    print(*ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import deque

N, M = map(int, input().split())
S = input()[::-1] +'1'*M

if M >= N:
  print(N)
  exit()
  
q = deque([])

i = 0
j = 0
while i < N:
  f = 0
  for k in range(i+M,j,-1):
    if S[k] == '0':
      f = 1
      break
  j = i + M
  q.appendleft(k-i)
  i = k
  if f == 0:
    print(-1)
    exit()

print(' '.join(map(str, q)))

Solution (Python):
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
S = list(input().rstrip())

def cost(S):
    minCost = [-1]*(N+1)
    minCost[0] = 0
    ind = 1
    for i,s in enumerate(S):
        if s == "1":
            continue
        while i < ind <= min(i+M, N):
            if S[ind] == "0":
                minCost[ind] = minCost[i] + 1
            ind += 1
    return minCost

M1 = cost(S)
M2 = cost(S[::-1])[::-1]
if M1[-1] == -1:
    print(-1)
else:
    C = M1[-1]
    Inds = [10**14]*(C+1)
    for i, (m1, m2) in enumerate(zip(M1, M2)):
        if m1 + m2 == C:
            Inds[m1] = min(Inds[m1], i)
    ans = []
    for i1, i2 in zip(Inds, Inds[1:]):
        ans.append(i2-i1)
    print(*ans)

Solution (Python):
n, m = map(int,input().split())
s = list(input())

s.reverse()
ng = False
c = 0
ans = []
while ng == False and c < n:
    for i in range(m, 0, -1):
        if c+i < n+1 and s[c+i] == '0':
            c += i
            ans.append(str(i))
            break
        elif i == 1:
            ng = True
if ng:
    print(-1)
else:
    ans.reverse()
    print(' '.join(ans))

Solution (Python):

import sys
def main(N, M, S):
    ans = []
    i = N
    while i > 0:
        for j in range(max(0, i - M), i):
            if S[j] == '0':
                ans.append(i - j)
                i = j
                break
        else:
            print(-1)
            return
    print(*list(reversed(ans)))

if __name__ == '__main__':
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = input().rstrip()
    main(N, M, S)

Solution (Python):
n, m = map(int, input().split())
s = input()
 
x = n
roulette = []
while x > m:
    for i in range(m, 0, -1):
        if s[x-i] == '0':
            x -= i
            roulette.append(i)
            break
    else:
        print(-1)
        exit()
roulette.append(x)
roulette.reverse()
print(' '.join(map(str, roulette)))

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

N, M = list(map(int, input().split()))
S = input()

m = N
record = []
while True:
    for i in range(M,-1,-1):
        if i == 0:
            print(-1)
            sys.exit()
        if m-i < 0: continue
        if S[m-i] == "0":
            m = m - i
            record.append(str(i))
            if m == 0:
                print(" ".join(reversed(record)))
                sys.exit()
            break

Solution (Python):
def solve():
  N, M = map(int, input().split())
  S = input()
  ans = []
  visited = [False]*(N+1)
  visited[-1] = True
  now = N
  while True:
    i = min(M,now)
    visited[now-i] = True
    while S[now-i]=='1':
      i -= 1
      if visited[now-i]==True:
        return [-1]
      visited[now-i] = True
    ans.append(i)
    if now-i==0:
      return ans[::-1]
    now -= i
print(*solve())

Solution (Python):

import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
s = input()


INF = float('inf')
r = [INF for _ in range(n+1)]
r[n] = 0
idx = n
for i in range(n-1,-1,-1):
  while(idx-i > m or r[idx] == INF):
    idx -= 1
  if idx <= i:
    print(-1)
    exit()
  if s[i] == '0':
    r[i] = r[idx]+1
    p = r[i]




ans = []
c = 0
for i in range(n+1):
  if r[i] != INF and r[i] != p:
    p = r[i]
    ans.append(c)
    c = 1
  else:
    c += 1
print(*ans)

Solution (Python):

import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
s = input()


INF = float('inf')
r = [INF for _ in range(n+1)]
r[n] = 0
idx = n
for i in range(n-1,-1,-1):
  while(idx-i > m or r[idx] == INF):
    idx -= 1
  if idx <= i:
    print(-1)
    exit()
  if s[i] == '0':
    r[i] = r[idx]+1
    p = r[i]




ans = []
c = 0
for i in range(n+1):
  if r[i] != INF and r[i] != p:
    p = r[i]
    ans.append(c)
    c = 1
  else:
    c += 1
print(*ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





def segfunc(x, y):
    return min(x, y)

ide_ele = float('inf')

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res



N, M = getNM()
S = input()
trap = set()
for i in range(len(S)):
    if S[i] == '1':
        trap.add(i)













dp = [float('inf')] * (N + 1)
dp[0] = 0
seg = SegTree([float('inf')] * (N + 1), segfunc, ide_ele)
seg.update(0, 0)


for i in range(1, N + 1):
    
    if i in trap:
        continue
    
    min_t = seg.query(max(0, i - M), i)
    seg.update(i, min_t + 1)
    dp[i] = min_t + 1


if dp[-1] == float('inf'):
    print(-1)
    exit()


dis = [[] for i in range(dp[-1] + 1)]
for i in range(len(dp)):
    if dp[i] == float('inf'):
        continue
    dis[dp[i]].append(i)


now = dp[-1]
now_index = N
ans = []


for i in range(now, 0, -1):
    
    
    
    index = bisect_left(dis[i - 1], now_index - M)
    
    ans.append(now_index - dis[i - 1][index])
    
    now_index = dis[i - 1][index]

for i in ans[::-1]:
    print(i)