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):
def main():
    N,Y = list(map(int,input().split()))

    flag = False

    loop_10000 = Y // 10000
    loop_5000 = Y // 5000
    loop_1000 = Y // 1000

    for i in range(loop_10000+1):
        for j in range(loop_5000+1):
            k = N - i - j
            if(k >= 0 and i+j+k == N and 10000 * i + 5000 * j + 1000 * k == Y):
                print(i,j,k)
                flag = True
                break
            
            
            
            
            
            
            
        if(flag):
            break
    if(not flag):
        print(-1,-1,-1)

if __name__ == "__main__":
    main()

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

x = -1
y = -1
z = -1
sum = 0
for a in range(N + 1):
    for b in range(N + 1 - a):
        c = N - a - b
        sum = 10000 * a + 5000 * b + 1000 * c
        if (sum == Y):
            x,y,z = a,b,c
print(x,y,z)

Solution (Python):
n, y = map(int, input().split())
for i in range(n + 1):
  for j in range(n + 1 - i):
    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())

res10000 = -1
res5000 = -1
res1000 = -1

for a in range(N+1):
    for b in range(N-a+1):
        c = N - a - b
        total = a * 10000 + b * 5000 + c * 1000
        if total == Y:
            res10000 = a
            res5000 = b
            res1000 = c

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

Solution (Python):
import sys
import numpy as np


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

ok = False
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        money = (10000 * i) + (5000 * j) + (1000 * k)
        if (money == y):
            ok = True
            break
    if  ok:
        break

if ok:
    print(i, j, k)
else:
    print("-1 -1 -1")

Solution (Python):
"""
まず、最大値と最小値は出せる。
その範囲外のYであれば不可

愚直にやる場合、
N(N-2) / 2
通りあると思うので、O(N*N)
動的計画法使うんかな？？？
どうやって使うっけ


"""

import sys

N, Y = list(map(lambda x: int(x), input().split()))


for n in range(N+1):
  for hi in range(N - n + 1):
    if n + hi >= N:
      hu = 0
    else:
      hu = N - n - hi

    if n * 1000 + hi * 5000 + hu * 10000 == Y:
      print(' '.join([str(hu), str(hi), str(n)]))
      sys.exit()
    
print('-1 -1 -1')

Solution (Python):
import sys
import numpy as np


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

ok = False
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        money = (10000 * i) + (5000 * j) + (1000 * k)
        if (money == y) and (i + j + k == n):
            ok = True
            break
    if  ok:
        break

if ok:
    print(i, j, k)
else:
    print("-1 -1 -1")

Solution (Python):
import sys

n, y = map(int, input().split())
for i in range(n+1):
  for j in range(min(n-i+1, 9)):
    k = n - i - j
    money = 10000 * i + 5000 * j + 1000 * k
    if y == money:
      print("{} {} {}".format(i, j, k))
      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):
    k = n - i - j
    money = 10000 * i + 5000 * j + 1000 * k
    if y == money:
      print("{} {} {}".format(i, j, k))
      sys.exit()
print(-1, -1, -1)

Solution (Python):


N,Y=map(int,input().split())
buf=0
buf2=0
flag=0
for i in range(0,N+1):
 buf=Y-10000*i
 for j in range(0,N+1-i):
  buf2=buf-5000*j
  if (buf2/1000)==(N-i-j):
   print(i,j,N-i-j)
   flag=1
   break
 if flag==1:
  break

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

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

result = "-1 -1 -1"
flag = False
for x in range(money//10000+1):
    if flag:
        break
    if x > n:
        break
    for y in range((money-10000*x)//5000+1):
        if x + y > n:
            break
        z = (money - 10000 * x - 5000 * y) // 1000
        if x + y + z == n:
            result = "{} {} {}".format(x,y,z)
            flag = True
            break
print(result)

Solution (Python):
def spline(func=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func, iter_)


N, Y = spline()
N += 1
res = None
for x in range(N):
    n = N - x
    xm = x * 10000
    if xm > Y:
        break
    for y in range(n):
        z = n - y - 1
        m = xm + y * 5000 + z * 1000
        if m == Y:
            res = (x, y, z)
            break
    else:
        continue
    break
if res is None:
    res = (-1, -1, -1)
print(*res)

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):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            a,b,c = (i,j,n-i-j)
            break

print(a,b,c)

Solution (Python):
n, y = map(int, input().split())
y //= 1000
a = 0; b = 0; c = 0
f = False
for i in range(n+1):
    for j in range(n+1):
        if 9*i + 4*j == y - n and i + j <= n:
            a = i
            b = j
            f = True
            break
if f: print(a, b, y-10*a-5*b)
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((Y-10000*i-5000*j)>=0 and (Y - 10000*i-5000*j)/1000 == N-i-j):
            print(i, j, (Y-10000*i-5000*j)//1000)
            quit()
else:
    print("-1",  "-1" , "-1")

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

y = y // 1000

yen = 0
for i in range(n + 1):
    for j in range(n + 1 - i):
        yen = (i * 10) + (j * 5)
        if i + j + (y - yen) == n and yen <= y:
            print(i, j, y - yen)
            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 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            exit()
print('-1 -1 -1')

Solution (Python):
from math import floor
N,Y = map(int,input().split(" "))



ans = [-1,-1,-1]
for x in range(N+1):
  y = (Y-1000*N-9000*x)/4000
  if y >= 0 and y - floor(y) == 0:
    y = int(y)
    if N - (x + y) >= 0 and 10000*x + 5000*y + 1000*(N-x-y) == Y:
      ans = [int(x),y,int(N-(x+y))]
      break
print(*ans)

Solution (Python):
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n+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):
n,y = map(int,input().split())
ans = [-1,-1,-1]

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

Solution (Python):

n,y=map(int,input().split())
for a in range(0,n+1):
    mon=y-10000*a
    cnt=n-a
    
    if (mon-1000*cnt)%4000==0 and (5000*cnt-mon)%4000==0:
        b=(mon-1000*cnt)//4000
        c=(5000*cnt-mon)//4000
        
        if 0<=b<=n and 0<=c<=n:
            print(a,b,c)
            exit()

print(-1,-1,-1)

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

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

Solution (Python):

def Otoshidama(n , y):

    for i in range(n + 1):
        for w in range(n - i + 1):
            if (10000*i) + (5000*w) + (1000*(n - (i + w))) == y:
                return str(i) + " " + str(w) + " " + str(n - (i + w))

    return "-1 -1 -1"

def main():
    n , y = map(int , input().split())
    print(Otoshidama(n , y))

if __name__ == '__main__':
    main()

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

ANS = []

for i in range(n + 1):
    for j in range(n + 1):
        k = n - i - j
        if (k >= 0) and (10*i + 5*j + k == y):
            ANS = [i, j, k]
            break

if len(ANS) > 0:
    print(*ANS)
else:
    print(-1, -1, -1)

Solution (Python):

s = input().split()
t = [int(p) for p in s]



N = t[0] 
Y = t[1] 

a = -1 
b = -1 
c = -1 

for i in range(N+1): 
    for j in range(N+1 - i): 
        
        k = N - i - j 
        
        sum = 10000*i+5000*j+1000*k
        if(sum == Y):
            a = i
            b = j
            c = k
            
print('{} {} {}'.format(a,b,c))

Solution (Python):
import numpy as np

N, Y = map(int, input().split())
res = Y - 1000*N
b = -1
for a in range(N+1):
    cand = 9000*a + np.linspace(0, 4000*(N-a), N-a+1)
    if (cand == res).sum() > 0:
        b = np.where(cand==res)[0][0]
        c = N-a-b
        break
if b == -1:
    print(-1, -1, -1)
else:
    print(a, b, c)

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

flag = False

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

        if a*10000 + b*5000 + c*1000 == Y and c >= 0:
            print(str(a) + ' ' + str(b) + ' ' + str(c))

            flag = True
            break
    if flag:
        break

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

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 + 1000*(N-i-j) == 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())

Y = Y/1000
kill = 0
for x in range(N+1):
  for y in range(N-x+1):
    if N + 9*x + 4*y == Y:
      print(x,y,N-x-y)
      kill = 1
      break
  if kill == 1:
    break
if kill == 0:
  print(-1,-1,-1)

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

out = '-1 -1 -1'
is_found = False


def price(t_thousand_num, f_thousand_num, thousand_num):
    return t_thousand_num * 10000 + f_thousand_num * 5000 + thousand_num * 1000


def sum_of_bills(t_thousand_num, f_thousand_num, thousand_num):
    return t_thousand_num + f_thousand_num + thousand_num


def is_over(t_thousand_num, f_thousand_num, thousand_num):
    return price(t_thousand_num, f_thousand_num, thousand_num) > Y or \
           sum_of_bills(t_thousand_num, f_thousand_num, thousand_num) > N


def is_match(t_thousand_num, f_thousand_num, thousand_num):
    return price(t_thousand_num, f_thousand_num, thousand_num) == Y and \
           sum_of_bills(t_thousand_num, f_thousand_num, thousand_num) == N


for t_thousand_num in range(N + 1):

    if is_over(t_thousand_num, 0, 0) or is_found:
        break
    elif is_match(t_thousand_num, 0, 0):
        out = '{} {} {}'.format(t_thousand_num, 0, 0)
        break

    for f_thousand_num in range(N + 1):
        thousand_num = N - f_thousand_num - t_thousand_num
        if is_over(t_thousand_num, f_thousand_num, thousand_num) or is_found or thousand_num < 0:
            break
        elif is_match(t_thousand_num, f_thousand_num, thousand_num):
            out = '{} {} {}'.format(t_thousand_num, f_thousand_num, thousand_num)
            is_found = True
            break

print(out)

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

num = [-1,-1,-1]

for i in range(0,N+1):
  for j in range(0,N+1-i):
    if i*10000+j*5000+(N-i-j)*1000 == Y:
      num = [i,j,N-i-j]
      break

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

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

for x in range(N+1)[::-1]:
  for y in range(N+1-x)[::-1]:
    
    if x*10000+y*5000+(N-x-y)*1000 == Y:
      print(x,y,N-x-y)
      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-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y)==Y:
            print("{} {} {}".format(x, y,(N-x-y)))
            exit()
print("-1 "+"-1 "+"-1")

Solution (Python):
n,y=map(int,input().split())
flag=True
for i in range(n+1):
    if flag:
        for j in range(n-i+1):
            k=n-i-j
            if 10000*i+5000*j+1000*k==y:
                print('{} {} {}'.format(i,j,k))
                flag=False
                break
    else:
        break
if flag:
    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 10000*x + 5000*y + 1000*z == Y and x+y+z == N:
      print(x, y, z)
      quit()

print("-1 -1 -1")

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

a=-1
b=-1
c=-1

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:
      a,b,c = i,j,k
      break

print("{} {} {}".format(a,b,c))

Solution (Python):
import sys

(str_n,str_y) = input().split()
n = int(str_n)
y = int(str_y)

if y % 1000 != 0:
    print (-1,-1,-1)
    sys.exit()

i_max = min(n,y//10000)
for i in range(i_max,-1,-1):
    left = y - 10000*i
    
    j_max = min(n-i,left//5000)
    for j in range(j_max,-1,-1):
        left = y - 10000*i - 5000*j
        
        k = left // 1000
        if i+j+k == n:
            print (i,j,k)
            sys.exit()

print (-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
ans = 0
for i in range(0, N + 1):
    for j in range(0, 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(lambda x:int(x),input().split())
if y%1000 or n*1000>y:print('-1 -1 -1')
else:
    y=y//1000
    b=(y-n)*7%9
    c=(y-n-4*b)//9
    if c<0:print('-1 -1 -1')
    else:
        a=n-b-c
        if a<0:print('-1 -1 -1')
        else:print("%d %d %d"%(c,b,a))

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

Y = Y // 1000
k10, k5, k1 = -1, -1, -1
success = False
price = 0

for i in range(N+1):
  for j in range(N-i+1):
    k = N - i - j
    price = i * 10 + j * 5 + k * 1
    if price == Y:
      k10, k5, k1 = i, j, k
      success = True
      break

  if success:
    break

print(k10, k5, k1)

Solution (Python):
N,Y=map(int,input().split())
answer=-1,-1,-1
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:
            answer=x,y,z
            break
    else:
        continue
    break
print(*answer)

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

exists = False
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(a, b, c)
      exists = True
      break
  
  if (exists == True):
    break

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

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

Solution (Python):

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

yukiti = 10000
higuti = 5000
noguti = 1000
re_yukiti = -1
re_higuti = -1
re_noguti = -1

for i in range(N+1):
    for j in range(N+1-i):
        k = N - i - j
        amount = yukiti*i + higuti*j + noguti*k
        if amount == Y:
            re_yukiti = i
            re_higuti = j
            re_noguti = k
            break

print(re_yukiti,re_higuti,re_noguti)

Solution (Python):

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

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

Solution (Python):
import sys

N, Y = list(map(int, input().split()))
x, y, z = -1, -1, -1
money = 0
for i in range(N + 1):
    for j in range(N - i + 1):
        if Y == i * 10000 + j * 5000 + (N - i - j) * 1000:
            print(i, j, N - i - j)
            sys.exit()

print(x, y, z)

Solution (Python):
N,Y=map(int,input().split())
answer=(-1,-1,-1)
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:
            answer=(x,y,z)
            break
    else:
        continue
    break
print(*answer)

Solution (Python):

N, Y = map(int, input().split())
for i in range(0, N + 1):
    x = 4/5*i + Y/5000 - N
    y = -9/5*i - Y/5000 + 2*N
    z = i
    if (x.is_integer() & y.is_integer()):
        
        
        if ((0 <= x <= N) & (0 <= y <= N)):
            print(int(x), int(y), z)
            break
else:
    print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
match = ""
matchs = []

for i in range(N+1):
    for j in range(N+1-i):
        k = N - i -j
        if (10000*i + 5000*j + 1000*k) == Y:
            match = str(i) + " " + str(j) + " " + str(k)
            matchs.append(match)
        else:
            continue

if matchs == []:
    print("-1 -1 -1")
else:
    print(matchs[0])

Solution (Python):
n, y = map(int, input().split())
y/=1000
for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if 10*i+5*j+k==y:
            print(i,j,k)
            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 (10000 * i + 5000 * j + 1000 * k == y) & (i+j+k==n):
            print(i,j,k)
            exit()
print('-1 -1 -1')

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

def otoshidamaChekcer(N,Y):
    combi = []
    for man in range(N+1):
        for gosen in range(N-man+1):
            sen = N-man-gosen
            if man + gosen + sen == N:
                otoshidama = (man * 10000) + (gosen * 5000) + (sen * 1000)
                
                if otoshidama == Y:
                    return ' '.join(map(str, [man,gosen,sen]))
    return False

combi = otoshidamaChekcer(N,Y)

if combi:
    print(combi)
else :
    print('-1 -1 -1')

Solution (Python):
n,y = map(int,input().split())
res = [-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):
            res = [i,j,n-i-j]
            break
                
print(*res)

Solution (Python):
from sys import stdin
n,y = map(int,stdin.readline().rstrip().split())
for i in range(n+1):
    for j in range(n+1-i):
        k = n-(i+j)
        if 10000*i+5000*j+1000*k == y:
            print(i,j,k)
            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):
        if 1000 * i + 5000 * j + 10000 * (N-i-j) == Y:
            print(N - i - j, j, i)
            exit()
print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
l=[]
c=0
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)
            c+=1
            break
    if c!=0:
        break
if c==0:
    print(-1," ",-1," ",-1)

Solution (Python):
def judge(n, s):
    for x in range(n, -1, -1):
        for y in range(n - x, -1, -1):
            if 10000 * x + 5000 * y + 1000 * (n - x - y) == s:
                return str(x) + " " + str(y) + " " + str(n - x - y)
    return "-1 -1 -1"

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

print(judge(n, s))

Solution (Python):
N_mai, Y_en = map(int, input().split())
N_man, N_5sen, N_sen = -1, -1, -1

for man in range(N_mai + 1):
    
    for sen_5 in range(0, N_mai - man + 1):
        
        mai = N_mai - man - sen_5
        summ = 10000 * man + 5000 * sen_5 + 1000 * mai
        
        if (summ == Y_en):
            N_man, N_5sen, N_sen = man, sen_5, mai
            break

print(N_man,N_5sen,N_sen)

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

def otoshidama():
    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)
                return
    print(-1, -1, -1)

otoshidama()

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

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

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

    for b1 in range(N + 1):
        for b5 in range(N - b1 + 1):
            b10 = N - b1 - b5
            sum = 1000*b1 + 5000*b5 + 10000*b10
            if sum == Y:
                print("{} {} {}".format(b10, b5, b1))
                return
    print("-1 -1 -1")


if __name__ == "__main__":
    resolve()

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

a = b = c = -1
for i in range((Y//10000)+1):
    for j in range((Y-10000*i)//5000+1):
        s = 10000*i + 5000*j + 1000*(N-i-j)
        if s == Y:
            a,b,c = i,j,N-i-j
            
print(a,b,c)

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

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

    print("-1 -1 -1")


if __name__ == "__main__":
    main()

Solution (Python):
n, y = (int(x) for x in input().split())
ans = 0
m = y // 10000 + 1
for i in reversed(range(m)):
    for j in range(n-i+1):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            ans = [i, j, n-i-j]
            break
    if ans != 0:
        break
if ans == 0: print(*[-1, -1, -1])
else: print(*ans)

Solution (Python):
n, y = (int(x) for x in input().split())
ans = 0
m = y // 10000 + 1
for m_i in reversed(range(m)):
    r = y - 10000 * m_i
    g = r // 5000 + 1
    for g_i in range(g):
        if 5000 * g_i + 1000 * (n - m_i - g_i) == r:
            ans = [m_i, g_i, n - m_i - g_i]
            break
    if ans != 0:
        break
if ans == 0: print(*[-1, -1, -1])
else: print(*ans)

Solution (Python):
import sys

num, yen = map(int, input().split())
a = yen//10000
if a > num:
    print(-1, -1, -1)
    sys.exit()

for i in range(a+1):
    yen_rest = yen - 10000*i
    num_rest = num - i

    b = yen_rest//5000
    if b <= num_rest:
        for j in range(b+1):
            yen_rest = yen - 10000*i - 5000*j
            num_rest = num - i - j

            if yen_rest == 1000*num_rest:
                print(i, j, num_rest)
                sys.exit()

print(-1, -1, -1)

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

N,Y=MI()
ans=[-1,-1,-1]

for i in range(N+1):
    for j in range(N+1):
        k=N-(i+j)
        if k<0:
            break
        if i*10000 + j*5000 +k*1000 == Y:
            ans=[i,j,k]
            
            
print(' '.join(map(str, ans)))

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

Solution (Python):
n, y = [int(e) for e in input().split()]

for xi in range(n + 1):
    for yi in range(n - xi + 1):
        zi = n - xi - yi
        if y == xi * 10000 + yi * 5000 + zi * 1000:
            print(xi, yi, zi)
            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):
        if i * 10000 + j * 5000 +(n - i - j)*1000 == y:
            print(i,j,n - i - j)
            exit()
print(-1,-1,-1)

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

ans = []
for x in range(n + 1):
    for y in range(n + 1 - x):
        z = n - x - y
        if a == 10000*x + 5000*y + 1000*z:
            ans.append([x,y,z])

if len(ans)!=0:
    print(*ans[0])
else:
    print(-1,-1,-1)

Solution (Python):
def resolve():
    n, Y = map(int, input().split())

    for x in range(0, n+1):
        for y in range(0, n-x+1):
            z = n-x-y
            sum = 10000*x + 5000*y + 1000*z
            if sum == Y:
                return print(' '.join(map(str, [x, y, z])))

    print(' '.join(map(str, [-1, -1, -1])))

if __name__ == '__main__':
    resolve()

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

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

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

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

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

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

Solution (Python):
N,Y = map(int,input().split())
x = 0
y = 0
z = 0
flag = False
for i in range(N+1):
  for j in range(N+1-i):
    if 0 <= (Y-10000*i-5000*j)/1000 and (Y-10000*i-5000*j)/1000 == N-i-j:
      x = i
      y = j
      z = N-i-j
      flag = True
      break
if flag == False:
  print(-1,-1,-1)
else:
  print(x,y,z)

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

res = 0
for a in range(n+1):
    for b in range(n+1-(a)):
        if 0 <= y - 10000*(a) - 5000*(b) <= 1000*(n-(a+b)):
            c = (y - 10000*(a) - 5000*(b) ) // 1000
            if a+b+c == n:
                r,e,s = a,b,c
                res += 1

if res > 0:
    print(r,e,s)
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):
        k=n-i-j
        m=10000*i+5000*j+1000*k
        if m==y:
            print(i,j,k)
            exit()
print(-1,-1,-1)

Solution (Python):
def main():
    n, y = map(int, input().split())
    ans = '-1 -1 -1'
    if (10000*n < y):
        print(ans)
        return
    for i in range(n+1):
        for j in range(n-i+1):
            k = n-i-j
            if (1000*i+5000*j+10000*k==y):
                ans = '{0} {1} {2}'.format(k,j,i)
                break
        else:
            continue
        break
    print(ans)
main()

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

a = -1   
b = -1   
c = -1   

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:
            a = i
            b = j
            c = k

print("{} {} {}".format(a, b, c))

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


if __name__ == "__main__":
    main()

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):
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):
import sys
N,Y=map(int,input().split())

total = 0

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

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

Solution (Python):
n, y = map(int, input().split())
ans = s = 0
ts = y // 10000 + 1
for i in reversed(range(ts)):
    for j in range(n-i+1):
        if 10000 * i + 5000 * j + 1000 * (n-i-j) == y:
            ans = [i, j, n-i-j]
            s = 1
            break
    if s == 1:
        break
if ans == 0:
    ans = [-1, -1, -1]
    print(*ans)
else: print(*ans)

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

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

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

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