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

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, *A = map(int, open(0))
    A.sort()
    ans = 0
    if N % 2 == 1:
        ans += sum(A[N//2:])*2 - sum(A[:N//2])*2
        ans -= A[N//2]+A[N//2+1]
    else:
        ans += sum(A[N//2:])*2 - sum(A[:N//2])*2
        ans -= A[N//2]-A[N//2-1]
    

    ans2 = 0
    if N % 2 == 1:
        ans2 += sum(A[N//2+1:])*2 - sum(A[:N//2+1])*2
        ans2 += A[N//2]+A[N//2-1]
    else:
        ans2 += sum(A[N//2:])*2 - sum(A[:N//2])*2
        ans2 += A[N//2-1]-A[N//2]

    print(max(ans,ans2))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, *A = map(int, open(0))
    A.sort()
    ans = 0
    if N % 2 == 1:
        ans += sum(A[N//2:])*2 - sum(A[:N//2])*2
        ans -= A[N//2]+A[N//2+1]
    else:
        ans += sum(A[N//2:])*2 - sum(A[:N//2])*2
        ans -= A[N//2]-A[N//2-1]
    

    ans2 = 0
    if N % 2 == 1:
        ans2 += sum(A[N//2+1:])*2 - sum(A[:N//2+1])*2
        ans2 += A[N//2]+A[N//2-1]
    else:
        ans2 += sum(A[N//2+1:])*2 - sum(A[:N//2+1])*2
        ans2 += A[N//2]-A[N//2+1]

    print(max(ans,ans2))

if __name__ == "__main__":
    main()
Problem p03241 (python)

Fixed submission:
#!/usr/bin/env python3
from bisect import bisect_left
from heapq import heappush

def cal_divisors(N):
    divisors = []
    i = 1
    while i*i <= N:
        if N % i == 0:
            divisors.append(i)
            if i != N // i:
                divisors.append(N//i)
        i += 1
    divisors.sort()
    return divisors

def main():
    N, M = map(int, input().split())
    ans = cal_divisors(M)
    # print(ans)
    i = bisect_left(ans,N)
    print(M//ans[i])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sympy
from bisect import bisect_left

def main():
    N, M = map(int, input().split())
    ans = sympy.divisors(M)
    i = bisect_left(ans,N)
    print(M//ans[i])

if __name__ == "__main__":
    main()
Problem p03260 (python)

Fixed submission:
A,B = map(int, input().split())
if A == 2 or B == 2:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
A,B = map(int, input(),split())
if A == 2 or B == 2:
  print('No')
else:
  print('Yes')
Problem p03262 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
import fractions

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    x = [abs(i - X) for i in x]
    if len(x) == 1:
        print(x[0])
        exit()
    
    ans = fractions.gcd(x[0], x[1])
    for i in range(2,N):
        ans = fractions.gcd(ans,x[i])

    print(ans)

if __name__ == '__main__':
    main()

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

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    x = [abs(i - X) for i in x]
    if len(x) == 1:
        print(x[0])
        exit()
    
    ans = math.gcd(x[0], x[1])
    for i in range(2,N):
        ans = math.gcd(ans,x[i])

    print(ans)

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

Fixed submission:
N=int(input())
ans=0
for i in range(1,N+1):
  count=0
  for j in range(1,i+1):
    if i%j==0:
      count+=1
  if i%2==1 and count==8:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ans=0
for i in range(N+1):
  count=0
  for j in range(i+1):
    if i%j==0:
      count+=1
  if i%2==1 and count==8:
    ans+=1
print(ans)
Problem p03323 (python)

Fixed submission:
A, B = map(int, input().split())
if A <= 8 and B <= 8:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if (A > 9 or B > 9):
    print(':(')
else:
    print('Yay!')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if (A > 9 or B > 9):
    print(':(')
else:
    print('Yay!')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A>9 or B>9:
  print ':('
else:
  print 'Yay!'

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if ((A > 9) or (B > 9)):
    print(':(')
else:
    print('Yay!')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if ((A < 9) and (B < 9)):
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if (A < 9) and (B < 9):
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A <9 and B < 9:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A <9 and B < 9:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A <9 and B < 9:
    print("Yay!")
else:
    print(":(")

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A <9 and B < 9:
    print("Yay!")
else:
    print(":(")
Problem p03351 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
print('Yes') if (abs(a-b)<=d and abs(b-c) <= d) or abs(a-c) <= d else print('No')

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
print('Yes') if (math.abs(a-b)<=d and math.abs(b-c) <= d) or math.abs(a-c) <= d else print('No')
Problem p03362 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right, bisect_left
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

# N以下の素数列挙(エラトステネスの篩)
def cal_primes(N):
    # 素数候補をリストでもつ
    candidate = [*range(2, N+1)]
    primes = []

    while candidate[0]**2 <= N:
        primes.append(candidate[0])
        candidate = [*filter(lambda x: x % candidate[0] != 0, candidate)]
    
    primes.extend(candidate)
    return primes

def main():
    N = int(input())
    primes = cal_primes(55555)
    primes = [*filter(lambda x: x % 5 == 1, primes)]
    
    print(*primes[:N])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right, bisect_left
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

# N以下の素数列挙(エラトステネスの篩)
def cal_primes(N):
    # 素数候補をリストでもつ
    candidate = [*range(2, N+1)]
    primes = []

    while candidate[0]**2 <= N:
        primes.append(candidate[0])
        candidate = [*filter(lambda x: x % candidate[0] != 0, candidate)]
    
    primes.extend(candidate)
    return primes

def main():
    N = int(input())
    primes = cal_primes(55555)
    ans = [2]
    
    for i in range(N-1):
        b = bisect_right(primes, ans[i]*2)
        ans.append(primes[b])
    print(*ans)


if __name__ == "__main__":
    main()
Problem p03393 (python)

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

def main():
    S = input()
    T = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) < 26:
        U = set(T) - set(S)
        print(S + sorted(U)[0])
    else:
        if S == T[::-1]:
            print(-1)
        else:
            count = 1
            for i in range(25):
                if S[25-i] > S[24-i]:
                    break
                else:
                    count += 1
            #print(S[26-count:])
            for s in sorted(S[26-count:]):
                if s > S[25-count]:
                    print(S[:25-count] + s)
                    exit()

if __name__ == '__main__':
    main()

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

def main():
    S = input()
    T = 'abcdefghijklmnopqrstuvwxyz'
    if len(S) < 26:
        U = set(T) - set(S)
        print(S + sorted(U)[0])
    else:
        if S == T[::-1]:
            print(-1)
        else:
            count = 1
            for i in range(25):
                if S[25-i] > S[24-i]:
                    break
                else:
                    count += 1
            t = T.index(S[25-count])
            print(S[:25-count] + T[t+1])

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

Fixed submission:
print(int(input()) // 3)

Buggy submission (verdict: Runtime Error):
import itertools
import math

N = int(input())
S_list = []
for i in range(N):
    S_list.append(input())

count_M = 0
count_A = 0
count_R = 0
count_C = 0
count_H = 0

for l in S_list:
    if l.startswith('M'):
        count_M += 1
    elif l.startswith('A'):
        count_A += 1
    elif l.startswith('R'):
        count_R += 1
    elif l.startswith('C'):
        count_C += 1
    elif l.startswith('H'):
        count_H += 1

count = [count_M,count_A,count_R,count_C,count_H]
a = sum(count)

x = a*(a-1)*(a-2)/math.factorial(3)

for c in count:
    if c > 2:
        x -= c*(c-1)*(c-2)/math.factorial(3)
    elif c == 2:
        x -= (a-2)

print(int(x))
Problem p03427 (python)

Fixed submission:
import sys
import math

def main():
    N = int(input())
    digit = int(math.log10(N))
    c = N // (10**digit)
    if N < int(str(c) + '9'*digit):
        print(9 * digit + c -1)
    else:
        print(9 * digit + c)

if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    digit = math.floor(math.log10(N))
    ans = [9 * digit]
    ans.append(sum([int(s) for s in str(N)]))
    
    for i in range(1, digit+1):
        tmp = [int(s) for s in str(N//(10**i) * (10**i) - 1)]
        ans.append(sum(tmp))
    print(max(ans))


if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    digit = math.floor(math.log10(N))
    ans = [9 * digit]
    ans.append(sum([int(s) for s in str(N)]))
    
    for i in range(1, digit+1):
        tmp = [int(s) for s in str(N//(10**i) * 10**i - 1)]
        ans.append(sum(tmp))
    print(max(ans))


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

Fixed submission:
X, Y = map(int, input().split())
if X % Y == 0:
  print(-1)
else:
  print(X)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input())
ans = X
while X <=10**18:
  if ans % Y != 0:
    print(ans)
    break
  else:
    ans += X
print(-1)
Problem p03455 (python)

Fixed submission:
a,b=map(int,input().split())
print('Odd')if a*b%2==1else print('Even')

Buggy submission (verdict: Runtime Error):
print('Odd')if (int(input())*int(input())%2)==1 else print('Even')

Buggy submission (verdict: Runtime Error):
print('Odd')if int(input())*int(input())%2==1else print('Even')
Problem p03472 (python)

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right,bisect_left
from itertools import accumulate

def main():
    N, H = map(int, input().split())
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = map(int, input().split())
    a.sort()
    b.sort()
    i = bisect_left(b,a[N-1])
    c = list(accumulate(b[i:][::-1]))
    # print(c)
    M = len(c)
    count = bisect_left(c,H)
    if count < M:
        print(count+1)
    else:
        print(count + (H-c[M-1] + a[N-1]-1)//a[N-1])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right,bisect_left
from itertools import accumulate

def main():
    N, H = map(int, input().split())
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = map(int, input().split())
    a.sort()
    b.sort()
    i = bisect_right(b,a[N-1])
    c = list(accumulate(b[i:][::-1]))
    # print(c)
    M = len(c)
    count = bisect_left(c,H)
    if count < M:
        print(count+1)
    else:
        print(count + (H-c[M-1] + a[N-1]-1)//a[N-1])

if __name__ == "__main__":
    main()
Problem p03473 (python)

Fixed submission:
print(48-int(input()))

Buggy submission (verdict: Runtime Error):
print(48-int(open(0)))
Problem p03477 (python)

Fixed submission:
l =list(map(int,input().split()));a=sum(l[:2])-sum(l[2:]);print('Left') if a>0 else print('Right')if a<0 else print('Balanced')

Buggy submission (verdict: Runtime Error):
l =map(int,input().split());a=sum(l[:2])-sum(l[3:]);print('Left') if a>0 else print('Right')if a<0 else print('Balanced')
Problem p03557 (python)

Fixed submission:
def binary_search(A,x,flag):
  start = 0
  end = len(A)-1
  
  while start < end:
    middle = (start + end) // 2
    if flag:# Aの時
      if A[middle] < x <= A[middle+1]:
        return middle + 1
      elif x <= A[middle]:
        end = middle
      else:
        start = middle + 1
    else:# Bの時
      if A[middle] <= x < A[middle+1]:
        return middle + 1
      elif x < A[middle]:
        end = middle
      else:
        start = middle + 1
  if end == 0: # 小さい
    return 0
  elif start == len(A)-1:
    return len(A)
        
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

# N=1はコーナーケース
if N == 1:
  print(1) if A[0] < B[0] < C[0] else print(0)
else:
  ans = 0
  for i in range(N):
    ans += binary_search(A,B[i],True)*(N-binary_search(C,B[i],False))#B[i]より小さいAの数とB[i]より大きいCの数の積
  print(ans)

Buggy submission (verdict: Runtime Error):
def binary_search(A,x,flag):
  start = 0
  end = len(A)-1
  
  while start < end:
    middle = (start + end) // 2
    if flag:# Aの時
      if A[middle] < x <= A[middle+1]:
        return middle + 1
      elif x <= A[middle]:
        end = middle
      else:
        start = middle + 1
    else:# Bの時
      if A[middle] <= x < A[middle+1]:
        return middle + 1
      elif x < A[middle]:
        end = middle
      else:
        start = middle + 1
    if end == 0: # 小さい
      return 0
    elif start == len(A)-1:
      return len(A)
        
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0

for i in range(N):
  ans += binary_search(A,B[i],True)*(N-binary_search(C,B[i],False))#B[i]より小さいAの数とB[i]より大きいCの数の積
print(ans)
Problem p03588 (python)

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    print(max(A)+B[A.index(max(A))])

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    print(max(A[i])+B.index(max(A[i])))

if __name__ == "__main__":
    main()
Problem p03597 (python)

Fixed submission:
a=open(0).read().split();print(int(a[0])**2-int(a[1]));

Buggy submission (verdict: Runtime Error):
a=open(0).read();print(int(a[0])**2-int(a[2]))
Problem p03651 (python)

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from fractions import gcd

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    
    if K > A[N-1]:
        print('IMPOSSIBLE')
    else:
        ans = 0
        for i in range(N):
            ans = gcd(ans,A[i])
            if ans == 1:
                print('POSSIBLE')
                exit()
        if (A[N-1]-K)%ans == 0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from math import gcd

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    
    if K > A[N-1]:
        print('IMPOSSIBLE')
    else:
        ans = 0
        for i in range(N):
            ans = gcd(ans,A[i])
            if ans == 1:
                print('POSSIBLE')
                exit()
        if (A[N-1]-K)%ans == 0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')


if __name__ == "__main__":
    main()
Problem p03657 (python)

Fixed submission:
A,B=map(int,input().split())
print('Possible') if A%3==0 or B%3==0 or(A+B)%3==0 else print('Impossible')

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
print('Possible') if A%3==0or B%3==0or(A+B)%3==0 else print('Impossible')
Problem p03671 (python)

Fixed submission:
l = list(map(int,input().split()))
print(sum(l)-max(l))

Buggy submission (verdict: Runtime Error):
l = list(map(int,input().split())
print(sum(l)-max(l))
Problem p03739 (python)

Fixed submission:
#!/usr/bin/env python3
from itertools import accumulate

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

    ans = 10**18

    for j in range(2):# 偶数行が正か奇数行が正
        ans2 = 0
        diff = 0
        for i in range(n):
            p = a[i] + diff
            # print(a[i],diff)
            if (i+j) % 2 == 0 and p <= 0:# 正になる
                ans2 += abs(p)+1
                diff += abs(p)+1
            elif (i+j) % 2 == 1 and p >= 0:# 負になる
                ans2 += abs(p)+1
                diff -= abs(p)+1

        ans = min(ans, ans2)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from itertools import accumulate

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = list(accumulate(a))
    
    if a[0] != 0:
        ans = 0
        diff = 0
        for i in range(1,n):
            p = a[i] + diff
            q = a[i-1] + diff
            if p * q >= 0:
                tmp = -q//abs(q) - p
                ans += abs(tmp)
                diff += tmp
        print(ans)
    else:
        ans = 10**18
        for d in [-1,1]:
            ans2 = 1
            for i in range(1,n):
                p = a[i] + d
                q = a[i-1] + d
                if p * q >= 0:
                    tmp = -q//abs(q) - p
                    ans2 += abs(tmp)
                    diff += tmp
            ans = min(ans, ans2)
        print(ans)

if __name__ == "__main__":
    main()
Problem p03943 (python)

Fixed submission:
a,b,c=map(int,input().split())
print('Yes')if a+b+c == max(a,b,c)*2 else print('No')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split())
print('Yes')if sum(a,b,c) == max(a,b,c)*2 else print('No')
Problem p03957 (python)

Fixed submission:
S = input()
a= S.find('C')
b= S.find('F',a+1)
print('Yes') if a>=0 and b>=0 and a<b else print('No')

Buggy submission (verdict: Runtime Error):
S = input()
a,b= S.find('C'),S.find('F')
print('Yes') if a>0 and b>0 and> a<b else print('No')
Problem p03992 (python)

Fixed submission:
S = input()
print(S[:4]+' '+S[4:])

Buggy submission (verdict: Runtime Error):
s = input()
print(S[:4]+' '+S[4:])
Problem p04013 (python)

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


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = 50
    dp = [[[0]*(N*X +1) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for j in range(1,N+1):
        for k in range(N+1):
            for s in range(N*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()

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


def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))
    X = max(x)
    dp = [[[0]*(N*X +1) for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 1
    for j in range(1,N+1):
        for k in range(N+1):
            for s in range(N*X+1):
                if s >= x[j-1] and k >= 1:
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j-1]]
                else:# x[j]を選ぶと合計sにできない
                    dp[j][k][s] = dp[j-1][k][s]
    ans = 0
    for i in range(N):
        ans += dp[N][i+1][(i+1)*A]
    print(ans)

if __name__ == "__main__":
    main()
Problem p02628 (python)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k]))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
print(sum(l[:k])
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=2
t=0
path=[]
s=set()
cycle=[]
while(c<=k):
    if a[t] in s:
        #print(path.index(a[t]),a[t])
        cycle=path[path.index(a[t]):]
        k-=c-1
        break
    path.append(a[t])
    s.add(a[t])
    t=a[t]-1
    c+=1
if cycle==[]:
    print(a[t])
else:
    print(cycle[k%len(cycle)])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=1
t=0
path=[]
s=set()
cycle=[]
while(c<=k):
    c+=1
    if a[t] in s:
        #print(path.index(a[t]),a[t])
        cycle=path[path.index(a[t]):]
        k-=c-1
        break
    path.append(a[t])
    s.add(a[t])
    t=a[t]-1
    #print(path,c)
#print(cycle)
print(cycle[k%len(cycle)])
Problem p03160 (python)

Fixed submission:
n=int(input())
f=[0]*n
a=list(map(int,input().split()))
f[0]=0
f[1]=abs(a[0]-a[1])
for i in range(2,n):
    a1=abs(a[i]-a[i-2])
    b=abs(a[i]-a[i-1])
    f[i]=min((f[i-2]+a1),(f[i-1]+b))
print(f[n-1])

Buggy submission (verdict: Runtime Error):
def maxreturn(t,n,a):
    ma=[0]*3
    b=[0]*n
    if t==n-1:
        for i in range(3):
           ma[i]=a[n-1][i]
    else:
      b=list(maxreturn(t+1,n,a))
      for i in range(3):
        for j in range(3):
            if i!=j:
                ma[i]=max(ma[i],a[t][i]+b[j])
                
    return ma
n=int(input())
a=[[0]*3]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
ma=maxreturn(0,n,a)
print(max(ma))