Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N, Ma, Mb = map(int, input().split())
A, B, C = [], [], []
for i in range(N):
    ai, bi, ci = map(int, input().split())
    A.append(ai)
    B.append(bi)
    C.append(ci)

INF = float('inf')
dp = [[[INF]*401 for i in range(401)] for j in range(N+1)]
dp[0][0][0] = 0

for i in range(1, N+1):
    for a in range(1, 401):
        for b in range(1, 401):
            if A[i-1] <= a and B[i-1] <= b:
                dp[i][a][b] = min(dp[i-1][a][b], dp[i-1][a-A[i-1]][b-B[i-1]] + C[i-1])
            else:
                dp[i][a][b] = dp[i-1][a][b]

ans = INF
for i in range(1, 401):
    target_a = Ma * i
    target_b = Mb * i
    if target_a > 400 or target_b > 400:
        break
    ans = min(ans, dp[N][target_a-1][target_b-1])

print(ans if ans != INF else -1)

### FIXED CODE ###

N, Ma, Mb = map(int, input().split())
A, B, C = [], [], []
for i in range(N):
    ai, bi, ci = map(int, input().split())
    A.append(ai)
    B.append(bi)
    C.append(ci)

INF = float('inf')
dp = [[[INF]*401 for i in range(401)] for j in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for a in range(401):
        for b in range(401):
            if dp[i][a][b] == INF:
                continue
            dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
            if a + A[i] <= 400 and b + B[i] <= 400:
                dp[i+1][a+A[i]][b+B[i]] = min(dp[i+1][a+A[i]][b+B[i]], dp[i][a][b]+C[i])

ans = INF
for i in range(1, 401):
    target_a = Ma * i
    target_b = Mb * i
    if target_a > 400 or target_b > 400:
        break
    ans = min(ans, dp[N][target_a][target_b])

print(ans if ans != INF else -1)
### BUGGY CODE ###

L, R = [[], []]
N, M = map(int, input().split())
for i in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

count = 0
for i in range(1,N+1):
  count = min(R)-max(L)+1
  
print('%d' % count)

### FIXED CODE ###

L, R = [[], []]
N, M = map(int, input().split())
for i in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

count = 0
minR = min(R)
maxL = max(L)
if minR < maxL:
  count = 0
else:
  for i in range(maxL, minR+1):
    if i <= N:
      count = count + 1
      
print('%d' % count)
### BUGGY CODE ###

H,W= map(int, input().split())

while not (H==0 and W==0):
    print('#'*W)
    for i in range(H-2):
        print('#'+'.'*(W-2)+'#')
    print('#'*W)
    print()        
    


### FIXED CODE ###

H,W= map(int, input().split())

while not (H==0 and W==0):
    print('#'*W)
    for i in range(H-2):
        print('#'+'.'*(W-2)+'#')
    print('#'*W)
    print()
    H,W= map(int, input().split())
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
 
cnt = 0

for i in range(1,N+1):
  a = P.index(min(P[:i]))
  if i == a+1:
    cnt += 1
    
print(cnt)

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
 
cnt = 0
M = 10**6

for i in range(N):
  if M >= P[i]:
    cnt += 1
    M = P[i]
    
print(cnt)
### BUGGY CODE ###

import sys
from collections import defaultdict

n = int(input())
aaa = list(map(int, sys.stdin))
MOD = 998244353

d2 = [1]
tmp = 1
for i in range(n):
    tmp = tmp * 2 % MOD
    d2.append(tmp)

s = sum(aaa)
dp = [defaultdict(lambda: 0) for _ in [0] * (s + 1)]
dp[0][0] = 1
for a in aaa:
    for i in range(s, -1, -1):
        dd = dp[i]
        if not dd:
            continue
        for k, p in dd.items():
            dp[i + a][k + 1] += p

ans = pow(3, n, MOD)
sub = 0
h = (s + 1) // 2
for dd in dp[h:]:
    for k, p in dd.items():
        sub += d2[n - k] * p * 3
    sub %= MOD
if s % 2 == 0:
    dd = dp[h]
    for k, p in dd.items():
        sub -= p * 3

ans = (ans - sub) % MOD
print(ans)


### FIXED CODE ###

import sys

n = int(input())
aaa = list(map(int, sys.stdin))
MOD = 998244353

s = sum(aaa)
dp1 = [0] * (s + 1)
dp2 = [0] * (s + 1)
dp1[0] = 1
dp2[0] = 1
tmp_sum = 0
for a in aaa:
    for i in range(tmp_sum, -1, -1):
        dp1[i + a] += dp1[i]
        dp1[i] *= 2
        dp2[i + a] += dp2[i]
    for i in range(tmp_sum, -1, -1):
        dp1[i] %= MOD
        dp2[i] %= MOD
    tmp_sum += a

h = (s + 1) // 2
ans = (pow(3, n, MOD) - sum(dp1[h:]) * 3) % MOD
if s % 2 == 0:
    ans = (ans + dp2[h] * 3) % MOD
print(ans)
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline

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

A = [int(i) for i in input().split()]

for i in range(M):
	A.sort(reverse=True)
	max = A.pop(0)
	A.append(int(max/2))

print(sum(A))
	


### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline

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

A = [int(i)*(-1) for i in input().split()]



# print(A)
# for i in range(M):
# 	max_index = A.index(max(A))
# 	A[max_index] = int(A[max_index]/2)

# print(sum(A))
heapq.heapify(A)

for i in range(M):
	

	min = heapq.heappop(A)
	# 最小値を削除と値を渡す
	# print(A)
	# print(min)

	heapq.heappush(A,int(min/2))
	# print(A)


print(sum(A)*(-1))
### BUGGY CODE ###

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

count = 0
A.sort()
for i in range(N):
    if A.count(A[i]) > 1:
        if A.index(A[i]) != i:
            count += 1

if count % 2 == 0:
    print(N - count)
else:
    print(N - (count + 1))


### FIXED CODE ###

import collections
counter = collections.defaultdict(int)
N = int(input())
A = input().split()

count = 0
for x in A:
    counter[x] += 1

for x in counter:
    if counter[x] != 1:
        count += counter[x] - 1

if count % 2 == 0:
    print(N - count)
else:
    print(N - (count + 1))
### BUGGY CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N,K = [int(zz) for zz in input().split()]
A = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = [int(zz)-1 for zz in input().split()]
    A[a].append(b)
    A[b].append(a)

dq = deque([0])
ans = K
check = [True]*N
check[0] = False
while dq:
    p = dq.popleft()
    if p == 0:
        cand = K-1
    else:
        cand = K-2
    for i in A[p]:
        if check[i]:
            check[i] = False
            ans *= cand
            cand -= 1
            dq.append(i)

print(ans%(10**9+7))


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
MOD = 10**9+7

N,K = [int(zz) for zz in input().split()]
A = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = [int(zz)-1 for zz in input().split()]
    A[a].append(b)
    A[b].append(a)

dq = deque([0])
ans = K
check = [True]*N
check[0] = False
while dq:
    p = dq.popleft()
    if p == 0:
        cand = K-1
    else:
        cand = K-2
    for i in A[p]:
        if check[i]:
            check[i] = False
            ans = (ans*cand)%MOD
            cand -= 1
            dq.append(i)

print(ans)
### BUGGY CODE ###

INF=10**18
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
	ans*=a[i]
if ans>INF:print(-1)
else:print(ans)

### FIXED CODE ###

INF=10**18
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
for val in a:
	ans*=val
	if val==0:
		print(0)
		exit()
	if ans>INF:
		print(-1)
		exit()
else:
	print(ans)
### BUGGY CODE ###

import sys


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

    Kcost = [min(row, N - 1 - row, clm, N - 1 - clm) for row in range(N) for clm in range(N)]

    Sitting = [1] * (N * N)
    Kcount = 0


    def Kcheck(qsn, cdsn):
        if Kcost[cdsn] > Kcost[qsn] + Sitting[qsn]:
            Kcost[cdsn] = Kcost[qsn] + Sitting[qsn]
            queue.append(cdsn)


    for sn in P:
        csn = sn - 1
        Kcount += Kcost[csn]
        Sitting[csn] = 0
        queue = [csn]

        while queue:
            qsn = queue.pop()
            div, mod = divmod(qsn, N)
            if mod: Kcheck(qsn, qsn - 1)
            if mod != N - 1: Kcheck(qsn, qsn + 1)
            if div: Kcheck(qsn, qsn - N)
            if div != N - 1: Kcheck(qsn, qsn + N)

    print(Kcount)


if __name__ == '__main__':
    main()

sys.exit()


### FIXED CODE ###

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

Kcost = [min(row, N - 1 - row, clm, N - 1 - clm) for row in range(N) for clm in range(N)]

Sitting = [1] * (N * N)
Kcount = 0


def Kcheck(qsn, cdsn):
    if Kcost[cdsn] > Kcost[qsn] + Sitting[qsn]:
        Kcost[cdsn] = Kcost[qsn] + Sitting[qsn]
        queue.append(cdsn)


for sn in P:
    csn = sn - 1
    Kcount += Kcost[csn]
    Sitting[csn] = 0
    queue = [csn]

    while queue:
        qsn = queue.pop()
        div, mod = divmod(qsn, N)
        if mod: Kcheck(qsn, qsn - 1)
        if mod != N - 1: Kcheck(qsn, qsn + 1)
        if div: Kcheck(qsn, qsn - N)
        if div != N - 1: Kcheck(qsn, qsn + N)

print(Kcount)
### BUGGY CODE ###

h = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

#ans_L = [0] * (10**12 + 1)

i = 0
ans_L = [1]
while True:
    h = h//2
    i += 1
    ans_L.append(2**i)
    if h == 1:
        break

print(sum(ans_L)) 

### FIXED CODE ###

h = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

#ans_L = [0] * (10**12 + 1)

i = 0
ans_L = [1]
while h!=1:
    h = h//2
    i += 1
    ans_L.append(2**i)

print(sum(ans_L))
### BUGGY CODE ###

n , a , b = map(int , input().split())
s = []
while n > len(s):
    for i in range(a):
        s.append("a")
    for i in range(b):
        s.append("b")
del s[n::]
print(s.count("a"))

### FIXED CODE ###

n , a , b = map(int , input().split())
ans = n // (a + b) * a
rem = n % (a + b)
ans += min(a , rem)
print(ans)
### BUGGY CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict

n = ni()
s = ns()

lenstr = []
dic = defaultdict(list)

for st in range(n):
    for ed in range(st+1, min(st+n//2+2, n+1)):
        lenstr.append((ed-st, s[st:ed]))
        dic[s[st:ed]].append(st)

ans = 0

lenstr.sort(reverse=True)
for leni, stri in lenstr:
    if dic[stri][-1] - dic[stri][0] >= leni:
        ans = leni
        break

print(ans)


### FIXED CODE ###

import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


class RollingHash(object):
    def __init__(self, source: str, base=10**9+7, mod=(1<<64)-1):
        self.source = source
        self.base = base
        self.mod = mod
        self.hash_from_zero_to = self._get_hash_from_zero_to()
        self.base_pow = self._get_base_pow()

    # 文字列sourceの区間 [0, right) のハッシュ値を前計算する
    def _get_hash_from_zero_to(self):
        hash_from_zero_to = [0]
        for si in self.source:
            hash_from_zero_to.append((hash_from_zero_to[-1] * self.base + ord(si)) % self.mod)

        return hash_from_zero_to

    # base値をi回掛けてmodをとった値を前計算する
    def _get_base_pow(self):
        base_pow = [1]
        for i in range(len(self.source)):
            base_pow.append(base_pow[-1] * self.base % self.mod)

        return base_pow

    # 文字列sourceの区間 [left, right) のハッシュを取得する
    def get_hash(self, left: int, right: int):
        return (self.hash_from_zero_to[right]
                - self.hash_from_zero_to[left] * self.base_pow[right - left]) % self.mod


def binsearch(func, rh: RollingHash, ok: int, ng: int):
    source_length = len(rh.source)
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if func(rh, mid, source_length):
            ok = mid
        else:
            ng = mid

    return ok


# 題意を満たす長さtarget_lengthの文字列があるか判定
def judge(rh: RollingHash, target_length: int, source_length: int):
    memo = {}
    for start_idx in range(source_length - target_length + 1):
        cur_hash = rh.get_hash(start_idx, start_idx + target_length)
        if cur_hash in memo:
            if start_idx - memo[cur_hash] >= target_length:
                return True
        else:
            memo[cur_hash] = start_idx

    return False


n = ni()
s = ns()

rh = RollingHash(s)
print(binsearch(judge, rh, 0, n//2 + 2))
### BUGGY CODE ###

n=int(input())
s=list(input())
q=int(input())
que=[list(input().split()) for _ in range(q)]
for q1,q2,q3 in que:
  if q1=='1':
    s[int(q2)-1]=q3
  else:
    print(len(set(s[int(q2)-1:int(q3)])))

### FIXED CODE ###

n=int(input())
s=list(input())
q=int(input())

def ctoi(c):
  return ord(c)-97
class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [[0]*(n+1) for _ in range(26)]
  def query(self,a,i):
    r = 0
    while i > 0:
      r += self.tree[a][i]
      i -= i & -i
    return r
  def update(self,i,a,x):
    while i<=n:
      self.tree[a][i]+=x
      i+=i&(-i)
bi=Bit(n)
for i in range(n):
  bi.update(i+1,ctoi(s[i]),1)
  
for _ in range(q):
  a,b,c=input().split()
  a,b=int(a),int(b)
  if a==1 and s[b-1]!=c:
    bi.update(b,ctoi(s[b-1]),-1)
    bi.update(b,ctoi(c),1)
    s[b-1]=c
  elif a==2:
    c=int(c)
    right=[bi.query(i,c) for i in range(26)]
    left=[bi.query(i,b-1) for i in range(26)]
    ans=0
    for r,l in zip(right,left):
      if r-l>0:
        ans+=1
    print(ans)
### BUGGY CODE ###

# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict


def solve():
  ## input
  N = int(input())
  route = defaultdict(set)
  costs = defaultdict(lambda:defaultdict(int))
  for _ in range(N-1):
    u,v,w = map(int, sys.stdin.readline().rstrip().split())
    route[u-1].add(v-1)
    route[v-1].add(u-1)
    costs[u-1][v-1] = w

  ## solve
  visited = set()
  p,q = [0,0]
  colors = [0]*N
  nxt = set([0])
  while len(visited)<N and len(nxt)>0:
    p = q
    q = nxt.pop()
    for r in route[q]:
      if p==r:
        continue
      else:
        colors[r] = (costs[q][r]+costs[r][q]+colors[q]) % 2
        nxt.add(r)
        visited.add(r)
  return colors


if __name__ == "__main__":
  ans = solve()
  for a in ans:
    print(a)

### FIXED CODE ###

# /usr/bin/python
# -*- coding: utf-8 -*-
from collections import deque,defaultdict


N = int(input())

colors = [-1 for _ in range(N)]
tree = [{} for _ in range(N)]
for _ in range(N-1):
  u,v,w = map(int, input().split())
  tree[u-1][v-1] = w % 2
  tree[v-1][u-1] = w % 2

visiting = deque([0])
colors[0] = 0
while len(visiting) > 0:
  p = visiting.popleft()
  for q in tree[p]:
    if colors[q] < 0:
      colors[q] = (tree[p][q]+colors[p]) % 2
      visiting.append(q)

for c in colors:
  print(c)
### BUGGY CODE ###

h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
x=[]

def find_element(k):
    global h,w
    for i in range(h):
        for j in range(w):
            if a[i][j]==k:
                return (i,j)

def make_distance(S,T):
    return abs(S[0]-T[0])+abs(S[1]-T[1])

for i in range(1,d+1):
    l=(h*w-i)//d
    x.append([0]*(l+1))
for i in range(1,d+1):
    l=len(x[i-1])
    for j in range(l-1):
        s=find_element(i+d*j)
        t=find_element(i+d*(j+1))
        x[i-1][j+1]=x[i-1][j]+make_distance(s,t)

q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    p=l%d
    if p==0:
        v1=l//d-1
        v2=r//d-1
        print(x[d-1][v2]-x[d-1][v1])
    else:
        v1=l//d
        v2=r//d
        print(x[p-1][v2]-x[p-1][v1])
#print(x)


### FIXED CODE ###

h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]

def find_element(k):
    global h,w,a
    for i in range(h):
        for j in range(w):
            if a[i][j]==k:
                return (i,j)

def make_distance(S,T):
    return abs(S[0]-T[0])+abs(S[1]-T[1])

x1=[]
x2=[]
for i in range(1,d+1):
    l=(h*w-i)//d
    x1.append([0]*(l+1))
    x2.append([[0,0]for i in range(l+1)])

for i in range(h):
    for j in range(w):
        p=a[i][j]%d
        if p==0:
            p=d-1
        else:
            p-=1
        l=(a[i][j]-(p+1))//d
        x2[p][l]=[i,j]


for i in range(1,d+1):
    l=len(x1[i-1])
    for j in range(l-1):
        x1[i-1][j+1]=x1[i-1][j]+make_distance(x2[i-1][j],x2[i-1][j+1])

q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    p=l%d
    if p==0:
        v1=l//d-1
        v2=r//d-1
        print(x1[d-1][v2]-x1[d-1][v1])
    else:
        v1=l//d
        v2=r//d
        print(x1[p-1][v2]-x1[p-1][v1])
#print(x)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
count = int(input())
num = []
num = input().split()

total = 1
for i in range(count):
    if total == 0:
        break
    total = int(num[i])*total
    
if total > 10**18:
    total = -1
    
print(total)

### FIXED CODE ###

# coding: utf-8
# Your code here!

count = int(input())
num = []
num = input().split()

hantei = 0
for i in range(count):
    if int(num[i]) == 0:
        hantei = 1
        total = 0
    else:
        continue
      #print("z")
      
if hantei == 0:
    total = 1
    for i in range(count):
        total = int(num[i])*total
        if total > 10**18:
            total = -1
            break
    
print(total)
### BUGGY CODE ###

import sys
import math
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
a.sort()
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=[a[-1],a[0]]
tmp=0
for i in range(n-1):
    cnt=combinations_count(a[-1],a[i])
    if tmp<cnt:
        ans[1]=a[i]
        tmp=cnt
print(ans[0])
print(ans[1])

### FIXED CODE ###

import sys
import math
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
a.sort()
half=float(a[-1])/2
len=float("inf")
ans=a[0]
for i in range(n-1):
    if len>abs(half-a[i]):
        ans=a[i]
        len=abs(half-a[i])
print(a[-1])
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

left, right = [], []
total = 0

while a != []:
    if total > 0:
        tmp = a.pop()
        right.append(tmp)
        total -= tmp
    else:
        tmp = a.pop(0)
        left.append(tmp)
        total += tmp

print(abs(sum(left) - sum(right)))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

left = sum(a)
right = 0

mini = float('inf')
for i in a:
    right += i
    left -= i
    tmp = abs(right - left)

    if tmp < mini:
        mini = tmp

print(mini)
### BUGGY CODE ###

from heapq import heappush, heappop
n, q = map(int, input().split())
events = []
for i in range(n):
    s, t, i = map(int, input().split())
    if t >= i:
        events.append([t - i, 0, i])
        events.append([s - i, 1, i])
for i in range(q):
    d = int(input())
    events.append([d, 2, i])
events.sort()
heap = []
working = set()
distance = [-1] * q
for t, kind, i in events:
    if kind == 0:
        working.remove(i)
    elif kind == 1:
        working.add(i)
        heappush(heap, i)
    elif working:
        while not heap[0] in working:
            heappop(heap)
        distance[i] = heap[0]
for d in distance:
    print(d)

### FIXED CODE ###

from heapq import heappush, heappop


n, q = map(int, input().split())
events = []

for i in range(n):
    s, t, x = map(int, input().split())
    if t >= x:
        events.append([t - x, 0, x])
        events.append([s - x, 1, x])
for i in range(q):
    d = int(input())
    events.append([d, 2, i])
events.sort()

dist = [-1] * q
walker = []
working = set()
heap = []
for t, kind, x in events:
    if kind == 0:
        working.remove(x)
    elif kind == 1:
        working.add(x)
        heappush(heap, x)
    elif working:
        while not heap[0] in working:
            heappop(heap)
        dist[x] = heap[0]

for d in dist:
    print(d)
### BUGGY CODE ###

import numpy as np


n = int(input())
arr = np.array(list(map(int, input().split())))


def solve(arr):
    cnt = np.bincount(arr)
    return np.all([cnt[i::i].sum() <= 1 for i in range(2, 10**6+1)])


ans1 = solve(arr)
ans2 = np.gcd.reduce(arr) == 1

if ans1 and ans2:
    print("pairwise coprime")
elif ans2:
    print("setwise coprime")
else:
    print("not coprime")

### FIXED CODE ###

import numpy as np
from numba import njit


n = int(input())
arr = np.array(list(map(int, input().split())))


n = 10**6 + 1
primes = set(range(3, n+1, 2))

for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes.add(2)


@njit
def solve(arr, primes):
    cnt = np.bincount(arr)
    for p in primes:
        if (cnt[p::p]).sum() > 1:
            return False
    else:
        return True


if np.gcd.reduce(arr) != 1:
    print("not coprime")
elif solve(arr, primes):
    print("pairwise coprime")
else:
    print("setwise coprime")
### BUGGY CODE ###

import sys
sys.setrecursionlimit(20000)

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

memo = {}


def unchi(maisu, kane, s):
    if(maisu == 0):
        if(kane == 0):
            return [0, 0, 0]
        else:
            return False
    elif(kane < 1000):
        return False

    if((maisu, kane) in memo):
        return memo[(maisu, kane)]

    if(s >= 10000):
        result1 = unchi(maisu - 1, kane - 10000, 10000)
        if (result1):
            result1[0] += 1
            memo[(maisu, kane)] = tuple(result1)
            return result1
    if(s >= 5000):
        result2 = unchi(maisu-1, kane-5000, 5000)
        if (result2):
            result2[1] += 1
            memo[(maisu, kane)] = tuple(result2)
            return result2
    if (kane == 1000 * maisu):
        result3 = [0, 0, maisu]
        memo[(maisu, kane)] = tuple(result3)
        return result3
    memo[(maisu, kane)] = False
    return False


result = unchi(n, y, 10000)
if(result):
    print(*result)
else:
    print(-1, -1, -1)

### FIXED CODE ###

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

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

from collections import deque
H, W = map(int, input().split())  # 迷路の縦、横の長さ
maze = [input() for iiii in range(H)]

# print(maze)
dist = [[-1] * W for iii in range(H)]  # スタートからの距離
check_que = deque()

for i in range(H):
    for j in range(W):
        if maze[i][j] == "#":
            dist[i][j] = 0
            check_que.append((i, j))
# print(dist)


def bfs(check_que, dist):  # distを編集する関数
    #print("{},{}".format(tate, yoko))
    d = 0
    while check_que:

        h, w = check_que.popleft()
        d = dist[h][w]
        for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            h_prime, w_prime = h + dh, w + dw

            if 0 > h_prime or h_prime >= H or 0 > w_prime or w_prime >= W:
                continue
            if dist[h_prime][w_prime] == -1:
                dist[h_prime][w_prime] = d + 1
                check_que.append((h_prime, w_prime))

    return d


dis = bfs(check_que, dist)
# print(dist)
print(dis)


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())  # 迷路の縦、横の長さ
maze = []
for _ in range(H):
    maze.append(input())
# print(maze)
dist = [[-1] * W for iii in range(H)]  # スタートからの距離
check_que = deque()

d = 0

for i in range(H):
    for j in range(W):
        if maze[i][j] == "#":
            dist[i][j] = 0
            check_que.append((i, j))
# print(dist)


def bfs(initial_d):  # distを編集する関数
    dis = 0
    #print("{},{}".format(tate, yoko))
    while len(check_que) != 0:

        h, w = check_que.popleft()
        d = dist[h][w]
        for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            h_prime, w_prime = h + dh, w + dw

            if 0 <= h_prime <= H - 1 and 0 <= w_prime <= W - 1:
                if dist[h_prime][w_prime] == -1:
                    dist[h_prime][w_prime] = d + 1
                    check_que.append((h_prime, w_prime))
                    if d + 1 > dis:
                        dis = d+1
    return dis


dis = bfs(0)
# print(dist)
print(dis)