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

Fixed submission:
n, k = map(int, input().split())
s = input()
pre = s[0]
ans = s[0]
first = s[0]

if s[0] == "R":
    second = "L"
else:
    second = "R"

for i in s[1:]:
    if i == second and k > 0:
        ans = ans + first
        pre = i
    elif i == first and pre == second:
        k -= 1
        ans = ans + i
        pre = i
    elif k == 0:
        ans = ans + i
    elif i == first and pre == first:
        ans = ans + i

pre = "0"
cnt = 0

for i in ans:
    if i == pre:
        cnt += 1
    pre = i

print(cnt)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
pre = s[0]
rsans = s[0]
first = s[0]

if s[0] == "R":
    second = "L"
else:
    second = "R"

for i in s[1:]:
    if i == second and k > 0:
        ans = ans + first
        pre = i
    elif i == first and pre == second:
        k -= 1
        ans = ans + i
        pre = i
    elif k == 0:
        ans = ans + i
    elif i == first and pre == first:
        ans = ans + i

pre = "0"
cnt = 0

for i in ans:
    if i == pre:
        cnt += 1
    pre = i

print(cnt)
Problem p02995 (python)

Fixed submission:
import fractions

a, b, c, d = map(int, input().split())
g = fractions.gcd(c, d)


t = b//c + b//d - b//(c*d//g)
l = (a - 1)//c + (a - 1)//d - (a - 1)//(c*d//g)
ans = b - (a - 1) - t + l

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())
g = math.gcd(c, d)


t = b//c + b//d - b//(c*d//g)
l = (a - 1)//c + (a - 1)//d - (a - 1)//(c*d//g)
ans = b - (a - 1) - t + l

print(ans)
Problem p03147 (python)

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

ans = 0
cnt = 0

for i in range(1, max(h) + 1)[::-1]:
    cnt = 0
    for j in range(n):
        if h[j] == i:
            h[j] -= 1
            cnt += 1
            if j + 1 < n:
                if h[j + 1] == i:
                    cnt -= 1
    ans += cnt

print(ans)

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

ans = 0
cnt = 0

for i in range(1, max(h) + 1)[::-1]:
    cnt = 0
    for j in range(n):
        if h[j] == i:
            h[j] -= 1
            cnt += 1
            if j + 1 < n:
                if h[j + 1] == i:
                    cnt -= 1
    ans += cnt

print(ans)
Problem p03150 (python)

Fixed submission:
n = "keyence"
s = input()

for i in s:
    if n[0] == i: #文字が一致するなら
        n = n[1:] #比較中の文字を削る
    else:
        break

n = n[::-1]

for i in s[::-1]:
    if n == "":
        break
    elif n[0] == i:
        n = n[1:]
    else:
        break

if n == "":
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
n = "keyence"
s = input()
cnt = 0


for i in s:
    if n[0] == i:
        n = n[1:]
        if cnt > 0:
            cnt = -1
    elif n[0] != i:
        if cnt == -1:
            break
        cnt += 1

if n == "":
    print("YES")
else:
    print("NO")
Problem p03262 (python)

Fixed submission:
import fractions

n, x = map(int, input().split())
xl = list(map(int, input().split()))
l = []

for i in xl:
    l.append(abs(i - x))

ans = l[0]

for i in l:
    ans = fractions.gcd(ans, i)

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n, x = map(int, input().split())
xl = list(map(int, input().split()))
l = []

for i in xl:
    l.append(abs(i - x))

ans = l[0]

for i in l:
    ans = math.gcd(ans, i)

print(ans)
Problem p03273 (python)

Fixed submission:
h, w = map(int, input().split())
a = []
delrow = []
delcol = []
cnt = 0

for i in range(h):
    a.append(list(input()))

for i in range(h):
    for j in range(w):
        if a[i][j] != ".":
            break
        else:
            cnt += 1
        if cnt == w:
            delrow.append(i)
    cnt = 0

for i in range(w):
    for j in range(h):
        if a[j][i] != ".":
            break
        else:
            cnt += 1
        if cnt == h:
            delcol.append(i)
    cnt = 0

for i in delrow [::-1]: #行を削除
    del a[i]
for i in delcol [::-1]: #列を削除
    for j in range(len(a)):
        del a[j][i]

for i in range(len(a)):
    print(*a[i], sep="")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = []
delrow = []
delcol = []


for i in range(h):
    a.append(list(input()))

for i in range(h):
    if set(a[i]) == {"."}:
        delrow.append(i)

for i in range(w):
    if set(a[0:w][i]) == {"."}:
        delcol.append(i)
        
for i in delrow [::-1]: #行を削除
    del a[i]
for i in delcol [::-1]: #列を削除
    for j in range(len(a)):
        del a[j][i]

for i in range(len(a)):
    print(*a[i], sep="")

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = []
delrow = []
delcol = []


for i in range(h):
    a.append(list(input()))

for i in range(h):
    print(set(a[i]))
    if set(a[i]) == {"."}:
        delrow.append(i)

for i in range(w):
    print(set(a[0:w][i]))
    if set(a[0:w][i]) == {"."}:
        delcol.append(i)
        
for i in delrow [::-1]: #行を削除
    del a[i]
for i in delcol [::-1]: #列を削除
    for j in range(len(a)):
        del a[j][i]

for i in range(len(a)):
    print(*a[i], sep="")
Problem p03281 (python)

Fixed submission:
n = int(input())
cnt = 0
ans = 0

for i in range(105, n + 1, 2):
    for j in range(1, n + 1):
        if i%j == 0:
            cnt += 1
    if cnt == 8:
        ans += 1
    cnt = 0
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
cnt = 0
ans = 0

for i in range(105, n + 1, 2):
    for j in range(1, n + 1):
        if i%j == 0:
            cnt += 1
    if cnt == 8:
        ans += 1
    cnt = 0
print(ans
Problem p03352 (python)

Fixed submission:
x = int(input())
ans = 0


for i in range(1, 100):
    if i**2 > x:
        ans = (i - 1)**2
        break

for i in range(1, 100):
    if i**3 > x:
        ans = max(ans, (i - 1)**3)
        break

for i in range(1, 100):
    if i**5 > x:
        ans = max(ans, (i - 1)**5)
        break

for i in range(1, 100):
    if i**7 > x:
        ans = max(ans, (i - 1)**7)
        break

print(ans)

Buggy submission (verdict: Runtime Error):
x = int(input())
ans = []

for i in range(2, 100):
    n = 2
    while i**n <= x:
        ans.append(i**n)
        n += 1

print(max(ans))
Problem p03523 (python)

Fixed submission:
s = input()

if len(s) < 5:
    print("NO")
    exit()

for i in range(0, 9, 2):
    if i == 8 and len(s) <= 8:
        s = s[:i] + "A" + s[i:]
    elif i != 2:
        if s[i] != "A":
            s = s[:i] + "A" + s[i:]
if s == "AKIHABARA":
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input()

for i in range(0, 9, 2):
    if i == 8 and len(s) <= 8:
        s = s[:i] + "A" + s[i:]
    elif i != 2:
        if s[i] != "A":
            s = s[:i] + "A" + s[i:]
if s == "AKIHABARA":
    print("YES")
else:
    print("NO")
Problem p04012 (python)

Fixed submission:
w = list(input())
ans = "Yes"

for i in w:
    cnt = 0
    for j in w:
        if i == j:
            cnt += 1
    if cnt%2 == 1:
        ans = "No"
        break

print(ans)

Buggy submission (verdict: Runtime Error):
w = list(input())
ans = "Yes"

for i in w:
    cnt = 0
    for j in w:
        if i == j:
            cnt += 1
    if cnt%2 == 1:
        ans = "No"
        break

print(ans
Problem p02657 (python)

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

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())

print(a*b)
Problem p02675 (python)

Fixed submission:
n = input()
a = ['2','4','5','7','9']
b = ['0','1','6','8']
if n[-1] in a:
    print('hon')
elif n[-1] in b:
    print('pon')
else:
    print('bon')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [2,4,5,7,9]
b = [0,1,6,8]

if n[-1] in a:
  print('hon')
elif n[-1] in b:
  print('pon')
else:
  print('bon')
Problem p02786 (python)

Fixed submission:
import math
h = int(input())
l = 1

while (h != 1):
    h = math.floor(h / 2)
    l += 1
ans = 0

for i in range(l):
    ans += 2**i
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
def rec(n):
    if n == 1: 
        return 1
    return rec(n/2)*2+1

n = int(input())
print(rec(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
def rec(n):
    if n == 1: 
        return 1
    return rec(n/2)*2+1

n = int(input())
ans = 0
ans += rec(n)
print(ans)

Buggy submission (verdict: Runtime Error):
def rec(n):
    if n == 1: 
        return 1
    return rec(n/2)*2+1

n = int(input())
ans = 0
ans += rec(n)
print(ans)

Buggy submission (verdict: Runtime Error):
def rec(n):
    if n == 1: return 1
    return rec(n/2)*2+1

n = int(input())
ans = 0
ans += rec(n)
print(ans)
Problem p02817 (python)

Fixed submission:
s,t = input().split()

print(t+s)

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

for i in range(k):
  if a >= 1:
    a -= 1
  elif b >= 1:
    b -= 1
  else:
    pass

print(a,b)
Problem p02818 (python)

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

if a > k:
  print(a-k,b)
elif a == k:
  print(0,b)
else:
  if (a+b) > k:
    print(0,a+b-k)
  else:
    print(0,0)

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

if k<=a
  print(a-k,b)
elif a<k<=a+b:
  print(k-a,b-(k-a))
else:
  print(0,0)
Problem p03068 (python)

Fixed submission:
n = int(input())
s = input()
s = list(s)
k = int(input())
word = s[k-1]
for i in range(n):
    if s[i] != word:
        s[i] = "*"
print("".join(s))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
s = list(s)
k = int(input())
word = s[k]
for i in range(n):
    if s[i] != word:
        s[i] = "*"
print("".join(s))
Problem p03086 (python)

Fixed submission:
s = input()
a = ['A','T','G','C']
ans = []
c = 0

for i in s:
    if i in a:
        c += 1
    else:
        ans += [c]
        c = 0
ans += [c]
if ans == []:
    print(len(s))
else:
    print(max(ans))

Buggy submission (verdict: Runtime Error):
s = input()
a = ['A','T','G','C']
ans = []
c = 0

for i in s:
    if i in a:
        c += 1
    else:
        ans += [c]
        c = 0
print(max(ans))

Buggy submission (verdict: Runtime Error):
s = input() ; c = 0 ; l = []

for i in s:
    if i == 'A' or i == 'T' or i == 'G' or i == 'C':
        c += 1
    if i != 'A' and i != 'T' and i != 'G' and i != 'C':
        l.append(c)
        c = 0
        
print(max(l))

Buggy submission (verdict: Runtime Error):
s = input() ; c = 0 ; l = []

for i in s:
    if i == 'A' or i == 'T' or i == 'G' or i == 'C':
        c += 1
    if i != 'A' and i != 'T' and i != 'G' and i != 'C':
        l.append(c)
        c = 0
        
print(l(max))
Problem p03239 (python)

Fixed submission:
n,t = map(int,input().split())
cost = []
time = []
ncost = []
f = 0
e = 0
for i in range(n):
    c,T = input().split()
    cost.append(int(c))
    time.append(int(T))

for i in time:
    if i > t:
        e += 1
    
if e == n:
    print('TLE')
    
for i in range(n):
    if time[i] <= t:
        ncost.append(cost[i])
        f = 1
    else:
        pass
if  f == 1:
    print(min(ncost))

Buggy submission (verdict: Runtime Error):
n,t = map(int,input().split())
cost = []
time = []
ncost = []
for i in range(n):
    c,T = input().split()
    cost.append(int(c))
    time.append(int(T))

    
for i in range(n):
    if time[i] <= t:
        ncost.append(cost[i])
    elif all(time) > t:
        print('TLE')
    else:
        pass
    
print(min(ncost))
Problem p03469 (python)

Fixed submission:
s = input()
s = list(s)
s[3] = '8'

s = ''.join(s)

print(s)

Buggy submission (verdict: Runtime Error):
s = input()
s[3] = '8'

print(s)
Problem p03477 (python)

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

if a + b > c + d:
    print('Left')
elif a + b == c + d:
    print('Balanced')
else:
    print('Right')

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
res = 0
for i in range(N+1):
    if A <= sum([int(s) for s in str(i)]) <= B:
        res += i
print(res)
Problem p03493 (python)

Fixed submission:
s = list(input())
c = 0


for i in range(3):
  if s[i] == '1':
    c += 1
   

print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int,input().split()))
ans = 0
while True:
    for i in range(n):
        if nums[i] % 2 == 0:
            nums[i] = nums[i] / 2
        else:
            break
    if nums[i] % 2 != 0:
      ans += 1
      print(ans)
      break   
    else:
      ans +=1

Buggy submission (verdict: Runtime Error):
s=int(input())
s=str(s)
a=int(s[0]);b=int(s[1]);c=int(s[2])
sum=a+b+c

if sum == 0:
  print(0)
elif sum == 1:
  print(1)
elif sum == 2:
  print(2)
else:
  print(3)

Buggy submission (verdict: Runtime Error):
s=int(input())
s=str(s)
a=int(s[0]);b=int(s[1]);c=int(s[2])
sum=a+b+c

if sum == 0:
  print('0')
elif sum == 1:
  print('1')
elif sum == 2:
  print('2')
else:
  print('3')
Problem p03502 (python)

Fixed submission:
n = input()
N = int(n)
I = []

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

S = sum(I)

if N % S == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
def s(n):
  s = 0
  for i in range(len(n)):
    s += int(s[i])
    
  return s

n = input()

if int(n) % s(n) == 0:
  print('Yes')
else:
  print('No')
Problem p03545 (python)

Fixed submission:
import sys
a,b,c,d = input()

for i in range(2**3):
    l = ['+','+','+']
    for j in range(3):
        if (i>>j) & 1 == 1:
            l[j] = '-'
    if eval(a+l[0]+b+l[1]+c+l[2]+d) == 7:
        print(a+l[0]+b+l[1]+c+l[2]+d+'=7')
        sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
a,b,c,d= input()
for i in range(2**(len(op)-1)):
    op = ["+"]*3
    for j in range(len(op)-1):
        if (i >> j) & 1 == 1:
            op[j] = "-"
    if eval(a+op[0]+b+op[1]+c+op[2]+d) == 7:
        print(a+op[0]+b+op[1]+c+op[2]+d+'=7')
        sys.exit()
Problem p03693 (python)

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

l = g+b

if int(l) % 4 == 0:
  print('YES')
else:
  print('NO')

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

l = g*b

if int(l) % 4 == 0:
  print('YES')
else:
  print('NO')
Problem p03697 (python)

Fixed submission:
a,b = map(int,input().split())
s=a+b
if s >= 10:
  print('error')
else:
  print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s += [int(input())]
a = sum(s)
if a % 10 != 0:
    print(a)
    exit()
else:
    for i in range(n):
        if s[i] % 10 != 0:
            a -= s[i]
        if a % 10 != 0:
            print(a)
            f = 0
            exit()
        else:
            f = 1
if f:
    print(0)
Problem p03698 (python)

Fixed submission:
s = input()
t = set(s)
if len(s) == len(t):
    print('yes')
else:
    print('no')

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

for i in range(1,len(s)):
    if s[i] == s[i-1]:
        print('no')
        exit()
print('yes')
Problem p03699 (python)

Fixed submission:
n = int(input())
s = []
for i in range(n):
    s += [int(input())]
s = sorted(s)
a = sum(s)
if a % 10 != 0:
    print(a)
    exit()
else:
    for i in range(n):
        if s[i] % 10 != 0:
            a -= s[i]
            if a % 10 != 0:
                print(a)
                f = 0
                exit()
        else:
            f = 1
if f:
    print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s += [int(input())]

if sum(s) % 10 != 0:
    print(sum(s))
else:
    a = []
    for i in range(n):
        a += [s[i]]
        if a[i] % 10 != 0 and (sum(s) - sum(a)) % 10 != 0:
            print(sum(s) - sum(a))
            f = 0
            exit()
        else:
            f = 1
if f:
    print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s += [int(input())]

if sum(s) % 10 != 0:
    print(sum(s))
else:
    a = []
    for i in range(n):
        a += [s[i]]
        if (sum(s) - sum(a)) % 10 != 0:
            print(sum(s) - sum(a))
            f = 0
            exit()
        else:
            f = 1
if f:
    print(0)
Problem p03814 (python)

Fixed submission:
import sys

s = input()
c = 0
C = 0

for i in range(len(s)):
    if s[i] == 'A':
        break

for j in range(len(s)):
    if s[-j] == 'Z':
        break
print(len(s[i:len(s) - j + 1]))

Buggy submission (verdict: Runtime Error):
import sys

s = input()
c = 0
C = 0

for i in range(len(s)):
    if s[i] == 'A':
        while(s[i] != 'Z'):
            c += 1
            i += 1
        if s[i] == 'Z':
            i += 1
            c += 1
            if s[i] == 'Z':
                c += 1
                break
    else:
        continue
    break
            
print(c)
Problem p03852 (python)

Fixed submission:
c=input()
list=['a','i','u','e','o']
if c in list:
  print('vowel')
else:
  print('consonant')

Buggy submission (verdict: Runtime Error):
c=input()
list=[a,i,u,e,o]
if c in list:
  print('vowel')
else:
  ('consonant')
Problem p04029 (python)

Fixed submission:
N=int(input())
result = 0;
for i in range(1,N+1):
    result += i
        
print(result)

Buggy submission (verdict: Runtime Error):
result = 0;
for i in range(1,N+1):
    result += i
        
print(result)

Buggy submission (verdict: Runtime Error):
result = 0;
    for i in range(1,N+1):
        result += i
        
    print(result)

Buggy submission (verdict: Runtime Error):
for i in range(N):
    print(i)

Buggy submission (verdict: Runtime Error):
S=sum(N/2(N+1))
print(S)

Buggy submission (verdict: Runtime Error):
S=sum(N/2(N-1))
print(S)
Problem p04030 (python)

Fixed submission:
s = input()
t = ''

for i in range(len(s)):
  if s[i] == 'B':
    t = t[:-1]
  else:
    t += s[i]
    
print(t)

Buggy submission (verdict: Runtime Error):
s = input()
t = ''

for i in range(len(s)):
  if s[i] == 'B':
    t = t[:-1]
  else:
    t += i
    
print(t)
Problem p04043 (python)

Fixed submission:
A,B,C=map(int,input().split())
if A*B*C == 5*5*7:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
if A*B*C == 5*5*7
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split)
if A+B+C == 17:
  print('YES')
else:
  print('NO)
Problem p02641 (python)

Fixed submission:
#!/usr/bin/env python3

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    if N == 100:
        print(0 if X<=50 else 101)
        exit()
    lst = [0] + list(set(range(1,101)) - p) + [101]
    lst2 = [abs(lst[i] - X) for i in range(len(lst))]
    min_ = min(lst2)
    print(lst[lst2.index(min_)])    



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    lst = set(range(1,101)) - p
    tmp = 130
    if min(lst) >= X:
        print(min(lst))
        exit()
    if max (lst) <= X:
        print(max(lst))
        exit()
    prev = min(lst)
    for s in lst:
        if abs(s - X) >= tmp:
            print(prev)
            exit()
        prev = s
        tmp = abs(s - X)
    print(max(lst))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    lst = set(range(1,101)) - p
    tmp = 130
    prev = min(lst)
    for s in lst:
        if abs(s - X) >= tmp:
            print(prev)
            exit()
        prev = s
        tmp = abs(s - X)
    print(max(lst))

if __name__ == '__main__':
    main()
Problem p02647 (python)

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

def s(n,a):
  b = [0]*n
  for i in range(n):
    l = max(0,i-a[i])
    r = min(n-1,i+a[i])
    b[l] += 1
    if r < n - 1:
      b[r+1] -= 1
  for i in range(n-1):
    b[i+1] += b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(*A)

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

def s(n,a):
  b = [0]*n
  for i in range(n):
    l = max(0,i-a[i])
    r = min(n-1,i+a[i])
    b[l] += 1
    if r < n - 1:
      b[r+1] -= 1
  for i in range(n):
    b[i+1] = b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(A)

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

def s(n,a):
  b = [0]*n
  for i in range(n):
    l = max(0,i-a[i])
    r = min(n-1,i+a[i])
    b[l] += 1
    if r < N - 1:
      b[r+1] -= 1
  for i in range(n):
    b[i+1] = b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(A)
Problem p02675 (python)

Fixed submission:
N = int(input()) % 10

hon = {2, 4, 5, 7, 9}
pon = {0, 1, 6, 8}
bon = {3}

if N in hon:
  print("hon")
if N in pon:
  print("pon")
if N in bon:
  print("bon")

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

if len(S) <=K:
  print(S)
else:a
  print(S[:K] + "...")
Problem p02681 (python)

Fixed submission:
s = input()
t = input()

if t[:-1] == s:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,K = map(int,input().split())

def solve(a,b,c,k):
  s = 0
  while k > 0:
    if a > 0:
      a -= 1
      s += 1
      k -= 1
    elif b > 0:
      b -= 1
      k -= 1
    else:
      c -= 1
      s -= 1
      k -= 1

  return s
    
print(solve(A,B,C,K))
Problem p02684 (python)

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

journey = [1]

for i in range(2*N+1000):
    nxt = a[journey[-1]]
    journey.append(nxt)

if K <= N:
    print(journey[K])
    exit()

loop_start = N-1
loop_end   = N
 
while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1
    
period = loop_end - loop_start

K %= period
while K < N:
  K += period

print(journey[K])

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
a = [0] + list(map(int,input().split()))

journey = [1]

for i in range(N+1000):
    nxt = a[journey[-1]]
    journey.append(nxt)

if K <= N:
    print(journey[K])
    exit()

loop_start = N-1
loop_end   = N
 
while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1
    
period = loop_end - loop_start

K %= period
while K < N:
  K += period

print(journey[K])

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
a = [0] + list(map(int,input().split()))

journey = [1]

for i in range(N):
    nxt = a[journey[-1]]
    journey.append(nxt)

if K < N:
    print(journey[K])
    exit()

loop_start = N-1
loop_end   = N

finished = False
for i in range(1,N):
    for j in range(i+1,N+1):
        if journey[i] == journey[j]:
            loop_start = i
            loop_end   = j
            finished = True
            break
    if finished:
        break

period = loop_end - loop_start

K %= period
while K < period:
  K += period

print(journey[K])

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
a = [0] + list(map(int,input().split()))

journey = [1]

for i in range(N):
    nxt = a[journey[-1]]
    journey.append(nxt)

if K < N:
    print(journey[K])
    exit()

loop_start = N-1
loop_end   = N

finished = False
for i in range(1,N):
    for j in range(i+1,N+1):
        if journey[i] == journey[j]:
            loop_start = i
            loop_end   = j
            finished = True
            break
    if finished:
        break

period = loop_end - loop_start

ans = K % period
while ans < period:
  ans += period

print(journey[ans])

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
a = [0] + list(map(int,input().split()))

journey = [1]

for i in range(N):
    nxt = a[journey[-1]]
    journey.append(nxt)

if K < N:
    print(journey[K])
    exit()

loop_start = N-1
loop_end   = N

finished = False
for i in range(N):
    for j in range(i,N+1):
        if journey[i] == journey[j]:
            loop_start = i
            loop_end   = j
            finished = True
            break
    if finished:
        break

period = loop_end - loop_start

ans = (K - loop_start) % period
print(ans)