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

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

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('{} {} {}'.format(i, j, k))
            break
    else:
        continue
    break
else:
    print('-1 -1 -1')

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

Solution (Python):
if __name__ == '__main__':
    N, Y = list(map(int, input().split(' '))) 
    for a in range(N+1):
        for b in range(N+1-a):
            c = N - a - b
            if ((a * 10000) + (b * 5000) + (c * 1000)) == Y:
                print(a,b,c)
                exit()
    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-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(" ".join(map(str, [i, j, n-i-j])))
            sys.exit()
else:
    print("-1 -1 -1")

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

for x in range(N+1):
    for y in range(N + 1 - x):
        z = N - x - y
        total_yen = 10000 * x + 5000 * y + 1000 * z
        if total_yen == Y:
            print(x, y, z)
            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):
n, y = map(int, input().split())
for a in range(y // 10000 + 1):
  for b in range((y - a*10000) // 5000 + 1):
    c = (y - a*10000 - b*5000) // 1000
    if a + b + c == n:
      print("{} {} {}".format(a, b, c))
      break
  else:
    continue
  break
else:
  print("-1 -1 -1")

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


def solve(N, Y):
    for a in range(0, N+1):
        rem = Y - a * 10000
        if rem < 0:
            break
        for b in range(0, N+1-a):
            if rem - b * 5000 < 0:
                break
            c, r =  divmod(rem - b * 5000, 1000)
            
            if r == 0 and c == (N - a - b):
                return a, b, c
    return -1, -1, -1

print(*solve(N, Y))

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

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

print('-1 -1 -1')

Solution (Python):
N,Y=map(int,input().split())
count=0
cost=0
for i in range(N+1):
    cost=10000*i
    cost2=cost
    for j in range(N-i+1):
        cost=cost+5000*j
        k=N-(i+j)
        cost=cost+1000*k
        if(cost==Y):
            print(str(i)+" "+str(j)+" "+str(k))
            count += 1
            break
        cost=cost2
    if(count==1):
        break
    cost=0
    cost2=0

if(count==0):
    print(str(-1)+" "+str(-1)+" "+str(-1))

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

x = -1
y = -1
z = -1
flag = False

for i in range(N+1):
    for j in range(N+1-i):
        if i*10000 + j*5000 + (N-i-j)*1000 == Y:
            flag = True
            x = i
            y = j
            z = N-i-j
            break
    if flag:
        break
    
    
str1 = str(x)
str2 = str(y)
str3 = str(z)
print(str1 + " " + str2 + " "+str3)

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

for i_1000 in range(n+1):
    for i_5000 in range(n-i_1000+1):
        if (i_1000*1000 + i_5000*5000 + (n-i_1000-i_5000)*10000) == y:
            print(n-i_1000-i_5000,i_5000,i_1000)
            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 i*10000+j*5000+k*1000==y:
            print(str(i)+' '+str(j)+' '+str(k))
            sys.exit()
print('-1 -1 -1')

Solution (Python):
n, y = map(int, input().split())
a = 10000
b = 5000
c = 1000

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

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

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

Solution (Python):

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

x = 0
z = 0
y = N
flg = False

while y >= 0:

    total = x * 1000 + y * 5000 + z *10000

    if total == Y:
        flg = True
        break

    elif total > Y:
        x += 1
        y -= 1

    else:
        z += 1
        y -= 1

if flg == False:
    x = -1
    y = -1
    z = -1

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

Solution (Python):
a, b = map(int, input().split())
o1 = o2 = o3 = -1
for i in range(min(a+1, (b//10000)+1)):
    for j in range(min(a-i+1, ((b-10000*i)//5000)+1)):
        k = a-i-j
        if b == i*10000+j*5000+k*1000:
            o1 = i
            o2 = j
            o3 = k
            break
print(o1, o2, o3)

Solution (Python):
a, b = map(int, input().split())
o1 = o2 = o3 = -1
for i in range(min(a+1, (b//10000)+1))[::-1]:
    for j in range(min(a-i+1, ((b-10000*i)//5000)+1))[::-1]:
        k = a-i-j
        if b == i*10000+j*5000+k*1000:
            o1 = i
            o2 = j
            o3 = k
            break
print(o1, o2, o3)

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

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

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

print(-1, -1, -1)

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

v = 0
def solve():
    for x in range(N+1):
        if Y // 10000 < x:
            return [-1,-1,-1]
        r = Y - 10000 * x
        for y in range(0, r // 5000 + 1):
            rr = r - 5000 * y
            z = rr // 1000
            if x + y + z == N:
                return [x, y, z]
    return [-1,-1,-1]

print(' '.join(map(str, solve())))

Solution (Python):
N,Y=map(int,input().split())
ichiman=0
gosen=0
sen=0
se_ichi=0
go_ichi=0
sen_go_ichi=0
mismatch=0
max_ichiman=int(2*(10**7)/(10**4))
for i in range(max_ichiman+1):
    if i*10**4==Y:
        ichiman=i
        break
    if i*10**4>Y:
        ichiman=i-1
        break
Y=Y-ichiman*10**4
for j in range(2+1):
    if j*5*10**3>Y:
        gosen=j-1
        break
Y=Y-gosen*5*10**3
for k in range(5):
    if k*10**3==Y:
        sen=k
min_N=ichiman+gosen+sen
if N-min_N<0:
    mismatch=1

for i2 in range(N-min_N+1):
    if N-min_N<0:
        mismatch=1
    if i2*9>N-min_N:
        se_ichi=i2-1
        break
N=N-se_ichi*9
for j2 in range(N-min_N+1):
    if N-min_N<0:
        mismatch=1
    if j2*5>N-min_N:
        sen_go_ichi=j2-1
        break
N=N-sen_go_ichi*5
for k2 in range(N-min_N+1):
    if N-min_N<0:
        mismatch=1
    if k2==N-min_N:
        go_ichi=k2
        break
N=N-go_ichi
if N-min_N<0:
    mismatch=1

ichiman=ichiman-se_ichi-sen_go_ichi-go_ichi
gosen=gosen+2*go_ichi+sen_go_ichi
sen=sen+5*sen_go_ichi+10*se_ichi

if sen|gosen|ichiman<0:
    mismatch=1
if mismatch==1:
    sen=-1
    ichiman=-1
    gosen=-1

print(ichiman, gosen, sen)

Solution (Python):
import math

def main():
    num, sum_money = map(int, input().split())
    flg = 0
    for i in range(num + 1):
        for j in range(num - i + 1):
            nokori = sum_money - i * 10000 - j * 5000
            k = nokori // 1000
            if i + j + k == num:
                print(i, j, k)
                flg = 1
                break
        if flg:
            break
    else:
        print(-1, -1,-1)


if __name__ == '__main__':
    main()

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

Solution (Python):



a, b = map(int, input().split())
sum = 0
uso = True
for i in range(a+1):
    for j in range(a+1-i):
        sum = 10000 * i + 5000 * j + 1000 * (a - i - j)
        if sum == b:
            print(i, j, a - i - j)
            uso = False
            break
    else:
        continue
    break

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

Solution (Python):
import sys

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

for bill10000 in range(n + 1):
    for bill5000 in range(n - bill10000 + 1):
        bill1000 = n - bill10000 - bill5000
        if bill10000 * 10000 + bill5000 * 5000 + bill1000 * 1000 == y:
            print(bill10000, bill5000, bill1000)
            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 = list(map(int,input().split()))

a, b, c = '-1', '-1', '-1'

for yen_10000 in range(n+1):
    for yen_5000 in range(n - yen_10000+1):
        yen_1000 = n - yen_10000 - yen_5000
        total = yen_10000*10000 + yen_5000*5000 + yen_1000*1000
        if total == y:
            a, b, c = str(yen_10000), str(yen_5000), str(yen_1000)
            break
            
print(a+' '+b+' '+c)

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

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




for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if 10000*x+5000*y+1000*z==Y and z>=0:
            print(x,y,z)
            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):
        tmp = 10000 * i + 5000 * j + 1000 * (N-i-j)
        if tmp == Y:
            print(str(i) + ' ' + str(j) + ' ' + str(N-i-j))
            quit()

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):
        tmp = 10000 * i + 5000 * j + 1000 * (N-i-j)
        if tmp == Y:
            print(str(i) + ' ' + str(j) + ' ' + str(N-i-j))
            quit()

print('-1 -1 -1')

Solution (Python):
def otoshi(n, y):
    x=0
    for i in range(n+1):
        x = i*10000
        if x >y :
            break
        for i2 in range(n+1 - i):
            x = i*10000 + i2 * 5000
            if x > y :
                break
                
            i3 = n - i - i2
            x =  i*10000 + i2 * 5000 + i3 *1000
            if x > y :
                break

            if i + i2 + i3 != n :
                pass
            else :
                if x  == y :
                    print(i, i2, i3)
                    return 

    print(-1, -1, -1)
    return 

n, y = [int(i)  for i in input().split()]

otoshi(n, y)

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

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

    print(answer)

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

ans = "-1 -1 -1"

for man in range(n + 1):
    for go in range(n - man + 1):
        sen = n - (man + go)
        if man * 10000 + go * 5000 + sen * 1000 == y:
            ans = "{} {} {}".format(man, go, sen)
print(ans)

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

Y = Y // 1000

ok = False
for x in range(N+1):
    tmp = Y - 10 * x
    for y in range(N-x+1):
        z = tmp - 5 * y
        if x + y + z == N:
            print(x, y, z)
            ok = True
            break
    if ok:
        break

if not ok:
    print(-1, -1, -1)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

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

main()

Solution (Python):
z=list(map(int,input().split()))
n=z[0]
y_y=z[1]
y=int(y_y/1000)
for e in range(0,n+1):
    if e*10 <= y:
        x=y-e*10
        for f in range(0,n+1):
            if f*5 <= x:
                z=x-5*f
                if z!=n-e-f :
                    a,b,c=-1,-1,-1
                else:
                    a,b,c=e,f,z
                    break
        else:
            continue
        break
      




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

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

print("-1 -1 -1")

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N,Y = (int(_) for _ in input().split())
    
    for i in range(N+1):
        
        for j in range(N+1):
            cnt_of_1000 = N - i -j
            if cnt_of_1000 < 0:
                continue
            sum_of_yen = i* 10000 + j* 5000 + cnt_of_1000*1000
            if sum_of_yen == Y:
                print(i,j,cnt_of_1000)
                return
    print('-1 -1 -1')
if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N,Y = (int(_) for _ in input().split())
    
    for i in range(N+1):
        
        for j in range(N+1):
            cnt_of_1000 = N - i -j
            if cnt_of_1000 < 0:
                continue
            sum_of_yen = i* 10000 + j* 5000 + cnt_of_1000*1000
            if sum_of_yen == Y:
                print(i,j,cnt_of_1000)
                return
    print('-1 -1 -1')
if __name__ == '__main__':
    main()

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

for i in range(n+1):
	for j in range(n-i+1):
		k = n - i - j
		if k >= 0:
			sum = 10000*i + 5000*j + 1000*k
			if sum == y:
				print(i, j, k)
				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 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 a in range(n+1):
    for b in range(n-a+1):
        c = n - (a+b)
        if y == 10000*a + 5000*b + 1000*c and c >= 0:
            print(a, b, c)
            exit()

print(-1, -1, -1)

Solution (Python):
Y,N = map(int,input().split())
def check():
    for i in range(N//10000,-1,-1):
        for j in range((N-10000*i)//5000,-1,-1):
            cy = Y - i - j
            if cy >= 0 and 10000*i+5000*j+1000*cy == N:
                return i,j,cy
    return -1,-1,-1
x,y,z = check()
print(x,y,z)

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

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

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

ans = [-1, -1, -1]

for x in range(Y//1000+1):
    y_Y = Y - 10000 * x
    y_N = N - x
    if (y_Y - 1000 * y_N) % 4000 == 0:
        y = (y_Y - 1000 * y_N) // 4000
        if 0 <= y and y <= y_N:
            z = y_N - y
            ans = [x, y, z]
            break

print(*ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,y=LI()

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

main()

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

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

for c_10000 in range(num+1):
    for c_5000 in range(num+1-c_10000):
        if (10000 * c_10000 + 5000 * c_5000 + 1000 * (num - c_10000 - c_5000)) == total:
            print('{} {} {}'.format(c_10000, c_5000, num - c_10000 - c_5000))
            exit()

print('-1 -1 -1')

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

Solution (Python):
n, y = list(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 10000*i + 5000*j + 1000*k == y and k >= 0:
      a = i
      b = j
      c = 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-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())
for i in range(n+1):
  for j in range(n-i+1):
    if n-i-j>=0 and 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())
for i in range(n+1):
  for j in range(n-i+1):
    if n-i-j>=0 and 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())

frg = True
if frg:
    for yukichi in range(n+1):
        for higuchi in range(n - yukichi + 1):
            noguchi = n - yukichi - higuchi
            if yukichi * 10000 + higuchi * 5000 + noguchi * 1000 == y and frg:
                print(yukichi, higuchi, noguchi)
                frg = False
                break
if  frg:
    print(-1, -1 ,-1)

Solution (Python):
n,y=map(int,input().split())
y//=1000
cnt=[0,0,0]
if n>y or n*10<y:print("-1 -1 -1")
else:
    for i in range(y//10+1):
        for j in range(y//5+1 - i):
            if i+j<=n and y-i*10-j*5==n-i-j:
                print("{} {} {}".format(i,j,n-i-j))
                exit()
    else:print("-1 -1 -1")

Solution (Python):
n,y=map(int,input().split())
y//=1000
cnt=[0,0,0]
if n>y or n*10<y:print("-1 -1 -1")
else:
    for i in range(y//10+1):
        for j in range(y//5+1 - i):
            if i+j<=n and y-i*10-j*5==n-i-j:
                print("{} {} {}".format(i,j,n-i-j))
                exit()
    else:print("-1 -1 -1")

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

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

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

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

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

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

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

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

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

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

Solution (Python):
N, Y = [int(i) for i in input().split()]
temp = Y - (N * 1000)
passed = False
for i in range(N + 1):
    t = temp-9000*i
    if t < 0:
        break
    a = t % 4000
    if a == 0:
        y = t/4000
        if i + y <= N:
            print(i, int(y), int(N-i-y))
            passed = True
            break
if not passed:
    print(-1, -1, -1)

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

for x in range(n + 1):
    for y in range(n + 1):
        if x + y > n:
            break
        z = (yen - x * 10000 - y * 5000) / 1000
        if x + y + z == n:
            print(x, y, int(z))
            exit()

print(-1, -1, -1)

Solution (Python):
N, Y = map(int,input().split())
l0 = ""
for i in range(N+1):
  for j in range(N+1):
    z = Y - (10000*i) - (5000*j)
    k = z // 1000
    if z % 1000 == 0 and i+j+k == N and 0 <= k <= N:
      l0 = str(i) + " " + str(j) + " " + str(k)
    else:
      l1 = "-1 -1 -1"
if l0 != "":
  print(l0)
else:
  print(l1)

Solution (Python):

import sys

L = list(map(int,input().split()))
N = int(L[0])
Y = int(L[1])

for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j

        if 10000*i+5000*j+1000*k==Y:
            print(i,j,k)
            sys.exit()


print("-1 -1 -1")

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

k = 0

for i in range(n+1):
    if k != 0:
        break
    for j in range(n+1):
        x = i
        y = j
        z = n - (i+j)
        
        if z < 0:
            break
        
        if 10000*x + 5000*y + 1000*z == Y:
            print(x,y,z)
            k += 1
            break
        

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

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

ans=0
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:
            ans+=1
            print(str(i),str(j),str(k))
            break
    else:
        continue
    break
if ans==0:
    print("-1 -1 -1")

Solution (Python):
import math

N, Y = (int(x) for x in input().split())
t = Y // 1000
a = max(0, math.ceil((5*N-t)/4))
b = (10*N-t) // 9
z = a - (a-t)%5
if z < a:
    z += 5
if z <= b:
    x = (t-z)//5 - (N-z)
    y = N-z-x
    print('{} {} {}'.format(x, y, z))
    exit()
else:
    print('-1 -1 -1')

Solution (Python):
N, Y = (int(x) for x in input().split())
t = Y // 1000
z = t % 5 - 5

while z <= N:
    z += 5
    x = (t-z-5*(N-z))//5
    if x < 0:
        continue
    y = N-z-x
    if y < 0:
        continue
    if 10*x + 5*y + z == t:
        print('{} {} {}'.format(x, y, z))
        exit()

print('-1 -1 -1')

Solution (Python):
import sys

N, Y = (int(x) for x in input().split())
t = Y // 1000
z = t % 5 - 5

while z <= N:
    z += 5
    x = (t-z-5*(N-z))//5
    if x < 0:
        continue
    y = N-z-x
    if y < 0:
        continue
    if 10*x + 5*y + z == t:
        print('{} {} {}'.format(x, y, z))
        sys.exit()

print('-1 -1 -1')

Solution (Python):
N, Y = (int(x) for x in input().split())
x, y, z, t = -1, -1, -1, Y // 1000

for i in range(N+1):
    for j in range(N+1):
        if 9*i + 4*j + N == t and i + j <= N:
            x, y, z = i, j, N - i - j
            break
        elif 9*i + 4*j + N > t:
            break
    else:
        continue
    if x != -1:
        break

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

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-i+1):
    if Y == 10000*i+5000*j+1000*(N-i-j):
      x,y,z = i,j,N-i-j
 
print(x,y,z)

Solution (Python):
N, Y = map(int, input().split())
x = -1
y = -1
z = -1
for i in reversed(range(N + 1)):
	cnt = Y - 10000*i
	if cnt < 0:
		continue
	else:
		for j in range(N + 1 - i):
			ans = cnt - 5000*j - 1000*(N - i - j)
			if ans == 0:
				x = i
				y = j
				z = N - i - j
				break
			elif ans < 0:
				break
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())

flag = False

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

print("-1 -1 -1")

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

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

ans = None

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

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

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

    if flag == False:
        x, y, z = -1, -1, -1

    print(x, y, z)

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

Solution (Python):
import sys
n, y = (int(i) for i in input().split())

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


print('-1 -1 -1')

Solution (Python):
def main():
    NOTFOUND = True
    maisu,money = map(int, input().split())
    for ichiman in range(maisu+1):
        if not NOTFOUND :
            break
        for gosen in range(maisu+1 - ichiman):
            sen = maisu - ichiman - gosen
            current_money = ichiman*10000 + gosen*5000 + sen*1000
            if current_money == money:
                print(ichiman,gosen,sen)
                NOTFOUND = False
                break
    if NOTFOUND :
        print(-1,-1,-1)

if __name__ == '__main__' :
    main()