Problem:
 Score : 300 points    Problem Statement The commonly used bills in Japan are 10000 -yen, 5000 -yen and 1000 -yen bills. Below, the word "bill" refers to only these.  According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.      Constraints  1 ≤ N ≤ 2000  1000 ≤ Y ≤ 2 × 10^7  N is an integer.  Y is a multiple of 1000 .         Input Input is given from Standard Input in the following format:  N  Y       Output If the total value of N bills cannot be Y yen, print -1 -1 -1 .  If the total value of N bills can be Y yen, let one such set of bills be " x  10000 -yen bills, y  5000 -yen bills and z  1000 -yen bills", and print x , y , z with spaces in between. If there are multiple possibilities, any of them may be printed.        Sample Input 1 9 45000      Sample Output 1 4 0 5  If the envelope contained 4  10000 -yen bills and 5  1000 -yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9  5000 -yen bills, so the output 0 9 0 is also correct.       Sample Input 2 20 196000      Sample Output 2 -1 -1 -1  When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000 -yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.       Sample Input 3 1000 1234000      Sample Output 3 14 27 959  There are also many other possibilities.       Sample Input 4 2000 20000000      Sample Output 4 2000 0 0

Solution (Python):
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i):
        total = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if total == y:
            print(i, j, n - i -j)
            exit()
print('-1 -1 -1')

Solution (Python):
import os

n,y = (int(x) for x in input().split())

for i in range(n+1):
    for j in range(n-i+1):
            if 10000*i+5000*j+1000*(n-i-j)==y:
                print(" ".join([str(i),str(j),str(n-i-j)]))
                exit()
print(" ".join([str(-1),str(-1),str(-1)]))

Solution (Python):
N,Y = [int(x) for x in input().split()]
for i in range(N+1):
  for j in range(N+1-i):
    k =N-i-j
    a = i*10000+j*5000+k*1000
    if a==Y:
      print(i,j,k)
      exit()
print(-1,-1,-1)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, y = list(map(int, input().rstrip('\n').split()))
    for i in range(n + 1):
        for j in range(n + 1 - i):
            t = n - i - j
            if 0 <= i <= n and 0 <= j <= n and 0 <= t <= n:
                if i + j + t == n and i * 10000 + j * 5000 + t * 1000 == y:
                    print(i, j, t)
                    exit()
            elif i + j > n or i * 10000 + j * 5000 > y:
                break
    print(-1, -1, -1)


if __name__ == '__main__':
    slove()

Solution (Python):
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")

Solution (Python):
n,y = map(int,input().split())
y = y//1000

greed = 10*n
target = greed - y
if target<0:
    print(-1,-1,-1)
    exit()

for c in range(0,n+1):
    if (target-9*c)%5==0:
        b = (target-9*c)//5
        a = n - b - c
        if 0<=a and 0<=b:
            print(a,b,c)
            exit()
print(-1,-1,-1)

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

i,j,k = 0,0,0
for x in range(N + 1):
    for y in range((N + 1) - x):
        if 4 * y == int(Y / 1000) - N - 9 * x:
            i = x
            j = y
            k = N - x - y
            break
        else:
            continue
if i == 0 and j == 0 and k == 0:
    print(-1,-1,-1)
else:
    print(i,j,k)

Solution (Python):
n,y=map(int,input().split())
ans=[-1]*3
y//=1000
for i in range(n+1):
    for j in range(n-i+1):
        if i*9+j*4+n==y:ans=[i,j,n-i-j]
print(*ans)

Solution (Python):
import sys

A = 10000
B = 5000
C = 1000

input = input()
inputs = input.split(' ')
n = int(inputs[0])
y = int(inputs[1])

for i in range(n+1):
    for j in range(n+1):
        if (A*i + B*j + C*(n-i-j) == y) & (n-i-j >= 0):
            print(str(i) + ' ' + str(j) + ' ' + str(n-i-j))
            sys.exit()

print('-1 -1 -1')

Solution (Python):
n, y = list(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")

Solution (Python):
import sys


n, Y = [int(_) for _ in input().split()]
x = -1
y = -1
z = -1
a = Y // 10000
for i in range(0, a+1):
    for j in range(0, n-i+1):
        if Y == 10000*i + 5000*j + 1000*(n-i-j):
            x = i
            y = j
            z = n-i-j
            print(x, y, z)
            sys.exit()
print(x, y, z)

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

if y%1000 != 0:
    print("-1 -1 -1")
else:
    for i in range(n+1):
        for j in range(n-i+1):
            if 10000*i + 5000*j + 1000*(n - i - j) == y:
                print(str(i) + " " + str(j) + " " + str(n - i - j))
                exit()
    print("-1 -1 -1")

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

a,b,c = 10000, 5000, 1000

for x in range(N,-1,-1):
    if a*x > Y:
        continue
    for y in range(N-x,-1,-1):
        z = N-x-y
        if a*x+b*y+c*z == Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())
ind = 0
for i in range(min(N,Y//10000)+1):
    for j in range(min(N-i,(Y-10000*i)//5000)+1):
        if (Y-10000*i-5000*j)%1000==0 and i+j+(Y-10000*i-5000*j)//1000==N:
            a= i
            b= j
            c = (Y-10000*i-5000*j)//1000
            ind=1
            break
if ind==0:
    print(-1,-1,-1)
else:
    print(a,b,c)

Solution (Python):

import sys


def solve(N: int, Y: int):
    for i in range(N + 1):
        for j in range(N - i + 1):
            k = N - i - j
            if 10000 * i + 5000 * j + 1000 * k == Y:
                print(i, j, k)
                return
    print('-1 -1 -1')
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(N: int, Y: int):
    for i in range(N + 1):
        for j in range(N - i + 1):
            k = N - i - j
            if 10000 * i + 5000 * j + 1000 * k == Y:
                print(' '.join([str(n) for n in [i, j, k]]))
                return
    print(' '.join([str(n) for n in [-1, -1, -1]]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):
i=list(map(int,input().split()))
N, Y =i[0], i[1]

x,y,z = -1,-1, -1
for i in range(N+1):
    for j in range(N- i+1):
        k = N - i - j
        if 10000*i +5000*j +1000*k == Y:
                x,y,z = i, j, k
                break
print("{} {} {}".format(x,y,z))

Solution (Python):
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")

Solution (Python):
N,Y=[int(s) for s in input().split()]

flag=0
i10=0
while i10*10000<=Y and i10<=N:
  i5=0
  while i10*10000+i5*5000<=Y and i10+i5<=N :
    i1=N-i10-i5
    if i10*10000+i5*5000+i1*1000==Y:
      print(*[i10,i5,i1])
      flag=1
      break
    i5+=1
  if flag==1 : break
  i10+=1
else:
  print(*[-1,-1,-1])

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

x,y,z = -1, -1, -1
for i in range(N+1):
    for j in range(N+1-i):
        k = (N-i-j)
        if i * 10000 + j * 5000 + (N-i-j) * 1000 == Y:
            x,y,z = i,j,k
            break
    else:
        continue
    break

print(x,y,z,sep=' ')

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, Y] = string_to_int(inputs[0])
    Y = Y // 1000

    for n10 in reversed(range(N+1)):
        for n5 in reversed(range(N - n10 + 1)):
            n1 = N - (n10 + n5)
            if n1 >= 0:
                money = 10 * n10 + 5 * n5 + 1 * n1
                if money == Y:
                    return "{} {} {}".format(n10, n5, n1)
    return '-1 -1 -1'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
n,k=map(int, input().split())
ans=-1
for i in range(n+1):
    for j in range(n-i+1):
        if k-(10000*i+5000*j)==(n-i-j)*1000:
            print(i,j,n-i-j)
            ans=1
            break
    if ans==1:
        break
if ans==-1:
    print(ans,ans,ans)

Solution (Python):
n,k=map(int, input().split())
ans=True
for i in range(n+1):
    for j in range(n-i+1):
        if k-(10000*i+5000*j)==(n-i-j)*1000:
            print(i,j,n-i-j)
            ans=False
            break
    if ans==False:
        break
if ans:
    print(-1)
    print(-1)
    print(-1)

Solution (Python):
N,Y = map(int,input().split())
ans = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1):
        k = N-i-j
        if k>=0 and 10000*i+5000*j+1000*k==Y:
            ans=[i,j,k]
            print(*ans)
            exit()
print(*ans)

Solution (Python):
n,y=map(int, input().split())
for p in range(n+1):
    for q in range(n-p+1):
        if 10000*p+5000*q+1000*(n-p-q)==y:
                print(p,q,n-p-q)
                exit()
print("-1 -1 -1")

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

flag = 0

for i in range(n + 1):
    x = (5000 * n - m + 5000 * i) / 4000
    y = (m - 1000 * n - 9000 * i) / 4000
    
    if  x >= 0 and y >= 0 and x % 1 == 0 and y % 1 == 0:
        print(int(i), int(y), int(x))
        flag = 1
        break

if flag == 0:
    print(-1, -1, -1)

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

f = False
for i in range(N+1):
  if f: break
  for j in range(N+1):
    if N - i - j < 0: break
    if i * 10000 + j * 5000 + (N - i -j) *1000 == Y:
      print (i,j,N-i-j)
      f = True
      break
if not f: print (-1, -1, -1)

Solution (Python):
n,y = map(int,input().split())
a,b,c = 10000,5000,1000
for i in range(y//a+1):
    for j in range((y-(a*i))//b+1):
        d = (y-(a*i)-(b*j))//c
        if i+j+d == n:print(i,j,d);exit()
else:print(-1,-1,-1)

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

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

res = ["-1", "-1", "-1"]
for i in range(N+1):
  if i * 10000 > Y:
    break
  for j in range(N-i+1):
    if i * 10000 + j * 5000 > Y:
      break
    k = N-(i+j)
    if i * 10000 + j * 5000 + k * 1000 == Y:
      res = [str(i), str(j), str(k)]
      break

print(" ".join(res))

Solution (Python):
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)

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

answer = []

if Y > 10000*N or Y < 1000*N:
    answer = [-1, -1, -1]
else:
    for i in range(N+1):
        x = i
        for j in range(N-x+1):
            y = j
            z = N-x-y
            if 10000*x + 5000*y + 1000*z == Y and z >= 0:
                answer = [x, y, z]
                answer = [str(v) for v in answer]
                print(' '.join(answer))
                exit()
        answer = [-1, -1, -1]

answer = [str(v) for v in answer]
print(' '.join(answer))

Solution (Python):
import sys

n,y = map(int,input().split())

if y // 10000 > n:
	print("-1 -1 -1")
	sys.exit()

for i in reversed(range(y//10000 + 1)):
	n -= i
	y -= 10000 * i
	if 10000 * i + 5000 * (n-i) < y:
		break
	for j in reversed(range(y//5000 + 1)):
		n -= j
		y -= 5000 * j
		for k in reversed(range(y//1000 + 1)):
			n -= k
			y -= 1000 * k
			if y == 0 and n == 0:
				print(i,j,k)
				sys.exit()
			else:
				n += k
				y += 1000 * k
				break
		n += j
		y += 5000 * j
	n += i
	y += 10000 * i

print("-1 -1 -1")

Solution (Python):
import sys

n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1):
        if 0 <= n - i - j <= n and i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(" ".join(map(str, [i, j, n - i - j])))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
import sys
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])
        sys.exit()
print(*[-1,-1,-1])

Solution (Python):
def c_otoshidama():
    """
    a, b, c: 1万円札/5千円札/千円札の枚数
    条件から変数 c を消去すると不定方程式 9a+4b=t が得られる．
    この方程式の解は a=4k+t, b=-9k-2t である (gcd(9,4)=1 より必ず存在する)．
    a, b, c >= 0 という条件から minimum <= maximum なら元の方程式に解がある．
    """
    from math import ceil, floor
    N, Y = [int(i) for i in input().split()]
    t = (Y - 1000 * N) // 1000
    minimum, maximum = max(ceil(-t / 4), ceil(-(N + t) / 5)), floor(-2 * t / 9)
    if minimum <= maximum:
        return '{} {} {}'.format(4 * minimum + t, -9 * minimum - 2 * t, N + 5 * minimum + t)
    return '-1 -1 -1'

print(c_otoshidama())

Solution (Python):
N,Y=map(int,input().split())
for i in range(N+1):
    for j in range(N+1-i):
        k=N-i-j
        if Y==10000*i+5000*j+1000*k:
            print(i, j, k)
            exit()
print(-1,-1,-1)

Solution (Python):
def main():
    n, y = map(int, input().split())
    for i in range(n+1):
        for j in range(0, i+1):
            x = 10000*(n-i) + 5000*(i-j) + 1000*(j)
            if x == y:
                print("{} {} {}".format(n-i, i-j, j))
                return
    print("-1 -1 -1")

main()

Solution (Python):
N,Y = map(int,input().split())
for a in range(N+1):
    for b in range(N+1-a):
        c=N-a-b
        if 10000*a + 5000*b + 1000*c == Y:
            print(a,b,c)
            exit()
print(-1,-1,-1)

Solution (Python):
n, y = list(map(int, input().split()))
ansFlg = False
for a in range(n+1):
    for b in range(n+1):
        if 9000*a + 4000*b == y-1000*n:
            c = n - a - b
            if c>=0:
                print(a, b, c)
                exit()
print("-1 -1 -1")

Solution (Python):
n, y = list(map(int, input().split()))
ansFlg = False
for a in range(n+1):
    for b in range(n+1):
        if 9000*a + 4000*b == y-1000*n:
            c = n - a - b
            if c>=0:
                print(a, b, c)
                ansFlg =True
        if ansFlg:
            break
    if ansFlg:
        break
if ansFlg==False or y-1000*n < 0:
     print("-1 -1 -1")

Solution (Python):
n, y = map(int, input().split())
result = 0

for i in range(n+1):
    for j in range(n+1):
        k = n - i - j
        z = 10000*i + 5000*j + 1000*k
        if z == y and k >= 0:
            result += 1
            print(i, j, k)
            exit()

if result == 0:
    print('-1 -1 -1')

Solution (Python):
n, y = map(int, input().split())
y /= 1000

a = [0]*3

a[1], a[2] = divmod(y, 5)
ans = [-1]*3

while sum(a)!=n:
    if n-sum(a) >= 4:
        tmp = (n-sum(a))//4
        a[1] -= tmp
        a[2] += tmp*5
    elif n-sum(a) <= -1:
        tmp = sum(a)-n
        a[1] -= tmp*2
        a[0] += tmp
    else:
        tmp = n-sum(a)
        a[1] -= (4-tmp)*2+1
        a[2] += 5
        a[0] += 4-tmp
    if a[1]<0:break
else: ans = a
ans = list(map(int, ans))
print(*ans)

Solution (Python):
N, Y = map(int, input().split())
import sys
for x in range(N+1):
  for y in range(N+1 - x):
    if 9000 * x + 4000 * y == Y - 1000 * N:
      print(x, y, N - x - y)
      sys.exit()
else:
  print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
for i in range(0,n+1):
    for j in range(0,n+1):
        if 10000*i+5000*j+1000*(n-i-j)==y and i+j<=n:
            print(i,j,(n-i-j))
            break
    else:
        continue
    break
if i==n and j==n:print('-1 -1 -1')

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n, y = map(int, input().split())
    for i in range(n+1):
        for j in range(n+1):
            if n - i - j < 0:
                continue
            if i * 10000 + j * 5000 + (n-i-j) * 1000 == y:
                print(i, j, n-i-j)
                exit()

    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n, y = map(int, input().split())
    for i in range(n+1):
        for j in range(n+1):
            if n - i - j < 0:
                continue
            if i * 10000 + j * 5000 + (n-i-j) * 1000 == y:
                print(i, j, n-i-j)
                exit()

    print(-1, -1, -1)


if __name__ == '__main__':
    main()

Solution (Python):
N,Y = map(int,input().split())
for x in range(N+1):
  for y in range(N-x+1):
    if 10000*x+5000*y+1000*(N-x-y) == Y:
      print(x,y,N-x-y)
      exit()
print(-1,-1,-1)

Solution (Python):
N,Y = map(int,input().split())
count = 0
for l in range(N+1):
    for m in range(N+1):
        n = N-l-m
        if 0<=n<=N:
            y = 10000*l+5000*m+1000*n
            if y==Y:
                list = [l,m,n]
                count = count+1
if count>=1:
    print(list[0], list[1], list[2])
else:
    print(-1, -1, -1)

Solution (Python):
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)

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

found = False
for a in range(n+1):
    for b in range(n-a+1):
        c = n - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if total == y:
            found = True
            print(a, b, c)
            break
    if found:
        break

if not found:
    print('-1 -1 -1')

Solution (Python):
import sys
n,y=(int(x) for x in input().split())
for i in range(n+1):
  for j in range(n-i+1):
    if 10000*i+5000*j+1000*(n-i-j)==y:
      print("{} {} {}".format(i,j,n-i-j))
      sys.exit()

print("-1 -1 -1")

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

for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if 0 <= k <= 2000 and 10000*i + 5000*j + 1000*k == Y:
            print(i, j, k)
            exit()
print(-1, -1, -1)

Solution (Python):
import sys


def aa():
    n, t = map(int, input().split())
    count = 0
    for x in range(n+1):
        if(10000 * x > t):
            break
        for y in range(n+1):
            if(10000 * x + 5000 * y> t):
                break
            z = n - (x + y)
            if(10000 * x + 5000 * y + 1000 * z == t and z >= 0):
                print(x,y,z)
                return 0
    print(-1,-1,-1)
    return 0
aa()

Solution (Python):

n, y = list(map(int, input().split()))

answer = [-1, -1, -1]
for y10000 in range(0, n+1):
    for y5000 in range(0, n+1-y10000):
        y1000 = n - y5000 - y10000
        if y1000 * 1000 + y5000*5000+y10000*10000 == y:
            answer = [y10000, y5000, y1000]
            break


print(" ".join(map(str, answer)))

Solution (Python):
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n+1):
        if 10000*i+5000*j+(n-i-j)*1000 == y and n-i-j >= 0:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

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

aMax = Y//10000

flag = False

for i in range(aMax+1):
    for j in range(N-i+1):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            a = i
            b = j
            c = N-i-j
            flag = True
            break
    if flag:
        break
            
if flag:
    print(a, b, c)
else:
    print(-1, -1, -1)

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

c = 0

for a in range(n + 1):
    for b in range(n + 1 - a):
        c = n - a - b
        ans = 10000 * a + 5000 * b + 1000 * c
        if (ans == y):
            print(a, b, c)
            exit()

print(-1, -1, -1)

Solution (Python):
a,b = map(int,input().split())

for i in range(2001):
    for j in range(2001):
        if 10000*i + 5000*j + 1000*(a-i-j) == b and a-i-j>=0:
            print(i,j,a-i-j)
            exit()
print(-1,-1,-1)

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

target = y - n * 1000
flag = 0
for i in range(n+1):
    b_4000 = (target - 9000 * i)
    if b_4000 % 4000 == 0 and b_4000 // 4000 >= 0:
        if n-i-b_4000//4000 >= 0:
            c = i
            b = b_4000 // 4000
            flag = 1
            break

if flag:
    print(c, b, n-b-c)
else:
    print('-1 -1 -1')

Solution (Python):
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")

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

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

ans = '-1 -1 -1'
for a in range(n+1):
    for b in range(n+1):
        rem = y - 10000*a - 5000*b
        if rem < 0:
            continue
        c = rem // 1000
        if a + b + c == n:
            ans = '{} {} {}'.format(a, b, c)
            break
print(ans)

Solution (Python):
def main():
    n, y = map(int, input().split())
    for i in range(n+1):
        for j in range(n-i+1):
            k = (n-i-j)
            if (i * 10000 + j * 5000 + k * 1000) == y:
                ans = [i, j, k]
                print(*ans)
                exit()
    ans = [-1, -1, -1]
    print(*ans)


if __name__ == "__main__":
    main()

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

for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - (x + y)
        if Y == x * 10000 + y * 5000 + z * 1000:
            print(x, y, z)
            exit()
print('-1 -1 -1')

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()


def solve(count, amount):
    for x in range(count+1):
        for y in range(count-x+1):
            z = count - x - y
            s = 10000*x + 5000*y + 1000*z
            if s == amount:
                return (x, y, z)
    return (-1, -1, -1)


def main():
    N, Y = map(int, input().split())
    print(*solve(N, Y), sep=" ")


if __name__ == "__main__":
    main()

Solution (Python):
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)

Solution (Python):
n, Y = map(int, input().split())
ntx = n * 10000
nty = n * 5000
ntz = n * 1000
ans = []
if Y > ntx or ntz > Y:
    ans = [-1, -1, -1]
elif ntx == Y:
    ans = [n, 0, 0]
elif nty == Y:
    ans = [0, n, 0]
elif ntz == Y:
    ans = [0, 0, n]
elif ntx > Y > nty:
    x = 0
    y = n
    z = 0
    for i in range(1, n+1):
        y = n - i
        x = i
        for j in range(0, i+1):
            x = j
            z = i - j
            if 10000*x + 5000*y + 1000*z == Y:
                ans = [x, y, z]
elif nty > Y > ntz:
    x = 0
    y = 0
    z = n
    for i in range(1, n+1):
        z = n - i
        x = i
        for j in range(0, i+1):
            x = j
            y = i - j
            if 10000*x + 5000*y + 1000*z == Y:
                ans = [x, y, z]
if len(ans) == 0:
    ans = [-1, -1, -1]
print(' '.join(map(str, ans)))

Solution (Python):
n, y = [int(x) for x in input().split()]
for i in range(n+1):
    for j in range(n - i + 1):
        if 10000*i + 5000*j + 1000*(n - i - j) == y:
            print(i, j, n - i - j)
            exit()
print(-1,-1,-1)

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

cnt1000 = -1
cnt5000 = -1
cnt10000 = -1


for a in range(n + 1):
    for b in range(n + 1 - a):
        c = n-a-b
        if y == 10000*a + 5000*b + 1000*c:
            cnt10000 = a
            cnt5000 = b
            cnt1000 = c
            print(str(cnt10000) + ' ' + str(cnt5000) + ' ' + str(cnt1000))
            exit()

print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000








D = Y-N
for i10 in range(D//9 + 1):
  D2 = D-9*i10
  if D2%4:
    continue
  else:
    i5 = D2//4
    if N-i10-i5 >= 0:
      print(i10, i5, (N-i10-i5))
      exit()
print(-1,-1,-1)

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


for i in range(N+1):
  for j in range(N+1 - i):
    k = N - (i+j)
    if Y == (10000*i + 5000*j + 1000*k):
      print(i,j,k)
      exit()
print(-1,-1,-1,)

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

ans=[-1,-1,-1]
for i in range(n+1):
    for j in range(n+1-i):
        if y-i*10000-j*5000==1000*(n-i-j):
            ans=[i,j,n-i-j]
            
print(*ans)

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

maxA=Y//10000
ans=[]

for a in range(maxA+1):
  for b in range(N+1-a):
      if Y==10000*a+5000*b+1000*(N-a-b):
        ans.append(str(a)+" "+str(b)+" "+str(N-a-b))
    
if len(ans)!=0:
  print(ans[0])
else:
  print(str(-1)+" "+str(-1)+" "+str(-1))

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

for i in range(N+1):
  for j in range(N+1-i):
    if 10000*i + 5000*j + 1000*(N-i-j) == Y:
      print(i, j, N-i-j)
      exit()
print(-1, -1, -1)

Solution (Python):
import sys
import math
import numpy as np
import copy

def main():
    n, y = map(int, input().split())
    ret = False
    ans = (-1, -1, -1)
    for i in range(0, n+1):
        for j in range(0, n-i+1):
            k = n - i - j
            if 10000*i + 5000*j + 1000*k == y:
                ans = (i, j, k)

    print("%d %d %d" % ans)
    
    return 0

if __name__ == '__main__':
    sys.exit(main())

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

for i in range(n+1):
    for j in range(n+1-i):
        if(10000*i+5000*j+1000*(n-i-j) == y):
            print(i, j, (n-i-j))
            exit()
print(-1, -1, -1)

Solution (Python):
import sys
input = sys.stdin.readline
n,y=map(int,input().split())


for i in range(0,n+1):
    for j in range(0,n+1):
        k=n-i-j
        if 10000*i+5000*j+1000*k==y and k>=0 :
            print(i, j, k)
            c=1
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)

Solution (Python):
import sys
input = sys.stdin.readline
n,y=map(int,input().split())

c=0
for i in range(0,n+1):
    for j in range(0,n+1):
        k=n-i-j
        if 10000*i+5000*j+1000*k==y and k>=0 and c==0:
            print(i, j, k)
            c=1
            break
if c==0:
    print(-1,-1,-1)

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


def main():
    N, Y = map(int, input().split())

    M = Y//1000
    for x in range(M//9 + 1):
        for y in range(M//4 + 1):
            z = M - x*10 - y*5
            if x+y+z == N and z>=0:
                print(' '.join(map(str, [x, y, z])))
                return
    print('-1 -1 -1')


if __name__ == '__main__':
    main()

Solution (Python):
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+1):
        k = y - i*10000 - j*5000
        k = k // 1000
        if i+j+k == n and k >= 0 and k <= n:
            print("{} {} {}".format(i, j ,k))
            exit()
print("-1 -1 -1")

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

x, y, z = 10000, 5000, 1000
for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if (x*i + y*j) == (Y - z*k):
            print(i, j, k)
            exit()
print("-1 -1 -1")

Solution (Python):
N, Y = list(map(int, input().split()))
flag = False
for n in range(N+1):
  for m in range(N+1 - n):
    if 10000 * n + 5000 * m + 1000 * (N - n - m) == Y:
      print(n, m , N - n- m)
      flag = True
      break
  if flag:
    break

if flag == False:
  print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
for x in range(0, N+1):
    for y in range(0, N+1):
        z = N - x - y
        if z < 0:
            continue
        if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

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

for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y
        if (10000*x + 5000*y + 1000*z) == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

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


count = 0
for x in range(0, N + 1):
    for y in range(0, N + 1 - x):
        z = N - x - y
        if (10000 * x) + (5000 * y) + (1000 * z) == Y:
            print(x, y, z)
            break
    else:  
        count += 1
        continue 
    break

if count == N + 1:
    print(str(-1), str(-1), str(-1))

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

count = 0
flag = 0

for x in range(n[0] + 1):

	for y in range(n[0] + 1 - x):

		if (n[1] == (10000 * x + 5000 * y + 1000 * (n[0] - (x + y) ))):
			flag = 1
			z = (n[0] - (x + y))
			break

	if flag == 1:
		break

if flag == 0:
	x = -1
	y = -1
	z  = -1

print(x ,y , z)

Solution (Python):
N, Y = map(int, input().split())
for x in range(0, N+1):
    for y in range(0, N+1):
        z = N - x - y
        if z < 0:
            continue
        if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

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

out = ''
for i in range(n+1):
  if out != '':
    break
  if i * 10000 > y:
    break
  for j in range(n-i+1):
    if i*10000+j*5000+(n-i-j)*1000 == y:
      out = '{} {} {}'.format(i,j,n-i-j)

if out == '':
  out = '-1 -1 -1'
print(out)

Solution (Python):
a, b = input().split()
a = int(a)
b = int(b)

def sebe(p,q):
    for i in range(p+1):
        for j in range(p+1):
            if (p-j-i) < 0:
                break
            if (10000*i +5000*j + 1000*(p-j-i)) == q :
                return i,j,(p-j-i)


    else: return -1, -1, -1

a,b,c = sebe(a,b)

print(a, b, c)

Solution (Python):

def main():
    N, Y = tuple(map(int, input().split()))
    Y //= 1000
    for i in range(N + 1):
        for j in range(N + 1 - i):
            k = N - i - j
            if i * 10 + j * 5 + k == Y:
                print(i, j, k)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    main()

Solution (Python):
N,Y=map(int,input().split())
count = 0
for i in range(0,N+1):
  for j in range(0,N-i+1):
    sum=i*10000+j*5000+(N-i-j)*1000
    if sum == Y:
      count +=1
      a=i
      b=j
      c=N-i-j
    else:
      next
if count == 0:
  a=b=c=-1
  print("{} {} {}".format(a,b,c))
else:
  print("{} {} {}".format(a,b,c))

Solution (Python):

import sys
n, y  = map(int, input().split( ))

m = y//10000
g = y//5000
for i in range(m+1):
    for j in range(g+1):
        s = (y-10000*i-5000*j)//1000
        if i+j+s == n and s>=0:
            print(i,j,s)
            sys.exit()
print(-1,-1,-1)