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

Yu = N
Hi = 0
No = 0

flag = False
bul = False

while True:

    if Yu * 10000 + Hi * 5000 + No * 1000 == Y:
        print (Yu,Hi,No)
        bul = True
        break

    Yu -= 1
    Hi = N - Yu
    No = 0
    

    while True:

        if Yu * 10000 + Hi * 5000 + No * 1000 == Y:
            print (Yu,Hi,No)
            bul = True
            flag = True
            break

        if Yu == 0 and Hi == 0 and No == N:
            flag = True
            break

        elif Hi == 0:
            break

        Hi -= 1
        No += 1


    if flag:
        break

if not bul:

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

Solution (Python):
N, Y = map(int, input().split())
x, y, z = -1, -1, -1

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

N, Y = LI()

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

print(-1, -1, -1)

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

ans=[]
for i in range(n+1):
    for j in range(n-i+1):
        if i*1000 + j*5000 + (n-i-j)*10000 == y:
            ans.append( str(n-i-j)+" "+str(j)+" "+str(i) )
            
if len(ans)==0:
    print(-1," ",-1," ",-1)
else:
    print(ans[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 sys

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

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

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

x = y = z = -1

for i, j in product(range(N+1), range(N+1)):
    if i+j > N:
        continue
    else:
        tmp = N - i - j
        if tmp < 0:
            continue
        elif 10000*i+5000*j+1000*tmp == Y:
            x = i
            y = j
            z = tmp
            break

print(x, y, z)

Solution (Python):
n,y = map(int,input().split())
x1,y1,z1 = -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):
            x1 = i
            y1 = j
            z1 = n-i-j
print(x1,y1,z1)

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

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, Y = nl()
for x in range(N+1):
    left = Y - x*10000
    if left < 0:
        continue
    for y in range(N - x + 1):
        if left == y*5000 + (N - x - y)*1000:
            print(x, y, N - x - y)
            import sys
            sys.exit()

print('-1 -1 -1')

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

Solution (Python):
n,y = map(int, input().split())
can = [10000, 5000, 1000]
cnd = range(0, n+1)
result = [(i, j, n-i-j) for i in cnd for j in cnd if n-i-j in cnd and i*10000+j*5000+(n-i-j)*1000 == y]
result = [[-1,-1,-1]] if len(result) == 0 else result
print(" ".join([str(i) for i in result[0]]))

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

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

print("-1 -1 -1")

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

x = -1
y = -1
z = -1

for i in range(N + 1):
    for j in range(N - i + 1):
        if (0 <= N - i - j) and (Y == 10000 * i + 5000 * j + 1000 * (N - i - j)):
            x = i
            y = j
            z = N - i - j

print(x, y, z)

Solution (Python):
N,Y = map(int,input().split())
cnt10 = 0
cnt5 = 0
cnt1 = 0
def wrong():
	print('-1 -1 -1')
	exit()
all1000 = int(Y / 1000)
if all1000 % 1 != 0:
	wrong()
for x in range(all1000 + 1):
	for y in range(all1000 - x + 1):
		if N - x - y < 0:
			break
		if x * 10 + y * 5 + (N - x - y) == all1000:
			print('{} {} {}'.format(x,y,N - x - y))
			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):
        yen = 10000*i+5000*j+1000*(n-i-j)
        if yen == y:
            print(i, j, n-i-j) 
            flag = True
            break
    else:
        continue
    break

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

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

ans = "-1 -1 -1"
for a in range(n+1):
    if ans != "-1 -1 -1":
        break
    for b in range(n+1):
        c = int((y - 10000 * a - 5000 * b) / 1000)
        if c >= 0 and a + b + c == n:
            ans = "{} {} {}".format(a, b, c)
            break
        elif c < 0:
            break
print(ans)

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

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

Solution (Python):
import sys

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

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

for i in range(N+1):
    if exit == True:
        break
    for j in range(N-i+1):
        if exit == True:
            break
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y:
            exit = True
            print("{} {} {}".format(i, j, k))
            
if exit == False:
    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==Y-1000*(N-i-j):
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)

Solution (Python):
[n,y] = [int(i) for i in input().split()]
checker = 0
if y < n * 1000 or y > n * 10000:
  print(-1,-1,-1)
else:
  a = y // 10000
  for i in range(a+1):
    y1 = y - 10000*i
    b = y1 // 5000
    for j in range(b+1):
      y2 = y1 - 5000*j
      c = y2/1000
      
      if c == n - i - j and checker != 1:
        checker = 1
        print(i,j,n-i-j)
        break
  if checker == 0:
    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=str(i)+" "+str(j)+" "+str(N-i-j)
print(ans)

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

Solution (Python):
N,Y = map(int,input().split())
ans = 0
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:
      z = a
      y = b
      x = c
      ans = 1
      break
      
if ans == 1:
  print(z,y,x)
else:
  print(-1,-1,-1)

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

Solution (Python):
n,y = map(int,input().split())
flag = True
if(y <= n *10000):
    for i10 in range(n+1):
        for i5 in range(n+1-i10):
            i1 = n-i5-i10
            if(i10*10000+i5*5000+i1*1000==y):
                print(i10,i5,i1)
                flag = False
                break
        else:
            continue
        break
if(flag):
    print(-1,-1,-1)

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

y = Y//1000
d = y - N
k = min(d//4, (N+d)//5)

if 9*k >= 2*d:
    print(d-4*k, -2*d+9*k, N+d-5*k)
else: print(-1,-1,-1)

Solution (Python):


NumOfBills, Amnt = map(int, input().split())
marker = 0

for i in range(NumOfBills+1):
    if marker != 0:
        break
    else:
        for k in range(NumOfBills-i+1):
            if i*10000 + k*5000 + (NumOfBills - i - k)*1000 == Amnt:
                print(i,k,NumOfBills-i-k)
                marker += 1
                break
            else: continue
else: 
    if marker == 0:
        print(-1,-1,-1)

Solution (Python):
m = input().split()
N = int(m[0])
Y = int(m[1])
if Y > 10000*N:
  print(-1,-1,-1)
else:
  frag = 0
  for i in range(N+1):
    for j in range(N-i+1):
      if frag == 0 and 10000*i + 5000*j + 1000*(N-i-j) == Y:
        frag = 1
        print(i,j,N-i-j)
        break
  if frag == 0:
    print(-1,-1,-1)

Solution (Python):
n, y = map(int, input().split())
 
a = -1
b = -1
c = -1
 
find = False
for i in reversed(range(int(y/10000)+1)) :
    for j in range(int((y-10000*i)/5000)+1) :
        if (i+j+int((y-10000*i-5000*j) / 1000)) == n :
            a = i
            b = j
            c = n-i-j
            find = True
            break
    if find :
        break
print("{} {} {}".format(a, b, c))

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

Solution (Python):
N,Y = (int(x) for x in input().split())
temp = [-1 for n in range(3)]
myflag = False
for x in range(N+1):
  if myflag:break
  for y in range(N+1-x):
    if myflag:break
    z = N - x - y
    if 10000*x + 5000*y + 1000*z == Y:
      temp=[x,y,z]

print('{} {} {}'.format(temp[0],temp[1],temp[2]))

Solution (Python):
N, Y = map(int, input().split())
Payable = False
try:
    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:
                print(i,j,k)
                Payable = True
                raise Exception
except Exception:
    pass

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

main()

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

total = 0
X = -1
Y = -1
Z = -1


for i in range(n + 1):
      for j in range(n - i + 1):
              k = n - i - j
              if k < 0:
                      break
              total = 10000 * i + 5000 * j + 1000 * k
              if total == y:
                      X = i
                      Y = j
                      Z = k
                      break
print(str(X) + " " + str(Y) + " " + str(Z))

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
z = Y % 5
for zz in range(z, N+1, 5):
    y = (Y-zz)//5 % 2
    for yy in range(y, N-zz+1, 2):
        if (N-zz-yy)*10 == Y-zz-5*yy:
            print(N-zz-yy, yy, zz)
            exit()
else:
    print(-1,-1,-1)

Solution (Python):
n,y=map(int,input().split())
r=y//1000
b=False
x0=0
for i in range((r//10)+1):
  x1=(r-n-9*i)
  x2=5*n-r+5*i
  if x1>=0 and x2>=0 and x1%4==0 and x2%4==0:
    b=True
    x0=i
    x1=x1//4
    x2=x2//4
    break
if b:
  print(x0,x1,x2)
else:
  print(-1,-1,-1)

Solution (Python):
data = input().split(" ")

N = int(data[0])
Y = int(data[1])


errmsg = "-1 -1 -1"

is_ok = False


max_x = int(Y/10000)
max_y = int(Y/5000)
max_z = int(Y/1000)

if max_x > N:
    max_x = N
if max_y > N:
    max_y = N
if max_z > N:
    max_z = N

for z in range(0,max_z+1):
    for y in range(0,max_y+1):
        if z + y > N:
            continue
        x = N - y - z
        if x * 10000 + y * 5000 + z * 1000 == Y:
            print(str(x) + " " + str(y) + " " + str(z))
            is_ok = True
            break
    if is_ok:
        break

if not is_ok:
    print(errmsg)

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

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


if flg == 0:
    print("-1 -1 -1")
else:
    pass

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

def solve(n,total):
    sen = n * 1000
    if total < sen:
        return [-1,-1,-1]
    
    sa = total - sen
    kyu = sa // 9000
    
    for i in range(kyu+1):
        zan = total - (i*10000 + (n-i)*1000)
        if zan % 4000 == 0:
            satu1 = i
            satu2 = zan // 4000
            satu3 = n-satu1-satu2
            if satu1 >= 0 and satu2 >= 0 and satu3 >= 0:
                return [satu1,satu2,satu3]
    return [-1,-1,-1]
    
print(' '.join(map(str,solve(N,T))))

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

k10 = 0
k5 = 0
k1 = 0

max_k10 = min(N, Y // 10000)
for i in reversed(range(max_k10 + 1)):
    remain10 = Y - i * 10000
    if remain10 == 0 and i == N:
        print(i, 0, 0)
        exit()
    max_k5 = min(N, remain10 // 5000)
    for j in reversed(range(max_k5 + 1)):
        remain5 = remain10 - j * 5000
        if remain5 == 0 and i + j == N:
            print(i, j, 0)
            exit()
        z = N - i - j
        if remain5 - z * 1000 == 0:
            print(i, j, z)
            exit()

print(-1, -1, -1)

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


def main():
    for a in range(N+1):
        aa = a * 10000
        for b in range(N+1-a):
            c = N - a - b
            if aa + b * 5000 + c * 1000 == Y:
                print("{} {} {}".format(a, b, c))
                exit()
    print("-1 -1 -1")

if __name__ == "__main__":
  	main()

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


for a in range(N+1):
    aa = a * 10000
    for b in range(N+1-a):
        c = N - a - b
        if aa + b * 5000 + c * 1000 == Y:
            print("{} {} {}".format(a, b, c))
            exit()
print("-1 -1 -1")

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

Y //= 1000




answer = [-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
  answer = [a,b,c]
  break

print(*answer)

Solution (Python):
def resolve():

    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))
                return
    print('-1 -1 -1')
    
resolve()

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

print("-1 -1 -1")

Solution (Python):
n,y=map(int, input().split())
 
count=0
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 0<=k:
        print(i,j,k)
        count+=1
        exit(0)
      else:
        continue

        
      
if count==0:
  print('-1 -1 -1')

Solution (Python):
from sys import stdin

def main():
    N, Y = map(int, stdin.readline().rstrip().split())
    ans=0
    for i in range(N+1):
      for j in range(N+1):
        k = N-i-j
        if (k >= 0 and 10000*i + 5000*j + 1000*k == Y):
          print("{} {} {}".format(i, j, k))
          return
    print("-1 -1 -1")

input = lambda: stdin.readline()
main()

Solution (Python):
from sys import stdin
N,Y = [int(x) for x in stdin.readline().rstrip().split()]
flag = False
for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
          continue
        if Y == 10000 * x + 5000 * y + 1000 * z:
            flag = True
            break
    else:
        continue
    break
if flag:
    print(x,y,z)
else:
    print(-1,-1,-1)

Solution (Python):
s = input().split(" ");
n = int(s[0]);
m = int(s[1]);
for x in range(int(m/10000),-1,-1) :
	nokori = m - 10000*x;
	for y in range(int(nokori / 5000),-1,-1) :
		z = int((m - 10000*x -5000 * y ) / 1000);
		if x + y + z == n :
			print(x,y,z);
			break;
		elif x == 0 and y == 0 and z != n :
			print(-1,-1,-1);
	else :
		continue
	break;

Solution (Python):

import sys


def solve(N: int, Y: int):

    for i in range(N+1):
        if 10000*i + 5000*(N-i) < Y:
            continue

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

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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    Y = int(next(tokens))  
    solve(N, Y)

if __name__ == '__main__':
    main()

Solution (Python):
N,Y= map(int, input().split())
a = 0
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i,j,(Y - (10000*i + 5000*j)) // 1000)
            a = 1
            break
    else:
        continue
    break
if a == 0:
    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):
        k = N-i-j
        gaku = 10000*i+5000*j+1000*k
        if 0<=k and k<=N and gaku == Y and flag == 0:
            print(i,j,k)
            flag = 1

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

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

ans =[]

for i10 in range(0,n+1):
  for i5 in range(0,n+1):
    i1 = n-i10-i5
    if (i1 >= 0) and ((i10*10000+i5*5000+1000*(i1))== k) :
      ans = [i10,i5,(n-i10-i5)]

              

if (ans)  :
  print(ans[0],ans[1],ans[2])
else:
  print('-1 -1 -1')

Solution (Python):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


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

    b = False
    for i in range(n + 1):
        if i > y or b:
            break
        for j in range(n + 1):
            if i + j > n:
                break
            if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
                b = True
                print(i, j, n-i-j)
                break

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


if __name__ == '__main__':
    main()

Solution (Python):

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

result = False
for i in range(0, N + 1):
  zan = Y - (i * 10000)
  for j in range(0, N + 1 - i):
    zan = Y - (i * 10000) - (j * 5000)
    zan_mai = N - i - j
    if zan_mai * 1000 == zan:
      print(str(i) + " " + str(j) + " " + str(zan_mai))
      result = True
      break
    if result:
      break
  if result:
    break

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

Solution (Python):
N,Y = map(int,input().split())
para = [10000,5000,1000]
cnt = 0
for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j 
        if para[0]*i + para[1]*j + para[2]*k == Y and k >= 0:
            print("{} {} {}".format(i,j,k))
            cnt += 1
            exit()
if cnt == 0 : print("-1 -1 -1")

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 and N-i-j >= 0:
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)

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 and N-i-j >= 0:
            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+1-i):
    if 10000*i + 5000*j + 1000*(n-i-j) == y:
      print("{} {} {}".format(i, j, n-i-j))
      exit()
print("-1 -1 -1")

Solution (Python):
n,y=list(map(int,input().split()))
q=-1
w=-1
e=-1
for i in range(n+1):
    for u in range(n+1):
        o=n-i-u
        if o>=0 and (10*i+5*u+1*o)==y/1000:
            q=i
            w=u
            e=o
print(q," ",w," ",e)

Solution (Python):

N,Y = map(int,input().split()) 
A=-1
B=-1
C=-1


for a in range(N+1):
    for b in range(N+1-a):
        c = N - a - b
        y = a * 10000 + b * 5000 + c * 1000
        if y == Y:
            A,B,C = a,b,c

print(A,B,C)

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

for y10k in range(N + 1):
	for y5k in range(0, N - y10k + 1):
		y1k = max(0, N - y10k - y5k)
		if Y == y10k * 10000 + y5k * 5000 + y1k * 1000:
			print(y10k, y5k, y1k)
			exit()
else:
	print(-1, -1, -1)

Solution (Python):
n,y=map(int,input().split())
max_10000=y//10000
max_5000=y//5000
ans=0
for i in range(max_10000+1):
  for j in range(max_5000+1):
    if i+j<=n:
      if i*10000+j*5000+1000*(n-i-j)==y:
        print(i,j,n-i-j)
        break
  else:
    continue
  break
else:
  print(-1,-1,-1)

Solution (Python):
N, Y = map(int, input().split())
Y //= 1000
n_10, n_5, n_1 = -1, -1, -1

r_1 = Y % 5
for i in range(r_1, N+1, 5):
    tmp_1 = i
    tmp_10 = int((Y + 4*tmp_1 - 5*N) // 5)
    tmp_5 = N - tmp_10 - tmp_1
    if tmp_10 >= 0 and tmp_5 >= 0 and (10*tmp_10 + 5*tmp_5 + tmp_1) == Y:
        n_10, n_5, n_1 = tmp_10, tmp_5, tmp_1
        print(n_10, n_5, n_1)
        break
else:
    print(n_10, n_5, n_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-i+1):

      sm=i*10000+j*5000+(n-i-j)*1000

      if sm>y:
        break

      if sm==y:
        return str(i)+' '+str(j)+' '+str(n-i-j)

  return '-1 -1 -1'

print(main())

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

min_1sen = (y%5000)//1000
n = n - min_1sen
y = y - 1000*min_1sen
max_1sen = min(n, y//1000)
max_5sen = min(n, y//5000)
max_1man = min(n, y//10000)

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

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

print(*ans)

Solution (Python):
N, Y = map(int, input().split())
n_10, n_5, n_1 = -1, -1, -1

r_1 = Y % 5000 // 1000
for i in range(r_1, N+1, 5):
    M = Y - 1000 * i
    r_5 = M % 10000 // 5000
    for j in range(r_5, N+1-i, 2):
        if Y == (1000 * i + 5000 * j + 10000 * (N - i - j)):
            n_1, n_5, n_10 = i, j, N-i-j
            print(n_10, n_5, n_1)
            exit()
else:
    print(n_10, n_5, n_1)

Solution (Python):
n, y = map(int,input().split())
m,g,s = 0,0,y // 1000
ans = ["-1","-1","-1"]

for i in range(2001):
    for j in range(2001):
        if s - n == 9 * i + 4 * j and n-i-j>=0:
            ans[0] = str(i)
            ans[1] = str(j)
            ans[2] = str(n-i-j)
            break

print(' '.join(ans))

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):
n,ye = map(int,input().split())
for x in range(n+1):
    if 10000 * x > ye: break
    for y in range(n-x+1):
        z = n - x - y
        tmp = 10000 * x + 5000 * y + 1000 * z
        if tmp == ye:
            print("{} {} {}".format(x,y,z))
            exit(0)
        elif tmp > ye:
            break
print("-1 -1 -1")

Solution (Python):
import re  
import sys 


def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))


def main():
    N, Y = s_input()

    for a in range(N + 1):
        for b in range(N + 1 - a):
            c = N - a - b
            abc_sum = 10000 * a + 5000 * b + 1000 * c
            if abc_sum == Y:
                print('{} {} {}'.format(a, b, c))
                sys.exit()
            
            
            
            
            

    print('-1 -1 -1')










if __name__ == "__main__":
    main()

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

if Y%1000!=0:
    print(-1,-1,-1)
    exit()
t = Y//1000 - N

i = 0
while True:
    tmp = (t-9*i)
    if tmp<0:
        print(-1,-1,-1)
        exit()
    if tmp%4==0:
        z = N-i-tmp//4
        if z >= 0:
            print(i, tmp//4, z)
        else:
            i += 1
            continue
        exit()
    i += 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
        val = 10000*i + 5000*j + 1000*k
        if val == y:
            print(i, j, k)
            exit()
print(-1, -1, -1)

Solution (Python):




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

for a in range(2000+1):
    for b in range(2000+1):
        c = n - a - b
        if c < 0:
            break
        if a * 10000 + b * 5000 + c * 1000 == y:
            print("{} {} {}".format(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
        val = 10000*i + 5000*j + 1000*k
        if val == y:
            print(i, j, k)
            exit()
        elif i == n:
            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
        val = 10000*i + 5000*j + 1000*k
        if val == y:
            print(i, j, k)
            exit()
        elif i == n:
            print(-1, -1, -1)

Solution (Python):
N, Y = list(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(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 = input().split(' ')
n,y = int(n),int(y)


for c_10000 in range(n+1):
	for c_5000 in range(n+1):
		current_money = 10000*c_10000 + 5000*c_5000
		remaining = y - current_money
		c_1000 = remaining//1000 
		if c_1000 == n-(c_10000+c_5000) and c_1000 >= 0:
			print("%i %i %i"%(c_10000,c_5000,c_1000))
			exit()
print("-1 -1 -1")

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

flag = False

yki = min(n,y//10000)
for i in range(yki+1):
    for j in range(n-i+1):
        nogu = n -i - j
        if nogu*1000 + i*10000 + j*5000 == y and nogu >= 0:
            ans = [i,j,nogu]
            flag = True
            break
    if flag:
        break

if flag:
    print(*ans,sep = " ")
else:
    print(-1,-1,-1)