Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03488 (python)

Fixed submission:
s = input()
x, y = map(int, input().split())
hL = len(s)
L = 2 * hL

dp = [[False] * (L + 1) for i in range(2)]
ndp = [False] * (L + 1)

def next(i):
    global s
    while i < hL and s[i] != 'T':
        i += 1
    i += 1
    return i

def c(x):
    global hL
    return x + hL

index = 0
t = 0
js = [1]
dp[0][c(0)] = True
dp[1][c(0)] = True
mini, maxi = 0, 1
while index < hL:
    ni = next(index)
    dx, index = ni - index - 1, ni
    for i in range(mini, maxi):
        for j in js:
            if -hL <= i + j * dx <= hL:
                nx = c(i + j * dx)
                ndp[nx] = ndp[nx] or dp[t][c(i)]
    for i in range(mini, maxi):
        dp[t][c(i)] = False
    dp[t], ndp = ndp, dp[t]
    mini, maxi = mini - dx, maxi + dx
    js = [-1, 1]
    t = (t + 1) % 2
print('Yes' if dp[0][c(x)] and dp[1][c(y)] else 'No')

Buggy submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
hL = len(s)
L = 2 * hL

dp = [[False] * L for i in range(2)]

def next(i):
    global s
    while i < hL and s[i] != 'T':
        i += 1
    i += 1
    # print('i: %d' % i)
    return i

def c(x):
    global hL
    return x + hL

index = 0
t = 0
dp[0][c(0)] = True
dp[1][c(0)] = True
# print('\n'.join(map(str, dp)))
while index < hL:
    nt = (t + 1) % 2
    ndp = [False] * L
    ni = next(index)
    dx, index = ni - index - 1, ni
    for i in range(-hL, hL, 1):
        for j in [-1, 1]:
            if -hL <= i + j * dx < hL:
                nx = c(i + j * dx)
                ndp[nx] = ndp[nx] or dp[t][c(i)]
    dp[t] = ndp
    # print('\n'.join(map(str, dp)))
    t = nt
# print('\n'.join(map(str, dp)))
# print(dp[0][c(x)], dp[1][c(y)])
print('Yes' if dp[0][c(x)] and dp[1][c(y)] else 'No')
Problem p03491 (python)

Fixed submission:
import sys
N, L = map(int, input().split())
sys.setrecursionlimit(200000)

class Node:
    def __init__(self, depth=0):
        self.parent = None
        self.children = {}
        self.depth = depth
    def add(self, n):
        self.children[n] = Node(self.depth+1)
    def has(self, n):
        return n in self.children
t = Node()
for i in range(N):
    s = input()
    nt = t
    for c in s:
        if not nt.has(c):
            nt.add(c)
        nt = nt.children[c]

def solve(node):
    global N, L
    ans = 0
    f = lambda d: (L - d) & -(L - d)
    if node.has('0'):
        ans ^= solve(node.children['0'])
    else:
        ans ^= f(node.depth)
    if node.has('1'):
        ans ^= solve(node.children['1'])
    else:
        ans ^= f(node.depth)
    return ans

ans = solve(t)
if ans == 0:
    print('Bob')
else:
    print('Alice')

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())

class Node:
    def __init__(self, depth=0):
        self.parent = None
        self.children = {}
        self.depth = depth
    def add(self, n):
        self.children[n] = Node(self.depth+1)
    def has(self, n):
        return n in self.children
t = Node()
for i in range(N):
    s = input()
    nt = t
    for c in s:
        if not nt.has(c):
            nt.add(c)
        nt = nt.children[c]

def solve(node):
    global N, L
    ans = 0
    f = lambda d: (L - d) & -(L - d)
    if node.has('0'):
        ans ^= solve(node.children['0'])
    else:
        ans ^= f(node.depth)
    if node.has('1'):
        ans ^= solve(node.children['1'])
    else:
        ans ^= f(node.depth)
    return ans

ans = solve(t)
if ans == 0:
    print('Bob')
else:
    print('Alice')
Problem p03732 (python)

Fixed submission:
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
minW = min(w)
for i in range(N):
    w[i] -= minW
MAX_W = 3 * 100
MAX_V = int(1e9)
INF = MAX_V + 2
dp = [[-INF] * (MAX_W + 10) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(MAX_W, -1, -1):
        for k in range(N-1, -1, -1):
            dp[k+1][j+w[i]] = max((dp[k+1][j+w[i]], dp[k][j] + v[i]))

ans = 0
for i in range(N+1):
    for j in range(MAX_W + 1):
        if i * minW + j <= W:
            # print('i * minW: %d, j: %d, dp: %d' % (i*minW, j, dp[i][j]))
            ans = max((ans, dp[i][j]))

print(ans)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
minW = min(w)
for i in range(N):
    w[i] -= minW
MAX_W = 3 * 100
MAX_V = int(1e9)
INF = MAX_V + 2
dp = [[-INF] * (MAX_W + 10) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(MAX_W, -1, -1):
        for k in range(N-1, -1, -1):
            dp[k+1][j+w[i]] = max((dp[k+1][j+w[i]], dp[k][j] + v[i]))

ans = 0
for i in range(N+1):
    for j in range(i * MAX_W + 1):
        if i * minW + j <= W:
            # print('i * minW: %d, j: %d, dp: %d' % (i*minW, j, dp[i][j]))
            ans = max((ans, dp[i][j]))

print(ans)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

minW = min(w)
for i in range(N):
    w[i] -= minW

INF = int(1e9)
dp = [[-INF] * (3 * N + 1) for i in range(N+1)]

dp[0][0] = 0
ans = 0
for i in range(N):
    for j in range(N, 0, -1):
        for k in range(3 * N + 1):
            if k + w[i] + minW * j <= W:
                dp[j][k+w[i]] = max((dp[j][k+w[i]], dp[j-1][k] + v[i]))
                ans = max((ans, dp[j][k+w[i]]))
# print('\n'.join(map(str, dp)))
print(ans)
Problem p04014 (python)

Fixed submission:
import math
import sys

n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

if s > n:
    print(-1)
    sys.exit(0)

sn = math.ceil(math.sqrt(n))
for i in range(2, sn+1):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

ans = n + 1
for i in range(1, sn+1):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if b >= 2 and f(b, b * i + n%b) == s:
            ans = min((ans, b))
if s == n:
    print(n+1)
elif ans < n + 1:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
import sys
n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

if s > n:
    print(-1)
    sys.exit(0)

sn = math.ceil(math.sqrt(n))
for i in range(2, sn):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

for i in range(1, sn):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if f(b + n%b, n) == s:
            print(b)
            sys.exit(0)
if s == n:
    print(n+1)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
import sys
n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

if s > n:
    print(-1)

sn = math.ceil(math.sqrt(n))
for i in range(2, sn):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

for i in range(1, sn):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if 1 + n % b == s and b + n % b == n:
            print(b)
            sys.exit(0)
if s == n:
    print(n)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
import sys
n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

sn = math.ceil(math.sqrt(n))
for i in range(2, sn):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

for i in range(1, sn):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if 1 + n % b == s and b + n % b == n:
            print(b)
            sys.exit(0)
print(-1)

Buggy submission (verdict: Runtime Error):
import math
import sys
n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

if s == 1:
    print(n)
    sys.exit(0)

sn = math.ceil(math.sqrt(n))
for i in range(2, sn):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

for i in range(1, sn):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if 1 + n % b == s:
            print(b)
            sys.exit(0)
print(-1)

Buggy submission (verdict: Runtime Error):
import math
import sys
n = int(input())
s = int(input())

def f(b, n):
    if n == 0:
        return 0
    return f(b, n//b) + n % b

if s == 1:
    print(n)
    sys.exit(0)

sn = math.ceil(math.sqrt(n))
for i in range(2, sn):
    if f(i, n) == s:
        print(i)
        sys.exit(0)

for i in range(1, sn):
    if (n - s) % i == 0:
        b = (n-s)//i + 1
        if b + n % b == s:
            print(b)
            sys.exit(0)
print(-1)
Problem p03472 (python)

Fixed submission:

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

a = []
b = []
finish = 0

for i in range(1,N+1):
    elem1, elem2 = map(int,input().split())
    a.append(elem1)
    b.append(elem2)


b = sorted(b, key=int, reverse=True)

maxB = max(b)
maxA = max(a)
sum = maxB
b.remove(maxB)
count = 1
for elem in b:
    if elem > maxA and sum < H:
        sum = sum + elem
        count += 1
    if sum >= H:
        finish = 1
        break


#print(sum)
if finish == 0:
    dev = int((H - sum)/maxA)
    count = count + dev
    sum = sum + dev * maxA
    if sum < H:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):

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

a = []
b = []
finish = 0

for i in range(1,N+1):
    elem1, elem2 = map(int,input().split())
    a.append(elem1)
    b.append(elem2)

maxB = max(b)
maxA = max(a)
sum = maxB
b.remove(maxB)
count = 1
for elem in b:
    if elem > maxA:
        sum = sum + elem
    #print(sum)
        count += 1
        if sum > H:
            finish = 1
            break


#print(sum)
if finish == 0:
    dev = int(((H - sum)/(maxA))
    count = count + dev
    sum = sum + dev * maxA
    if sum < H:
        count += 1

print(count)
Problem p03567 (python)

Fixed submission:
a=input("");
flag=False;
for i in range(0,len(a)-1):
  if a[i]=='A' and a[i+1]=='C':
    flag=True;
if flag==True:
  print("Yes");
else:
  print("No");

Buggy submission (verdict: Runtime Error):
a=input("");
flag=False;
for i in xrange(0,len(a)-2):
  if a[i]=='A' and a[i+1]=='C':
    flag=True;
if flag==True:
  print("Yes");
else:
  print("No");

Buggy submission (verdict: Runtime Error):
a=input("")
flag=False
for i in xrange(0,len(a)-2):
  if a[i]=='A' and a[i+1]=='C':
    flag=True
if flag==True:
  print("Yes")
else:
  print("No")
Problem p03463 (python)

Fixed submission:
moji = input()
moji = moji.split(" ")
N = moji[0]
A = moji[1]
B = moji[2]

res = ""

if ((int)(B) - (int)(A))%2 == 0:
    res = "Alice"
else:
    res = "Borys"

print(res)

Buggy submission (verdict: Runtime Error):
moji = input()
N = moji[0]
A = moji[2]
B = moji[4]

res = ""

if ((int)(B) - (int)(A))%2 == 0:
    res = "Alice"
else:
    res = "Borys"

print(res)

Buggy submission (verdict: Runtime Error):
N = input()
A = input()
B = input()

res = ""

if ((int)(B) - (int)(A))%2 == 0:
    res = "Alice"
else:
    res = "Borys"

print(res)
Problem p03633 (python)

Fixed submission:
import fractions
        
def lcm(a, b):
    return a * b // fractions.gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))

print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
	t = b
	b = a % b
	
	if b == 0:
		return t
	else:
		return gcd(t,b)
        
def lcm(a, b):
    return a * b / gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))

print(int(ans))

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
	t = b
	b = a % b
	
	if b == 0:
		return t
	else:
		return gcd(t,b)
        
def lcm(a, b):
    return a * b / gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))

print(ans)

Buggy submission (verdict: Runtime Error):
import math 
def lcm(a, b):
    return a * b / math.gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))

print(ans)

Buggy submission (verdict: Runtime Error):
import math 
def lcm(a, b):
    return a * b // math.gcd(a, b)

n = int(input())

ans = 1
for i in range(n):
    ans = lcm(ans, int(input()))

print(ans)
Problem p03826 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
print(max(a*b, c*d))

Buggy submission (verdict: Runtime Error):
pr = [True] * 1001
n = int(input())
ans = 1
MOD = 10 ** 9 + 7

for i in range(2, n + 1):
    if pr[i]:
        for j in range(i * 2, n + 1, i):
            pr[j] = False
        cnt = 0
        now = n
        while now:
            cnt += now // i
            now //= i
        ans = ans * (cnt + 1) % MOD

print(ans)
Problem p03852 (python)

Fixed submission:
print("vowel" if input() in "aiueo" else "consonant")

Buggy submission (verdict: Runtime Error):
a=["eraser","erase","dreamer","dream"]
s=input()
for i in range(4):
    s=s.replace(a[i],"")
if s="":
    print("YES")
else:
    print("NO")
Problem p03854 (python)

Fixed submission:
s=input()
s=s.replace("eraser","")
s=s.replace("erase","")
s=s.replace("dreamer","")
s=s.replace("dream","")
if len(s)==0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a=["eraser","erase","dreamer","dream"]
s=input()

for i in range(4):
    s=s.replace(a[i],"")
if s="":
    print("YES")
else:
    print("NO")
Problem p03951 (python)

Fixed submission:
n=int(input())
s=input()
t=input()
i=0
while n>i:
    if i==0 and s==t:
        break
    if t[:-i]==s[i:]:
        break
    i+=1
print(n+i)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
if s==t:
    print(n)
else:
    ans=2*n
    f=False
    for i in range(n):
        for j range(i+1):
            if t[j]!=s[n-1-i+j]:
                f=True
        if not f:
            break
        ans-=1
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
if s==t:
    print(n)
else:
    ans=2*n
    f=True
    for i in range(n):
        for j in range(i+1):
            if t[j]==a[n-1-i+j]:
                f=False
        if not f:
            break
        ans-=1
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
if s==t:
    print(n)
else:
    ans=2*n
    f=True
    for i in range(n):
        for j range(i+1):
            if t[j]==a[n-1-i+j]:
                f=False
        if !f:
            break
        ans-=1
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
if s==t:
    print(n)
else:
    ans=2*n
    f=True
    for i in range(n):
        for j range(i+1):
            if t[j]==a[n-1-i+j]:
                f=False
        if not f:
            break
        ans-=1
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
if s==t:
    print(n)
else:
    ans=2*n
    f=True
    for i in range(n):
        for j range(i+1):
            if t[j]==a[n-1-i+j]:
                f=False
        if not f:
            break
    print(ans)
Problem p03970 (python)

Fixed submission:
s=input()
v="CODEFESTIVAL2016"
cnt=0
for i in range(16):
    if s[i]==v[i]:
        cnt+=1
print(16-cnt)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
s=input()
for i in s:
    if a+b>0:
        if i=="a":
            a-=1
            print("Yes")
            continue
        elif i=="b" and b>0:
            b-=1
            print("Yes")
            continue
    print("No")

Buggy submission (verdict: Runtime Error):
        s=list(input())
        v=list("CODEFESTIVAL2016")
        cnt=0
        for i in range(16):
            if s[i]!=v[i]:
                cnt+=1
        print(cnt)

Buggy submission (verdict: Runtime Error):
    s=input()
    v="CODEFESTIVAL2016"
    cnt=0
    for i in range(16):
        if s[i]!=v[i]:
            cnt+=1
    print(cnt)
Problem p03971 (python)

Fixed submission:
n,a,b=map(int,input().split())
s=input()
for i in s:
    if a+b>0:
        if i=="a":
            a-=1
            print("Yes")
            continue
        if i=="b" and b>0:
            b-=1
            print("Yes")
            continue
    print("No")

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
s=input()
for i in s:
    if a+b>0:
        if i=="a":
            a-=1
            print("Yes")
            continue
       elif i=="b" and b>0:
            b-=1
            print("Yes")
            continue
    print("No")
Problem p04043 (python)

Fixed submission:
a=sorted([int(i) for i in input().split()])
print("YES" if a==[5,5,7] else "NO")

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
d=[i for i in input().split()]
while True:
    f=False
    for i in d:
        if i not in str(n):
            f=True
            break
    if f:
        break
    n+=1
print(n)
Problem p04044 (python)

Fixed submission:
n,_=map(int,input().split())
print("".join(sorted([input() for i in range(n)])))

Buggy submission (verdict: Runtime Error):
n,l=map(int,input().split())
print("".join(sorted[input() for i in range(n)]))
Problem p03486 (python)

Fixed submission:
s = list(input())
s.sort()

t = list(input())
t.sort(reverse=True)

if s < t:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = list(input())
s.sort()

t = list(input())
t.sort(reverse=True)

if s == t:
    print('No')
else:
    j = 0
    for i in s:
        if i < t[j]:
            print('Yes')
            break

        if i > t[j]:
            print('No')
            break
        j += 1
Problem p03547 (python)

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

if a > b:
    print('>')
elif a < b:
    print('<')
else:
    print('=')

Buggy submission (verdict: Runtime Error):
 a, b = input().split()


if a > b:
    print('>')
elif a < b:
    print('<')
else: print('=')
Problem p03555 (python)

Fixed submission:
a = [0,0]
temp = [0,0]

for k in range(2):
    temp[k] = input()
    a[1-k] = temp[k][::-1]

if (temp[0] == a[0]) and (temp[1] == a[1]):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
# using sort

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Brute force
for i in a[0]:
    for j in a[1]:
        if i < j:
            index = 0
            for k in a[2]:
                if j < k:
                    count += n - index
                    break
                else:
                    index += 1

print(count)

Buggy submission (verdict: Runtime Error):
# using sort

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Brute force

index = 0

for i in a[0]:
    for j in a[1]:
        if i < j:
            for k in a[2]:
                if j < k:
                    count += n - index
                    break
                else:
                    index += 1

print(count)
Problem p03557 (python)

Fixed submission:
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)

    index2_right = bisect.bisect_right(a[2], i)

    count += (index0_left -1 + 1)*(n - index2_right)

print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)
    index2_right = bisect.bisect_right(a[2], i)
    if ( i > a[0][index0_left-1] and a[2][index2_right+1] > i):
        count += (index0_left -1 + 1)*(n - index2_right)

print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)
    while i == a[0][index0_left-1]:
        if index0_left == 0:
            break
        index0_left -= 1

    index2_right = bisect.bisect_right(a[2], i)
    while a[2][index2_right+1] == i:
        if index2_right > n:
            break
        index2_right += 1

    if ( i > a[0][index0_left-1] and a[2][index2_right+1] > i):
        count += (index0_left)*( n - index2_right)
        
print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n = int(input())
count = 0
a = [[0 for i in range(n)] for i in range(3)]

for i in range(3):
    a[i] = [int(x) for x in input().split()]
    a[i].sort()

# Binary Search
for i in a[1]:
    index0_left = bisect.bisect_left(a[0], i)
    while i == a[0][index0_left-1]:
        if index0_left == 0:
            break
        index0_left -= 1

    index2_right = bisect.bisect_right(a[2], i)
    while a[2][index2_right+1] == i:
        if index2_right > n:
            break
        index2_right += 1

    if ( i > a[0][index0_left-1] and a[2][index2_right+1] > i):
        count += (index0_left)*( n - index2_right)
Problem p03469 (python)

Fixed submission:
str = input()
print(str[:3] + "8" + str[4:])

Buggy submission (verdict: Runtime Error):
n = input()
print(input[:4] + "8" + [5:])

Buggy submission (verdict: Runtime Error):
n = input()
print n[0:4]
Problem p03469 (python)

Fixed submission:


import re 

print(re.sub("2017/01", "2018/01", input()))

Buggy submission (verdict: Runtime Error):

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

y = y // 1000
print(n, y)


def find_by_for(v, n):
    """
        the tuple by example
        ((0, 0, 0), (10, 5, 1), 100, 10)
    """
    queue = []
    queue.append(((0, 0, 0), (1, 5, 10), v, n))
    while queue:
        xs, fv, v, n = queue.pop()
        if v == 0 and n == 0:
            return "%d %d %d"%(xs[2], xs[1], xs[0])
        elif not fv or v <= 0 or n <= 0:
            pass
        else:
            queue.append((xs, fv[:-1], v, n))
            z = list(xs) 
            idx = len(fv) -1
            z[idx] +=1
            queue.append((tuple(z), fv, v - fv[idx], n -1))
    return "-1 -1 -1"

print(find_by_for(y, n))

Buggy submission (verdict: Runtime Error):

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

y = y // 1000
print(n, y)


def find_by_for(v, n):
    """
        the tuple by example
        ((0, 0, 0), (10, 5, 1), 100, 10)
    """
    queue = []
    queue.append(((0, 0, 0), (1, 5, 10), v, n))
    while queue:
        xs, fv, v, n = queue.pop()
        if v == 0 and n == 0:
            return "%d %d %d\n"%(xs[2], xs[1], xs[0])
        elif not fv or v <= 0 or n <= 0:
            pass
        else:
            queue.append((xs, fv[:-1], v, n))
            z = list(xs) 
            idx = len(fv) -1
            z[idx] +=1
            queue.append((tuple(z), fv, v - fv[idx], n -1))
    return "-1 -1 -1\n"

print(find_by_for(y, n))