Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product, takewhile
# count = 0


def iter_break():
    yield True
    raise StopIteration


def main():
    N, Y = (int(x) for x in input().split(" "))
    y10 = 10000
    y5 = 5000
    y1 = 1000
    max_y10 = Y // y10
    max_y5 = Y // y5
    max_y1 = Y // y1
    if (max_y10) > N:
        max_y10 = N
    if (max_y5) > N:
        max_y5 = N
    if (max_y1) > N:
        max_y1 = N
    # guess = [(x, y, z) for (x, y, z) in
    #          if x+y+z == N]
    # result = list((n_y10, n_y5, n_y1) for n_y10, n_y5,
    #               n_y1 in guess if n_y10 * y10 + n_y5 * y5 + n_y1 * y1 == Y & iter_break())
    for (n_y10, n_y5, n_y1) in product(
        range(max_y10, -1, -1),
        range(max_y5, -1, -1),
            range(max_y1, -1, -1)):
        if (n_y10 + n_y5 + n_y1 != N) or (n_y10 * y10 + n_y5 * y5 + n_y1 * y1 != Y):
            continue
        print(n_y10, n_y5, n_y1)
        exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    main()


Fixed submission:
from itertools import product, takewhile
# count = 0


def iter_break():
    yield True
    raise StopIteration


def main():
    N, Y = (int(x) for x in input().split(" "))
    Y = Y//1000
    y10 = 10
    y5 = 5
    y1 = 1
    max_y10 = Y // y10
    max_y5 = Y // y5
    max_y1 = Y // y1
    if (max_y10) > N:
        max_y10 = N
    if (max_y5) > N:
        max_y5 = N
    # if (max_y1) > N:
    #     max_y1 = N
    for (n_y10, n_y5) in product(
        range(max_y10, -1, -1),
            range(max_y5, -1, -1)):
        n_y1 = N-n_y10-n_y5
        if n_y1 < 0 or (n_y10 * y10 + n_y5 * y5 + n_y1 * y1 != Y):
            continue
        print(n_y10, n_y5, n_y1)
        exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product


def main():
    N, Y = (int(x) for x in input().split(" "))
    y10 = 10000
    y5 = 5000
    y1 = 1000
    max_y10 = Y // y10
    max_y5 = Y // y5
    max_y1 = Y // y1
    if (max_y10) > N:
        max_y10 = N
    if (max_y5) > N:
        max_y5 = N
    if (max_y1) > N:
        max_y1 = N
    for n_y10, n_y5, n_y1 in product(
            range(max_y10, -1, -1),
            range(max_y5, -1, -1),
            range(max_y1, -1, -1)):
        if (n_y10 + n_y5 + n_y1) != N:
            continue
        if n_y10 * y10 + n_y5 * y5 + n_y1 * y1 == Y:
            print(n_y10, n_y5, n_y1)
            exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    main()


Fixed submission:
from itertools import product, takewhile
# count = 0


def iter_break():
    yield True
    raise StopIteration


def main():
    N, Y = (int(x) for x in input().split(" "))
    Y = Y//1000
    y10 = 10
    y5 = 5
    y1 = 1
    max_y10 = Y // y10
    max_y5 = Y // y5
    max_y1 = Y // y1
    if (max_y10) > N:
        max_y10 = N
    if (max_y5) > N:
        max_y5 = N
    # if (max_y1) > N:
    #     max_y1 = N
    for (n_y10, n_y5) in product(
        range(max_y10, -1, -1),
            range(max_y5, -1, -1)):
        n_y1 = N-n_y10-n_y5
        if n_y1 < 0 or (n_y10 * y10 + n_y5 * y5 + n_y1 * y1 != Y):
            continue
        print(n_y10, n_y5, n_y1)
        exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    main()