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

Fixed submission:
import sys
N, T = map(int, sys.stdin.readline().split(" "))
roots = [tuple(map(int, sys.stdin.readline().split(" "))) for i in range(N)]

from operator import itemgetter
#roots = sorted(roots, key=lambda x:x[1])
roots = (sorted(roots, key=itemgetter(1, 0)))

def dfs(i, csum, tsum):
    if tsum + roots[i][1] <= T:
        if i+1 == N:
          return csum + roots[i][0]
        else:
          return dfs(i+1, csum+roots[i][0], tsum+roots[i][1])
    else:
        return 100000000 if csum == 0 else csum

ans = 100000000
for ii in range(N):
  csum = dfs(ii, 0, 0)
  if ans > csum:
    ans = csum
  if csum == 100000000:
    is_do = False
    break

if ans == 100000000:
    print('TLE')
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N, T = map(int, sys.stdin.readline().split(" "))
roots = [tuple(map(int, sys.stdin.readline().split(" "))) for i in range(N)]

from operator import itemgetter
#roots = sorted(roots, key=lambda x:x[1])
roots = (sorted(roots, key=itemgetter(1, 0)))

def dfs(i, csum, tsum):
    if tsum + roots[i][1] <= T:
        return dfs(i+1, csum+roots[i][0], tsum+roots[i][1])
    else:
        return 100000000 if csum == 0 else csum

ans = 100000000
for ii in range(len(roots)):
  csum = dfs(ii, 0, 0)
  if ans > csum:
    ans = csum
  if csum == 100000000:
    is_do = False
    break

if ans == 100000000:
    print('TLE')
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split(" "))
roots = [tuple(map(int, input().split(" "))) for i in range(N)]
roots = sorted(roots, key=lambda x:x[1])

is_do = True
def dfs(i, csum, tsum):
    if tsum + roots[i][1] <= T:
        return dfs(i+1, csum+roots[i][0], tsum+roots[i][1])
    else:
        return 100000000 if csum == 0 else csum

ans = 100000000
for i in range(len(roots)):
  csum = dfs(i, 0, 0)
  if ans > csum:
    ans = csum
  if csum == 100000000:
    is_do = False

if ans == 100000000:
    print('TLE')
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split(" "))
roots = [tuple(map(int, input().split(" "))) for i in range(N)]
roots = sorted(roots, key=lambda x:x[1])

def dfs(i, csum, tsum):
    c, t = roots[i]

    if tsum + t <= T:
        return dfs(i+1, csum+c, tsum+t)
    else:
        return csum

import numpy as np
clist = np.array([dfs(i, 0, 0) for i in range(len(roots))])
nzclist = clist[np.nonzero(clist)]
if len(nzclist) == 0:
    print('TLE')
else:
    print(min(nzclist))

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split(" "))
roots = [tuple(map(int, input().split(" "))) for i in range(N)]
roots = sorted(roots, key=lambda x:x[1])

ans = 1000000000
for i in range(len(roots)):
  ii = i
  csum = 0
  tsum = 0
  
  while True:
    c, t = roots[ii]
    tsum += t

    if T >= tsum:
      ii += 1
      csum += c
    else:
      break
    
  if ans > csum and csum != 0:
      ans = csum
  else:
      tsum = 0
      break

print('TLE' if ans == 1000000000 else ans)
Problem p03244 (python)

Fixed submission:
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  if cmc1[0][0] == cmc2[0][0]:    
    ans1 = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[1][1])
    ans2 = (len(v1) - cmc1[1][1]) + (len(v2) - cmc2[0][1])
    print(min(ans1, ans2))
  else:
    ans = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[0][1])
    print(ans)

Buggy submission (verdict: Runtime Error):
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cl1 = collections.Counter(v1)
  cl2 = collections.Counter(v2)
  
  cmc_1st_1 = cl1.most_common()[0][1]
  cmc_1st_2 = cl2.most_common()[0][1]
  
  if cmc_1st_1 == cmc_1st_2:
    cmc_2nd_1 = cl1.most_common()[1][1]
    cmc_2nd_2 = cl2.most_common()[1][1] 
    
    if cmc_2nd_1 > cmc_2nd_2:
      ans = len(v1) - cmc_2nd_1
      ans += len(v2) - cmc_1st_2
    else:
      ans = len(v1) - cmc_1st_1
      ans += len(v2) - cmc_2nd_2
  else:
    ans = len(v1) - cmc_1st_1
    ans += len(v2) - cmc_1st_2
  
  print(ans)

Buggy submission (verdict: Runtime Error):
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cl1 = collections.Counter(v1)
  cl2 = collections.Counter(v2)
  
  cmc_1st_1 = cl1.most_common()[0][1]
  cmc_1st_2 = cl2.most_common()[0][1]
  cmc_2nd_1 = cl1.most_common()[1][1]
  cmc_2nd_2 = cl2.most_common()[1][1] 
  
  if cmc_1st_1 == cmc_1st_2:
    if cmc_2nd_1 > cmc_2nd_2:
      ans = len(v1) - cmc_2nd_1
      ans += len(v2) - cmc_1st_2
    else:
      ans = len(v1) - cmc_1st_1
      ans += len(v2) - cmc_2nd_2
  else:
    ans = len(v1) - cmc_1st_1
    ans += len(v2) - cmc_1st_2
  
  print(ans)
Problem p03449 (python)

Fixed submission:
import numpy as np

N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
 
ma = -np.inf
for i in range(N-1):
  if sum(A1[:i+1]) + sum(A2[i:]) > ma:
    ma = sum(A1[:i+1]) + sum(A2[i:])
    
if N == 1:
  ma = A1[0] + A2[0]
  
print(ma)

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

ma = -np.inf
for i in range(N-1):
  if sum(A1[:i+1]) + sum(A2[i:]) > ma:
    ma = sum(A1[:i+1]) + sum(A2[i:])
    
if N == 1:
  ma = A1[0] + A2[0]
  
print(ma)

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


ma = -np.inf
for i in range(N-1):
  if sum(A1[:i+1]) + sum(A2[i:]) > ma:
    ma = sum(A1[:i+1]) + sum(A2[i:])

  if N == 1:
    ma = A1[0] + A2[0]

print(ma)
Problem p03612 (python)

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

ans = 0
for i, _ in enumerate(p[:-1]):
    #print(p_, i+1)
    p_ = p[i]
    if p_ == i + 1:
        ans += 1
        p[i], p[i+1] = p[i+1], p[i]

if p[-1] == n:
  ans += 1
        
print(ans)

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

ans = 0
for i, _ in enumerate(p[:-1]):
    #print(p_, i+1)
    p_ = p[i]
    if p_ == i + 1:
        ans += 1
        p[i], p[i+1] = p[i+1], p[i]

if p[-1] = N:
  ans += 1
        
print(ans)
Problem p03633 (python)

Fixed submission:
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np
import functools
 
#  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
t  = [int(input()) for i in range(n)]
#
# c = collections.Counter()

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

def multiple(a, b):
    return a*b // euclid(a, b)

def gcd(nums):
    return functools.reduce(euclid, nums)

def lcm(nums):
        return functools.reduce(multiple, nums)

print(lcm(t))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
t  = [int(input()) for i in range(n)]
#
# c = collections.Counter()
print(np.lcm.reduce(t))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections
import itertools as it
import math
from functools import reduce
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
t  = [int(input()) for i in range(n)]
#
# c = collections.Counter()

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(t))
Problem p03712 (python)

Fixed submission:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
h, w  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()
 
print('{}'.format('#' * (w + 2)))
for _ in range(h):
    print('#{}#'.format(input()))
print('{}'.format('#' * (w + 2)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
h, w  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

print(f'{"#" * (w + 2)}')
for _ in range(h):
    print(f'#{input()}#')
print(f'{"#" * (w + 2)}')
Problem p04011 (python)

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

ans = 0
for i in range(N):
  if i < K:
    ans += X
  else:
    ans += Y
print(ans)

Buggy submission (verdict: Runtime Error):
import collections

# N, K = map(int, input().split())
# A = list(map(int, input().split()))
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

ans = 0
for i in range(N):
  if i < K:
    ans += X
    else:
      ans += Y
print(ans)

Buggy submission (verdict: Runtime Error):
    import collections

    # N, K = map(int, input().split())
    # A = list(map(int, input().split()))
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())

    ans = 0
    for i in range(N):
        if i < K:
            ans += X
        else:
            ans += Y
    print(ans)
Problem p02658 (python)

Fixed submission:
import numpy as np
N = int(input())
value = 1

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

if 0 in A:
  print(0)
else:
  for a in A:
    if value * a > 10**18:
      value = -1
      break
    else:
      value *= a
  print(value)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
value = 1

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

if 0 in A:
  print(0)
else:
  for a in A:
    if np.log10(value * a) > 18:
      value = -1
      break
    else:
      value *= a
  print(value)
Problem p02934 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split(" ")))
sum = 0
for i in range(N):
  sum += 1. / A[i]
print(1/sum)

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

for i in range(N):
  sum += 1 / A[i]
print(1/sum)
Problem p03125 (python)

Fixed submission:
A, B = map(int, input().split(" "))
if B % A == 0:
  print(A + B)
else:
  print(B - A)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())
if B % A == 0:
  print(A + B)
else:
  print(A - B)
Problem p03126 (python)

Fixed submission:
N, M = map(int, input().split(" "))
data = []
for i in range(N):
  A = list(map(int, input().split(" ")))
  A_ = sorted(A[1:])
  data.append(A_)
  
counter = 0  
for m in range(M):
  flag = 1
  for d in data:
    if m+1 in d:
      flag *= 1
    else:
      flag *= 0
  if flag == 1:
    counter += 1

print(counter)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
data = []
for i in range(N):
  A = list(map(int, input().split(" ")))
  A_ = A[1:].sort()
  data.append(A_)
  
counter = 0  
for m in range(M):
  flag = 1
  for d in data:
    if m in d:
      flag *= 1
    else:
      flag *= 0
  if flag == 1:
    counter += 1

print(counter)
Problem p02684 (python)

Fixed submission:
import sys

n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
d2 = {}
d3 = {}
loopc = 0
for i in range(1, n + 1):
    d[i] = a[i - 1]


b = d[1]
d2[b] = 1
d3[i] = b
amari = 0
if k >= 2:
    if n >= k:
        for i in range(2, k + 1):
            if b in d:
                b = d[b]
        print(b)
    else:
        for i in range(2, n + 1):
            if b in d:
                b = d[b]
                if b not in d2:
                    d2[b] = i
                    d3[i] = b
                elif b in d2:
                    loopc = i - d2[b]
            else:
                print(b)
                sys.exit()

        amari = k - n
        amari = amari % loopc
        for i in range(amari):
            b = d[b]
        print(b)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
d2 = {}
d3 = {}
loopc = 0
for i in range(1, n + 1):
    d[i] = a[i - 1]


b = d[1]
d2[b] = 1
d3[i] = b
amari = 0
if k >= 2:
    if n >= k:
        for i in range(2, k + 1):
            if b in d:
                b = d[b]
    else:
        for i in range(2, n + 1):
            if b in d:
                b = d[b]
                if b not in d2:
                    b = d[b]
                    d2[b] = i
                    d3[i] = b
                elif b in d2:
                    loopc = i - d2[b]
            else:
                print(b)
                sys.exit()

        amari = k - n
        amari = amari % loopc
        for i in range(amari + 1):
            b = d[b]
        print(b)
else:
    print(b)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
d2 = {}
d3 = {}
loopc = 0
for i in range(1, n + 1):
    d[i] = a[i - 1]


b = d[1]
d2[b] = 1
d3[i] = b
amari = 0
if k >= 2:
    if n >= k:
        for i in range(2, k + 1):
            if b in d:
                b = d[b]
    else:
        for i in range(2, n + 1):
            if b in d:
                b = d[b]
                if b not in d2:
                    b = d[b]
                    d2[b] = i
                    d3[i] = b
                elif b in d2:
                    loopc = i - d2[b]
            else:
                print(b)
                exit()

        amari = k - n
        amari = amari % loopc
        for i in range(amari + 1):
            b = d[b]
        print(b)
else:
    print(b)
Problem p02719 (python)

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

print(min(n%k,k-n%k))

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

print(min(n%k,k-n%k))
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
sl = []
cl = []
ans = [-1] * n
a = ""
for _ in range(m):
    s, c = map(int, input().split())
    sl.append(s)
    cl.append(c)
    if ans[s - 1] == -1:
        ans[s - 1] = c
    elif ans[s - 1] == c:
        continue
    else:
        ans[s - 1] = -10
        break

if ans.count(-10) > 0:
    print(-1)
else:
    if n == 1:
        if ans[0] == -1:
            print(0)
        else:
            print(ans[0])
    else:
        for i in range(n):
            if i != n - 1 and ans[i] == 0:
                print(-1)
                exit()
            elif ans[i] == -1 and i == 0:
                ans[i] = 1
            elif ans[i] == -1 and i != 0:
                ans[i] = 0
        for i in ans:
            a += str(i)
        print(a)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
l = [-1] * n
ans = 0
for _ in range(m):
    a, b = map(int, input().split())
    a = a - 1
    if l[a] == -1 or l[a] == b:
        l[a] = b
    else:
        print(-1)
        exit()

if n > 1 and l[0] == 0:
    print(-1)
elif n == 1:
    print(l[0])
else:
    for i in range(n):
        if i == 0 and l[0] == -1:
            l[0] = 1
        elif l[i] == -1:
            l[i] = 0
        # ans += l[i] * (10 ** (n - i - 1))
        ans += str(l[i])
    print(int(ans))
Problem p02818 (python)

Fixed submission:
import sys

sys.setrecursionlimit(1000000000)


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

if a >= k:
    a = a - k
    print("{} {}".format(a, b))
elif k > a and a + b >= k:
    b = a + b - k
    print("{} {}".format(0, b))
else:
    print("{} {}".format(0, 0))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(1000000000000000)


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

if a >= k:
    a = a - k
    print("{} {}".format(a, b))
elif k > a and a + b >= k:
    b = a + b - k
    print("{} {}".format(0, b))
else:
    print("{} {}".format(0, 0))
Problem p03161 (python)

Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    for i in range(2, n):
        dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
    print(dp[n - 1])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    if n == 2:
    print(dp[1])
    else:
        for i in range(2, n):
            if i <= k:
                dp[i] = min(abs(h[i] - h[i - j]) + dp[i - j] for j in range(1, i + 1))
            else:
                dp[i] = min(abs(h[i] - h[i - j]) + dp[i - j] for j in range(1, k + 1))
        print(dp[n - 1])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def input():
    return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])

    for i in range(2, n):
        dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
    print(dp[n - 1])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline().strip
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, n):
    dp[i] = min(abs(h[i] - h[j]) + dp[j] for j in range(max(0, i - k), i))
print(dp[n - 1])
Problem p03206 (python)

Fixed submission:
d=int(input())
if d==25:
    print('Christmas')
elif d==24:
    print('Christmas Eve')
elif d==23:
    print('Christmas Eve Eve')
elif d==22:
    print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
d=int(input())
if d==25:
    print('Christmas')
elif d==24:
    pirnt('Christmas Eve')
elif d==23:
    print('Christmas Eve Eve')
elif d==22:
    print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
d=int(input())
if d==25:
    print('Christmas')
elif d==24:
    pirnt('Christmas Eve')
elif d==23:
    print('Christmas Eve Eve')
elif d==22:
    print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
d=int(input())
if d==25:
    print('Christmas')
elif d==24:
    pirnt('Christmas Eve')
elif d==23:
    print('Christmas Eve Eve')
elif d==22:
    print('Christmas Eve Eve Eve')
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split(' '))

s_old = []
s_c_old =[]
result = 0
FLAGS = True
for i in range(M):
  s, c = map(int, input().split(' '))

  if (N != 1) & (s == 1) & (c == 0):
    print('-1')
    FLAGS = False
    break
  elif (s in s_old):
    if ([s,c] in s_c_old):
      s_old.append(s)
      s_c_old.append([s,c])
    else:
      print('-1')
      FLAGS = False
      break
  else:
    result += c*10**(N - s)
    s_old.append(s)
    s_c_old.append([s,c])

if (N == 1) and (M == 0):
  result = 0
elif 1 in s_old:
  result = result
#elif N != 1:
else:
  result += 1*10**(N - 1)
  
if FLAGS == True:
  print(result)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = []
FLAGS = True
for i in range(3):
  N1 = list(map(int, input().split(' ')))
  N.append(N1)

N = np.array(N)

M = int(input())

for i in range(M):
  a = int(input())
  
  for j in range(3):
    for k in range(3):
      if N[j, k] == a:
        N[j, k] = 0
  if (np.all(N == 0, axis = 0).any(0)) or (np.all(N == 0, axis = 1).any(0)) or (np.all(np.diag(N) == 0).any(0)) or (np.all(np.diag(N) == 0).any(0)):
  #if (N[0, :].all() == 0) or (N[1, :].all() == 0) or  (N[2, :].all() == 0) or  (N[:, 0].all() == 0) or (N[:, 1].all() == 0) or (N[:, 2].all() == 0) or (np.diag(N).all() == 0) or (np.diag(np.transpose(N)).all() == 0):
    print('Yes')
    FLAGS = True
    break
  else:
    FLAGS = False
    continue
      
if FLAGS == False:     
  print('No')
Problem p02684 (python)

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

memo = [-1]*(n+1)
start = 1
syuuki = 0
haji = 0

for i in range(k):
    if memo[start] != -1:
        syuuki = i - memo[start]
        haji = memo[start]
        break
    memo[start] = i
    start = li[start]
else:
    print(start)
    exit()

#print(syuuki,haji)
k-=haji
k%=syuuki
k+=haji

start = 1
for kk in range(k):
    start = li[start]
print(start)

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

start = 0
atesaki = 0
atesaki_li = [0]
target = atesaki
last = -1
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        last = atesaki
        break
    else:
        atesaki_li.append(atesaki)
#print(last,atesaki_li)
#[0, 2, 3]

ma = len(atesaki_li)
if k+1<=ma:
    print(ma[k])
else:
    fi = atesaki_li.index(last)
    kurikaeshi = ma - fi
    ama = (k+1-ma)%kurikaeshi
    new_li = atesaki_li[fi:]
    #print(fi,kurikaeshi,ama,atesaki_li)
    #print(atesaki_li,last,kurikaeshi,ama)
    #print(new_li)
    print(new_li[ama-1]+1)

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

start = 0
atesaki = 0
atesaki_li = [0]
target = atesaki
last = -1
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        last = atesaki
        break
    else:
        atesaki_li.append(atesaki)
#print(last,atesaki_li)
#[0, 2, 3]

ma = len(atesaki_li)
if k+1<=ma:
    print(ma[k])
else:
    fi = atesaki_li.index(last)
    kurikaeshi = ma - fi
    ama = (k+1-ma)%kurikaeshi
    #print(fi,ama,atesaki_li)
    print(atesaki_li[(fi-1)+ama]+1)

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

start = 0
atesaki = 0
atesaki_li = [0]
target = atesaki
last = -1
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        last = atesaki
        break
    else:
        atesaki_li.append(atesaki)
#print(last,atesaki_li)
#[0, 2, 3]

ma = len(atesaki_li)
if k+1<=ma:
    print(ma[k])
else:
    fi = atesaki_li.index(last)
    kurikaeshi = ma - fi
    ama = (k+1-ma)%kurikaeshi
    #print(fi,ama,atesaki_li)
    print(atesaki_li[(fi-1)+ama]+1)

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

start = 0
atesaki = 0
start_li = [0]
atesaki_li = []
count = 0
target = atesaki
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        count = i+1
        break
    else:
        atesaki_li.append(atesaki)
    #print(atesaki,'tes')

first_ind = atesaki_li.index(atesaki)+1
#print(atesaki_li,atesaki,first_ind)

atesaki_li[(k-len(atesaki_li))%(len(atesaki_li)-first_ind+1)]
print(atesaki_li[(k-len(atesaki_li))%(len(atesaki_li)-first_ind+1)])+1
Problem p02697 (python)

Fixed submission:
n,m = map(int,input().split())
if n%2 ==1:
    for i in range(1,m+1):
        print(i,n-i)
else:
    left_end = 1+m if m%2 == 1 else m
    left_start = left_end//2
    right_start = left_end+m//2
    for i in range(1,m+1):
        if i%2 == 1:
            print(left_start,left_start+i)
            left_start-=1
        else:
            print(right_start,right_start+i)
            right_start-=1

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
if n%2 ==1:
    for i in range(1,m+1):
        print(i,n-i)
else:
    last = 0
    li = [j for j in range(1,n+1)]
    #print(li)
    for i in range(1,m+1):
        a = min(li)
        b = min(li)+i
        print(a,b)
        li.remove(a)
        li.remove(b)