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

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

for i in range(n + 1):
    for j in range(n - 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 math
import sys
import numpy as np
import collections


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



max1 = int(y/1000) + 1

for i in range(max1):
  rest = y-i*9000-n*1000
  mod = rest%4000
  ii  = int((rest)/4000)
  iii = n-i-ii
  if(mod == 0 and iii>=0 and ii>=0):
    print(i, ii, iii)
    sys.exit()
    
print(-1,-1,-1)

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

    for tho in range(N+1):
        for fif in range(N+1-tho):
            ten = N - fif - tho
            if ten*10000 + fif*5000 + tho*1000 == Y:
                print(ten, fif, tho)
                return

    print("-1 -1 -1")

main()

Solution (Python):

"""
Created on Tue Feb  4 00:34:00 2020

@author: yama
"""

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

f = False
for i in range(n+1):
    for j in range(n-i+1):
        k = (y - (i*10000 + j*5000))//1000
        if i + j + k == n and i*10000 + j*5000 + k*1000 == y:
            f = True
            break
    if f == True:
        break
    
if f == True:
    print(i, j, k)
else:
    print("-1 -1 -1")

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
tmp_a = Y//10 + 1
tmp_b = Y//5 + 1

for i in range(tmp_a):
    for j in range(tmp_b):
        k = N-(i+j)
        if k>=0 and 10*i+5*j+k==Y:
                print(i,j,k)
                exit()
print('-1 -1 -1')

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

ca, cb, cc = -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:
            ca, cb, cc = a, b, c
            
print(ca, cb, cc)

Solution (Python):
[n,y]=list(map(int,input().split()))
wa=y-1000*n
ans=0
if wa<0:
    ans=[-1,-1,-1]
else:
    for i in range(n+1):
        for j in range(n-i+1):
            if wa==9000*i+4000*j:
                ans=[i,j,n-i-j]
                break
if ans==0:
    ans=[-1,-1,-1]
for i in range(3):
    print(ans[i],end=" ")

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

for i in range(N+1):
    A = i
    for j in range(N+1):
        B = j
        C = N - A - B
        if C < 0:
            break
        s = 10000*A+5000*B+1000*C
        if s == Y:
            a = str(A)
            b = str(B)
            c = str(C)
            print(a+" "+b+" "+c)
            exit()

print("-1"+" "+"-1"+" "+"-1")

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

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

print("-1 -1 -1")

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


y = 0


exist_answer = False

for i in range(N + 1):
    for j in range((N + 1) - i):
        k = N - (i + j)
        y = i * 10000 + j * 5000 + k * 1000
        if y == Y:
            exist_answer = True
            print(i, j, k)
            break
    if exist_answer is True:
        break

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

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

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

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

ans=False

for man in range(N+1):
    for gosen in range(N-man+1):
            if man*10000+gosen*5000+(N-man-gosen)*1000==Y:
                print(man,gosen,N-man-gosen)
                ans=True
                exit()



if not ans:
    print("-1 -1 -1")

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

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

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

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

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

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

Y = Y//1000

ans = '-1 -1 -1'

for x in range(0, n+1):
    for y in range(0, n+1-x):
        if (0 <= n-x-y) and (10*x + 5*y + n-x-y == Y):
            ans = '%s %s %s' % (x, y, n-x-y)
            break

print(ans)

Solution (Python):
import sys

n,y=map(int,input().split())
ans=[-1]*3
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:
			ans[0]=i
			ans[1]=j
			ans[2]=k
print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

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

is_false = True
for i in range(n+1):
  for j in range(n+1):
    if i+j > n:
      pass
    else:
      k = n-i-j
      otoshi = 10000*i + 5000*j + 1000*k
      if otoshi == X:
        print(i, j, k)
        is_false = False
        break
  else:
    continue
  break

if is_false:
  print('-1 -1 -1')

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

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

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

print(-1,-1,-1)

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

flag=False
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:
            flag=True
            break
    if flag:
        break

if flag:
    print(i,j,k)
else:
    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-i*10000)//5000 + 1):
        if ((Y-i*10000-j*5000)//1000) == N-i-j:
            print(i, j, N-i-j)
            sys.exit()
print(-1,-1,-1)

Solution (Python):
n,y=[int(x) for x in input().split()]
import sys
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("{0} {1} {2}".format(i,j,k))
            sys.exit()
print("-1 -1 -1")

Solution (Python):

n,y = map(int,input().split())
ans = (-1,-1,-1)
for i in range(n+1): 
	for j in range(n+1-i):
		if y == 1000*(i + j * 5 + (n-i-j) * 10 ): 
			print( n-i-j, j, i ) 
			exit(0)
print(-1,-1,-1)

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

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())
a=10000
b=5000
c=1000
x=Y//a+1
ans=['-1','-1','-1']
for i in range(x):
  if Y-i*a<0:
    break
  if ans!=['-1','-1','-1']:
    break
  jtmp=(Y-i*a)//5000+1
  for j in range(jtmp):
    k=(Y-a*i-b*j)//c
    if Y-a*i-b*j-c*k==0 and i+j+k==N:
      ans=[str(i),str(j),str(k)]
      break
print(' '.join(ans))

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

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


i5000 = 0
i10000 = 0
N = n + 1
for i1000 in range(N):
    for i5000 in range(N - i1000):
        i10000 = n - i1000 - i5000
        sum = i10000*10000 + i5000*5000 + i1000*1000
        if sum == y:
            print(i10000,i5000,i1000)
            exit()
print("-1 -1 -1")

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

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

print('-1 -1 -1')

Solution (Python):
n,y = map(int,input().split())
y = y//1000
flag = 0
for i in range(n+1):
    for j in range(n+1-i):
        if i*10 + j*5 + (n-i-j) == y:
            print(i, j, n-i-j)
            flag = 1
            break
    if flag == 1:
        break
if flag == 0:
    print('-1 -1 -1')

Solution (Python):

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

answer1 = -1
answer2 = -1
answer3 = -1
for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y and k >= 0:
            answer1 = i
            answer2 = j
            answer3 = k

print(str(answer1) + " " + str(answer2) + " " + str(answer3))

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

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

    print(-1, -1, -1)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

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

nm = Y // 10000

for y in range(N + 1):
    for z in range(N - y + 1):
        temp = Y - 5000*y - 1000*z
        if temp//10000 == N - y - z and temp%10000 == 0:
            print(temp//10000, y, z)
            sys.exit()
else:
    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):
    rest = y - 10000*i - 5000*j
    if i+j+rest//1000 == n:
      print('{} {} {}'.format(i,j,rest//1000))
      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
      break
      
print(a,b,c)

Solution (Python):
def solve(n, y):
    for i in range(0, n + 1):
        for j in range(i, n + 1):
            a, b, c = i, j - i, n - j
            if 10000 * a + 5000 * b + 1000 * c == y:
                return (a, b, c)
    return (-1, -1, -1)

_n, _y = map(int, input().split())
print(*solve(_n, _y))

Solution (Python):
flag = 0
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 and k >= 0:
      flag = 1
      print(i,j,k)
      break
  if flag == 1:
    break
    
if flag == 0:
  print(-1,-1,-1)

Solution (Python):
n, y = map(int, input().split())
f = False
import math

m1 = math.ceil(y / 10000)
for i in range(m1 + 1):
    if y % 1000 != 0:
        break

    s = y - 10000 * i
    m2 = math.ceil( s / 5000)

    for j in range(m2 + 1):
        s = y - 10000*i - 5000*j
        k = s // 1000
        if k < 0:
            continue
        if i + j + k == n and 10000*i + 5000*j + 1000*k == y:
            f = True
            break
    if f:
        break

if f is False:
    print("-1 -1 -1")
else:
    print("{0} {1} {2}".format(i, j, k))

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):
        s = i*10000+j*5000+(n-i-j)*1000
        if s == y:
            ans = [i, j, n-i-j]
            break

print(*ans)

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

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

Solution (Python):
n, y = map(int, input().split())
def main():
  for m in range(n+1):
    s = y - 10000 * m
    if s < 0: break
    if s > 5000 * (n-m):
      continue
    for g in range(n - m + 1):
      s2 = s -5000 * g
      if s2 < 0: break
      if s2 == 1000 * (n -m -g):
        return m, g, n-m-g
  return -1, -1, -1

print(*main())

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

print(*[-1]*3)

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


def judge(n, target):
    for x in range(n+1):
        for y in range(n+1-x):
            
            
            tmp = Y - 10000 * x - 5000 * y
            z = n - x - y
            if tmp / 1000 == z:
                return '{} {} {}'.format(x, y, z)
    return '-1 -1 -1'


print(judge(N, Y))

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

a = 10000
b = 5000
c = 1000





def solve(n):
    for i in range(N+1):
        for j in range(N-i+1):
            tmp = Y - a * i - b * j
            k = N - i - j
            if (tmp == 0 and k == 0) or tmp // c == k:
                return i, j, k
    return -1, -1, -1


i, j, k = solve(N)
print(i, j, k)

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

a = 10000
b = 5000
c = 1000





is_ok = False
for p in range(N+1):
    for q in range(N-p+1):
        tmp = Y - a * p - b * q
        if tmp < 0:
            continue
        if (tmp == 0 and N-p-q == 0) or tmp // c == N-p-q:
            is_ok = True
            break
    if is_ok:
        break
if is_ok:
    print('{} {} {}'.format(p, q, N-p-q))
else:
    print('-1 -1 -1')

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

judge = False
for i in range(0, N[0]+1):
    for j in range(0, N[0]+1-i):
        k = N[0]-i-j
        if(10000*i + 5000*j + 1000*k == N[1]):
            judge = True
            break
    else:
        continue
    break

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

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

t = int(Y/1000 - N)
x = -1
y = -1
z = -1
for i in range(N+1):
  if ((t - 9*i)/4 < 0):
    break
  elif (int((t - 9*i)/4) == (t - 9*i)/4) and (N - i - int((t - 9*i)/4) >= 0) and (t - 9*i)/4 >= 0:
    x = i
    y = int((t - 9*i)/4)
    z = int(N - x - y)
    break
  else:
    continue
    
print('{0} {1} {2}'.format(x,y,z))

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

Solution (Python):
N,Y = map(int,input().split())
Y = Y // 1000
ans = False
for i in range(N+1):
    for j in range(N-i+1):
        if 10*i + 5*j + (N-i-j) == Y:
            ans = True
            x = i; y = j; z = N-i-j
            break

if ans == True:
    print(x,y,z)
else:
    print(-1,-1,-1)

Solution (Python):
n,y = map(int, input().strip().split())
a_x, a_y, a_z = -1, -1, -1
for xi in range(n + 1):
  for yi in range(n - xi + 1):
    zi = n - xi - yi
    if 10000*xi + 5000*yi + 1000*zi == y:
      a_x = xi
      a_y = yi
      a_z = zi
      break
 
print(a_x, a_y, a_z)

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

cnt = [int(-1)for i in range(3)]
for A in range(N+1):
    for B in range(N+1 - A):
        C = N - A - B
        calc = A*10000 + B*5000 + C*1000
        if calc == Y:
            cnt = [A, B, C]
            break
    else:
        continue
    break
print(' '.join(map(str,cnt)))

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

for i in range(N+1):
    for j in range(N+1-i):
        if Y == i * 10000 + j * 5000 + (N-i-j) * 1000 and flag == 1:
            print("{} {} {}".format(i, j, N-i-j))
            flag = 0

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

Solution (Python):
import sys


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

ans_x, ans_y, ans_z = -1, -1, -1









for i in range(N+1) :
  x = i
  
  
  

  for j in range(N+1-x) :
    y = j
    z = N - x - y
    sum = 10000*x + 5000*y + 1000*z
    
    if sum == Y :
      ans_x=x
      ans_y=y
      ans_z=z

print(str(ans_x) + " " + str(ans_y) + " " + str(ans_z))

Solution (Python):
(k, s),  = [list(map(int, s.split())) for s in open(0)]
flag = 0 
for i in range(k + 1):
    for j in range(k - i + 1):
        l = k - i - j
        if 10000 * i + 5000 * j + 1000 * l == s:
            print(i, j, l)
            flag += 1 
            break
    else:
        continue 
    break

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

Solution (Python):
n, y = list(map(int, input().split()))
result = [-1, -1, -1]
for m_10000 in range(n + 1):
    for m_5000 in range(n + 1 - m_10000):
        m_1000 = n - m_10000 - m_5000
        k = 10000 * m_10000 + 5000 * m_5000 + 1000 * m_1000
        if k == y:
            result = [m_10000, m_5000, m_1000]
            break

    else:
        continue
    break
print("{} {} {}".format(result[0], result[1], result[2]))

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

for i in range(n+1):
 for j in range(n+1-i):
  z_m=y-(10000*i+5000*j)
  z_n=n-(i+j)
  if z_m>=0 and z_m//1000==z_n:
   print(i,j,z_n)
   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):
        x=n-i-j
        if 1000*i+5000*j+10000*x==y:
            print(x,j,i)
            exit()
print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
for a in range(n+1):
    for b in range(n+1):
        c=(y-(a*10000+b*5000))//1000
        if a+b+c==n and c>=0:
            print(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+1-i):
        if (y - 10000 * i - 5000 * j - 1000 * (n-i-j)) == 0:
            print(i, j, n-i-j)
            exit()

print(-1, -1, -1)

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

Solution (Python):
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


n, y = map(int, input().strip().split())
y = y // 1000
if y - n < 0:
    print("-1 -1 -1")
else:
    i = 0
    while y - n - 9 * i >= 0:
        if (y - n - 9 * i) % 4 == 0 and n - i - (y - n - 9 * i) // 4 >= 0:
            j = (y - n - 9 * i) // 4
            k = n - i - j
            print(i, j, k)
            sys.exit()
        i += 1
    del i
    print("-1 -1 -1")

Solution (Python):
def check(N, Y):
  for i in reversed(range(N+1)):
    if i > N:
      continue
    j = 0
    while (i*10000)+(j*5000) <= Y:
      if i+j > N:
        break
      k = N - (i+j)
      if (i*10000)+(j*5000)+(k*1000) == Y:
        return str(i) + ' ' + str(j) + ' ' + str(k)
      j += 1
  return '-1 -1 -1'

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

Solution (Python):

import sys
import math
import os

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N,Y = cin.mapInt()
for x in range(N + 1):
    for y in range(N + 1):
        z = N - x - y
        if(z < 0):
            continue
        yen = 10000 * x + 5000 * y + 1000 * z
        if yen == Y:
            print("{} {} {}".format(x,y,z))
            sys.exit()

print("{} {} {}".format(-1,-1,-1))

Solution (Python):

 
import math
import itertools
import sys
import copy
 






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

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

Solution (Python):

import sys


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

for i in range(N+1):
    M = N + 1 - i
    for j in range(M):
        if Y == 10000*i+5000*j+1000*(N-i-j):
            print('{} {} {}'.format(i, j, N-i-j))
            sys.exit()
else:
    print('-1 -1 -1 ')

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

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

print(a, b, c)

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
        if 10000 * a + 5000 * b + 1000 * c == Y:
            print(a,b,c)
            sys.exit()

print("-1 -1 -1")

Solution (Python):
import sys
maisu,goukei = map(int,input().split())

for i in range(0,maisu+1):
  for s in range(0,maisu-i+1):
    tmpSum = i*1000+s*5000+(maisu-s-i)*10000
    if tmpSum == goukei:
      print(str(maisu-s-i)+' '+str(s)+' '+str(i))
      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
        if 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())

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


print(" ".join([str(i) for i in ans]))

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

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


print(" ".join([str(i) for i in ans]))

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








ans = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1):
        tmp_sum = 10000 * i + 5000 * j
        x = Y - tmp_sum
        if x >= 0:
            k = int(x//1000)
            if i + j + k == N:
                ans = [i, j, k]
        


print(" ".join([str(i) for i in ans]))

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, m = na()

flag = False
for x in range(n + 1):
    if flag is True:
        break
    for y in range(n + 1):
        if flag is True:
            break
        if x + y <= n and x * 10000 + y * 5000 + (n - x - y) * 1000 == m:
            print(x, y, (n - x - y))
            flag = True

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

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

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

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

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

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

print(-1, -1, -1)

Solution (Python):
N, Y = 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
        total = i * 10000 + j * 5000 + k * 1000
        if total == Y:
            ans = [i, j, k]
            break
    else:
        continue
    break

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

Solution (Python):
n, y = [int(i) for i in input().split()]
a = b = c = -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 = i
            b = j
            c = k
            break
    else:
        continue
    break

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

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

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

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

res10000 = -1
res5000 = -1
res1000 = -1
n=0
s=0

for i in range(N+1):
  for j in range(N-i+1):
    n = N - i - j
    s = 10000*i+5000*j+1000*n
    if s == Y:
      res10000 = i
      res5000 = j
      res1000 = n
      break
print(res10000,res5000,res1000)

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

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

for i in range(n+1):
   for j in range(n-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):
X, Y = map(int, input().split())
statement = False
for a in range(X+1):
  for b in range(X-a+1):
    c = X - a - b
    if a * 10000 + b * 5000 + c * 1000 == Y:
      print(str(a) + " " + str(b) + " " + str(c))
      statement = True
      break
  if statement:
    break
if not statement:
  print("-1 -1 -1")

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

def calc_total(yukichi, ichiyo, hideyo):
  return 10000 * yukichi + 5000 * ichiyo + 1000 * hideyo

result_string = ""
for yukichi in range(n + 1):
  for ichiyo in range(n + 1):
    hideyo = n - yukichi - ichiyo
    if hideyo < 0:
      continue
      
    if (calc_total(yukichi, ichiyo, hideyo) == total) and (yukichi + ichiyo + hideyo == n):
      result_string = "{} {} {}".format(yukichi, ichiyo, hideyo)
      break
        
if len(result_string) == 0:
  print("-1 -1 -1")
else:
  print(result_string)

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

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
ans = [-1,-1,-1]
for c in range(Y%5,N+1,5):
	x = (Y-c)//5
	a = x - (N-c)
	b = 2*(N-c) - x
	if a < 0:
		continue
	if b < 0:
		continue
	ans = [a,b,c]
	break

print(*ans)

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("{0} {1} {2}".format(i, j, (n - i - j)))
            exit(0)
print("-1 -1 -1")

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

Solution (Python):
n, y= map(int, input().split())
yu = -1
hi = -1
no = -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 and k >= 0:
            yu = i
            hi = j
            no = k
print(yu, hi, no)

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

noguchi = 1000
higuchi = 5000
yukichi = 10000

ans = '-1 -1 -1'
for i in range(n+1):
    for j in range(n+1-i):
        k = n - (i+j)
        yen = noguchi * i + higuchi * j + yukichi * k
        if yen == y:
            ans = '{0} {1} {2}'.format(k,j,i)
            break

print(ans)

Solution (Python):
input_str = input().split()
N = int(input_str[0])
Y = int(input_str[1])

x_quo = Y//10000

flag = False
for x in range(min([x_quo,N]),-1,-1):
  Y_x = Y - 10000*x
  N_x = N - x
  y_quo = Y_x // 5000
  for y in range(min([y_quo,N_x]),-1,-1):
    z = N-x-y
    if 10000*x + 5000*y + 1000*z == Y and x+y+z == N:
      flag = True;
      break;
  else:
    continue
  break

if flag == True:
  print(str(x) + " " + str(y) + " " + str(z))
else:
  print("-1 -1 -1")

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

man = -1
gosen = -1
sen = -1

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

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

Solution (Python):

"""AtCoder Beginner Contest 085: C - Otoshidama
https://atcoder.jp/contests/abc086/tasks/abc085_c
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def calc(N, Y):
    for x in range(N + 1):
        for y in range(0, N+1-x):
            z = N - x - y
            if 10000*x + 5000*y + 1000*z == Y:
                return [str(x), str(y), str(z)]
    return ['-1', '-1', '-1']


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

    answer = calc(N, Y)
    print(' '.join(answer))


if __name__ == '__main__':
    main()

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

yukichi = -1
higuchi = -1
noguchi = -1

for x in range(0, N + 1):
    for y in range(0, N + 1 - x):

        z = N - x - y

        if 10000 * x + 5000 * y + 1000 * z == Y:
            yukichi = x
            higuchi = y
            noguchi = z

print(yukichi, higuchi, noguchi)