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())
max_10000 = Y // 10000
max_5000 = (Y % 10000) // 5000
max_1000 = (Y % 5000) // 1000
mininum = max_1000 + max_5000 + max_10000
maximum = Y // 1000
n_10000 = -1
n_5000 = -1
n_1000 = -1
if (mininum) <= N and (maximum) >= N:
    diff = maximum - N
    for i in range(diff // 9, -1, -1):
        if (diff - i*9)%4 == 0:
            n_10000 = i
            n_5000 = (diff - i*9)//4
            n_1000 = N - n_10000 - n_5000
            break
print(n_10000, n_5000, n_1000)

Solution (Python):
tuple=input()
list=tuple.split()
list=[int(i) for i in list]
N=list[0]
Y=list[1]
for i in range(int(Y/10000)+1):
    for j in range(int((Y-10000*i)/5000)+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())
flag = 0
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:
         flag = 1
         print('{} {} {}'.format(i, j, k))
         break
   else:
      continue
   break
if flag == 0:
   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(i*10000+j*5000+(N-i-j)*1000 == Y):
            print(i,j,N-i-j)
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
s=y//1000
if s<n:
    print("-1 -1 -1")
else:
    if s==n:
        print("0 0 "+str(s))
    else:
        d=s-n
        for i in range(min(9,d//4+1)):
            if (d-4*i)%9==0:
                if (d-4*i)//9+i<=n:
                    print(str((d-4*i)//9)+" "+str(i)+" "+str(n-i-(d-4*i)//9))
                    break
        else:
             print("-1 -1 -1")

Solution (Python):
def main(n, y):
    for n1000 in range(n + 1):
        for n5000 in range(n - n1000 + 1):
            n10000 = n - n1000 - n5000
            if (1000 * n1000 + 5000 * n5000 + 10000 * n10000) == y:
                return [n10000, n5000, n1000]

    return [-1, -1, -1]

n, y = map(int, input().split())
print(' '.join(map(str, main(n, y))))

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

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

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

Solution (Python):


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

detected = False
ans1 = -1
ans2 = -1
ans3 = -1
for i in range(0, n + 1):
    if detected:
        break

    for j in range(0, n + 1 - i):
        if detected:
            break

        temp_x = y - (i * 10000) - (j * 5000) - ((n - i - j) * 1000)
        if temp_x == 0:
            detected = True
            ans1 = i
            ans2 = j
            ans3 = n - i - j
            break

print(ans1, ans2, ans3)

Solution (Python):

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

for a in range(N + 1):
    for b in range(N + 1):
        if a + b > N:
            break
        else:
            c = N - a - b
            total = 10000 * a + 5000 * b + 1000 * c
            if total == Y:
                print('{0} {1} {2}'.format(a, b, c))
                exit()

print('-1 -1 -1')

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

none = True

for i in range(n+1):
    for j in range(n+1):
        k = n-i-j
        if (i*10000 + j*5000 + k*1000) == y and k >= 0:
            none = False
            break
    if none == False:
        break
if none:
    print('-1 -1 -1')
else:
    print("{} {} {}".format(i, j, k))

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

num_10 = 0
num_5  = 0
num_1  = 0
none = True

for i in range(n+1):
    for j in range(n+1):
        k = n-i-j
        if (i*10000 + j*5000 + k*1000) == y and k >= 0:
            num_10 = i
            num_5 = j
            num_1 = k
            none = False
            break
    if none == False:
        break
if none:
    print('-1 -1 -1')
else:
    print("{} {} {}".format(num_10, num_5, num_1))

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

if N*10000 == Y:
    print(' '.join(map(str, (N, 0, 0))))
    exit()

for a in range(N):
    for b in range(N+1-a):
        c = N-a-b
        if a*10000 + b * 5000 + c * 1000 == Y:
            print(' '.join(map(str, (a, b, c))))
            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(k >= 0):
      if(10000*i + 5000*j + 1000*k == Y):
        print(i, j, k)
        exit()
print(-1, -1, -1)

Solution (Python):
if __name__ == '__main__':
    n, Y = map(int, input().split())

    for x in reversed(range(n+1)):
        for y in reversed(range(n-x+1)):
            z = n - x - y
            if x*10000+y*5000+z*1000 == Y:
                print('{} {} {}'.format(x, y, z))
                exit()
    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-i):
        if i*10000+j*5000+(N-i-j)*1000 == Y:
            flag = 1
            break
    if flag:
        break

if flag:
    print(i,j,N-i-j)
else:
    print(-1,-1,-1)

Solution (Python):
import sys
int_n, int_y = list(map(int, input().split()))

find = False

for ichimanen in range(int_n + 1):
    for gosenen in range(int_n + 1):
        if int_n - ichimanen - gosenen >= 0:
            if ichimanen + gosenen + (int_n - ichimanen - gosenen) == int_n and find is False:
                if (ichimanen * 10000 + gosenen * 5000 + (int_n - ichimanen - gosenen) * 1000) == int_y:
                    find = True
                    print(ichimanen, gosenen, (int_n - ichimanen - gosenen))
                    sys.exit()

if find is False:
    print(-1, -1, -1)

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

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

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

Solution (Python):


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

for i in range(N+1):
  if result == True:
    break
  Y_left = Y - 10000 * i
  for j in range(N-i+1):
    Y_last = Y_left - 5000 * j
    k = Y_last // 1000
    if i+j+k == N:
      result = True
      print('{} {} {}'.format(i, j, k))
      break

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

Solution (Python):

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

num_ten_thouthand = int(Y / 10000)



for i_ten_thouthand in range(0,num_ten_thouthand+1):
    for i_five_thouthand in range(0,N - i_ten_thouthand +1):
        i_thouthand = N  - i_ten_thouthand - i_five_thouthand
        if i_thouthand * 1000 + i_five_thouthand * 5000 + i_ten_thouthand * 10000 == Y:
            print("{} {} {}".format(i_ten_thouthand,i_five_thouthand,i_thouthand))
            sys.exit()

print("-1 -1 -1")

Solution (Python):

n,y=map(int,input().split())
y=int(y/1000)
s=[]
for a in range(1+y//10):
    now=y
    now-=10*a
    for b in range(1+now//5):
        nex=now-5*b
        if n-a-b==nex:
            s=[a,b,nex]
if s==[]:print('-1 -1 -1')
else:print(' '.join(map(str,s)))

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

Solution (Python):
inp = input().split()
satu= int(inp[0])
en = int(inp[1])
h =0

for i in range(satu+1):
	nokori = satu - i
	for k in range(nokori+1):
		nokori2 = nokori - k
		kin = i * 1000 + k * 5000 + nokori2 * 10000
		if kin == en:
			h = 1
			break
	else:
		continue
	break
if h != 1:
    
	nokori2 = -1
	k = -1
	i  = -1
print(nokori2,k,i)

Solution (Python):
N,Y = map(int,input().split(" "))
M10000,M5000,M1000 = -1,-1,-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:
      M10000 = a
      M5000 = b
      M1000 = c
ans = str(M10000) + " " + str(M5000) + " " + str(M1000)
print(ans)

Solution (Python):
n,y = map(int, input().split())
ans=0
flag=False
for i in range(y//10000 + 1):
    for j in range((y-i*10000)//5000 + 1):
        if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
            print('{} {} {}'.format(i,j,n-i-j))
            flag=True
            break
    if flag:
        break
if not flag:
    print('{} {} {}'.format(-1,-1,-1))

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

def f(n,y):
    for i in range(n+1):
        for j in range(n-i+1):
            s = 10000*i + 5000*j + 1000*(n-i-j)
            if s == y:
                return '{0} {1} {2}'.format(i,j,n-i-j)

    return '-1 -1 -1'

print(f(n,y))

Solution (Python):
N,Y=map(int,input().split())
flag=False
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            flag=True
            a=i
            b=j
            c=N-i-j
if flag==True:
    print(a,b,c)
else:
    print('-1 -1 -1')

Solution (Python):
N,Y=map(int,input().split())
flag=False
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            flag=True
            a=i
            b=j
            c=N-i-j
if flag==True:
    print(a,b,c)
else:
    print('-1 -1 -1')

Solution (Python):
N,Y = map(int,input().split())
answer = 0 
s,t,u = -1,-1,-1

for i in range(N+1):
    for j in range(N+1-i):
        if i * 10000 + j * 5000 + (N-i-j) * 1000 == Y:
            s = i
            t = j
            u = N-i-j

print(s,t,u)

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 ai in range(N+1):
    for bi in range(0, N-ai+1):
        ci = N - ai - bi
        total = 10000*ai + 5000*bi + 1000*ci
        if total == Y:
            res10000 = ai
            res5000 = bi
            res1000 = ci
            break

print(str(res10000) + " " + str(res5000) + " " + str(res1000))

Solution (Python):
import sys
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)
            sys.exit()
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):
        sum = 10000*i + 5000*j + 1000*(N-(i+j))
        if Y == sum:
            x = i
            y = j
            z = N - i - j

print("{} {} {}".format(x, y, z))

Solution (Python):
def count(n, y):
    for i in range(n + 1):
        for j in range(n + 1 - i):
            k = n - i - j
            total = i * 10000 + j * 5000 + k * 1000
            if total == y:
                return [i, j, k]                
    return [-1, -1, -1]


(n, y) = map(int, input().split())
ans = count(n, y)
print("{} {} {}".format(ans[0], ans[1], ans[2]))

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

x,y,z = 0,0,0

flg = False
for x in range(N+1):
    for y in range(0,N-x+1):
        z = N-x-y
        m = 10000*x+5000*y+1000*z
        if m == Y:
            print(x,y,z)
            flg = True
            break
    if flg==True:
        break

if flg==False:
    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 i*10000+j*5000+(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())
check = 1
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)
      check = 0
      break
  else:
    continue
  break
if check:
  print(-1, -1, -1)

Solution (Python):
n, y = map(int, input().split())
check = 1
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)
      check = 0
      break
  else:
    continue
  break
if check:
  print(-1, -1, -1)

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

def func(n, y):
    for m in range(n + 1):
        for g in range(n - m + 1):
            s = n - m - g
            if m * 10000 + g * 5000 + s * 1000 == y:
                return m, g, s
    return -1, -1, -1

m, g, s = func(n, y)

print(m, g, s)

Solution (Python):


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


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

result = calc(N, Y)
print('%d  %d %d' % (result[0], result[1], result[2]))

Solution (Python):
N, Y = map(int, input().split())
for y in range(9):
    for x in range(N + 1):
        if Y == (10000 * x) + (5000 * y) + (1000 * (N - x - y)) and N >= x + y:
                print(x, y, N - x - y)
                break
        else:
            continue
        break
    else:
        if y == 8:
            print(-1, -1, -1)
        continue
    break

Solution (Python):


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

ans = 0
for n10K in range(N + 1):
    for n5K in range(N + 1 - n10K):
        if Y - n10K * 10000 - n5K * 5000 == (N - n10K - n5K) * 1000:
            print("{} {} {}".format(n10K, n5K, N - n10K - n5K))
            exit()

print("-1 -1 -1")

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

for m in range(n + 1):
    for g in range(n + 1 - m):
        s = n - m - g
        yen = 10000 * m + 5000 * g + 1000 * s
        if yen == y:
            break
    if yen == y:
        break
if yen == y:
    print(m, g, s)
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(N+1-i):
        k = N - i -j
        if i*10000 + j*5000 + 1000*k == Y:
            print(i, j, k)
            sys.exit()

print(-1, -1, -1)

Solution (Python):
line = input().split(" ")
n = int(line[0])
yy = int(line[1])

for x in range(0, n+1, 1):
    if((10000 * x) <= yy):
        for y in range(0, (n-x+1), 1):
            if(((5000 * y) + (10000 * x)) <= yy):
                z = n - x - y
                if(((1000 * z) + (5000 * y) + (10000 * x)) == yy and (n == (x + y + z))):
                    print(x,y,z)
                    exit()
x = -1
y = -1
z = -1
print(x,y,z)

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

judge = False
result = []
for i in range(n+1):
  if judge:
    break
  for j in range(n+1-i):
    if 10000*i + 5000*j + 1000*(n-i-j) == cost:
      judge = True
      result = [i, j, n-i-j]
      break

if not judge:
  result = [-1, -1, -1]
  

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

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

def main(Y):
    for i in range(Y//5000+1):
        b = i
        c = Y//1000 - 5*i
        if b//2 + b%2 + c <= N <= b + c:
            for j in range(b//2+1):
                if j + (b - 2*j) + c == N:
                    return (j, b - 2*j, c)
    return (-1, -1, -1)

result = main(Y)
print(' '.join(map(str, result)))

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

def chooseMoney(n, x):
    for i in range(n + 1):
        remain = x - 10000 * i
        for j in range(min(remain // 5000, n - i) + 1):
            if remain - j * 5000 == (n - i - j) * 1000:
                return "{} {} {}".format(i, j, n - i - j)
    return "-1 -1 -1"

print(chooseMoney(n, x))

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 10000 * i + 5000 * j + 1000 * (n-i-j) == y:
            ans = [i, j, n -i-j]
            
print(' '.join(map(str, ans)))

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

for x,y in product(range(0,N+1),repeat=2):
    z=N-x-y
    if z>=0 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())
 
ans =[-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1 - i):
            if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
                ans = [i, j, n - i - j]
                break
print(' '.join(map(str, ans)))

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

Y /= 1000


def search(N, Y):
    for i in range(N+1):
        for j in range(N+1-i):
            if 10*i+5*j+(N-i-j) == Y:
                return [i, j, N-i-j]
    return [-1, -1, -1]


print(' '.join(list(map(str, search(N, Y)))))

Solution (Python):


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

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

print(-1,-1,-1)

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

Solution (Python):
n,y=map(int,input().split());r=range
for i in r(n+1):
  for j in r(n-i+1):
    if i*9+j*4+n==y/1000and i+j<=n:print(i,j,n-i-j);exit()
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split());r=range
for i in r(n+1):
  for j in r(n-i+1):
      o=n-i-j
      if i*10+j*5+o==y/1000and i+j<=n:print(i,j,o);exit()
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
r=range
for i in r(n+1):
  for j in r(n-i+1):
      o=(n-i-j)
      if i*10+j*5+o==y/1000 and i+j<=n:
          print(i,j,o)
          exit()
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
y//=1000
a=False
r=range
for i in r(n+1):
    for j in r(n-i+1):
        o=(n-i-j)
        if i*10+j*5+o==y and i+j<=n:
            print(i,j,o)
            a=True
    if a:break
if not a:print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
y //= 1000
a = False
for i in range(n+1):
    for j in range(n-i+1):
        if i*10 + j*5 + (n-i-j) == y and i+j <= n:
            print(i, j, (n-i-j))
            a = True
            break
    if a:
        break
if not a:
    print(-1,-1,-1)

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

y = Y//1000
a_ans = -1
b_ans = -1
c_ans = -1
for a in range(0,N+1):
	b = (y-9*a-N)//4
	c = N-a-b
	if b >= 0 and c >= 0 and (y-9*a-N)%4 == 0:
		print(a,b,c)
		exit()

print(-1,-1,-1)

Solution (Python):
count,total = list(map(int,input().split()))
ret1 = -1
ret2 = -1
ret3 = -1
NF = True
if total <= count * 10000:
	for i in range(count + 1):
		rCount = count - i
		if total-10000*i <= rCount * 5000:
			for j in range(rCount + 1):
				if (i*10000 + j*5000 + (count-i-j)*1000) == total:
					ret1 = i
					ret2 = j
					ret3 = count-i-j
					NF = False
					break
if NF:
	ret1 = -1
	ret2 = -1
	ret3 = -1
print(str(ret1) + " " + str(ret2) + " " + str(ret3))

Solution (Python):
def main(N,Y):
    
    Y = Y // 1000
    lb = (2*(Y-N)-1) // 9 + 1
    ub = min ((Y-N) // 4, Y // 5)
    ans = [ (x,y,z) for w in range(lb,ub+1) for x in [Y-N-4*w] for y in [w - 2*x] for z in [N - x - y] ]
    assert(all(map(lambda a: a[0]>=0 and a[1]>=0 and a[2]>=0, ans)))
    if ans == []:
        print("-1 -1 -1")
    else:
        x,y,z = ans[0]
        print("{0} {1} {2}".format(x,y,z))
    return

if __name__ == '__main__':
    N, Y, *_ = map(int, input().split())
    main(N,Y)

Solution (Python):
def main(N,Y):
    
    """
    次の方程式
        x + y + z = N
        10x + 5y + z = Y
    の解を探索する．zを消去すると
        9x + 4y = Y - N
      where
        x >= 0
        y >= 0
        x + y <= N
    w = 2x+y と置くと
        x + 4w = Y - N
      where
        x >= 0
        w >= 0
        w - x <= N
    xを消去すると条件は
        w  >= 0
        4w <= Y - N
        5w <= Y
        9w >= 2(Y - N)
    であり
        x = Y - N - 4w
        y = w - 2x
        z = N - x - y
    wを適当にboundした後は x>=0 and y>=0 and z >= 0 でfilteringするのが安心だが
    練習のために w のみでfilteringしてみる
    """
    Y = Y // 1000
    lb = (2*(Y-N)-1) // 9 + 1
    ub = min ((Y-N) // 4, Y // 5)
    ans = [ (x,y,z) for w in range(lb,ub+1) for x in [Y-N-4*w] for y in [w - 2*x] for z in [N - x - y] ]
    if ans == []:
        print("-1 -1 -1")
    else:
        x,y,z = ans[0]
        print("{0} {1} {2}".format(x,y,z))
    return

if __name__ == '__main__':
    N, Y, *_ = map(int, input().split())
    main(N,Y)

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

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

Solution (Python):
import numpy as np
n, y = np.array(list(input().split()), dtype=int)

vals = np.array([10000, 5000, 1000])

table = []
for c in range(n + 1):
    part = np.zeros((n + 1 - c, 3), dtype=int)
    part[:, 0] = c
    part[:, 1] = np.arange(n + 1 - c)
    table += [part]
table = np.concatenate(table)
table[:, 2] = n - table[:, 0:2].sum(axis=1)

accum = (table * vals).sum(axis=1)
flags = np.where(accum == y)[0]

if len(flags) == 0:
    print("-1 -1 -1")
else:
    nums = table[flags[0]]
    print("{} {} {}".format(*nums))

Solution (Python):
N, Y = map(int, input().split())
flg = False
if N * 1000 <= Y <= N * 10000:
    for i in range(N + 1)[::-1]:
        if Y < i * 10000:
            continue
        if flg or i * 10000 + (N - i) * 5000 < Y:
            break
        for j in range(N + 1 - i)[::-1]:
            m = i * 10000 + j * 5000 + (N - i - j) * 1000
            if Y < m:
                continue
            if m == Y:
                print(i, j, N - i - j)
                flg = True
            if m <= Y:
                break
if not flg:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
flg = False
if N * 1000 <= Y <= N * 10000:
    for i in range(N + 1)[::-1]:
        if Y < i * 10000:
            continue
        if flg or i * 10000 + (N - i) * 5000 < Y:
            break
        for j in range(N + 1 - i)[::-1]:
            m = i * 10000 + j * 5000 + (N - i - j) * 1000
            if Y < m:
                continue
            if m == Y:
                print(i, j, N - i - j)
                flg = True
            if m <= Y:
                break
if not flg:
    print(-1, -1, -1)

Solution (Python):
N, Y = map(int, input().split())
flg = False
if N * 1000 <= Y <= N * 10000:
    for i in range(N + 1)[::-1]:
        if Y < i * 10000:
            continue
        if flg or i * 10000 + (N - i) * 5000 < Y:
            break
        for j in range(N + 1 - i)[::-1]:
            m = i * 10000 + j * 5000 + (N - i - j) * 1000
            if Y < m:
                continue
            if m == Y:
                print(i, j, N - i - j)
                flg = True
            if m <= Y:
                break
if not flg:
    print(-1, -1, -1)

Solution (Python):




def solveProblem(AllSheet,GivenMoney):
	cash1000 = 0
	cash5000 = 0
	cash10000 = 0
	searchFlag = False
	for cash1000 in range(0,AllSheet+1,+1):
		for cash5000 in range(0,AllSheet+1-cash1000):
			cash10000=AllSheet-cash1000-cash5000
			nowTotal = cash10000*10000+cash5000*5000+cash1000*1000
			if nowTotal == GivenMoney:
				answer=[cash10000,cash5000,cash1000]
				searchFlag = True
				break
	if searchFlag != True:
		answer=[-1,-1,-1]
	return answer

if __name__ == '__main__':
	N,Y = map(int,input().strip().split(' '))
	solution=solveProblem(N,Y)
	print("{} {} {}".format(solution[0], solution[1], solution[2]))

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

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

import sys
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:
            print(i,j,k)
            sys.exit()

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-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 ib in range(9):
    if (Y-4000*ib-1000*N) % 9000 == 0:
        a = (Y-4000*ib-1000*N)//9000
        if a >= 0 and N-a-ib >= 0:
            print(a, ib, N-a-ib)
            exit()
print(-1, -1, -1)

Solution (Python):

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

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

print(' '.join(list(map(str,fcn()))))

Solution (Python):
def judge(N,Y):
    if(Y%1000!=0):
        return print('-1 -1 -1')
    for x in range(N+1):
        for y in range(N+1-x):
            if(9*x+4*y+N == Y/1000):
                return print(x, y, N-x-y)
    return print('-1 -1 -1')

if __name__ == '__main__':
    N, Y = map(int, input().split())
    judge(N,Y)

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

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

a, b ,c = calc(N, Y)
print(str(a) + " " + str(b) + " " + str(c))

Solution (Python):

N, Y = [int(x) for x in input().split()]

Y //= 1000
c1m = Y // 10
c5c = Y // 5
c1c = Y

found = False
for i in range(c1m+1):
    for j in range(c5c+1):
        k = N - i - j
        
        if k>=0 and k<=c1c and i*10 + j*5 + k == Y:
            found = True
            break
    if found: break
if not found:
    i,j,k = -1,-1,-1
print('%d %d %d' % (i,j,k))

Solution (Python):
n, y = map(int, input().split())
for a in range(0, n+1):
    for b in range(0, 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):
def a():return input()
def ai():return int(input())
def ma():return map(int, input().split())
def ms():return map(str, input().split())
def lma():return list(map(int, input().split()))
def lms():return list(map(str, input().split()))
a,b = ma()
c=d=e=-1
for i in range(a+1):
    for j in range(a-i+1):
        if b == i*10000 + j*5000 + (a-i-j)*1000: 
            c,d,e=i,j,a-i-j
            break
print(c,d,e)

Solution (Python):
n,y = (int(i) for i in input().split())
ans = 0
for i in range(n+1):
  for j in range(n+1):
    sen = n-i-j
    if sen >= 0:
     if i*10000+j*5000+sen*1000 ==y:
      ans = 1
      judge = [i,j,sen]
if ans >0 :
  print(*judge)
else:
  print("-1 -1 -1")

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

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

while True:
    a = Y_1 - N - 9*x

    if a < 0:
        break
    elif (a%4 == 0):
        y = a // 4
        if (N - x - y >= 0):
            print(x,y,N-x-y)
            exit()
        else:
            x += 1

    else:
        x += 1

print('-1 -1 -1')

Solution (Python):
N,Y=[int(a) for a in input().split()]
for x in range(N+1):
    for y in range(N+1-x):
        z=N-x-y
        if 10*x+5*y+z==Y//1000:
            print(x,y,z)
            import sys
            sys.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())
for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if 0<=z<=2000:
            if 10000*x+5000*y+1000*z==Y:
                print(x,y,z)
                exit()
print(-1,-1,-1)

Solution (Python):


def read_input():
    n, y = map(int, input().split())
    return n, y


def check_1000(y, n):
    return n * 1000 == y


def check_5000(y, n):
    test_n = range(n + 1)

    for tn in test_n:
        rest_y = y - tn*5000
        rest_n = n - tn

        if rest_y < 0:
            break

        if check_1000(rest_y, rest_n):
            return True, tn, rest_n

    return False, -1, -1


def check_10000(y, n):
    test_n = range(n + 1)

    for tn in test_n:
        rest_y = y - tn*10000
        rest_n = n - tn

        if rest_y < 0:
            break

        check_under, n5000, n1000 = check_5000(rest_y, rest_n)
        if check_under:
            return tn, n5000, n1000

    return -1, -1, -1


n, y = read_input()
print('{} {} {}'.format(*check_10000(y, n)))

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

def judge(maisuu, kingaku, man, gesen):
  sen = maisuu - (man + gesen)
  if kingaku == (10000 * man + 5000 * gesen + 1000 * sen):
    return True
  return False

for i in range(n + 1):
  for j in range(n - i + 1):
    if judge(n, y, i, j):
      print('{} {} {}'.format(i, j, (n - i - j)))
      quit()
print('-1 -1 -1')

Solution (Python):
import sys

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

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

print("{i} {j} {k}".format(i=-1,j=-1,k=-1))

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