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

Fixed submission:
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    a, b = rli()
    if (a + b) % 2 == 1:
        print("IMPOSSIBLE")
    else:
        print((a+b) // 2)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

from collections import namedtuple

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def dist(pf, pt):
    return abs(pf[0]-pt[0]) + abs(pf[1]-pt[1])

def print_ans(sx, sy, ans):
    print(len(ans))
    for p in ans:
        print(sx*p[0], sy*p[1])

def move(k, pf, pt):
    assert(pt[1]>pf[1])
    d = min(pt[0]-pf[0], k)
    return [pf[0]+d,pf[1]+k-d]

def main():
    k = ri()
    x, y = rli()
    sx = 1 if x >= 0 else -1
    sy = 1 if y >= 0 else -1
    x = abs(x)
    y = abs(y)

    pf = [0, 0]
    pt = [x, y]
    if k % 2 == 0 and (x+y) % 2 == 1:
        print(-1)
        return
    d = dist(pf, pt)

    ans = []

    # 3回で到達
    if d < k and d % 2 == 1:
        ans.append(((x+y-k)//2, (k+x+y)//2))
        ans.append((x+y-k, 0))
        ans.append((x, y))
        print_ans(sx, sy, ans)
        return

    n = (x+y+k-1) // k
    d = (n*k-(x+y))//2
    if d > 0:
        pf = [k-d, -d]
        ans.append(tuple(pf))
    while dist(pf, pt) > 0:
        pf = move(k, pf, pt)
        ans.append(tuple(pf))
    print_ans(sx, sy, ans)
    assert(pf[0] == x and pf[1] == y)



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

Fixed submission:
#!/usr/bin/env python
# coding: utf-8

import fractions

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def calc(n, x):
    return n // x

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

def main():
    a, b, c, d = rli()
    lcm_cd = lcm(c, d)
    n_a = a-1 - calc(a-1, c) - calc(a-1, d) + calc(a-1, lcm_cd)
    n_b = b - calc(b, c) - calc(b, d) + calc(b, lcm_cd)
    print(n_b-n_a)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def calc(n, x):
    return n // x

def lcm(a, b):
    return (a * b) // math.gcd(a, b)

def main():
    a, b, c, d = rli()
    lcm_cd = lcm(c, d)
    n_a = a-1 - calc(a-1, c) - calc(a-1, d) + calc(a-1, lcm_cd)
    n_b = b - calc(b, c) - calc(b, d) + calc(b, lcm_cd)
    print(n_b-n_a)


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

Fixed submission:
#!/usr/bin/env python
# coding: utf-8

from collections import Counter

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lx, ly = [], []
    for _ in range(n):
        x, y = rli()
        lx.append(x)
        ly.append(y)
    dd = {}
    dc = Counter()
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            d = (lx[i]-lx[j], ly[i]-ly[j])
            dd[(i, j)] = d
            dc[d] += 1
    if len(dc) == 0:
        print(n)
    else:
        v = dc.most_common()[0][1]
        print(n-v)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

from collections import Counter

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lx, ly = [], []
    for _ in range(n):
        x, y = rli()
        lx.append(x)
        ly.append(y)
    dd = {}
    dc = Counter()
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            d = (lx[i]-lx[j], ly[i]-ly[j])
            dd[(i, j)] = d
            dc[d] += 1
    v = dc.most_common()[0][1]
    print(n-v)


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

Fixed submission:
#!/usr/bin/env python
# coding: utf-8

def main():
    n = int(input())
    g = [dict() for _ in range(n)]
    for _ in range(n-1):
        u, v, w = list(map(int, input().split()))
        g[u-1][v-1] = w
        g[v-1][u-1] = w
    dist = [-1 for _ in range(n)]
    dist[0] = 0
    q = [0]
    while len(q) > 0:
        f = q.pop()
        for t in g[f]:
            if dist[t] != -1:
                continue
            dist[t] = dist[f] + g[f][t]
            q.append(t)
    for i in range(n):
        if dist[i] % 2 == 0:
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

import sys
sys.setrecursionlimit(10000)

def paint(k, same, diff, visited, csame, cdiff):
    if k in visited:
        return
    if k in same:
        return
    csame.add(k)
    visited.add(k)
    if k in diff:
        for e in diff[k]:
            if e in visited:
                continue
            paint(e, same, diff, visited, cdiff, csame)
    if k in same:
        for e in same[k]:
            if e in visited:
                continue
            paint(e, same, diff, visited, csame, cdiff)

def main():
    n = int(input())
    same = {}
    diff = {}
    for _ in range(n-1):
        u, v, w = list(map(int, input().split()))
        if w % 2 == 0:
            same.setdefault(u, [])
            same.setdefault(v, [])
            same[u].append(v)
            same[v].append(u)
        else:
            diff.setdefault(u, [])
            diff.setdefault(v, [])
            diff[u].append(v)
            diff[v].append(u)
    white = set()
    black = set()
    visited = set()
    for k in diff:
        paint(k, same, diff, visited, white, black)
    ret = []
    for i in range(n):
        if i+1 in white:
            ret.append("0")
        else:
            ret.append("1")
    print("\n".join(ret))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

import math

def paint(k, v, diff, visited, same, opposite):
    if k in visited:
        return
    if k in same:
        return
    same.add(k)
    visited.add(k)
    for e in v:
        if e in visited:
            continue
        paint(e, diff[e], diff, visited, opposite, same)

def main():
    n = int(input())
    diff = {}
    for _ in range(n-1):
        u, v, w = list(map(int, input().split()))
        if w % 2 == 1:
            diff.setdefault(u, [])
            diff.setdefault(v, [])
            diff[u].append(v)
            diff[v].append(u)
    white = set()
    black = set()
    visited = set()
    for k in diff:
        paint(k, diff[k], diff, visited, white, black)
    ret = []
    for i in range(n):
        if i+1 in white:
            ret.append("0")
        else:
            ret.append("1")
    print("\n".join(ret))


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

Fixed submission:
#!/usr/bin/env python
# coding: utf-8


def main():
    n = int(input())
    a = int(input())
    print(n*n-a)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

def main():
    A, B, C, D, E, F = [int(x) for x in input().split()]
    max_rate = E / (100 + E)
    best_weight, best_suger, best_rate = A*100, 0, 0.0
    for a in range(F//100 +1):
        for b in range((F-a*A)//100 + 1):
            water = (a*A+b*B)*100
            if water > F:
                continue
            for c in range((F-water)//C + 1):
                d = min((F - water - c*C) // D, int((E*water-100*c*C) / (100*D)))
                if d < 0:
                    continue
                suger = c*C + d*D
                if water + suger > F:
                    continue
                if water + suger == 0:
                    rate = 0.0
                else:
                    rate = suger / (water + suger)
                if rate > max_rate:
                    continue
                if rate > best_rate:
                    best_weight = water + suger
                    best_suger = suger
                    best_rate = rate
    print(best_weight, best_suger)

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

Fixed submission:
for i in range(int(input())):
  print('ACL', end ='')
print()

Buggy submission (verdict: Runtime Error):
for i in range(int(intput())):
  print('ACL', end ='')
print()
Problem p02628 (python)

Fixed submission:
no, sct = map(int, input().split(' '))
flut = list(map(int, input().split(' ')))
flut = sorted(flut, reverse=False)
sum_ = 0
for i in range(sct):
  sum_ += flut[i]
print(sum_)

Buggy submission (verdict: Runtime Error):
def num2alpha(num):
    if num<=26:
        return chr(97+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(97+num%26)

if __name__ == '__main__':
  n = int(input())
  print(num2alpha(n))
Problem p02640 (python)

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

x = (legs - 2*n)/2
y = (4*n - legs)/2

if x%1==0 and y%1==0 and (x>=0 and y>=0):
  print('Yes')
else:
  print('No')

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

x = (legs - 2*n)/2
y = (4*n - legs)/2

if X%1==0 and y%1==0 and x>0 and y>0:
  print('Yes')
else:
  print('No')
Problem p02641 (python)

Fixed submission:
x, N = map(int, input().split(" "))
try:
  data = list(map(int, input().split(" ")))
except:
  data = []
point = 0
i = 0
while(1):
    if x not in data:
        print(x)
        break
    elif x+i not in data:
        print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
        i=i-1

Buggy submission (verdict: Runtime Error):
x, N = map(int, input().split(" "))
data = list(map(int, input().split(" ")))
point = 0
i = 0
while(1):
    if x not in data:
        print(x)
        break
    elif x+i not in data:
        print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
        i=i-1

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split(" "))
data = list(map(int, input().split(" ")))
point = 0
i = -1
while(1):
    if x not in data:
        print(x)
        break
    elif x+i not in data:
        print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
        i=i-1

Buggy submission (verdict: Runtime Error):
X, N = map(int, input().split(" "))
data = list(map(int, input().split(" ")))
point = 0
i = -1
while(1){
	if x not in data:
  		print(x)
  		break;
  	elif x+i not in data:
  		print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
  		i=i-1  
}
Problem p02646 (python)

Fixed submission:
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())

diff_x=abs(A-B)
diff_a=max(V-W,0)

if T*diff_a>=diff_x:
  print('YES')
else:
  print('NO')

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

a_st = 0
a_ed = 0
if a < a_v*t:
  a_st = a
  a_ed = a+a_v*t
else:
  a_st = a+a_v*t
  a_ed = a

b_st = 0
b_ed = 0
if b < b_v*t:
  b_st = b
  b_ed = b+b_v*t
else:
  b_st = b+b_v*t
  b_ed = b

v=a_v-b_v
if (a_st-b_st)%v == 0 or (a_ed-b_ed)%v==0 or (a_st-b_ed)%v==0 or (b_st-a_ed):
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
a, a_v = map(int, input().split())
b, b_v = map(int, input().split())
t = int(input())
flag=0
t_set = 0

if a-b==0 and a_v-b_v == 0:
  flag = 1
elif a-b==0 or a_v-b_v == 0:
  flag = 0
else:
  t_set = (a-b)/(b_v - a_v)

if t_set>0:
    if int(t_set)==0:
      	flag = 1
	elif 0<t_set and t_set<=t:
  		flag = 1
	else:
  		flag = 0
        
if flag == 0:
  print('No')
else:
  print('Yes')
Problem p02675 (python)

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

Buggy submission (verdict: Runtime Error):
n = int(input())
if n[-1] in [1, 4, 5, 7, 9] :
	print("hon")
elif n[-1] in [0, 1, 6, 8]:
  print("pon")
else:
  print("bon")
Problem p02694 (python)

Fixed submission:
num = int(input())
year = 0
cash = 100
while(True):
  cash += int(cash/100)
  year+=1
  if(num <= cash):
    print(year)
    break

Buggy submission (verdict: Runtime Error):
num = int(input())
year = 0
cash = 100
while(True){
	cash += int(cash/100)
  	year++
	if(num < cash):
  		print(year)
  		break
	}
Problem p02713 (python)

Fixed submission:
n = int(input())
 
from math import gcd
 
y = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        x = gcd(i, j)
        for k in range(1, n+1):
            y += gcd(x,k)
 
print(y)

Buggy submission (verdict: Runtime Error):
import copy
K=int(input)
primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]
yakusuu_array=[]
for i in range(200):
  i+=1
  tmp=[]
  while i!=1:
    for prime in primes:
      if i % prime ==0:
        tmp.append(prime)
        i//=prime
  yakusuu_array.append(tmp)


def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
    return x

ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        x=gcd(i,j)
        for k in range(1,K+1):
            ans+=gcd(x,k)
print(ans)
Problem p02885 (python)

Fixed submission:
data = input()
print(max(int(data.split(' ')[0])-int(data.split(' ')[1])*2,0))

Buggy submission (verdict: Runtime Error):
import itertools
num = int(input())
cmlist = input().split(' ')
count = 0
for i,j,k in itertools.combinations(cmlist, 3):
  if int(i)<int(j)+int(k) and int(j)<int(i)+int(k) and int(k)<int(i)+int(j):
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
data = input()
if data.split(' ')[0] > data.split(' ')[1]*2:
	print(0)
else:
  print(int(data.split(' ')[0]-data.split(' ')[1]*2)
Problem p02641 (python)

Fixed submission:
X, N = map(int,input().split())
L = list(map(int,input().split()))

NL = []
for i in range(102):
    NL.append(i)

for l in L:
    NL.remove(l)

NL.append(X)
NL.sort()

LR = NL.index(X)+1
LL = NL.index(X)-1


if (NL[LR]-X) < (X-NL[LL]):
    print(NL[LR])
else:
    print(NL[LL])

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

NL = []
for i in range(100):
    NL.append(i+1)

for l in L:
    NL.remove(l)

NL.append(X)
NL.sort()

LR = NL.index(X)+1
LL = NL.index(X)-1


if (NL[LR]-X) < (X-NL[LL]):
    print(NL[LR])
else:
    print(NL[LL])
Problem p02602 (python)

Fixed submission:
n,k=map(int, input().split())
a=list(map(int, input().split()))
for i in range(n-k):
    if a[i]<a[i+k]:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n,k=map(int, Input.split())
a=list(map(int, Input.split()))
for i in range(n-k):
    if a[i]<a[i+k]:
        print("Yes")
    else:
        print("No")
Problem p03408 (python)

Fixed submission:
n=int(input())
s=[input() for i in range(n)]
m=int(input())
t=[input() for i in range(m)]

print(max(0,max(s.count(i)-t.count(i) for i in set(s))))

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

print(max(0,max(s.count(i)-t.count(i) for i in set(s))))
Problem p03760 (python)

Fixed submission:
o=list(input())
e=input()
for i in range(len(e)):
    o.insert(2*i+1,e[i])
print(*o,sep="")

Buggy submission (verdict: Runtime Error):
o=input()
e=input()
for i in range(len(o)):
    print(o[i],end="")
    print(e[i],end="")
Problem p04011 (python)

Fixed submission:
n,k,x,y=[int(input()) for i in range(4)]
if n<=k:
    print(n*x)
else:
    print(k*x+(n-k)*y)

Buggy submission (verdict: Runtime Error):
n,k,x,y=[int(input()) for i in range(n)]
if k<=x:
    print(n*k)
else:
    print(k*x+(n-k)*y)
Problem p02885 (python)

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

if A <= 2*B:
  print(int(0))
else:
  print(A-2*B)

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(N):
  for j in range(i+1, N):
    min_sum = L[i]+L[j]
    more_than = bisect.bisect_left(L[j+1:], min_sum)
    ans += more_than
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
 
def solve2():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            min_sum = L[i]+L[j]
            more_than = bisect.bisect_left(L[j+1:], min_sum)
            ans += more_than
    print(ans)
 
 
solve2()
Problem p02888 (python)

Fixed submission:
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)

Buggy submission (verdict: Runtime Error):
mport bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
 
def solve2():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            min_sum = L[i]+L[j]
            more_than = bisect.bisect_left(L[j+1:], min_sum)
            ans += more_than
    print(ans)
 
 
solve2()
Problem p02945 (python)

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

print(max(a+b,a*b,a-b))

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

print(max(a+b,a*b,a-b,a/b))
Problem p02630 (python)

Fixed submission:
import sys, math

def calcSum(AList, B, C, Sum):
    Len = AList[B]
    if(Len == 0):
        return Sum
    Sum += (C-B) * Len

    AList[B] = 0
    AList[C] += Len
    return Sum

if(__name__ == "__main__"):
    N= int( input().strip() )

    Max = int(10**5)+1
    AList = [0] * Max
    A_str = input().strip().split()
    N_Queries = int( input().strip() )

    sum = 0
    for i in range(N):
        value = int(A_str[i])
        AList[value] += 1
        sum += value
    BCs = []
    Sums = [sum]
    for i in range(N_Queries):
        BC_str =  input().strip().split()
        B = int(BC_str[0])
        C = int(BC_str[1])
        Sums.append( calcSum(AList, B, C, Sums[-1]) )
        """
        BC = [ int(BC_str[0]), int(BC_str[1]) ]
        BCs.append(BC)
        """

    for i in range(1, 1+N_Queries):
        print(Sums[i])

Buggy submission (verdict: Runtime Error):
import sys, math

def calcSum(AList, B, C, Sum):
    Len = AList[B]
    if(Len == 0):
        return Sum
    Sum += (C-B) * Len

    AList[B] = 0
    AList[C] += Len
    return Sum

if(__name__ == "__main__"):



    N= int( input().strip() )

    Max = 10**5
    AList = [0] * Max
    A_str = input().strip().split()
    N_Queries = int( input().strip() )

    sum = 0
    for i in range(N):
        value = int(A_str[i])
        AList[value] += 1
        sum += value
    BCs = []
    Sums = [sum]
    for i in range(N_Queries):
        BC_str =  input().strip().split()
        B = int(BC_str[0])
        C = int(BC_str[1])
        Sums.append( calcSum(AList, B, C, Sums[-1]) )
        """
        BC = [ int(BC_str[0]), int(BC_str[1]) ]
        BCs.append(BC)
        """

    for i in range(1, 1+N_Queries):
        print(Sums[i])

Buggy submission (verdict: Runtime Error):
import sys, math

def calcSum(AList, B, C, Sum):
    Len = AList[B]
    Sum += (C-B) * Len

    AList[B] = 0
    AList[C] += Len
    return Sum

if(__name__ == "__main__"):

    

    N= int( input().strip() )

    Max = 10**5
    AList = [0] * Max
    A_str = input().strip().split()
    N_Queries = int( input().strip() )

    sum = 0
    for i in range(N):
        value = int(A_str[i])
        AList[value] += 1
        sum += value
    BCs = []
    for i in range(N_Queries):
        BC_str =  input().strip().split()
        BC = [ int(BC_str[0]), int(BC_str[1]) ]
        BCs.append(BC)

    for i in range(N_Queries):
        B= BCs[i][0]
        C= BCs[i][1]
        sum = calcSum(AList, B, C, sum)
        print(sum)
Problem p02641 (python)

Fixed submission:
import sys

def prepare(X):
    N = 101
    List = [X] * N
    for i in range(0, 50):
        List[2*i+1] = X-i-1
        List[2*i+2] = X+i+1
    return List

def remove(List, N, PList):
    for Num in range(N):
        if(PList[Num] in List):
            List.pop( List.index(PList[Num]) )
    print(List[0])
if(__name__ == "__main__"):

    XY = input().strip().split()
    X = int(XY[0])
    N = int(XY[1])

    PList = [0] * N
    if(N > 0):
        P_str = input().strip().split()

        for i in range(N):
            PList[i] = int( P_str[i] )

        List = prepare(X)
        remove(List, N, PList)
    else:
        print(X)

Buggy submission (verdict: Runtime Error):
import sys

def prepare(X):
    N = 101
    List = [X] * N
    for i in range(0, 50):
        List[2*i+1] -= i+1
        List[2*i+2] += i+1
    return List

def remove(List, N, PList):
    for Num in range(N):
        List.pop( List.index(PList[Num]) )
    print(List[0])
if(__name__ == "__main__"):

    XY = input().strip().split()
    X = int(XY[0])
    N = int(XY[1])

    PList = [0] * N
    if(N > 0):
        P_str = input().strip().split()

        for i in range(N):
            PList[i] = int( P_str[i] )

        List = prepare(X)
        remove(List, N, PList)
    else:
        print(X)
Problem p02684 (python)

Fixed submission:
n,k = map(int, input().split())
l = [0]+list(map(int, input().split()))

journey = [1]

for i in range(2*n):
    next = l[journey[-1]]
    journey.append(next)
if k <= n+1:
    print(journey[k])
    exit()

end = n
start = n-1

while journey[start] != journey[end]:
    start -= 1

period = end - start
k %= period

while k < n:
    k += period

print(journey[k])

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

l = list(map(int, input().split()))

city = 1
l2 = [1]
while True:
    city = l[city-1]
    if city in l2:
        break
    l2.append(city)
first = l2.index(city)
if len(l2) <= k:
    if city == l2[-1]:
        print(city)
    elif city == l2[city]:
        print(city)
    else:
        l2 = l2[first:]
        print(l2[(k-first)%(len(l2))])
else:
    print(l2[k])
Problem p02730 (python)

Fixed submission:
S = []
S_reverse = []
S_first = []
S_first_reverse = []
S_last = []
S_last_reverse = []

S = list(input())
S_reverse = S.copy()
S_reverse.reverse()
S_first = S[:len(S)//2]
S_last = S[(len(S)+1)//2:]
S_first_reverse = S_first.copy()
S_first_reverse.reverse()
S_last_reverse = S_last.copy()
S_last_reverse.reverse()


if S != S_reverse:
    print("No")
elif S_first == S_first_reverse and S_last == S_last_reverse:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
akacaka
S = []
S_reverse = []
S_first = []
S_first_reverse = []
S_last = []
S_last_reverse = []

S = list(input())
S_reverse = S.copy()
S_reverse.reverse()
S_first = S[:len(S)//2]
S_last = S[(len(S)+1)//2:]
S_first_reverse = S_first.copy()
S_first_reverse.reverse()
S_last_reverse = S_last.copy()
S_last_reverse.reverse()


if S != S_reverse:
    print("No")
elif S_first == S_first_reverse and S_last == S_last_reverse:
    print("Yes")
else:
    print("No")