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):
l = list(map(int, input().split()))

N = l[0]
Y = l[1]
ans = [-1,-1,-1]

if Y/10000 <= N:
    for i in range(int(Y/10000)+1):
        a = i
        n = N - a
        Y1 = Y - (a * 10000)
        if Y1/5000 <= n:
            for j in range(int(Y1/5000)+1):
                b = j
                c = n - j
                if 10000 * a + 5000 * b + 1000 * c == Y:
                    ans = [a,b,c]

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

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

f, t = -1, -1

start = 1000 * n

for i in range(n+1):
    if f != -1:
        break
    else:
        start = 1000 * n + 4000 * i
        for j in range(n-i+1):
            tmp = start + 9000 * j
            if tmp == y:
                f, t = i, j
                break

if f == -1:
    print('-1 -1 -1')
else:
    print(t, f, n-f-t)

Solution (Python):
def c_Otoshidama_C(N, Y):
    import math
    
    t = (Y - 1000 * N) // 1000  
    
    q = t % 4
    r = (t - 9 * q) // 4
    
    left = max(math.ceil(-q / 4), math.ceil((q + r - N) / 5))
    right = math.floor(r / 9)
    if left <= right:
        k = left
        a = 4 * k + q
        b = -9 * k + r
        c = N - a - b
        return '{} {} {}'.format(a, b, c)
    else:
        return '-1 -1 -1'
    

N,Y=[int(i) for i in input().split()]
print(c_Otoshidama_C(N, Y))

Solution (Python):
setting = input().rstrip().split(" ")
N = int(setting[0])
Y = int(setting[1])
A = -1
B = -1
C = -1

for x in range(N+1):
    for y in range(N+1):
        if N-x-y >= 0:
            if 10000*x + 5000*y + 1000*(N-x-y) == Y :
                A , B , C = x ,y,N-x-y
                break
    else:
            continue
    break
print(A," ",B," ",C)

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

Solution (Python):
def solve(yen,cnt):
  if yen<0:
    print("-1 -1 -1")
    return False
  elif yen==0:
    print(cnt,0,0)
    return True
  else:
    res=0
    while res<=cnt:
      for i in range(0,cnt-res+1):
        if res*5000+i*9000 == yen:
          print(cnt-i-res,res,i)
          return True
      res+=1
    print("-1 -1 -1")
    return False

N,Y=map(int,input().split())
ans=N*10000-Y

solve(ans,N)

Solution (Python):
N, Y = map(int,input().split())
import sys
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)
      sys.exit()
else: print(-1,-1,-1)

Solution (Python):

def inpl(): return list(map(int, input().split()))

N, Y = inpl()

yuki= Y//10000
tY = Y%10000
higu = tY//5000
tY = tY%5000
nogu = tY//1000

for y in range(0, yuki+1):
    if (Y - 9000*y - 1000*N)%4000 != 0:
        continue
    h = (Y - 9000*y - 1000*N)//4000
    n = N - y - h
    if (h>=0) and (n>=0):
        print("{} {} {}".format(y, h, n))
        break
else:
    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(0)
print(-1, -1, -1)

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


for x in range(N+1):
    for y in range(N+1):
        z = N - (x + y)
        if (z >= 0) & (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())


res = 0;
if y % 5000 != 0:
    res = y % 5000 // 1000
    y = y - res * 1000

if res > n:
    print("-1 -1 -1")
    exit(0)


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

print("-1 -1 -1")
exit(0)

Solution (Python):
n, y = map(int, input().split())
ans = [-1, -1, -1]
for i in range(n + 1):
    if y < 10000 * i:
        break
    m = n - i
    x = y - 10000 * i
    k = (x - 1000 * m) // 4000
    if 0 <= k <= m and 1000 * (m - k) + 5000 * k == x:
        ans = [i, k, m - k]
        break

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

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

print('-1 -1 -1')

Solution (Python):
ans = False
count, sum = map(int, input().split())
for x in range(count+1):
    for y in range(count-x+1):
        if sum == 10000 * x + 5000 * y + 1000 * (count-x-y) and not ans:
            print("{0} {1} {2}".format(x, y, (count-x-y)))
            ans = True
if not ans:
    print("-1 -1 -1")

Solution (Python):

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

def solve():
    for x in range(3 * 10**3):
        for y in range(5 * 10**3):
            if x + y <= N and 9 * x + 4 * y == Y // 1000 - N:
                print(x, y, N - x - y)
                return
    print(-1, -1, -1)
    return

solve()

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

for x in range(N+1):
    for y in range(N+1-x):
        if N+9*x+4*y == Y:
            print(x,y,N-x-y)
            exit()

print('-1 -1 -1')

Solution (Python):
import sys

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

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:
            print(x,y,z)
            sys.exit(0)

print(-1,-1,-1)

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)


dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b):return (a + b - 1) // b


def solve(N, Y):
    for a in range(N + 1):
        for b in range(N + 1):
            r = Y - (10000 * a + 5000 * b)
            if r >= 0 and r % 1000 == 0:
                c = r // 1000
                if a + b + c == N:
                    return a, b, c
    return -1, -1, -1


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


if __name__ == '__main__':
    main()

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

res = [-1] * 3
for x in range(N + 1):
	for y in range(N + 1):
		if x + y > N:
			break
		z = N - x - y
		if 10000 * x + 5000 * y + 1000 * z == Y:
			res[0], res[1], res[2] = x, y, z
			break

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

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

res = [-1] * 3

for x in range(0, N + 1):
	if 10000 * x > Y:
		break; 
	for y in range(0, N - x + 1):
		if 10000 * x + 5000 * y > Y:
			break;
		remain = Y - 10000 * x - 5000 * y
		if remain < 0:
			break
		if x + y > N:
			break
		z = remain // 1000
		if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
			res[0],res[1],res[2] = x, y, z
			break

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

Solution (Python):
N, Y = map(int, input().split())
flag = False
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:
            print(x, y, z)
            flag = True
            break
    if flag:
        break
else:
    print(-1, -1, -1)

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

flag = False

for z in range(N + 1)[::-1]:
    rem1 = N - z + 1
    for y in range(rem1)[::-1]:
        x = N - z - y
        val = 10000 * x + 5000 * y + 1000 * z
        if val == Y:
            flag = True
            break
    if flag:
        break

if not flag:
    x = -1
    y = -1
    z = -1

print(x, y, z)

Solution (Python):



import sys

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

Solution (Python):
a = list(map(int, input().split()))
result = [-1, -1, -1]

for i in range(a[0]+1):
   for j in range(a[0]+1-i):
      if (10000*i + 5000*j  + (a[0] - i - j )* 1000) == a[1]:
         result = [i, j, a[0] - i - j]
         break

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

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


def oto(num,yen):
    for x in range(num+1):
        for y in range(num+1):
            z = num - x -y
            if yen - (10000*x + 5000*y + 1000*z) == 0 and \
                    x + y + z == num and \
                    0 <= z <=num:
                print(x,y,z)
                return

    print('-1 -1 -1')

oto(N,Y)

Solution (Python):

import sys

n,y=map(int,raw_input().split())
for a in xrange(n+1):
 for b in xrange(n+1):
  if y==10000*a+5000*b+1000*(n-a-b) and n-a-b>=0:
   print a,b,n-a-b
   sys.exit()
print '-1 -1 -1'

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

    exhaustive_search(N, Y)

def exhaustive_search(N, Y):
    
    for m in range(N + 1):
        for g in range(N + 1):
            s = N - m - g
            
            if 0 <= s <= N and \
                    m + g + s == N and \
                    m * 10000 + g * 5000 + s * 1000 == Y:
                print(m, g, s)
                return

    print(-1, -1, -1)

main()

Solution (Python):
def c_Otoshidama_C(N, Y):
    yen = Y // 1000
    """
    変数x,y,z(それぞれ1万円札、5千円札、千円札の枚数)は以下の条件を満たす。
    a. x + y + z = N      <=> x + y = N - z      (1)
    b. 10x + 5y + z = yen <=> 2x + y = (yen-z)/5 (2)
    c. 0 <= z <= min(N,yen)       (方程式1,2より)
    d. z ≡ yen (mod 5)            (方程式2の右辺が整数となるため)
    e. N-z <= (yen-5)/2 <= 2(N-z) (方程式1,2より)
    cdeを満たすzを1つ見つけたのち、連立方程式を解けばよい。
    """
    for z in range(min(N, yen) + 1):
        if (z % 5 == yen % 5) and (N - z <= (yen - z) / 5 <= 2 * (N - z)):
            noguchi = z
            tmp1 = -5 * N + yen + 4 * noguchi
            tmp2 = 10 * N - yen - 9 * noguchi
            if tmp1 % 5 == 0 and tmp2 % 5 == 0:
                yukichi = tmp1 // 5
                higuchi = tmp2 // 5
                if yukichi >= 0 and higuchi >= 0:
                    return '{} {} {}'.format(yukichi, higuchi, noguchi)
    return '-1 -1 -1'

N,Y=[int(i) for i in input().split()]
print(c_Otoshidama_C(N, Y))

Solution (Python):
n, y = map(int, input().split())
y //= 1000
for c in range(max((5*n - y)//4,0), (10*n - y)//9+1):
    if (y - c) % 5 == 0:
        a = (y-c)//5 - n + c
        b = n - a - c
        print(a,b,c)
        exit()
print(-1,-1,-1)

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

Y = Y / 1000

flag = False
for i in range(N+1):
    for j in range(N+1-i):
        k = N - i - j
        if i * 10 + j * 5 + k == Y:
            print(i,j,k)
            flag = True
            break
    if flag:
        break

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

Solution (Python):
N, Y = map(int, input().split())
result = [-1, -1, -1]

for i in reversed(range(N + 1)):
  for j in reversed(range(N + 1 - i)):
    if (i * 10000 + j * 5000 + (N - i - j) * 1000) == Y:
      result = [i, j, N - i - j]
      break
print(' '.join(map(str, result)))

Solution (Python):
def c_Otoshidama_C(N, Y):
    yen = Y // 1000
    """
    変数x,y,z(それぞれ1万円札、5千円札、千円札の枚数)は以下の条件を満たす。
    a. x + y + z = N      <=> x + y = N - z      (1)
    b. 10x + 5y + z = yen <=> 2x + y = (yen-z)/5 (2)
    c. 0 <= z <= min(N,yen)       (方程式1,2より)
    d. z ≡ yen (mod 5)            (方程式2の右辺が整数となるため)
    e. N-z <= (yen-5)/2 <= 2(N-z) (方程式1,2より)
    cdeを満たすzを1つ見つけたのち、連立方程式を解けばよい。
    """
    for z in range(min(N, yen) + 1):
        if (z % 5 == yen % 5) and (N - z <= (yen - z) / 5 <= 2 * (N - z)):
            noguchi = z
            tmp1 = -5 * N + yen + 4 * noguchi
            tmp2 = 10 * N - yen - 9 * noguchi
            if tmp1 % 5 == 0 and tmp2 % 5 == 0:
                yukichi = tmp1 // 5
                higuchi = tmp2 // 5
                if yukichi >= 0 and higuchi >= 0:
                    return '{} {} {}'.format(yukichi, higuchi, noguchi)
    return '-1 -1 -1'

N,Y=[int(i) for i in input().split()]
print(c_Otoshidama_C(N, Y))

Solution (Python):
n, y = map(int, input().split())
y //= 1000
c = -1
for i in range(min(n,y)+1):
    if (y - i) % 5 != 0: continue
    if n - i <= (y - i)/5 and (y - i)/5 <= 2*(n - i):
        c = i
        break
if c == -1:
    print(-1,-1,-1)
else:
    a = (y-c)//5 - n + c
    b = n - a - c
    print(a,b,c)

Solution (Python):
a,b=map(int,input().split())
x=0
y=0
z=0
m=0
if(b//1000<a or b//10000>a):
	print("-1 -1 -1")
else:	
	c=(b//1000)-a
	for i in range(0,a+1):
		if((c-(4*i))%9==0):
			y=i
			z=(c-(4*i))//9
			break
		m+=1
	if(m==a and a!=y):
		print("-1 -1 -1")
	else:
		if(a-z-y<0 or z<0 or y<0):
			print("-1 -1 -1")
		else:	
			print(z,y,a-z-y)

Solution (Python):
def c_Otoshidama_N(N, Y):
    yen = Y // 1000
    
    for yukichi in range(0, 2001):
        
        
        tmp1 = (yen - N - 9 * yukichi)
        tmp2 = (5 * N - yen + 5 * yukichi)
        if tmp1 % 4 == 0 and tmp2 % 4 == 0:
            higuchi = tmp1 // 4
            noguchi = tmp2 // 4
            if higuchi >= 0 and noguchi >= 0:
                return '{} {} {}'.format(yukichi, higuchi, noguchi)
    
    return '-1 -1 -1'

N,Y=[int(i) for i in input().split()]
print(c_Otoshidama_N(N, Y))

Solution (Python):
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque








def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)


def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))





def main():
	n,yen = LI()
	f = False
	for x in range(0,n+1):
		for y in range(0,n-x+1):
			z = n-x-y
			r = yen - 10000*x - 5000*y - 1000*z
			if r == 0:
				print(x,y,z)
				f = True
				break
		if f:
			break

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



if __name__ == '__main__':
	main()

Solution (Python):
import sys

N, Y = map(int, input().split())
Y2 = Y // 1000

for a in range(2001):
    for b in range(2001 - a):
        if 9 * a + 4 * b + N == Y2 and a + b <= N:
            print(a, b, N - a - b)
            sys.exit(0)
print(-1, -1, -1)

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

    target = 10000 * N - Y

    ans_x = -1
    ans_y = -1
    for x in range(0, N + 1):
        y = 0
        while x + y <= N:
            if 9000 * x + 5000 * y == target:
                ans_x = x
                ans_y = y
                break
            y += 1

    if ans_x != -1:
        print(str(N - ans_x - ans_y) + ' ' + str(ans_y) + ' ' + str(ans_x))
    else:
        print("-1 -1 -1")

Solution (Python):





















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



d = (Y/1000) - N

ercd = -1

for i in range(N+1):

    B = ((d - 9*i)/4)
    C = (N - i - B)

    if(((d - (9*i)) % 4) == 0 )and( B <= N) and (B >= 0)and(C <= N) and (C >= 0):
        ercd  = 1
        break

if ercd != -1:
    print i, ((d - 9*i)/4) , (N - i - B)
else:
    print -1, -1, -1

Solution (Python):
S = input()
s = S.split()

N = int(s[0])
Y = int(s[1]) 
a = True

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

Solution (Python):
n,y=map(int,raw_input().split())
for i in range(2001):
	for j in range(2001):
		foo=y-10000*i-5000*j
		z=1000
		if foo%z==0 and i+j+foo/z==n and foo/z>=0:
			print i,j,foo/z
			exit(0)
print -1,-1,-1

Solution (Python):

N, Y = input().split(" ")
N = int(N)
Y = int(Y)
F = Y - (1000 * N)
for x in range(int(F/9000)+1):
    y = int((F - (9000 * x)) / 4000)
    if (F - (9000 * x)) % 4000 == 0 and y >= 0 and (N - x - y) >= 0:
        print(str(x)+" "+str(y)+" "+str(N-x-y))
        break
else:
    print("-1 -1 -1")

Solution (Python):
def solve(n, y):
    for man in range(n + 1):
        for gosen in range(n - man + 1):
            sen = n - man - gosen
            if 10000*man + gosen*5000 + sen*1000 == y and man + gosen + sen == n:
                print('{} {} {}'.format(man, gosen, sen))
                return
    print("-1 -1 -1")
    return            


n, y = map(int, raw_input().split())
solve(n, y)

Solution (Python):



def solve():
    n, y = map(int, input().split())
    y //= 1000

    for noguchi in range(n + 1):
        for higuchi in range(n + 1 - noguchi):
            yukichi = n - noguchi - higuchi
            if noguchi + higuchi * 5 + yukichi * 10 == y:
                print(yukichi, higuchi, noguchi)
                return
    
    print("-1 -1 -1")

if __name__=="__main__":
    solve()

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,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, Y = map(int, input().split())

moneys = [10000, 5000, 1000]

man = 0
gosen = 0
sen = 0
'''
方針：とりあえず、できるかの計算
その後は、１万円札から５０００円に両替
その次に５０００円札を１００００円に両替していく
'''

max_man = Y//10000
max_gosen = Y//5000

for m in range(max_man, -1, -1):
    for g in range(max_gosen, -1, -1):
        s = N - m - g
        if s < 0:
            continue
        if 10000*m + 5000*g + 1000*s == Y:
            print(m,g,s)
            exit()
print(-1,-1,-1)

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

flag = False

for z in range(N + 1)[::-1]:
    rem1 = N - z + 1
    for y in range(rem1)[::-1]:
        x = N - z - y
        val = 10000*x + 5000*y + 1000*z
        if val == Y:
            flag = True
            break
    if flag:
        break

if not flag:
    x = -1
    y = -1
    z = -1
    
print(x, y, z)

Solution (Python):
R = lambda type_ = "int": list(map(eval(type_), input().split(' ')))

N, Y = R()
Y //= 1000

a, b, c = -1, -1, -1
for i in range(N + 1):
    for j in range(N - i + 1):
        if Y - i * 10 - j * 5 == N - i - j:
            a = i
            b = j
            break

if a != -1:
    c = N - a - b
print('{} {} {}'.format(a, b, c))

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

n1, n2, n3 = -1, -1, -1
for z in range(N+1):
    x = (Y - 5*N + 4*z)/5
    y = (10*N - 9*z - Y)/5
    if x.is_integer() and y.is_integer() and x >= 0 and y >= 0:
        n1, n2, n3 = x, y, z

n1 = int(n1)
n2 = int(n2)
n3 = int(n3)
print('{} {} {}'.format(n1, n2, n3))

Solution (Python):

import sys
import itertools

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

for c in itertools.combinations(range(N + 2), 2):
    M[0] = c[0]
    M[1] = c[1] - c[0] - 1
    M[2] = N - c[1] + 1
    money = M[0]*10000 + M[1]*5000 + M[2]*1000
    if money == Y:
        print(M[0], M[1], M[2])
        sys.exit()

print("-1 -1 -1")

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

man_max = Y//10000

go_max = Y // 5000

sen_max = Y // 1000


for i in range(N,-1,-1):
    for j in range (N-i+1):
        if 10000*i +5000*j +1000*(N-(i+j)) == Y: 
            print(str(i)+" "+str(j) + " " + str(N-(i+j)))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
N, Y = [int(k) for k in input().split(' ') if k]
Y //= 1000
x = Y // 10
Y -= x * 10
y = Y // 5
Y -= y * 5
z = Y
if N < x + y + z:
	print(-1, -1, -1)
	exit()
d = N - x - y - z
for dx in range(min(d, x) + 1):
	nx = x - dx
	ny = y + 2 * dx
	nd = N - nx - ny - z
	dy = min(nd // 4, ny)
	ny = ny - dy
	nz = z + dy * 5
	if nx + ny + nz == N:
		print(nx, ny, nz)
		exit()
print(-1, -1, -1)

Solution (Python):
def c_Otoshidama(N, Y):
    ans = ''

    for yukichi in range(0, 2001):
        for higuchi in range(0, 2001):
            noguchi = N - yukichi - higuchi
            if noguchi >= 0:
                if Y == yukichi * 10000 + higuchi * 5000 + noguchi * 1000:
                    return '{} {} {}'.format(yukichi, higuchi, noguchi)
    return '-1 -1 -1'
  
N,Y=[int(i) for i in input().split()]
print(c_Otoshidama(N, Y))

Solution (Python):
N,Q = (map(int,input().split()))
for a in range(N,-1,-1):
    A = a*10000
    if A > Q:
        continue
    if (a==N)and(A == Q):
        print("{0} 0 0".format(a))
        exit()
    for b in range(N-a,-1,-1):
        B = A+b*5000
        if B > Q:
            continue
        if (a+b==N)and(B == Q):
            print("{0} {1} 0".format(a,b))
            exit()
        if ((Q-B)%1000==0)and((Q-B)/1000==(N-a-b)):
            print("{0} {1} {2}".format(a,b,int((Q-B)/1000)))
            exit()
print("-1 -1 -1")

Solution (Python):

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

li = map(str, [-1] * 3)

if N * 10000 >= price and N * 1000 <= price:
    x = price // 10000
    for i in range(x + 1):
        y = (price - i * 10000) // 5000
        for j in range(y + 1):
            if N >= i + j and price == i * 10000 + j * 5000 + (N - i - j) * 1000:
                li = map(str, [i, j, N - i - j])

print(" ".join(li))

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N, Y = map(int, input().split())
Y2 = Y // 1000

for a in range(2001):
    for b in range(2001 - a):
        if 9 * a + 4 * b + N == Y2 and a + b <= N:
            print(a, b, N - a - b)
            sys.exit(0)
print(-1, -1, -1)

Solution (Python):
import numpy as np
a, b=[int(i) for i in input().split()]

for i in range(9):
  c = np.array([[10000,1000],[1,1]])
  d = np.array([b - i*5000 , a-i])
 
  x=np.linalg.solve(c, d)

  if x[0]>=0 and x[1]>=0 and round(x[0],5)-int(round(x[0],5))<0.001 and round(x[1],5)-int(round(x[1],5))<0.001:
    break
else:
  x=np.array([])
y=list(x)

if y==[]:
  print('-1 -1 -1')
else: 
  print(str(int(round(y[0],5)))+' '+str(i)+' '+str(int(round(y[1],5))))

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

Solution (Python):

import sys

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

a, b, c = 0, 0, 0

am = y // 10000
bm = y // 5000
cm = y // 1000

for i in range(am+1):
    for j in range(bm+1):
        if (9000*i + 4000*j + 1000*n == y) and (n-i-j >= 0):
            print(i, j ,n-i-j)
            sys.exit()
        if (y - 1000*n - 4000*j < 0):
            break
        if (n-i-j < 0):
            break

print(-1,-1,-1)

Solution (Python):

line = input().split(" ")
N = int(line[0])
Y = int(line[1])

ret = ["-1","-1","-1"]
for z in range(N+1):
    x = (Y-5000*N+4000*z)
    if x%5000==0:
        x = x/5000
        y = N-z-x
        if x>=0 and y>=0:
            ret = [str(int(x)),str(int(y)),str(int(z))]
            break

print(" ".join(ret))

Solution (Python):
data = [int(x) for x in input().split(' ')]
n, y = data[0], data[1]
y //= 1000
for cnt1 in range(n+1):
	for cnt5 in range(n+1-cnt1):
		cnt10 = n-cnt1-cnt5
		if cnt1+5*cnt5+10*cnt10 == y:
			print(cnt10, cnt5, cnt1)
			exit()
print(-1, -1, -1)

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

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

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

x = 0
y = 0
z = int(money/1000)
n_sum = x + y + z

if z < n:
    print("-1 -1 -1")
elif n_sum == n:
    print(x, y, z)
else:
    div1000 = min(int((n_sum-n)/4), int(z/5))
    z = z - (5*div1000)
    y += div1000
    n_sum = x+y+z
    if n_sum == n:
        print(x, y, z)
    else:
        if int(y/2) >= n_sum-n:
            y -= (n_sum-n)*2
            x += (n_sum-n)
            print(x, y, z)
        else:
            print("-1 -1 -1")

Solution (Python):
import sys
from math import ceil

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

y = Y / 1000

minC = max(int(ceil((5*N - y)/4.)), 0)
maxC = min(int((10*N-y)/9.), N)

if maxC < minC:
    print "-1 -1 -1"
    sys.exit()

for c in range(minC, maxC+1):
    if ((10*N-y-9*c)%5 == 0) and ((-5*N+y+4*c)%5 == 0):
        print "%d %d %d"%((-5*N+y+4*c)/5, (10*N-y-9*c)/5, c)
        sys.exit()
print "-1 -1 -1"

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

if N*10000<Y:
	print "-1 -1 -1"
	sys.exit()

a=[]
for x in range(N+1):
	for y in range(N+1):
			if x*9000+y*4000==Y-(N*1000):
				z=(Y-(10000*x+5000*y)) /1000
				if x+y+z==N and x>=0 and y>=0 and z>=0:
					print x,y,z
					sys.exit()
else:
	print "-1 -1 -1"

Solution (Python):

import sys

N, Y = map(int, input().split())
max1000 = int(Y/1000)
c1000 = [i for i in range(max1000, -1, -5) if i <= N]
for z in c1000:
    max5000 = int((max1000-z) / 5)
    for y in range(0, max5000+1):
        x = N - y - z
        if x*10000 + y*5000 + z*1000 == Y:
            print(str(x) + ' ' + str(y) + ' ' + str(z))
            sys.exit()
print("-1 -1 -1")

Solution (Python):
n, total = 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 10000 * i + 5000 * j + 1000 * k == total:
            x, y, z = i, j, k
print(x, y, z)

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

Solution (Python):
l = map(int, raw_input().split())
a=0
for i in xrange(l[0]+1):
    for j in xrange(l[0]+1-i):
        k=l[0]-i-j
        if k*10000+j*5000+i*1000==l[1]:
            a=1
            print "%d %d %d" % (k,j,i)
            break
    if a==1:
        break
if a==0:
    print "-1 -1 -1"

Solution (Python):
import sys

[n, y] = map(int, raw_input().split())
a = y // 10000
r = y % 10000
b = r // 5000
r = r % 5000
c = r // 1000
d = n - (a + b + c)
if d < 0:
    print -1, -1, -1
    sys.exit(0)
else:
    if d >= 9:
        k = d // 9
        k = min(a, k)
        a -= k
        c += k * 10
        d -= k * 9
    if d >= 4:
        k = d // 4
        if k > b and a >= 1 and (d != 4 and d != 8 or b == 0):
            a -= 1
            b += 2
            d -= 1
            k = d // 4
        k = min(b, k)
        b -= k
        c += k * 5
        d -= k * 4
    if d > 0:
        if a < d:
            print -1, -1, -1
            sys.exit(0)
        else:
            a -= d
            b += d * 2
    print a, b, c

Solution (Python):
a = map(int, raw_input().split())
N = a[0]
Y = a[1]
x = y = z = 0
z = N
while(1):
    if 10000*x+5000*y+1000*z == Y:
        print x,y,z
        break
    else:
        if z > 0:
            y += 1
            z -= 1
        elif y > 0:
            x += 1
            y = 0
            z =	N - x
        else:
            print -1, -1, -1
            break

Solution (Python):



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

Y = Y//1000

flag = 0

for i in range(N+1):
    NN = N-i
    YY = Y - i
    for j in range(NN+1):
        NNN = NN - j
        YYY = YY - 5*j


        if 10*NNN == YYY:
            flag = 1
            cc = i
            bb = j
            aa = NNN
            
        

if flag == 0:
    aa=-1
    bb=-1
    cc=-1
print(aa,bb,cc)

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

i_max = min(y // 10000, n)
i_min = max((y - n * 5000 + 4000) // 5000, 0)

for i in range(i_min, i_max + 1):
    j_4 = y // 1000 - n - i * 9
    if not j_4 % 4:
        j = j_4 // 4
        k = n - i - j_4 // 4
        if j >= 0 and k >= 0:
            print(i, j, k)
            break
        else:
            continue
    else:
        continue
else:
    print(-1, -1, -1)

Solution (Python):


import sys

ind = input()

ind = ind.split()
N,Y = int(ind[0]),int(ind[1])

Y /= 1000
for x in range(N+1,-1,-1):
    for y in range(0,N-x+1):
        z = N - x - y
        s = x*10 + y*5 + z
        if s == Y:
            print(x,y,z)
            sys.exit()
print(-1,-1,-1)

Solution (Python):

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

flag = 0



for i in range(0,N+1):
    for j in range(0,N-i+1):
        k = N-i-j
        sum = i * 10000 + j * 5000 + k * 1000
        if sum == Y:
            num1 = i
            num2 = j
            num3 = k
            flag = 1
        

if flag == 1:
    print(num1, num2, num3)
else:
    print('-1 -1 -1')

Solution (Python):

def main():
	n, y = list(map(int, input().split()))
	bills = [0, 0, y // 1000]
	cnt = y // 1000

	print(sub(bills, n))

def sub(bills, n):
	while True:
		
		if n - sum(bills) == 0:
			return " ".join([str(x) for x in bills])
		if n - sum(bills) <= -1:
			if n - sum(bills) <= -4 and bills[2] >= 5:
				bills[1] += 1
				bills[2] -= 5
			elif bills[1] >= 2:
				bills[0] += 1
				bills[1] -= 2
			else:
				break
		else:
			break

	return "-1 -1 -1"



if __name__ == '__main__':
	main()