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 = [int(e) for e in input().split(' ')]

for i in range(N+1):
  for j in range(N+1-i):
    sum = i * 1000 + j * 5000
    if (sum <= Y) and ((Y - sum) % 10000 == 0) and (i + j + (Y - sum) / 10000 == N):
      print('%d %d %d' % ((Y - sum) / 10000, j, i))
      quit()

print('-1 -1 -1')

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

Solution (Python):
N, Y = map(int, input().split())
 
X = (10000 * N - Y) // 1000
 
for y in range(N + 1):
    a = X - 5 * y
    if a >= 0 and a % 9 == 0:
        z = a // 9
        if y + z <= N:
            print(N - y - z, y, z)
            exit()

print('-1 -1 -1')

Solution (Python):
def main():
    N,Y=map(int,input().split())
    for i in range(N+1):
        j=0
        if Y==10000*N-5000*i:
            print("{0} {1} {2}".format(N-i-j,i,j))
            return
        for j in range(N-i+1):
            if Y==10000*N-5000*i-9000*j:
                print("{0} {1} {2}".format(N-i-j,i,j))
                return
    print("-1 -1 -1")

if __name__=="__main__":
    main()

Solution (Python):
N, Y = [int(_) for _ in input().split()]
Y=int(Y/1000)
 
if Y<N or Y > 10* N:
    print("-1 -1 -1")
else:
    Y-=N
    a, b=0, 0
    while Y%9 != 0:
        b+=1
        Y-=4
    a=Y//9
    c=N-(a+b)
    if a>=0 and b>=0 and c>=0:
        print("{} {} {}".format(a,b,c))
    else:
        print("-1 -1 -1")

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

s = Y%5000//1000
for i in range(s,N+1,5):
    y = Y - i*1000
    n = N - i
    upper = n*10000
    if upper < y:
        print(-1,-1,-1)
        sys.exit()
    j = (upper - y) // 5000
    k = n - j
    if k >=0:
        print(k,j,i)
        sys.exit()
print(-1,-1,-1)

Solution (Python):


import sys

def next(values):
    if values[0] > 0:
        values[0]

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, Y = map(lambda i: int(i), line.rstrip("\n").split(" "))

        values = [-1, -1, -1]
        n = Y / 1000
        for i in xrange(int(n / 5) + 1):
            for j in xrange(int(i / 2) + 1):
                if (j + i - 2 * j + n - 5 * i) == N:
                    values = [j, i - 2 * j, n - 5 * i]
                    break

        print " ".join([str(v) for v in values])

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

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

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

main()

Solution (Python):
N, a = map(int,input().split())
s = 0
t = 0
u = 0

for i in range(N+1):
    for j in range(N+1-i):
        k = N - i - j
        if i * 10000 + j * 5000 + k * 1000 == a:
            s = i
            t = j
            u = k
            break
if s == t == u == 0:
    print("-1" + " " + "-1" + " " + "-1")
else:
    print(str(s) + " " + str(t) + " " + str(u))

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

for i in range(0,N+1):
    for j in range(0, N+1):
        if Y==10000*(N-i-j)+5000*i+1000*j and i+j<=N:
            flag=True
            print(N-i-j, i, j)
            break
    if flag:
        break
else:
    print('-1 -1 -1')

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

answer = [-1, -1, -1]

flag = True
NF = int(Y / 10000) + 1
for nf in range(NF):
    if flag:
        cashf = Y - nf * 10000
        NH = int(cashf / 5000) + 1
        for nh in range(NH):
            cashh = cashf - nh * 5000
            if cashh < 0:
                break
            nn = int(cashh / 1000)
            if nf + nh + nn == N:
                flag = False
                answer = [nf, nh, nn]
                break

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

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

for i in range(n + 1):
    for j in range(i, n + 1):
        m = i
        g = j - i
        s = n - j
        if y == m * 10000 + g * 5000 + s * 1000:
            print("{} {} {}".format(m, g, s))
            exit()

print("-1 -1 -1 ")

Solution (Python):
N = list(map(int,input().split()))
sen=0
gosen=0
man = N[0]
while(N[0]+1>gosen):
    sen = 0
    while(N[0]+1>sen):
        man = N[0] - sen - gosen
        if(man < 0):
            sen += 1
            continue
        if(N[1]==(10000*man+5000*gosen+1000*sen)):
            print(str(man)+" "+str(gosen)+" "+str(sen))
            exit()
        sen += 1
    gosen += 1

print("-1 -1 -1")

Solution (Python):

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

    
    if 5000 * N < Y:
        n_yukichi = 1
        while True:
            if n_yukichi * 10000 + (N - n_yukichi) * 5000 >= Y:
                yukichi_need = n_yukichi
                break
            n_yukichi += 1
    else:
        yukichi_need = 0

    
    noguchi_start = (Y % 5000) // 1000

    for yukichi in range(yukichi_need, N+1):
        for higuchi in range(N+1):
            if yukichi + higuchi > N:
                break

            noguchi = N - yukichi - higuchi

            if yukichi + higuchi + noguchi == N:
                if yukichi*10000 + higuchi*5000 + noguchi*1000 == Y:
                    print(yukichi, higuchi, noguchi)
                    return

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

main()

Solution (Python):



INVALID = (-1, -1, -1)


def solve(n, y):
    y //= 1000
    for num_10 in range((y - n) // 9 + 1):
        z = y - n - 9 * num_10
        if z < 0 or z % 4 != 0:
            continue
        num_5 = z // 4
        num_1 = n - num_5 - num_10
        if num_1 >= 0 and num_5 >= 0 and num_10 >= 0:
            return (num_10, num_5, num_1)
    return INVALID


def main():
    n, y = (int(x) for x in input().split())
    print(*solve(n, y))


if __name__ == '__main__':
    main()

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

if Y == N * 10000:
    print " ".join(map(str, [N, 0, 0]))
elif Y > N * 10000:
    print " ".join(map(str, [-1, -1, -1]))
elif Y < N * 1000:
    print " ".join(map(str, [-1, -1, -1]))
elif Y == N * 1000:
    print " ".join(map(str, [0, 0, N]))


else:
    dif = N * 10000 - Y

    ext = dif % 9000
    if ext == 0:
        noguchi = dif / 9000
        print " ".join(map(str, [N-noguchi, 0, noguchi]))
    else:
        if ext == 1000:
            higuchi = 2
        elif ext == 2000:
            higuchi = 4
        elif ext == 3000:
            higuchi = 6
        elif ext == 4000:
            higuchi = 8
        elif ext == 5000:
            higuchi = 1
        elif ext == 6000:
            higuchi = 3
        elif ext == 7000:
            higuchi = 5
        elif ext == 8000:
            higuchi = 7

        dif = ((N - higuchi) * 10000 + higuchi * 5000)- Y
        if dif < 0:
            print " ".join(map(str, [-1, -1, -1]))
        else:
            noguchi = dif / 9000
            yukichi = N - (noguchi + higuchi)

            if not noguchi < 0 and not higuchi < 0 and not yukichi < 0:
                print " ".join(map(str, [yukichi, higuchi, noguchi]))
            else:
                print " ".join(map(str, [-1, -1, -1]))

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

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

print(x,y,z)

Solution (Python):
def solve():
    N, Y = list(map(int, input().split()))
    for a in range(N+1):
        b = ((Y - 10000*a) - 1000*(N - a))
        if b % 4000 != 0:
            continue
        else:
            b = int(b/4000)
            c = N - a - b
            if a >= 0 and b >= 0 and c >= 0:
                return a,b,c
    return -1, -1, -1

res = solve()
print(res[0], res[1], res[2])

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

def solve():
    y = Y//1000
    if Y%1000 != 0:
        print('-1 -1 -1')
        return

    flag = False
    for i in range(2*10**3+1):
        for j in range(10**3+1):
            if y - 10*i - 5*j == N - i - j and N-i-j >= 0:
                print(i, j, N - i - j)
                return

    print('-1 -1 -1')


if __name__ == "__main__":
    solve()

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

if y > 10 * n:
    print(-1,-1,-1)
elif y < n:
    print(-1,-1,-1)
else:
    flg = False

    for i in range(n+1):
        for j in range(n-i+1):
            k = n-i-j
            if y == i + 5 * j + 10 * k:
                print(k,j,i)
                flg = True
                break
        if flg == True:
            break

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

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

def main(n, y):
    if y > (n * 10000):
        return('-1 -1 -1')

    if y < 5000:
        if int(y / 1000) == n:
            return('0 0 ' + str(n))
        else:
            return('-1 -1 -1')
        
    elif 5000 <= y and y < 10000:
        for i in range((y // 5000) + 1):
            if (i + (y - 5000 * i) // 1000) == n:
                return('0 ' + str(i) + ' ' + str(n - i))
        
        return('-1 -1 -1')
    
    else:
        for i in range((y // 10000) + 1):
            for j in range(((y - 10000 * i) // 5000) + 1):
                if (i + j + (y - (10000 * i) - (5000 * j)) // 1000) == n:
                    return(str(i) + ' ' + str(j) + ' ' + str(n - i - j))
        
        return('-1 -1 -1')
    
print(main(n, y))

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

for a in range(N+1):
    b = (Y - 9000*a - 1000*N) // 4000
    mod = (Y - 9000*a - 1000*N) % 4000
    if 0 <= b <= N - a and mod == 0:
        print("{} {} {}".format(a, b, N-a-b))
        import sys
        sys.exit()

print("-1 -1 -1")

Solution (Python):
import sys
N, Y = map(int, input().split())
for x in reversed(range(N + 1)):
    for y in reversed(range(N - x + 1)):
        if x * 10000 + y * 5000 + (N - y - x) * 1000 == Y:
            if N - y - x < 0:
                continue
            print("{} {} {}".format(x, y, N - y - x))
            sys.exit()

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

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

Solution (Python):
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,y = Is()
for i in range(min(n+1,2001)):
    for j in range(min(n-i+1,4001)):
        k = n-i-j
        if k < 0:
            continue
        if y == i*10000 + j*5000 + k*1000 and i + j + k == n:
            print(i,j,k)
            exit()
print(-1,-1,-1)

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

goal = N_Y[1]/1000 - N_Y[0]
counter = 0

for i in range(N_Y[0]+1):
    if counter == 1:
        break
    number = [[j, N_Y[0]-i-j] for j in range(N_Y[0]-i +1)]
    
    for k in number:
        if 9*k[0] + 4*k[1] == goal:
            counter += 1
            print(k[0], k[1], int(N_Y[0]-k[0]-k[1]))
            break
            
if counter == 0:
    print(-1,-1,-1)

Solution (Python):
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

INF = float('inf')
MOD = 1000000000 + 7

def LI(): return [int(x) for x in input().split(" ")]
def LS(): return [str(x) for x in input().split(" ")]
def ItoS(L): return [str(x) for x in L]
def StoI(L): return [int(c) for c in L]


def solve():
    while 1:
        try:
            n, y = LI()
            for i in range(n + 1):
                for j in range(n + 1):
                    if 9 * i + 4 * j + n == y // 1000 and n - i - j >= 0:
                        print(i, j, n - i - j)
                        raise EndLoop

            print(-1, -1, -1)
            break
        except:
            break
solve()

Solution (Python):

import sys
n, y = map(int, input().split())
for a in range(n+1):
    for b in range(n+1-a):
        if 5000*a+9000*b == 10000*n-y and n-a-b >= 0:
            print(str(n-a-b)+' '+str(a)+' '+str(b))
            sys.exit()
        else:
            pass
'''
for a in range(n+1):
    for b in range(n-a+1):
        for c in range(n-a-b+1):
            if 10000*a+5000*b+1000*c == y:
                print(str(a)+' '+str(b)+' '+str(c))
                sys.exit()
            else:
                pass
'''
print("-1 -1 -1")

Solution (Python):
N,Y = map(int,input().split())
Y //= 1000
found = False
for a in range(Y//10+1):
   for b in range(Y//5-2*a+1):
      c = Y - 10*a - 5*b
      if a + b + c == N:
         print('{} {} {}'.format(a,b,c))
         found = True
         break
      if a + b + c < N:
         break
   if found:
      break
else:
   print('-1 -1 -1')

Solution (Python):
otoshidama = list(map(int, input().split()))
thousand_yen = int(otoshidama[1]/1000)
first_list = [0, 0, thousand_yen]
exchange_1 = min(int((thousand_yen - otoshidama[0]) // 4), int(thousand_yen // 5))
second_list = [0, exchange_1, thousand_yen - 5 * exchange_1]
exchange_2 = second_list[0] + second_list[1] + second_list[2] - otoshidama[0]
third_list = [exchange_2, exchange_1 - 2 * exchange_2, thousand_yen - 5 * exchange_1]
if third_list[0] < 0 or third_list[1] < 0 or third_list[2] < 0:
    print("-1 -1 -1")
else:
    print(str(third_list[0]),  str(third_list[1]),  str(third_list[2]))

Solution (Python):
'''
x+y+z=N
10000x+5000y+1000z=Y

z=N-x-y
10000x+5000y+1000(N-x-y)=Y
=> 9000x+4000y=Y-1000N
=> 9x+4y=(Y/1000)-N

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


right = (Y/1000) - N



for x in range(N+1):
	for y in range(N-x+1):
		tmp = 9*x + 4*y
		
		if tmp == right and x+y <= N:
			print('{} {} {}'.format(x,y,(N-x-y)))
			quit()

print('-1 -1 -1')

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

  for man in range(n + 1):
    for gos in range(n + 1 - man):
      sen = n - man - gos
      if man * 10000 + gos * 5000 + sen * 1000 == y:
        print(man, gos, sen)
        return
  print(-1, -1, -1)

solve()

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,y = LI()
    y //= 1000
    for k in range(10**3*4+1):
        for j in range(10**3*2+1):
            if k+j>n:
                break
            i = n-k-j
            if i+j*10+k*5 == y:
                return '{} {} {}'.format(j,k,i)

    return '-1 -1 -1'

print(main())

Solution (Python):
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Y] = [int(input_raw[0]), int(input_raw[1])]

    is_exist = False;
    for x in range(0, 2000 + 1):
        for y in range(0, 2000 + 1):
            z = N - x - y
            if z >= 0:
                if 10000*x + 5000 *y + 1000 * z == Y:
                    is_exist = True
                    break;
        if is_exist == True:
            break;
    if is_exist== True:
        print x, y, z;
    else:
        print -1, -1, -1;

if __name__ == '__main__':
    main()

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

for y in range(N+1):
	for x in range(N-y+1):
		if 9000*x+4000*y==Y-1000*N:
			print(x,y,N-x-y)
			sys.exit()
		elif  9000*x+4000*y>Y-1000*N:
			break

else:
	print("-1 -1 -1")

Solution (Python):
import sys

N, Y = [int(x) for x in sys.stdin.readline().strip().split()]

a = Y // 10000
b = (Y - a * 10000) // 5000
c = (Y - a * 10000 - b * 5000) // 1000

while 1:
    t = a + b + c
    if N >= t + 9 and a > 0:
        a -= 1
        c += 10
        continue
    if N >= t + 4 and b > 0:
        b -= 1
        c += 5
        continue
    if N > t and a > 0:
        a -= 1
        b += 2
        continue
    break

if a + b + c != N or a < 0 or b < 0 or c < 0:
    print("-1 -1 -1")
else:
    print(a, b, c)

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

Solution (Python):



import sys

n, y = map(int, sys.stdin.readline().strip().split(" "))
currents = [10000, 5000, 1000]
flag = True
for i in range(0, n + 1):
    for j in range(0, n + 1 - i):
        if flag and currents[0] * i + currents[1] * j + currents[2] * (n - i - j) == y:
            print("{} {} {}".format(i, j, n - i - j))
            flag = False
if flag:
    print("-1 -1 -1")

Solution (Python):
N, Y = list(map(int, input().split(sep=" ")))
left = (10 * N) - (Y // 1000)
for z in range(0, left // 9 + 1):
    y, y_rem = divmod(left - 9 * z, 5)
    if y_rem != 0:
        continue
    else:
        x = N - (y + z)
        if x >= 0:
            print(" ".join(map(str, (x, y, z))))
            exit()
print("-1 -1 -1")

Solution (Python):
def main():
    l = list(map(int,input().split(" ")))
    N = l[0]
    Y = l[1]
    c1 = N
    c2 = 0
    c3 = 0
    if Y>N*10000 or Y<N*1000:
        print(-1,-1,-1)
        exit()
    while c1>=0:
        tar1 = Y-c1*10000
        c2 = N-c1
        while c2>=0:
            tar2 = tar1-c2*5000
            c3 = N-c2-c1
            tar3 = tar2-c3*1000
            if tar3==0:
                print(c1,c2,c3)
                exit()
            c2-=1
        c1-=1
    print(-1,-1,-1)

if __name__=="__main__":
    main()

Solution (Python):
n,y = map(int,input().split())
if 10000*n == y:
	print('{0} 0 0'.format(n))
elif 5000*n == y:
	print('0 {0} 0'.format(n))
else:
	a = 0
	b = 0
	c = 0
	i = 0
	while i < n:
		for k in range(n-i):
			total = 10000*i + 5000*k + 1000*(n-i-k)
			if total == y:
				 a = i
				 b = k
				 c = n-i-k
				 break
		i += 1
	if 10000*a + 5000*b + 1000*c == y:
		print('{0} {1} {2}'.format(a,b,c))
	else:
		print('-1 -1 -1')

Solution (Python):
[n, yen] = list(map(int, input().split()))
ans = [-1, -1, -1]
for x in range(0, yen // 10000 + 1):
    for y in range(0, (yen - 10000*x)//5000 + 1):
        z = (yen - 10000*x - 5000*y) // 1000
        if x + y + z == n:
            ans = [x, y, z]
print("{} {} {}".format(ans[0], ans[1], ans[2]))

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

ho = 10000 * N - Y
x = y = z = -1
for i in range(N + 1):
    for j in range(N + 1 - i):
        if(ho == 5000 * i + 9000 * j):
            y = i
            z = j
            x = N - i - j
            break

print(x,y,z)

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

Solution (Python):


n, price = map(int, input().split(' '))
delta = int(price / 1000 - n)
res = '-1 -1 -1'
for x in range(n + 1):
    for y in range(n + 1):
        if delta == 9 * x + 4 * y and x + y <= n:
            res = '{} {} {}'.format(x, y, n - x - y)
            break
print(res)

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

list = [-1,-1,-1]
for x in range(0,N+1):
    for y in range(0,N+1-x):
        z = N - x - y
        sumOfMoney = 10000*x + 5000*y + 1000*z

        if sumOfMoney == Y:
            list[0] = x
            list[1] = y
            list[2] = z

print(str(list[0]) + " " + str(list[1]) + " " + str(list[2]))

Solution (Python):
from pprint import pprint as pp

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

def func():
  for k10 in range(n+1):
    if k10 * 10000 > y:
      continue
    for k5 in range(n-k10+1):
      k1 = n - k10 - k5
      if (k10 * 10000) + (k5 * 5000) + (k1 * 1000) == y:
        print("{} {} {}".format(k10, k5, k1))
        return
  print("{} {} {}".format(-1, -1, -1))
func()

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

N, Y = na()
found = False

for i in range(N, -1, -1):
  if(i*10000 > Y):
    continue
  for j in range(N-i, -1, -1):
    if(found):
      break
    if(i*10000 + j*5000 + (N-i-j)*1000 == Y):
      found = True
      print(str(i) + ' ' + str(j) + ' ' + str(N-i-j))
      break

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

Solution (Python):
N,Y = map(int,input().split())
A,B,C = 10000,5000,1000

def solve():
    for x in range(Y//A + 1):
        rem = Y - x*A
        if B*(N-x) < rem:
            continue
        if rem == 0 and x == N:
            return (x,0,0)
        for y in range(rem//B + 1):
            rem = Y - x*A - y*B
            z = rem // C
            if z < 0: break
            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(' '))
y = y/1000

m = 0
g = 0
s = 0

m = int(y/10)
g = int((y-10*m)/5)
s = int(y-10*m-5*g)

tmpn = m+g+s

while(tmpn != n ):
    if g>0 and n-tmpn >=4:
        g= g-1
        s= s+5
        tmpn=m+g+s
    elif m > 0 and n-tmpn >=1:
        m=m-1
        g=g+2
        tmpn=m+g+s
    else:
        m=-1
        g=-1
        s=-1
        break

print(m,g,s)

Solution (Python):
a=input()
n=a.split(" ")[0]
y=a.split(" ")[1]
n=int(n)
y=int(y)
flag=True
for i in range(0,n+1): 
    for j in range(0,n+1-i): 
        k=n-j-i
        if i*10000+j*5000+k*1000==y and i+j+k==n:
            print(str(i)+" "+str(j)+" "+str(k))
            flag=False
            break
    if not flag:
        break
        
if flag:
    print("-1 -1 -1")

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

def main():
  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)
        return
  print('-1 -1 -1')      

main()

Solution (Python):
N, Y = map(int, input().split())
Y = Y / 1000
isOk = False
for i in range(N + 1):
    for j in range(N - i + 1):
        if Y == i + 5 * j + 10 * (N - i - j):
            isOk = True
            senen = str(i)
            gosenen = str(j)
            ichimanen = str(N - i - j)
if isOk:
    print(ichimanen + " " + gosenen + " " + senen)
else:
    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):
			num = (10000*i+5000*j+1000*(N-i-j))
			if num == Y:
				print(str(i) + " " + str(j) + " " + str(N-i-j))
				exit(0)

print("-1 -1 -1")

Solution (Python):
n, Y = list(map(int, input().split()))
Y = int(Y/1000)
max_x = Y // 10

def calc(money, N):
    max_y = money // 5
    for i in range(max_y, -1, -1):
        if i * 5 + (N - i) == money:
            return [i, N-i]
    return [-1, -1]

flag = 0
for i in range(max_x, -1, -1):
    result = calc(Y - i * 10, n - i)
    if result != [-1, -1]:
        result.insert(0, i)
        flag = 1
        break
else:
    result.append(-1)
print (result[0], result[1], result[2])

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

y = Y / 1000

flag = 0

if 10 * n < y:
    print("-1 -1 -1")
elif y - n < 0:
    print("-1 -1 -1")
else:
    for a in range(0, n+1):
        for b in range(0, n-a+1):
            if 9*a + 4*b == y - n:
                print(a, b, n-a-b)
                flag = 1
                break
        if flag == 1:
            break
    if flag == 0:
        print("-1 -1 -1")

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

Solution (Python):
N, Y = map(int,input().split())
mi,fi,sa = 0,0,0
value = 0
num = 0
for m in range(Y//10000+1):
    for f in range((Y-m*10000)//5000+1):
        sa = (Y-m*10000-f*5000)//1000
        num = m+f+sa        
        if num == N:
            print(m,f,sa)
            exit()
print(-1,-1,-1)

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

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

Solution (Python):
N,Y = map(int,input().split())
Y = Y/1000
torf = False
for numoft in range(N+1):
    for numof5t in range(N-numoft+1):
        numof10t = (N)-(numoft+numof5t)
        if Y == numoft + 5*numof5t + 10*numof10t:
            print(numof10t,numof5t,numoft)
            exit()
print("-1 -1 -1")

Solution (Python):
n, z = [int(x) for x in input().split()]
z //= 1000
if n > z:
    print('-1 -1 -1')
    raise SystemExit
if n == z:
    print(0, 0, z)
    raise SystemExit

over = z - n
y = x = 0
while over >= 4 and z >= 5:
    y += 1
    z -= 5
    over -= 4
while over > 0 and y >= 2:
    x += 1
    y -= 2
    over -= 1
if over == 0:
    print(x, y, z)
else:
    print('-1 -1 -1')

Solution (Python):
n, Y = map(int, input().split())
Y //= 1000
for z in range(Y//10+1):
    for y in range((Y-z*10)//5+1):
        x = Y - z*10 - y*5
        if x < 0:
            break
        if x + y + z == n:
            print(z, y, x)
            exit(0)
print(-1, -1, -1)

Solution (Python):

import sys

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

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

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

Solution (Python):
def solve(n, y):
    tmp1000 = n * 1000
    if tmp1000 > y:
        return -1, -1, -1
    diff = y - tmp1000
    for y in range(diff // 4000 + 1):
        tmp5000 = y * 4000
        if diff - tmp5000 < 0:
            break
        if (diff - tmp5000) % 9000 == 0:
            x = (diff - tmp5000) // 9000
            if x >= 0 and x + y <= n:
                return x, y, n - x - y
    return -1, -1, -1


print(*solve(*map(int, input().split())))

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

Solution (Python):
n, Y = map(int, input().split())
Y //= 1000
for z in range(Y//10+1):
    for y in range((Y-z*10)//5+1):
        x = Y - z*10 - y*5
        if x < 0:
            break
        if x + y + z == n:
            print(z, y, x)
            exit(0)
print(-1, -1, -1)