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())

sum = y
wasFound = False
for i in range(n+1):
    if wasFound:
        break
    for j in range(n+1):
        if i+j > n:
            break
        rest = sum - i*10000 - j*5000
        if rest < 0:
            break
        k = int(rest/1000)
        if rest % 1000 == 0 and (i+j+k==n):
            print(i, j, k)
            wasFound = True
            break
if not wasFound:
    print(-1, -1, -1)

Solution (Python):
import bisect
import sys


def input():
    return sys.stdin.readline()[:-1]









n, y = map(int, input().split())
ans = [-1, -1, -1]
for man in range(n+1):
    for gosen in range(n+1-man):
        if 10000*man + 5000*gosen + 1000*(n-man-gosen) == y:
            ans = [man, gosen, n-man-gosen]
            break
print(" ".join(map(str, ans)))

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

Man=Y//10000
for x in range(Man+1)[::-1]:
	zanM=Y-x*10000
	Gos=zanM//5000
	for y in range(Gos+1)[::-1]:
		zanG=zanM-y*5000
		z=zanG//1000
		if zanG%1000==0 and x+y+z==N:
			print('{} {} {}'.format(x,y,z))
			sys.exit()
print('{} {} {}'.format(-1,-1,-1))

Solution (Python):
a,b = map(int,input().split())
 
t = b//1000
 
f = False
 
for i in range(t//10+1):
    for j in range((t-i*10)//5+1):
        if a == t - i*9 - j*4 and t == i*10+j*5+(a-i-j) and a-i-j>=0:
            f = True
            break
    if f:
        break
 
if f:
    print(i,j,a-i-j)
else:
    print(-1,-1,-1)

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



for a in range(N + 1):
    for b in range(N - a + 1):
        c = N - a - b

        if 0 <= c <= N and 10000 * a + 5000 * b + 1000 * c == Y:
            print(a, b, c)
            exit()

print(-1, -1, -1)

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

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

print(-1, -1, -1)

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 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
y//=1000
a=y%5
for i in range(n+1):
    if a==i%5:
        b=(y-i)//5
        c=n-i
        if c<=b<=2*c:
            print(b-c,2*c-b,i)
            exit()
print(-1,-1,-1)

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 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

Solution (Python):
import numpy as np

N, Y = map(int,input().split())

n_max10000 = int(Y / 10000)

ans = '-1 -1 -1'
for i in range(n_max10000 + 1): 
  n_max5000 = int((Y - 10000 * i) / 5000)
  for j in range(n_max5000 + 1): 
    if 10000*i + 5000*j + 1000*(N-i-j) == Y: 
      n_bill = [i, j, N-i-j]
      ans = str(n_bill[0]) +' '+ str(n_bill[1]) +' '+ str(n_bill[2])
      
print(ans)

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

Solution (Python):
n, y = map(int,input().split())
a, b, c = -1, -1, -1

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

print(a, b, c)

Solution (Python):
n, y = map(int,input().split())
a, b, c = -1, -1, -1
i = 0
while 10000 * i <= y:
    j = 0
    s = y - 10000 * i
    if 5000 * (n-i) >= s:
        while 5000 * j <= s:
            r = y - 10000 * i - 5000 * j
            if r % 1000 == 0 and r // 1000 == n - i - j:
                a, b, c = i, j, n - i - j
                break
            j += 1
    if a != -1:
        break
    i += 1

print(a, b, c)

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

def check(N, Y):
    for i in range(N+1):
        for j in range(N+1 - i):
            if i * 10000 + j * 5000 + (N-i-j) * 1000 == Y:
                return ' '.join(map(str, (i, j, N-i-j)))
    else:
        return '-1 -1 -1'

print(check(N, Y))

Solution (Python):
in_n, in_cond = map(int, input().split())
def hoge(n, cond):
    for i in range(n+1):
        for j in range(n + 1 -i):
            if(10000 * i + 5000 * j + 1000 * (n - i - j) == cond):
                return [str(i), str(j), str(n - i - j)]
    return ["-1","-1","-1"]
print(" ".join(hoge(in_n, in_cond)))

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

for i in range(0,n+1):
  for j in range(0, n-i+1):
    if y == 10000*i + 5000*j + 1000*(n-i-j):
      print("{0} {1} {2}".format(i, j, n-i-j))
      exit()
print("-1 -1 -1")

Solution (Python):
import sys


N, Y = map(int, input().split())



for a in range(N + 1):
    for b in range(N - a + 1):
        c = N - a - b
        sum = 10000 * a + 5000 * b + 1000 *c
        if sum == Y:
            print(str(a) + ' ' + str(b) + ' ' + str(c) )
            sys.exit()
print(str(-1) + ' ' + str(-1) + ' ' + str(-1))

Solution (Python):

N, Y = map(int, input().split())



a, b, c = 0, 0, 0







flg = True
while flg:
	x = Y/1000 - N - 9*a
	b = int(x//4)

	c = N -a - b
	if  10*a+5*b+c == Y/1000 and a >=0 and b >= 0 and c >= 0:
		flg = False
	elif x < 0:
		a, b, c = -1, -1, -1
		flg = False
	else:
		a += 1



print(a, b, c)

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

res10000 = -1
res5000 = -1
res1000 = -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):
            res10000 = i
            res5000 = j
            res1000 = k


print('{} {} {}'.format(res10000, res5000, res1000))

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 i+j+k == n and i*10000 + j*5000 + k*1000 ==y:
            print(i,j,k)
            quit()
print(-1,-1,-1)

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

Solution (Python):
from itertools import product
n,y = map(int,input().split())

bill_combination = '-1 -1 -1'
for bill10,bill5 in product(range(n+1),repeat=2):
    bill1 = n - (bill10 + bill5)
    if bill1 >= 0 and y == (bill10 * 10000 + bill5 * 5000 + bill1 * 1000):
        print(bill10,bill5,bill1)
        break
else:
    print(bill_combination)

Solution (Python):
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1):
        if (N - i - j) * 10000 + i * 5000 + j * 1000 == Y:
            if (N - i - j) < 0:
                continue
            print(N - i - j, i, j)
            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):
    k = n-i-j
    if i*10000+j*5000+k*1000 == y and k>=0:
      ans[0] = i
      ans[1] = j
      ans[2] = k
      break
print(ans[0], ans[1], ans[2])

Solution (Python):
N,Y=map(int,input().split())
flag=False
for i in range(min(Y//10000,N)+1):
    if flag:
        break
    for j in range(min((Y-i*10000)//5000,N-i)+1):
        if (Y-i*10000-j*5000)%1000==0 and i+j+(Y-i*10000-j*5000)//1000==N:
            print(" ".join(map(str,[i,j,N-i-j])))
            flag=True
            break
if not flag:
    print("-1 -1 -1")

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

a=0
while a*10000<=Y:
  c=0
  while a*10000+c*1000<=Y:
    if a+c>N:break
    B=Y-a*10000-c*1000
    if B%5000==0:
      b=B//5000
      if a+b+c==N:
        print(a,b,c)
        exit()
    c+=1
  a+=1
else :print(-1,-1,-1)

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

for i in range(N+1):
    if Y/1000 - 10*i < 0:
        a = 2
    else:
        for j in range(N-i+1):
            z = Y/1000 - 10 * i - 5 * j
            if z + i + j == N:
                print(i,j,int(z))
                a = 1
    
    if a == 1 or a == 2:
        break
    else:
        continue

if a == 0 or a == 2:
    print(-1,-1,-1)

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 0<=z<=2000 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()
print(-1,-1,-1)

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

for i in range(Y // 10000 + 1):
    for j in range((Y - 10000 * i) // 5000 + 1):
        if ((i + j + (Y - 10000 * i - 5000 * j) // 1000 == N) and
                ((Y - 10000 * i - 5000 * j) // 1000 >= 0)):
            print(i, j, (Y - 10000 * i - 5000 * j) // 1000)
            quit()
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 9000 * i + 4000 * j + 1000 * N == Y:
      print(i, j, N-i-j)
      sys.exit()
print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split(' '))
res10000 = -1
res5000 = -1
res1000 = -1

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:
            res10000 = a
            res5000 = b
            res1000 = c

print(str(' '.join(map(str, [res10000, res5000, res1000]))))

Solution (Python):

def solve(n, y):
    for a in range(n + 1):
        for b in range(n - a + 1):
            if a * 10 + b * 5 + (n - a - b) == y / 1000:
                print("{} {} {}".format(a, b, n - a - b))
                return

    print("-1 -1 -1")
    return

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

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

flag = False
result = [-1,-1,-1]
for i in range(min(N, X // 10**4) + 1):
  for j in range(min(N-i, (X-10**4*i) // 5000) + 1):
    if (X - 10**4*i - 5000*j) // 1000 == N - i - j:
      result = (i,j,N-i-j)
      flag = True
      break
  if flag:
    break
print(*result)

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,sep=' ')
            break
    else:
        continue
    break
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
		tmp = i * 10000 + j * 5000 + k * 1000
		if tmp == Y:
			x,y,z = i,j,k
			break
	else:
		continue
	break
print("{} {} {}".format(x,y,z))

Solution (Python):

N,Y = map(int, input().split())
cnt = 0
for x in range(N + 1):
    if x > N or 10000 * x > Y:
        break
    for y in range(N + 1):
        if x + y > N or 10000 * x + 5000 * y > Y:
            break
        if N - (Y / 1000) == -9 * x - 4 * y:
            print(x, y, N - x - y)
            exit()
print('-1 -1 -1')

Solution (Python):

  
n,y=map(int,input().split())
a,b,c=-1,-1,-1

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

print(a,b,c)

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

Y //= 1000

n = 0
y = 0
while y <= Y and n <= N:
    if (Y-y-(N-n))%4==0 and 0<=(Y-y-(N-n))//4<=N-n:
        print(y//10,(Y-y-(N-n))//4,N-n-(Y-y-(N-n))//4)
        exit()
    y += 10
    n += 1

print(-1,-1,-1)

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

Y //= 1000

n = 0
y = 0
while y <= Y and n <= N:
    yy = y
    nn = n
    while yy <= Y and nn <= N:
        if Y - yy == N - nn:
            print(y//10,(yy-y)//5,Y-yy)
            exit()
        yy += 5
        nn += 1
    y += 10
    n += 1

print(-1,-1,-1)

Solution (Python):
n,y=map(lambda x:int(x),input().strip().split())
y//=1000
res =[-1]*3
flag=False

for i in range(n+1):
    if flag:
        break
    for j in range(n-i+1):
        yen=i*10+j*5+(n-i-j)

        if yen ==y:
            res=[i,j,n-i-j]
            flag=True
            break
print(res[0],"",res[1],"",res[2])

Solution (Python):
N,Y = map(int, input().split())
 
num10000 = -1
num5000 = -1
num1000 = -1
 
total = 0
 
for i in range(0,N+1):
    for j in range(0, N-i+1):
        k = N - i - j
        total = 10000*i + 5000*j + 1000*k
        if total == Y:
            num10000 = i
            num5000 = j
            num1000 = k
 
print(str(num10000)+' ' +str(num5000) + ' ' +str(num1000))

Solution (Python):
import itertools as itr
n,y = map(int,input().split())

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

Solution (Python):
n,m=map(int,input().split())
a=0
b=0
c=0
ans=0
for i in range(n+1):
  AA=10000*i
  for j in range(n-i+1):
    BB=5000*j
    CC=1000*(n-i-j)
    if(AA+BB+CC==m and ans==0):
      print(i,j,n-i-j)
      ans+=1

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

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

for delim1 in range(N + 1):
    for delim2 in range(delim1, N + 1):
        yukichi = delim1
        ichiyo = delim2 - delim1
        hideyo = N - delim2
        y = yukichi * 10000 + ichiyo * 5000 + hideyo * 1000
        if y > Y:
            break
        if y == Y:
            print(yukichi, ichiyo, hideyo)
            exit(0)
else:
    print(-1, -1, -1)

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

for delim1 in range(N + 1):
    for delim2 in range(delim1, N + 1):
        yukichi = delim1
        ichiyo = delim2 - delim1
        hideyo = N - delim2
        y = yukichi * 10000 + ichiyo * 5000 + hideyo * 1000
        if y > Y:
            break
        if y == Y:
            print(yukichi, ichiyo, hideyo)
            exit(0)
else:
    print(-1, -1, -1)

Solution (Python):
a, b = map(int, input().split(" "))
positive = 0
 
for i in range(a + 1):
  value = 0
  stock = 0
  stock = a - i
  for j in range(stock + 1):
    value = 10000 * i + 5000 * j + 1000 * (a - i - j)
    if value == b:
      print(i, j, a - i - j)
      positive = 1
      break
  else:
    continue
  break

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

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

num10000 = -1
num5000 = -1
num1000 = -1

total = 0

for i in range(0,N+1):
    for j in range(0, N-i+1):
        k = N - i - j
        total = 10000*i + 5000*j + 1000*k
        if total == Y:
            num10000 = i
            num5000 = j
            num1000 = k

print(str(num10000)+' ' +str(num5000) + ' ' +str(num1000))

Solution (Python):
n,y=[int(i) for i in input().split()]
def main():
    for i in range(y//10000+1):
        for j in range(n-i+1):
            sen=(y-i*10000-j*5000)
            if sen%1000==0 and i+j+sen//1000==n:
                print("{} {} {}".format(i,j,sen//1000))
                return True
    return False
if not main():
    print("-1 -1 -1")

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

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

print(-1,-1,-1)

Solution (Python):
found = False
def solve(N, Y):
    global found
    for i in range(N + 1):
        if i * 10000 > Y: continue
        for j in range(N - i + 1):
            k = N - i - j
            if i * 10000 + j * 5000 + k * 1000 == Y:
                print(i, j, k)
                found = True
                return
            else:
                continue

N, Y = [ int(val) for val in input().split() ]
solve(N,Y)
if not found:
    print("-1 -1 -1")

Solution (Python):
import sys
n,yen=map(int,input().split())

for x in range(n+1):
    for y in range(n+1):
        z=int((yen-(x*10000+y*5000))/1000)
        if z>=0 and x+y+z==n:
            print('{} {} {}'.format(x,y,z))
            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+1):
        if  10000*i + 5000*j + 1000*(N-i-j) == Y and (N-i-j)>=0:
            print('%d %d %d'%(i,j,(N-i-j)))
            sys.exit()
print('-1 -1 -1')

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

def calc(x, y):
    for i in range(x + 1):
        for j in range (x + 1 - i):
            if i * 10 + j * 5 + (x - i - j) * 1 == y:
                return  print(i, j, (x - i - j))
    return print('-1 -1 -1')
calc(x, y)

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

def calc(x, y):
    for i in range(x + 1):
        for j in range (x + 1 - i):
            if i * 10000 + j * 5000 + (x - i - j) * 1000 == y:
                return  print(i, j, (x - i - j))
    return print('-1 -1 -1')
calc(x, y)

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

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

for i in range(N + 1):
	y10 = N - i
	for j in range(i + 1):
		y5 = i - j
		y1 = j
		if Y == sum([y10 * 10000, y5 * 5000, y1 * 1000]):
			print(y10, y5, y1)
			exit()
else:
	print(-1, -1, -1)

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

def otoshidama(N,Y):
	ok_flag = 0
	money = 0
	for i in range(N+1):
		for j in range(N+1-i):
			money = 10000*i + 5000*j + 1000*(N-i-j)
			if money == Y:
				print(i,j,N-i-j)
				ok_flag = 1
				return
			money = 0
		money = 0
	if ok_flag == 0:
		print(-1,-1,-1)
  
otoshidama(N,Y)

Solution (Python):
N, Y = map(int, input().split())
def otoshidama(n,y):
  No = -1
  for b in range(n+1):
    if b == 0:
      total = 10000*n
      if total == y:
        print('{} 0 0'.format(n))
        return
    for a in range(0, b+1):
      total = 1000*a + 5000*(b-a) + 10000*(n-b)
      if total == y:
        print(n-b,b-a,a)
        return
  print('-1 -1 -1')
  return
otoshidama(N,Y)

Solution (Python):
from sys import stdin

def calc(N, Y):
    for i in range(N+1):
        for j in range(N+1-i):
            if 10000*i + 5000*j + 1000*(N-i-j) == Y:
                return '%s %s %s' % (i, j, (N-i-j))
    return '-1 -1 -1'

if __name__ == '__main__':
    N, Y = [int(x) for x in stdin.readline().rstrip().split()]
    print(calc(N, Y))

Solution (Python):
from sys import stdin

def calc(N, Y):
    for i in range(N+1):
        for j in range(N+1-i):
            if 10000*i + 5000*j + 1000*(N-i-j) == Y:
                return '%s %s %s' % (i, j, (N-i-j))
    return '-1 -1 -1'

if __name__ == '__main__':
    flag = True
    N, Y = [int(x) for x in stdin.readline().rstrip().split()]
    print(calc(N, Y))

Solution (Python):

import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    N, Y = readi(2)
    for i in range(N + 1):
        for j in range(i + 1):
            a = j
            b = i - j
            c = N - i
            if a * 10000 + b * 5000 + c * 1000 == Y:
                print(a, b, c)
                return
    print(-1, -1, -1)


if __name__ == "__main__":
    main()

Solution (Python):
inp = [int(x) for x in input().split()]
ans = []

def findway():
    for x in range(inp[0] + 1):
        for y in range(inp[0] - x + 1):
                z = inp[0] - x - y
                sum = x * 1000 + y * 5000 + z * 10000
                if sum == inp[1] :
                    ans = [z,y,x]
                    return ans


    return [-1,-1,-1]

l = findway()

print(" ".join([str(x) for x in l]),end="")

Solution (Python):
from math import sqrt


def log(s):
    
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def main():
    num_bills, total_value = tuple(input_ints())
    for i in range(0, num_bills + 1):
        for j in range(0, num_bills - i + 1):
            k = num_bills - i - j
            if i * 10000 + j * 5000 + k * 1000 == total_value:
                print(i, j, k)
                return

    print(-1, -1, -1)


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())
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())
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()
x = -1
print(x,x,x)

Solution (Python):

def main():
    n,y = map(int,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") 
main()

Solution (Python):

def main():
    n,y = map(int,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") 
main()

Solution (Python):
N,Y = [int(n) for n in input().split()]
flag = False
for noguchi in range(N + 1):

    for higuchi in range(N - noguchi + 1):
        yukichi = N - noguchi - higuchi
        if (noguchi * 1000 + higuchi * 5000 + yukichi * 10000) == Y:
            print(yukichi,higuchi,noguchi)
            flag = True
            break
    
    if flag:
        break
        
if not flag:
    print(-1,-1,-1)

Solution (Python):

N, Y = map(int, input().split())
flag = False
for x in range(0, N+1):
    for y in range(0, N+1):
        z = N - x - y
        z_yen = Y - 10000 * x - 5000 * y
        if  z_yen == 1000 * z and z >= 0 and z <= N:
            ans_x = x
            ans_y = y
            ans_z = z
            flag = True
            break

def ans(flag):
    if flag:
        print(ans_x, ans_y, ans_z)
    else:
        print(-1, -1, -1)
        
ans(flag)

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

flg = -1
for i in range(N+1):
  for j in range(N+1):
    goke = 9000*i + 4000*j
    if (goke == Y - 1000*N) and (i + j <= N):
      A = i
      B = j
      flg = 1
      break

if flg == 1:
  C = N - A -B
  print('{} {} {}'.format(A, B, C))
else:
  print('-1 -1 -1')

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

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

    yukichi = 10000
    ichiyou = 5000
    hideyo  = 1000

    ans_x, ans_y, ans_z = -1, -1, -1
    for ix in range(0, n+1):
        for iy in range(0, n+1-ix):
            iz = n - ix - iy
            total = yukichi * ix + ichiyou * iy + hideyo * iz
            if total == y:
                ans_x, ans_y, ans_z = ix, iy, iz

    print(ans_x, ans_y, ans_z)


if __name__ == "__main__":
    main()

Solution (Python):

import sys


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

    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):
N,Y=[int(a) for a in input().split(" ")]
if Y%1000!=0:
    print("-1 -1 -1")
    exit()
for i in range(0,N+1):
    for j in range(i,N+1):
        if 10000*(i)+5000*(j-i)+1000*(N-j) == Y:
            print(" ".join([str(a) for a in [i,j-i,N-j]]))
            exit()
print("-1 -1 -1")

Solution (Python):
N ,Y = map(int, input().split())
total = 0
flag1 = False
ans = [-1,-1,-1]
for i in range(N + 1):
    for j in range(N - i + 1):
        total = (10000 * i) + (5000 * j) + (1000 * (N - i - j))
        if total == Y:
            ans[0] = i
            ans[1] = j
            ans[2] = N - i - j
            flag1 = True
            break
        if total > Y:
            break

    if flag1:
        break

print(ans[0],ans[1],ans[2])

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

Solution (Python):
n, t = map(int, input().split())
flag = False
for x in range(n+1):
    if flag is True:
        break
    for y in range(n-x+1):
        
        if (10000 * x + 5000 * y + 1000 * (n-x-y)) == t:
            print(str(x) + ' ' + str(y) + ' ' + str(n-x-y))
            flag = True
            break

if flag is False:
    print('-1 ' * 3)

Solution (Python):

n, total = list(map(int, input().split()))
total //= 1000
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        if i * 10 + j * 5 + k == total:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):

n, total = list(map(int, input().split()))
total //= 1000
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = n - i - j
        if i * 10 + j * 5 + k == total:
            print(i, j, k)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Solution (Python):

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

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

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

if N*10000 < Y:
    print('-1 -1 -1')
    sys.exit()

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

print('-1 -1 -1')

Solution (Python):
import sys

N, Y = map(int, input().split())

for x in range(N + 1):
    for y in range(N + 1 - x):
        value = 10000 * x + 5000 * y + 1000 * (N - x - y)
        if value > Y:
            break
        elif value == Y:
            print(x, y, N - x - y)
            sys.exit(0)
else:
    print(-1, -1, -1)

Solution (Python):
n, y = (int(_) for _ in input().split())

total = n*10000
found = False
five = 0
one = 0
if total < y:
    print('-1 -1 -1')
elif total == y:
    print(str(n) + ' ' + str(five) + ' ' + str(one))
else:
    for i in range(n, -1, -1):
        ten = i
        remainder = n - i
        for j in range(n - i + 1):
            five = j
            one = n - i - j
            total = ten*10000 + five*5000 + one*1000
            if total == y:
                print(str(ten) + ' ' + str(five) + ' ' + str(one))
                found = True
                exit()
        if found:
            break
            
    if not found:
        print('-1 -1 -1')

Solution (Python):



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

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

if flag == 0:
    print("-1 -1 -1")
else:
    print(i, j, n-i-j)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')


def solve():
    n,y = f()

    a = [10, 5, 1]
    y = 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)
    

solve()

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

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