Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    x = a[i]
    for j in range(i+1,n-1):
        y = a[j]
        for k in range(j+1,n):
            if a[k] < x+y:
                ans += 1
            else:
                break

print(ans) 
            
            

Fixed submission:
import bisect
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(a,a[i]+a[j])
        ans += index-j-1
        
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
import itertools
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    x = a[i]
    for j in range(i+1,n-1):
        y = a[j]
        for k in range(j+1,n):
            if a[k] < x+y
                ans += 1
            else:
                break

print(ans) 
            

Fixed submission:
import bisect
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(a,a[i]+a[j])
        ans += index-j-1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
 
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = 0
for i in range(n-2):
    x = a[i]
    for j in range(i+1,n-1):
        y = a[j]
        if x/2 > y:
            break
        for k in range(j+1,n):
            if y+a[k] > x:
                ans += 1
            else:
                break

print(ans) 
            

Fixed submission:
import bisect
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(a,a[i]+a[j])
        ans += index-j-1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools
 
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

ans = 0
for i in range(n-2):
    x = a[i]
    for j in range(i+1,n-1):
        y = a[j]
        for k in range(j+1,n):
            if y+a[k] > x:
                ans += 1
            else:
                break

print(ans) 
            

Fixed submission:
import bisect
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(a,a[i]+a[j])
        ans += index-j-1
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
import itertools

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

c = itertools.combinations(a,3)

ans = 0
for v in c:
    x,y,z = v[0],v[1],v[2]
    if x < y+z and y < x+z and z < x+y:
        ans += 1
print(ans)

Fixed submission:
import bisect
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(a,a[i]+a[j])
        ans += index-j-1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
k = int(input())

s2 = s + s
s3 = s + s + s

tmp = s[0]
c = 0
for i in range(1,len(s)):
    if s[i] == tmp:
        s[i] = "@"
        c += 1
    tmp = s[i] 

tmp = s2[0]
c2 = 0
for i in range(1,len(s2)):
    if s2[i] == tmp:
        s2[i] ="@"
        c2 += 1
    tmp = s2[i]

tmp = s3[0]
c3 = 0
for i in range(1,len(s3)):
    if s3[i] == tmp:
        s3[i] ="@"
        c3 += 1
    tmp = s3[i]

if c2-c == c3-c2:
    ans = c + (k-1)*(c2-c)
else:
    if K%2 != 0:
        ans = c + ((k-1)//2)*(c3-c)
    else:
        ans = c + ((k-2)//2)*(c3-c2) + c2 - c
print(ans)


Fixed submission:
s = list(input())
k = int(input())

s2 = s + s
s3 = s + s + s

tmp = s[0]
c = 0
for i in range(1,len(s)):
    if s[i] == tmp:
        s[i] = "@"
        c += 1
    tmp = s[i] 

tmp = s2[0]
c2 = 0
for i in range(1,len(s2)):
    if s2[i] == tmp:
        s2[i] ="@"
        c2 += 1
    tmp = s2[i]

tmp = s3[0]
c3 = 0
for i in range(1,len(s3)):
    if s3[i] == tmp:
        s3[i] ="@"
        c3 += 1
    tmp = s3[i]

if c2-c == c3-c2:
    ans = c + (k-1)*(c2-c)
else:
    if k%2 != 0:
        ans = c + ((k-1)//2)*(c3-c)
    else:
        ans = c + ((k-2)//2)*(c3-c2) + c2 - c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(map(int,input().split()))


ans = [0]*n
for i in range(1,n+1):
    ans[i-1] = s.index(i) + 1

print(*ans)

Fixed submission:
n = int(input())
s = list(map(int,input().split()))

ans = [0]*n
for i in range(n):
    ans[s[i]-1] = i+1

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

a,b = map(int,input().split())


ans = 1
sosuu = [2]
A = min(a,b)+1
for L in range(3, A, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)
        if a%L==0 and b%L==0:
            ans += 1

if a%2==0 and b%2==0:
    ans += 1
print(ans)

Fixed submission:
a,b = map(int,input().split())

if min(a,b) == 1:
    print(1)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr

A = factorization(a)
B = factorization(b)
ans = len(set(A) & set(B))
print(ans+1)

Buggy python submission (verdict: Time Limit Exceeded):
import math

a,b = map(int,input().split())


ans = 1
sosuu = [2]
A = min(a,b)+1
for L in range(3, A, 2): # 2 以外の素数は奇数なので
    if all(L % L2 != 0 for L2 in sosuu):  # すべての既存素数で割り切れなかったら素数
        sosuu.append(L)
        if a%L==0 and b%L==0:
            ans += 1

if a%2==0 and b%2==0:
    ans += 1
print(ans)

Fixed submission:
a,b = map(int,input().split())

if min(a,b) == 1:
    print(1)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr

A = factorization(a)
B = factorization(b)
ans = len(set(A) & set(B))
print(ans+1)

Buggy python submission (verdict: Time Limit Exceeded):
import math

a,b = map(int,input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

if min(a,b) == 1:
    print(1)
    exit()

ans = 1
tmp = 1
for i in range(2,(max(a,b)+1)):
    if a%i == 0 and b%i == 0:
        l = factorization(i)
        for j in range(len(l)):
            if tmp%l[j][0] == 0:
                break
            else:
                tmp *= l[j][0]
        else:
            ans += 1

print(ans)



Fixed submission:
a,b = map(int,input().split())

if min(a,b) == 1:
    print(1)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr

A = factorization(a)
B = factorization(b)
ans = len(set(A) & set(B))
print(ans+1)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import math

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

a.sort()

ans = sum(a)
for i in range(m):
    tmp = a.pop()
    ans -= tmp
    cost = math.floor(tmp/2)
    ans += cost
    idx = bisect.bisect_left(a,cost)
    a.insert(idx,cost)

print(ans)


Fixed submission:
import bisect
import math

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

a.sort()

ans = sum(a)
for i in range(m):
    tmp = a.pop()
    ans -= tmp
    cost = math.floor(tmp/2)
    ans += cost
    idx = bisect.bisect_left(a,cost)
    a.insert(idx,cost)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n 
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)



Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n 
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)



Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)

Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0 for i in range(n)]
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)
Buggy python submission (verdict: Runtime Error):
l,r = map(int,input().split())

if r < 2019:
    print(l*(l+1))
    exit()

for i in range(l,r+1):
    if i%2019 == 0:
        print(0)
        exit()

ans = (l*(l+1))%2019
print(error)


Fixed submission:
l,r = map(int,input().split())

if r < 2019:
    print(l*(l+1)%2019)
    exit()

ans = 2019
for i in range(l,r):
    for j in range(i+1,r+1):
        ans = min(ans,(i*j)%2019)
        if ans == 0:
            print(0)
            exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))



for i in range(0,a[0]*2+1,2):
    ans1 = [i]
    ans2 = [i]
    for j in range(1,n//2+1):
        tmp1 = (a[j-1]-ans1[j-1]//2)*2
        tmp2 = (a[-j]-ans2[j-1]//2)*2
        ans1.append(tmp1)
        ans2.append(tmp2)
    if (ans1[-1]/2 + ans2[-1]/2) == a[n//2]:
        ans2.reverse()
        ans2.pop()
        print(*ans1, end=" ")
        print(*ans2)
        exit()


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

s = sum(a)
s1 = 0
for i in range(1,n,2):
    s1 += a[i]

ans = [s-s1*2]
for i in range(1,n):
    ans.append((a[i-1]-ans[i-1]//2)*2)

print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))



for i in range(0,a[0]*2+1,2):
    ans = [0]*n
    ans[0] = i
    for j in range(1,n):
        tmp = (a[j-1]-ans[j-1]//2)*2
        ans[j] = tmp
    if (ans[-1]/2 + ans[0]/2) == a[-1]:
        print(*ans)
        exit()



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

s = sum(a)
s1 = 0
for i in range(1,n,2):
    s1 += a[i]

ans = [s-s1*2]
for i in range(1,n):
    ans.append((a[i-1]-ans[i-1]//2)*2)

print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

for i in range(0,a[0]*2+1,2):
    ans = [0]*n
    ans[0] = i
    for j in range(1,n):
        tmp = (a[j-1]-ans[j-1]//2)*2
        if tmp%2 == 0:
            ans[j] = tmp
        else:
            break
    if (ans[-1]//2 + ans[0]//2) == a[-1]:
        print(*ans)
        exit()

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

s = sum(a)
s1 = 0
for i in range(1,n,2):
    s1 += a[i]

ans = [s-s1*2]
for i in range(1,n):
    ans.append((a[i-1]-ans[i-1]//2)*2)

print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

for i in range(0,a[0]*2+1,2):
    ans = [i]
    for j in range(1,n):
        tmp = (a[j-1]-ans[j-1]//2)*2
        if tmp%2 == 0:
            ans.append(tmp)
        else:
            break
    if (ans[-1]//2 + ans[0]//2) == a[-1]:
        print(*ans)
        exit()

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

s = sum(a)
s1 = 0
for i in range(1,n,2):
    s1 += a[i]

ans = [s-s1*2]
for i in range(1,n):
    ans.append((a[i-1]-ans[i-1]//2)*2)

print(*ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())

s = [0]*(n+1)
for i in range(m):
    s[int(input())] = 1

mod = (10**9)+7
ans = 0

def steps(now):
    if now == n:
        global ans
        ans += 1
        ans %= mod
    else:
        if s[now+1] == 0:
            steps(now+1)
        if now+2 <= n:
            if s[now+2] == 0:
                steps(now+2)
            
steps(0)
print(ans)

Fixed submission:
n,m = map(int,input().split())

ng = [0]*(n+1)
for i in range(m):
    ng[int(input())] = 1

mod = (10**9)+7
dp = [0]*(n+1)
dp[0] = 1

for i in range(1,n+1):
    if ng[i] == 1:
        dp[i] = 0
        continue
    if i == 1:
        dp[1] = 1
        continue
    dp[i] = (dp[i-2] + dp[i-1])%mod

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n,m = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(m):
    b,c = map(int,input().split())
    s.append((c,b))

a.sort()
s.sort(reverse=True)

for i in range(m):
    b = s[i][1]
    c = s[i][0]
    idx = bisect.bisect_left(a,c)
    if idx == 0:
        break
    del a[0:min(b,idx)]
    for j in range(min(b,idx)):
        a.insert(bisect.bisect_left(a,c),c)

print(sum(a))
    

Fixed submission:
import bisect

n,m = map(int,input().split())
a = list(map(int,input().split()))
s = []
for i in range(m):
    b,c = map(int,input().split())
    s.append((c,b))

a.sort()
s.sort(reverse=True)

for i in range(m):
    b = s[i][1]
    c = s[i][0]
    idx = bisect.bisect_left(a,c)
    if idx == 0:
        break
    del a[0:min(b,idx)]
    for j in range(min(b,idx)):
        a.insert(bisect.bisect_left(a,c),c)

print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r +1):
    for j in range(n//g +1):
        if 0 <= n-r*i-g*j and (n-r*i-g*j)%b == 0:
            ans += 1

print(ans)

Fixed submission:
r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r +1):
    for j in range(n//g +1):
        if 0 <= n-r*i-g*j and (n-r*i-g*j)%b == 0:
            ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        if 0 <= n-r*i-g*j:
            if (n-r*i-g*j)%b == 0:
                ans += 1

print(ans)

Fixed submission:
r,g,b,n = map(int,input().split())

ans = 0
for i in range(n//r +1):
    for j in range(n//g +1):
        if 0 <= n-r*i-g*j and (n-r*i-g*j)%b == 0:
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,q = map(int,input().split())
s = list(input())

start_list = [0]*(n)
end_list = [0]*(n+1)

num = 0
for i in range(n):
    if s[i] == "A" and s[i+1] == "C":
        num += 1
    start_list[i] = num
    end_list[i+1] = num
start_list.insert(0,0)

for i in range(q):
    l,r = map(int,input().split())
    print(end_list[r-1] - start_list[l-1])


Fixed submission:
n,q = map(int,input().split())
s = list(input())

count = [0]*n

num = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        num += 1
    count[i] = num
count.insert(0,0)
count[-1] = count[-2]

for i in range(q):
    l,r = map(int,input().split())
    print(count[r-1] - count[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import collections

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

s.sort()

while len(s) > 1:#最も体力のあるのが攻撃を受ける
    temp = s.pop()
    for j in s:
        damege = (temp//j)*j
    if temp != 0 and temp != damege:
        index = bisect.bisect_left(s,temp-damege)
        s.insert(index,temp-damege)

print(s[0])


Fixed submission:
import math

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

tmp = a[0]
for i in range(1,len(a)):
    tmp = math.gcd(tmp,a[i])
print(tmp)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import collections

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

s.sort()

while len(s) > 1:#最も体力のあるのが攻撃を受ける
    temp = s.pop()
    for j in s:
        temp -= (temp//j)*j
    if temp != 0:
        index = bisect.bisect_left(s,temp)
        s.insert(index,temp)

print(s[0])





Fixed submission:
import math

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

tmp = a[0]
for i in range(1,len(a)):
    tmp = math.gcd(tmp,a[i])
print(tmp)
Buggy python submission (verdict: Runtime Error):
import bisect
import fractions

n,x = map(int,input().split())
s = list(map(int,input().split()))

s.sort()
index = bisect.bisect_left(s,x)
s.insert(index,x)

if n == 1:
    print(s[1]-s[0])
    exit()

for i in range(len(s)-1):
    tmp = s[i+1] - s[i]
    if tmp%2 != 0:
        print(1)
        exit()
    ans = fractions.gcd(tmp,ans)

print(ans)

Fixed submission:
import fractions as math

n,x = map(int,input().split())
s = list(map(int,input().split()))

a = []
for i in s:
    a.append(abs(i-x))

tmp = a[0]
for i in range(1,len(a)):
    tmp = math.gcd(tmp,a[i])

print(tmp)

Buggy python submission (verdict: Runtime Error):
import bisect

n,x = map(int,input().split())
s = list(map(int,input().split()))

s = list(set(s))
s.sort()
index = bisect.bisect_left(s,x)
index2 = bisect.bisect_right(s,x)
if index == 0:
    ans = abs(s[0] - x)
elif index2 == len(s)-1:
    ans = abs(x - s[-1])
else:
    s.insert(index,x)
    ans = min(abs(s[index] - s[index-1]), abs(s[index2] -s[index2+1]))
    
print(ans)

Fixed submission:
import fractions as math

n,x = map(int,input().split())
s = list(map(int,input().split()))

a = []
for i in s:
    a.append(abs(i-x))

tmp = a[0]
for i in range(1,len(a)):
    tmp = math.gcd(tmp,a[i])

print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(map(int,input().split()))

for i in range(n):#とばす番号
    ans = 0
    tmp = 0
    for j in range(n):
        if j == i:
            pass
        elif tmp*s[j] >= 0:#符号が同じとき
            if abs(s[j]) > abs(tmp):#外側へ移動
                ans += abs(tmp - s[j])
                tmp = s[j]
            elif abs(s[j]) < abs(tmp):#内側へ移動
                ans += abs(tmp - s[j])
                tmp = s[j]
        elif tmp*s[j] < 0:#符号が違う時
            ans += abs(tmp - s[j])
            tmp = s[j]
    ans += abs(tmp)
    print(ans)

Fixed submission:
n = int(input())
s = list(map(int,input().split()))

ans = 0
tmp = 0
for i in range(n):
    ans += abs(s[i] - tmp)
    tmp = s[i]
ans += abs(tmp)

s.insert(0,0)
s.insert(n+1,0)
for i in range(1,n+1):#とばす番号
    tmp_ans = ans
    a = s[i-1]
    tmp = s[i]
    b = s[i+1]
    if (b >= tmp and tmp >= a) or (b <= tmp and tmp <= a):
        pass
    else:
        if (a >= b and tmp > a) or (a <= b and tmp < a):
            tmp_ans -= abs(2*(tmp-a))
        else:
            tmp_ans -= abs(2*(tmp-b))
    print(tmp_ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,Y = map(int,input().split())
 
ans_x = -1
ans_y = -1
ans_z = -1
 
for x in range(n+1):
    for y in range(n+1):
        z = int((Y -10000*x - 5000*y)/1000)
        if z >= 0 and (z%1==0 or z==0) and x+y+z == n:
            ans_x = x
            ans_y = y
            ans_z = z
            break
 
print(ans_x, ans_y, ans_z)

Fixed submission:
n,Y = map(int,input().split())
 
ans_x = -1
ans_y = -1
ans_z = -1
 
for x in range(n+1):
    for y in range(n+1-x):
        z = int((Y -10000*x - 5000*y)/1000)
        if z >= 0 and (z%1==0 or z==0) and x+y+z == n:
            ans_x = x
            ans_y = y
            ans_z = z
            break
 
print(ans_x, ans_y, ans_z)