Buggy python submission (verdict: Time Limit Exceeded):
m = 10000
g = 5000
s = 1000
n, y = map(int, input().split())
if y > n * m or y < n * s:
    print("-1 -1 -1")
    exit()
if y / n == 10000:
    print(n, "0 0")
    exit()
elif y / n == 5000:
    print("0", n, "0")
    exit()
elif y / n == 1000:
    print("0 0", n)
    exit()
if y / n > 7500:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    else:
        print("-1 -1 -1")
elif y/n > 3000:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1 - i):
                if i * s + j * m + h * g == y and i + j + h == n:
                    print(j, h, i)
                    exit()
    else:
        print("-1 -1 -1")
else:
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1 - i):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    else:
        print("-1 -1 -1")

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy python submission (verdict: Time Limit Exceeded):
m = 10000
g = 5000
s = 1000
n, y = map(int, input().split())
if y > n * m or y < n * s:
    print("-1 -1 -1")
    exit()
if y / n == 10000:
    print(n, "0 0")
    exit()
elif y / n == 5000:
    print("0", n, "0")
    exit()
elif y / n == 1000:
    print("0 0", n)
    exit()
if y / n > 7500:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    else:
        print("-1 -1 -1")
elif y/n > 3000:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * m + h * g == y and i + j + h == n:
                    print(j, h, i)
                    exit()
    else:
        print("-1 -1 -1")
else:
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    else:
        print("-1 -1 -1")

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy python submission (verdict: Time Limit Exceeded):
m = 10000
g = 5000
s = 1000
n, y = map(int, input().split())
if y > n * m or y < n * s:
    print("-1 -1 -1")
    exit()
if y / n == 10000:
    print(n, "0 0")
    exit()
elif y / n == 5000:
    print("0", n, "0")
    exit()
elif y / n == 1000:
    print("0 0", n)
    exit()
if y / n > 5000:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    else:
        print("-1 -1 -1")
else:
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    else:
        print("-1 -1 -1")

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy python submission (verdict: Time Limit Exceeded):
m = 10000
g = 5000
s = 1000
n, y = map(int, input().split())
if y > n * m or y < n * s:
    print("-1 -1 -1")
    exit()
if y / n == 10000:
    print(n, "0 0")
    exit()
elif y / n == 5000:
    print("0", n, "0")
    exit()
elif y / n == 1000:
    print("0 0", n)
    exit()
if y / n > 5000:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    else:
        print("-1 -1 -1")
else:
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    else:
        print("-1 -1 -1")

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Buggy python submission (verdict: Time Limit Exceeded):
m = 10000
g = 5000
s = 1000
n, y = map(int, input().split())
if y > n * m or y < n * s:
    print("-1 -1 -1")
    exit()
if y / n == 10000:
    print(n, "0 0")
    exit()
elif y / n == 5000:
    print("0", n, "0")
    exit()
elif y / n == 1000:
    print("0 0", n)
    exit()
if y / n > 5000:
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    else:
        print("-1 -1 -1")
else:
    for i in range(n):
        for j in range(n-i+1):
            for h in range(n-j+1):
                if i*m+j*g+h*s==y and i+j+h == n:
                    print(i, j, h)
                    exit()
    for i in range(n):
        for j in range(n - i+1):
            for h in range(n - j+1):
                if i * s + j * g + h * m == y and i + j + h == n:
                    print(h, j, i)
                    exit()
    else:
        print("-1 -1 -1")

Fixed submission:
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")