Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    cur = [0]
    while cur:
        nxt = []
        for loc in cur:
            if loc == N:
                a = []
                while loc > 0:
                    w = S[loc]
                    loc -= w
                    a.append(w)
                return ' '.join(str(j) for j in reversed(a))
            for i in range(1, M + 1):
                nloc = loc + i
                if nloc > N or S[nloc]:
                    continue
                S[nloc] = i
                nxt.append(nloc)
        cur = nxt
    return '-1'


print(main())


Fixed submission:
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    loc = N
    a = []
    while loc:
        for i in range(min(loc, M), 0, -1):
            if S[loc - i] == 1:
                continue
            a.append(i)
            loc -= i
            break
        else:
            return '-1'
    return ' '.join(str(i) for i in reversed(a))


print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    cur = [0]
    while cur:
        nxt = []
        for loc in cur:
            if loc == N:
                a = []
                while loc > 0:
                    w = S[loc]
                    loc -= w
                    a.append(w)
                return ' '.join(str(j) for j in reversed(a))
            for i in range(1, M + 1):
                nloc = loc + i
                if nloc > N or S[nloc]:
                    continue
                S[nloc] = i
                nxt.append(nloc)
        cur = nxt
    return '-1'


print(main())


Fixed submission:
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    loc = N
    a = []
    while loc:
        for i in range(min(loc, M), 0, -1):
            if S[loc - i] == 1:
                continue
            a.append(i)
            loc -= i
            break
        else:
            return '-1'
    return ' '.join(str(i) for i in reversed(a))


print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [i == '1' for i in input()]
    cur = [(0, [])]
    while cur:
        nxt = []
        for loc, hist in cur:
            if loc == N:
                return ' '.join(str(j) for j in hist)
            for i in range(1, M + 1):
                nloc = loc + i
                if nloc > N or S[nloc]:
                    continue
                S[nloc] = True
                nxt.append((nloc, hist + [i]))
        cur = nxt
    return '-1'


print(main())


Fixed submission:
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    loc = N
    a = []
    while loc:
        for i in range(min(loc, M), 0, -1):
            if S[loc - i] == 1:
                continue
            a.append(i)
            loc -= i
            break
        else:
            return '-1'
    return ' '.join(str(i) for i in reversed(a))


print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [i == '1' for i in input()]
    cur = [(0, [])]
    while cur:
        nxt = []
        for loc, hist in cur:
            for i in range(1, M + 1):
                nloc = loc + i
                if nloc == N:
                    return ' '.join(str(j) for j in hist + [i])
                elif nloc > N:
                    continue
                elif S[nloc]:
                    continue
                S[nloc] = True
                nxt.append((nloc, hist + [i]))
        cur = nxt
    return '-1'


print(main())


Fixed submission:
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    loc = N
    a = []
    while loc:
        for i in range(min(loc, M), 0, -1):
            if S[loc - i] == 1:
                continue
            a.append(i)
            loc -= i
            break
        else:
            return '-1'
    return ' '.join(str(i) for i in reversed(a))


print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [i == '1' for i in input()]
    cur = [(0, [])]
    while cur:
        nxt = []
        for loc, hist in cur:
            for i in range(1, M + 1):
                nloc = loc + i
                if nloc == N:
                    return ' '.join(str(j) for j in hist + [i])
                elif nloc > N:
                    continue
                elif S[nloc]:
                    continue
                S[nloc] = True
                nxt.append((nloc, hist + [i]))
        cur = nxt
    return '-1'


print(main())


Fixed submission:
def main():
    N, M  = [int(i) for i in input().split()]
    S  = [int(i) for i in input()]
    loc = N
    a = []
    while loc:
        for i in range(min(loc, M), 0, -1):
            if S[loc - i] == 1:
                continue
            a.append(i)
            loc -= i
            break
        else:
            return '-1'
    return ' '.join(str(i) for i in reversed(a))


print(main())