Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt <= m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])

Fixed submission:
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt < m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt <= m:
        if lis[i][1] + cnt <= m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])


Fixed submission:
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt < m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt <= m:
        if lis[i][1] + cnt <= m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
print(m*lis[0][0])


Fixed submission:
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
cnt = 0
mon = 0
i = 0
if n >= 2:
    while cnt < m:
        if lis[i][1] + cnt < m:
            cnt += lis[i][1]
            mon += lis[i][0]*lis[i][1]
            i += 1
        else:
            break
    print(mon + (m-cnt) * lis[i][0])
else:
    print(m*lis[0][0])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
for i in range(n):
    for j in range(k+1):
        if i - j >= 0:
            dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [10**10]*n
dp[0] = 0
for i in range(n):
    for j in range(k+1):
        if i - j >= 0:
            dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]))
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lis = list(map(int,input().split()))
S = lis[0]
for i in range(2,N+1):
    S *= lis[i-1]
cnt = 0
while S % 2 == 0:
    S = S//2
    cnt += 1
print(cnt)


Fixed submission:
N = int(input())
lis = list(map(int,input().split()))
cnt = 0
for i in range(N):
    while lis[i] % 2 == 0:
        lis[i] = lis[i]//2
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
butnum = {}
for i in range(1,n+1):
    butnum[i] = int(input())
pushbut = 1
pushedbut =[]
jud = 0
for j in range(1,n+1):
    pushedbut.append(pushbut)
    pushbut = butnum[pushbut]
    if pushbut == 2:
        print(j)
        jud = 1
        break
    elif pushbut in pushedbut:
        print(-1)
        jud = 1
        break
if jud == 0:
    print(-1)

Fixed submission:
n = int(input())
butnum = {}
for i in range(1,n+1):
    butnum[i] = int(input())
pushbut = 1
pushedbut =[]
jud = 0
for j in range(1,n+1):
    pushbut = butnum[pushbut]
    if pushbut == 2:
        print(j)
        jud = 1
        break
if jud == 0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
butnum = {}
for i in range(1,n+1):
    butnum[i] = int(input())
pushbut = 1
pushedbut =[]
for j in range(1,n+1):
    pushedbut.append(pushbut)
    pushbut = butnum[pushbut]
    if pushbut == 2:
        print(j)
        break
    elif pushbut in pushedbut:
        print(-1)
        break

Fixed submission:
n = int(input())
butnum = {}
for i in range(1,n+1):
    butnum[i] = int(input())
pushbut = 1
pushedbut =[]
jud = 0
for j in range(1,n+1):
    pushbut = butnum[pushbut]
    if pushbut == 2:
        print(j)
        jud = 1
        break
if jud == 0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dic = {}
for i in range(1,N+1):
    dic[i] = int(input())
b = 1
lis = []
cnt = 0
while True:
    lis.append(b)
    b = dic[b]
    cnt += 1
    if b == 2:
        print(cnt)
        break
    elif b in lis:
        print(-1)
        break

Fixed submission:
n = int(input())
butnum = {}
for i in range(1,n+1):
    butnum[i] = int(input())
pushbut = 1
pushedbut =[]
jud = 0
for j in range(1,n+1):
    pushbut = butnum[pushbut]
    if pushbut == 2:
        print(j)
        jud = 1
        break
if jud == 0:
    print(-1)
Buggy python submission (verdict: Runtime Error):
s = input()

for i in range(2**(len(s)-1)):
    plus = [""]*(len(s))
    fomula = ""
    for j in range(len(s)-1):
        if(i >> j & 1):
            plus[j] = "+"
    for k in range(len(s)):
        fomula += s[k] + plus[k]
    ans += eval(fomula)
print(ans)

Fixed submission:
s = input()
ans = 0
for i in range(2**(len(s)-1)):
    plus = [""]*(len(s))
    fomula = ""
    for j in range(len(s)-1):
        if(i >> j & 1):
            plus[j] = "+"
    for k in range(len(s)):
        fomula += s[k] + plus[k]
    ans += eval(fomula)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int( input() )

ans = 0

while n != 0:
    ans += n % 10
    n = n // 10

if ans % 9 == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
n = list(input())

ans = 0

for i in range(len(n)):
    ans += int(n[i])

if ans % 9 == 0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list( int(x) for x  in input().split() )

fumidai = 0

for i in range(n):
    x_list = A[0:i+1]
    max_list = max(x_list)
    if max_list > A[i]:
        fumidai += max_list - A[i]

print(fumidai)

Fixed submission:
n = int(input())
A = list( int(x) for x  in input().split() )

fumidai = 0
great = A[0]

for i in range(n):
    if great > A[i]:
        fumidai += great - A[i]
    else:
        great = A[i]

print(fumidai)
Buggy python submission (verdict: Runtime Error):
n = int( input() )
a = list( map(int, input().split()) )
x = 0
for i in a:
    x ^= i
print( * list( map( lamda y: x^y , a ) ) )

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

def main():
    n = int( input() )
    input_a = list ( map( int, input().split() ) )
    a = deque( input_a )

    while( len(a) != 1 ):
        x = a.popleft()
        y = a.popleft()
        z = x ^ y
        a.append(z)
    sum = a.popleft()
    ans = []
    for i in input_a:
        x = i ^ sum
        ans.append(x)

    for i in ans:
        print( i , end = ' ' )



main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B
count = 0

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                count += 1

print(sum - count)

Fixed submission:
import sys
input = sys.stdin.readline

def main():

    n = str(input())
    for i in range(len(n)):
        if n[i] == '7':
            print('Yes')
            sys.exit()
    print('No')


main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N = int(input())
I = input()

R =0
G =0
B =0
for i in range(N):
    if (I[i] == 'R'):
        R+=1
    if (I[i] == 'G'):
        G+=1
    if (I[i] == 'B'):
        B+=1


sum = R * G * B
count = 0

for i in range(N):
    for j in range(i+1,N):
        if I[i] != I[j]:
            k = j + j - i
            if k >= N:
                continue
            if I[i] != I[k] and I[j] != I[k]:
                count += 1

print(sum - count)

Fixed submission:
import sys
input = sys.stdin.readline

def main():

    n = str(input())
    for i in range(len(n)):
        if n[i] == '7':
            print('Yes')
            sys.exit()
    print('No')


main()
Buggy python submission (verdict: Runtime Error):
import sys
N=input()

for i in range(1,9):
    a=N//i
    b=N%i
    if (0<a<10 && b==0):
        print("Yes")
        break
else print("No")

Fixed submission:
import sys
X=input()
N=int(X)

for i in range(1,10):
    a=N//i
    b=N%i
    if (0<a<10 and b==0):
        print("Yes")
        break
else:
     print("No")
Buggy python submission (verdict: Runtime Error):
import math
import sympy
#from sympy import sieve

N = int(input())
'''
lenN = math.floor(math.log(N,10)) + 1
# lenN = Nの桁数
rootN = math.floor(math.sqrt(N))
#rootN = floor( N ^ 1/2 )
Primes = list(sieve.primerange(1,rootN))
'''

Divisors = list(sympy.divisors(N))
Len_d = len(Divisors)

Ans = Divisors[ Len_d // 2 ]
print(math.floor(math.log(Ans,10))+1)

Fixed submission:
import math

def make_divisors(n):
    lo_d , up_d = [] , []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lo_d.append(i)
            if i != n // i:
                up_d.append( n // i )
        i += 1
    return lo_d + up_d[::-1]

N = int(input())
List = make_divisors(N)
len_a = len(List)
ans = List[ len_a // 2 ]
print( math.floor(math.log(ans , 10)) + 1 )
Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

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

ans = 0
for i in range(n-1):
    ans = (ans+(A[i]*sum(A[i+1:])%MOD)%MOD)%MOD
print(ans)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

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

ans = 0
for i in range(n-1):
    ans = (ans+(A[i]*sum(A[i+1:])%MOD)%MOD)%MOD
print(ans)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

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

MOD = 10**9 + 7
import itertools

ans = 0
Cmb = itertools.combinations(A, 2)
for cmb in Cmb:
    ans = (ans + cmb[0]*cmb[1]%MOD)%MOD
print(ans%MOD)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)

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

MOD = 10**9 + 7
import itertools

ans = 0
Cmb = itertools.combinations(A, 2)
for cmb in Cmb:
    ans += cmb[0]*cmb[1]%MOD
print(ans%MOD)

Fixed submission:
MOD = 10**9 + 7
n = int(input())
A = list(map(int, input().split()))

import numpy
A_CS = numpy.cumsum(sorted(A, reverse=True))
A_CS = A_CS%MOD

A = sorted(A)

#print(A_CS)
ans = 0
for i in range(n-1):
#    print(A[i], A_CS[-i-2])
#    A_CS -= A[i]
    ans = (ans+(A[i]*A_CS[-i-2])%MOD)%MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
A = list(map(int, input().split()))

#A = sorted(A)

ansN = A[0]
for i in range(1, n):
    ansN = math.gcd(ansN, A[i])
if ansN > 1:
    print('not coprime')
else:
    ans2 = True
    C = [0 for _ in range(10**6+10)]
    for a in A:
        F = factorization(a)
#        print(F)
        for f in F:
            if C[f[0]] == 0:
                C[f[0]] = 1
#                print('!!')
            else:
                ans2 = False
                break
        else:
            continue
        break
    if ans2:
        print('pairwise coprime')
    else:
        print('setwise coprime')

Fixed submission:
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

#factorization(24) 

## [[2, 3], [3, 1]] 
##  24 = 2^3 * 3^1


import math
n = int(input())
A = list(map(int, input().split()))

#A = sorted(A)

ansN = A[0]
for i in range(1, n):
    ansN = math.gcd(ansN, A[i])
if ansN > 1:
    print('not coprime')
else:
    ans2 = True
    C = [0 for _ in range(10**6+10)]
    for a in A:
        F = factorization(a)
#        print(F)
        for f in F:
            if f[0] != 1:
                if C[f[0]] == 0:
                    C[f[0]] = 1
                else:
                    ans2 = False
                    break
        else:
            continue
        break
    if ans2:
        print('pairwise coprime')
    else:
        print('setwise coprime')
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
k = int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)


ans = 0
if a < b < c:
    ans = 1

for i in range(3**k):
    a = A
    b = B
    c = C
    i3 = Base_10_to_n(i, 3).zfill(k)
    mem = 0
    Pick = []
    for j in range(k):
        if i3[j] == '0':
            a *= 2
        elif i3[j] == '1':
            b *= 2
        elif i3[j] == '2':
            c *= 2
#        print(a, b, c)
    if a < b < c:
        ans = 1
#        print('!!')
if ans:
    print('Yes')
else:
    print('No')

Fixed submission:
A, B, C = map(int, input().split())
k = int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

a = A
b = B
c = C
ans = 0
if a < b < c:
    ans = 1

for i in range(3**k):
    a = A
    b = B
    c = C
    i3 = Base_10_to_n(i, 3).zfill(k)
    mem = 0
    Pick = []
    for j in range(k):
        if i3[j] == '0':
            a *= 2
        elif i3[j] == '1':
            b *= 2
        elif i3[j] == '2':
            c *= 2
#        print(a, b, c)
    if a < b < c:
        ans = 1
#        print('!!')
if ans:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))

i = n - k
score_prev = 1
for i in range(k):
    score_prev *= A[i]
#print(score_prev)
for i in range(k, n):
    score_now = score_prev*A[i]//A[i-k]
#    print(score_now)
    if score_now > score_prev:
        print('Yes')
    else:
        print('No')
    score_prev = score_now

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

for i in range(k, n):
    if A[i] > A[i-k]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

from collections import deque


cash = 1000
stock = 0

peak_min = deque()
peak_max = deque()

d_prev = 0
for i in range(1, n):
    a = A[i]
    if A[i] > A[i-1]:
        d = 1
    elif A[i] == A[i-1]:
        d = d_prev
    else:
        d = -1
    if d_prev*d == -1:
        if d == 1:
            peak_min.append(i-1)
        elif d == -1:
            peak_max.append(i-1)
    d_prev = d
#print(peak_min, peak_max)

if len(peak_min) == 0 and len(peak_max) == 0:
    if A[0] < A[-1]:
        ans = cash%A[0] + cash//A[0]*A[-1]
    else:
        ans = cash
elif len(peak_min) == 0:
    ans = cash%A[0] + cash//A[0]*A[peak_max]
elif len(peak_max) == 0:
    ans = cash%A[peak_min] + cash//A[peak_min]*A[-1]
else:
    if peak_max[0] < peak_min[0]:
        peak_min.appendleft(0)
    if peak_max[-1] < peak_min[-1]:
        peak_max.append(n-1)
#    print(peak_min, peak_max)
    
    while len(peak_min) != 0:
        i = peak_min.popleft()
        stock += cash//A[i]
        cash = cash%A[i]
#        print(i, cash , stock)
        
        i = peak_max.popleft()
        cash += stock*A[i]
        stock = 0
#        print(i, cash , stock)
    ans = cash
print(ans)

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

from collections import deque


cash = 1000
stock = 0

peak_min = deque()
peak_max = deque()

d_prev = 0
for i in range(1, n):
    a = A[i]
    if A[i] > A[i-1]:
        d = 1
    elif A[i] == A[i-1]:
        d = d_prev
    else:
        d = -1
    if d_prev*d == -1:
        if d == 1:
            peak_min.append(i-1)
        elif d == -1:
            peak_max.append(i-1)
    d_prev = d
#print(peak_min, peak_max)

if len(peak_min) == 0 and len(peak_max) == 0:
    if A[0] < A[-1]:
        ans = cash%A[0] + cash//A[0]*A[-1]
    else:
        ans = cash
elif len(peak_min) == 0:
    ans = cash%A[0] + cash//A[0]*A[peak_max[0]]
elif len(peak_max) == 0:
    ans = cash%A[peak_min[0]] + cash//A[peak_min[0]]*A[-1]
else:
    if peak_max[0] < peak_min[0]:
        peak_min.appendleft(0)
    if peak_max[-1] < peak_min[-1]:
        peak_max.append(n-1)
#    print(peak_min, peak_max)
    
    while len(peak_min) != 0:
        i = peak_min.popleft()
        stock += cash//A[i]
        cash = cash%A[i]
#        print(i, cash , stock)
        
        i = peak_max.popleft()
        cash += stock*A[i]
        stock = 0
#        print(i, cash , stock)
    ans = cash
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

import numpy as np
A_cumsum = np.cumsum(A)
B_cumsum = np.cumsum(B)
#AB_cumsum = np.sort(np.concatenate([A_cumsum, B_cumsum]))


lenA = len(A)
lenB = len(B)

if lenA < lenB:
    A_cumsum = np.concatenate([A_cumsum, [np.inf]*(lenB-lenA)])
else:
    B_cumsum = np.concatenate([B_cumsum, [np.inf]*(lenA-lenB)])


i = 0
j = 0
t = 0
ans = 0
while i < lenA or j < lenB:
    if A_cumsum[i] < B_cumsum[j]:
        ans += 1
        t += A[i]
        i += 1
    else:
        ans += 1
        t += B[j]
        j += 1
#    print(ans, t)
    if t > K:
        ans -= 1
        break
print(ans)
        
    

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

import numpy as np
A0 = [0] + A
B0 = [0] + B
AA = np.cumsum(A0)
BB = np.cumsum(B0)

ans = 0
jmax = M
for i in range(0, N+1):
    a = AA[i]
    if a > K:
        break
    for j in range(jmax, -1, -1):
        b = BB[j]
#        print(a, b)
        if a + b <= K:
            ans = max(ans, i+j)
#            print('ok')
            break
    jmax = j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
flag = True
for a in A:
    ans *= a
if ans > 10**18:
    flag = False
if flag:
    print(ans)
else:
    print(-1)

Fixed submission:
N = int(input())
B = list(input().split())
A = list(map(int, B))

ans = 1
flag_over = False
flag_0 = False
len0 = 0

if 0 in A:
    flag_0 = True
for b in B:
    len0 += len(b) - 1
if len0 > 18:
    flag_over = True

if flag_0 == False and flag_over == 0:
    for a in A:
        ans *= a

if ans > 10**18:
    flag_over = True

if flag_0:
    print(0)
elif flag_over:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())
a_num = a
b_num = b
c_num = c
ans = 0

for i in range(1, k+1):
    if a_num > 0:
        ans += 1
        a_num -= 1
    elif b_num > 0:
        b_num -= 1
    else:
        ans -= 1
        c_num -= 1
print(ans)

Fixed submission:
a, b, c, k = map(int, input().split())
if a >= k:
    ans = k
elif a+b >= k:
    ans = a
else:
    ans = a - (k - a - b)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [0] + A

L = [[] for _ in range(N)]
L[0] = 1
prev = 1
count = 1
for i in range(1, N):
    now = A[prev]
    if now == 1:
        break
    elif now == prev:
        flag_inf = True
        ans_inf = now
    else:
        L[i] = now
        prev = now
        count += 1
#        print(L)
L = L[:count]
print(L)

if flag_inf:
    print(ans_inf)
else:
    print(L[K%count])

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [0] + A

Root = []
Visited = [0 for _ in range(N+1)]

now = 1
after = A[now]
while Visited[now] == 0:
    Root.append(now)
    Visited[now] = 1
    now = after
    after = A[now]
ind = Root.index(now)
Init = Root[:ind]
Loop = Root[ind:]

if K <= len(Init)-1:
    print(Init[K])
else:
    print(Loop[(K-len(Init))%len(Loop)])
Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'ABC':
    print('ARC')
else:
    print('ABC')

Fixed submission:
S = input()
if S == 'ABC':
    print('ARC')
else:
    print('ABC')