Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int,input().split())
yz = []
for y in range(K+1):
  for z in range(y,K+1):
    if y == z:
      yz.append([y+z,1])
    else:
      yz.append([y+z,2])
cnt = 0
for x in range(K+1):
  for i in range(len(yz)):
    if x + yz[i][0] == S and yz[i][1] == 1:
      cnt += 1
    elif x + yz[i][0] == S and yz[i][1] == 2:
      cnt += 2
print(cnt)

Fixed submission:
K, S = map(int,input().split())
cnt=0
for y in range(K+1):
  for z in range(y,K+1):
    if y == z and 0 <= S-y-z <=K:
      cnt+=1      
    elif 0 <= S-y-z <=K:
      cnt += 2
      
print(cnt)
Buggy python submission (verdict: Runtime Error):
t=int(input().split())
l=[1,0,-1]
k=t[3]
s=0
i=0
while(k!=0):
  if(k>t[i]):
    s+=l[i]*t[i]
    k-=t[i]
  else:
    s+=l[i]*k
    k=0
  i+=1
print(s)

Fixed submission:
t=list(map(int,input().split()))
l=[1,0,-1]
k=t[3]
s=0
i=0
while(k!=0):
  if(k>t[i]):
    s+=l[i]*t[i]
    k-=t[i]
  else:
    s+=l[i]*k
    k=0
  i+=1
print(s)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
flag = 1
for i in S:
    if not 96<ord(s) and ord(s)<122:
        flag=0

    if T[len(t)-1]:
        flag=0
    if not len(T)-len(S)==1:
        flag=0
    if not T[:-1]==S:
        flag=0
print(Yes if flag==1 else No)


Fixed submission:
S = input()
T = input()
flag = 1
for i in range(0,len(T)):
    if not 96<ord(T[i]) and ord(T[i])<122:
        flag=0

if not len(T)-len(S)==1:
    flag=0

if not T[:-1]==S:
    flag=0
print("Yes" if flag==1 else "No")
Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,K = map(int,input().split())
count=0
for i in range(0,K):
    if A>0:
        count+=1
        A-=1
    elif A==0 and B>0:
        B -=1
    else:
        count-=1
print(count)



Fixed submission:
A,B,C,K = map(int,input().split())
count=0

if K<=A:
    print(K)

elif A<K and K<B:
    print(A)

else:
    print(A-(K-A-B))
Buggy python submission (verdict: Runtime Error):
K = int(input())
A,B = map(int,input().split())

for i in range(A,B+1):
    if i%K=0:
        return print("OK")
return print("NG")


Fixed submission:
K = int(input())
A,B = map(int,input().split())
flag=0
for i in range(A,B+1):
    if i%K==0:
        flag=1

if flag==1:
    print("OK")
else:
    print("NG")
Buggy python submission (verdict: Runtime Error):
x = int.input()

print(x*x*x)

Fixed submission:
x = int(input())

print(x*x*x)
Buggy python submission (verdict: Runtime Error):
x = input()
 
def Combination(x):
  if x[0] == x[1]　and x[2] == x[3]:
      return "Yes"
  elif x[0] == x[2]　and x[1] == x[3]:
      return "Yes"
  elif x[0] == x[3] and x[1] == x[2]:
      return "Yes"
  else:
    return "No"
print(Combination(x))

Fixed submission:
x = input()
 
def Combination(x):
  if x[0] == x[1] and x[2] == x[3] and x[0] != x[2]:
      return "Yes"
  elif x[0] == x[2] and x[1] == x[3] and x[0] != x[1]:
      return "Yes"
  elif x[0] == x[3] and x[1] == x[2] and x[0] != x[2]:
      return "Yes"
  else:
    return "No"
print(Combination(x))

Buggy python submission (verdict: Runtime Error):
x = input()

def Combination(x):
  if x[0] = x[1]:
    if x[2] = x[3]:
      return "Yes"
  elif x[0] = x[2]:
    if x[1] = x[3]:
      return "Yes"
  elif x[0] = x[3]:
    if x[1] = x[2]:
      return "Yes"
  else:
    return "No"
print(Combination(x))


Fixed submission:
x = input()
 
def Combination(x):
  if x[0] == x[1] and x[2] == x[3] and x[0] != x[2]:
      return "Yes"
  elif x[0] == x[2] and x[1] == x[3] and x[0] != x[1]:
      return "Yes"
  elif x[0] == x[3] and x[1] == x[2] and x[0] != x[2]:
      return "Yes"
  else:
    return "No"
print(Combination(x))
Buggy python submission (verdict: Runtime Error):
x = input()
def samenum(string):
  for i in range(3):
  	if string[i] == string[i+1]:
    	return "Bad"
  		quit()
  return "Good"

print(samenum(x))

Fixed submission:
x = input()
def samenum(string):
  for i in range(3):
    if string[i] == string[i+1]:
        return "Bad"
        quit()
  return "Good"

print(samenum(x))
Buggy python submission (verdict: Runtime Error):
a_1, b_0, c_m1, k = map(int, input().split())

def dfs(n, a_n, b_n, c_n, max_):
	#print(n, a_n, b_n, c_n, max_)
	#print(type(n), type(a_n), type(b_n), type(c_n), type(max_))
	if (a_n > a_1 or b_n > b_0 or c_n > c_m1):
		return max_
	if (n == 0):
		max__ = int(a_n) - int(c_n) 
		if (max__ > max_):
	#		print(max__, type(max__), "***")
			return max__
		else:
			return max_
	m1 = dfs(n-1, a_n+1, b_n, c_n, max_)
	#print(m1, type(m1), "+++")
	m2 = dfs(n-1, a_n, b_n+1, c_n, m1)
	m3 = dfs(n-1, a_n, b_n, c_n+1, m2)
	return m3
            
max_ = dfs(k, 0, 0, 0, -99999)
print(max_)

Fixed submission:
a, b, c, k = [int(x) for x in input().split()]
a_x = min(a, k)
k -= a_x
b_x = min(b, k)
k -= b_x
c_x = min(c, k)
ans = a_x - c_x
print(ans)
Buggy python submission (verdict: Runtime Error):
from re import sub
LIST = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
K = int(input())
return sub(r"[,\s]", "", LIST)[K-1]

Fixed submission:
from re import sub
LIST = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
K = int(input())
print(sub(r"[\s]", "", LIST).split(",")[K-1])

Buggy python submission (verdict: Runtime Error):
from re import sub
LIST = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
K = int(input())
return sub(r"[,\s]", "", LIST)[K+1]

Fixed submission:
from re import sub
LIST = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
K = int(input())
print(sub(r"[\s]", "", LIST).split(",")[K-1])
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
from math import ceil

if H == 1 or W == 1:
  print(1)
else:
  print(ceil(H*W/2)
  


Fixed submission:
H, W = map(int, input().split())
from math import ceil
 
if H == 1 or W == 1:
  print(1)
else:
  print(ceil(H*W/2))
Buggy python submission (verdict: Runtime Error):
human_num = int(input())

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

for i in range(human_num):
    print(nyu.count(i + 1))

Fixed submission:
day_num, homework_num = map(int, input().split(" "))

requ_day = list(map(int, input().split()))
sum_day = 0

for day in requ_day:
  sum_day += day
  
activ_day = day_num - sum_day

if activ_day >= 0:
  print(activ_day)
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
human_num = int(input())

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

for i in range(human_num):
    print(nyu.count(i + 1))

Fixed submission:
human_num = int(input())
jousi_num = [0 for i in range(human_num)]

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

for k in nyu:
    jousi_num[k - 1] += 1

for ri in jousi_num:
    print(ri)

Buggy python submission (verdict: Time Limit Exceeded):
human_num = int(input())

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

for i in range(human_num):
    print(nyu.count(i + 1))

Fixed submission:
human_num = int(input())
jousi_num = [0 for i in range(human_num)]

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

for k in nyu:
    jousi_num[k - 1] += 1

for ri in jousi_num:
    print(ri)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
#from mod10**9 import *

purasu_num, num_ijou = list(map(int, input().split(" ")))

sum_ways = 0 #和の個数
rupe_num = purasu_num - num_ijou + 2

atai_list = [i for i in range(purasu_num + 1)]
for i in range(rupe_num):
    kosu = i + num_ijou
    mi = sum(atai_list[:kosu])
    ma = sum(atai_list[-kosu:])
    sum_ways += ma - mi + 1
    #print(kosu, sum_ways)

print(sum_ways)


Fixed submission:
mod = 10**9 + 7
def sum(a, b):
    r = (a + b)*(b - a + 1) / 2
    return int(r)

def main():
    sum_num = 0
    N, K = list(map(int, input().split(" ")))
    for i in range(K, N+2):
        mi = sum(0, i - 1)
        ma = sum(N-i+1, N)
        sum_num += ma - mi + 1

    print(sum_num % mod)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return -1

if __name__ == '__main__':
    N = int(input())
    l = []
    for i in range(N):
        word = input()
        index = binary_search(l,word)
        if  index == -1:
            l.append(word)
        l = sorted(l)
    print(len(l))


Fixed submission:
N = int(input())
l = []
for i in range(N):
    l.append(input())
l = sorted(l)
new_list = []
new_list.append(l[0])
for i in range(1,len(l)):
    if l[i-1] != l[i]:
        new_list.append(l[i])
print(len(new_list))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = []
for i in range(N):
    word = input()
    if not word in l:
        l.append(word)

print(len(l))


Fixed submission:
N = int(input())
l = []
for i in range(N):
    l.append(input())
l = sorted(l)
new_list = []
new_list.append(l[0])
for i in range(1,len(l)):
    if l[i-1] != l[i]:
        new_list.append(l[i])
print(len(new_list))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,100):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j
for i in range(100,N // 100 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)

Fixed submission:
N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,1000000):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j
for i in range(1000000,N // 1000000 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,N // 2 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)

Fixed submission:
N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,1000000):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j
for i in range(1000000,N // 1000000 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,N):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)

Fixed submission:
N = int(input())
min = N
max_i = 0
max_j = 0
for i in range(1,1000000):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j
for i in range(1000000,N // 1000000 + 1):
    if N % i == 0:
        j = N // i
        if abs(i - j) < min:
            min = abs(i - j)
            max_i = i
            max_j = j

print(max_i + max_j - 2)
Buggy python submission (verdict: Runtime Error):
N,X = [int(x) for x in input().split()]
data_jump = [int(x) for x in input().split()]
count = 1
sum_dis = 0
for i in range(N+1):
    sum_dis += data_jump[i]
    if sum_dis > X:
        break
    count += 1
print(count)

Fixed submission:
N,X = [int(x) for x in input().split()]
data_jump = [int(x) for x in input().split()]
count = 1
sum_dis = 0
for i in range(N):
    sum_dis += data_jump[i]
    if sum_dis > X:
        break
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b,c = map(int, input().split())
k = int(input())
n = 0

for s in range(k):
  if a > 0:
    n += 1
  elif b > 0:
    n += 0
  else:
    n -= 1
    
print(n)


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

if k <= a:
  print(k)
elif a < k <= a+b:
  print(a)
elif a+b < k <= a+b+c:
  print(2*a + b - k)

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

for _ in range(k):
  if a > 0:
    n += 1
  elif b > 0:
    n += 0
  elif c > 0:
    n -= 1
    
print(n)

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

if k <= a:
  print(k)
elif a < k <= a+b:
  print(a)
elif a+b < k <= a+b+c:
  print(2*a + b - k)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = set()

for _ in range(k):
  d = int(input())
  while m <= d:
    l = int(input())
    a.append(l)
    m += 1

print(n - len(a))


Fixed submission:
s = input()
b = "ABC"
r = "ARC"

if s == b:
  print("ARC")
elif s == r:
  print("ABC")

Buggy python submission (verdict: Runtime Error):
s = input()
b = "ABC"
r = "ARC"

if s == b:
  print("ARC")
else if s == r:
  print("ABC")


Fixed submission:
s = input()
b = "ABC"
r = "ARC"

if s == b:
  print("ARC")
elif s == r:
  print("ABC")

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

if s == "ABC":
  print("ARC")
else if s == "ARC":
  print("ABC")

Fixed submission:
s = input()
b = "ABC"
r = "ARC"

if s == b:
  print("ARC")
elif s == r:
  print("ABC")

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

if s == "ARC":
  print("ABC")
else if s == "ABC":
  print("ARC")

Fixed submission:
s = input()
b = "ABC"
r = "ARC"

if s == b:
  print("ARC")
elif s == r:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
  a = input()
  b = input()
  if (len(b)>len(a)) and (a==b[:len(a)]):
  	print('Yes')
  else:
  	print('No')

Fixed submission:
a = input()
b = input()
if (len(b)>len(a)) and (a==b[:len(a)]):
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
    a = input()
    b = input()
    if len(b)> len(a) and a==b[:len(a)]:
      print('Yes')
    else:
      print('No')

Fixed submission:
a = input()
b = input()
if (len(b)>len(a)) and (a==b[:len(a)]):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
A , B, C, K = map(int, input().split())
result = 0
for i in range(K):
    if A > 0:
        result +=1
        A -= 1
    elif B > 0:
        B -= 1
    else:
        result -= 1
        c -= 1
print(result)

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

if K >= A:
    result = A
    K -= A
else:
    result = K
    K = 0

if K >= B:
    K -= B

if K > 0:
    result -=K
print(result)
Buggy python submission (verdict: Runtime Error):
S = input()
if S ='ABC':
    print('ARC')
else:
    print('ABC')

Fixed submission:
S = input()
if S =='ABC':
    print('ARC')
else:
    print('ABC')
Buggy python submission (verdict: Runtime Error):
s = input()

if s // 2 ==1:
	print('Np')
	exit()

if s == "hi"* (s // 2):
	print('Yes')
else:
	print('No')

Fixed submission:

s = input()

if len(s) % 2 ==1:
	print('No')
	exit()

if s == "hi"* (len(s) // 2):
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
T = int(input(""))
X = int(input(""))

if T < 1 or T > 100:
    exit()
if X < 1 or X > 100:
    exit()
print(T/X)


Fixed submission:
input_str = input("")
T = int(input_str.split(" ")[0])
X = int(input_str.split(" ")[1])

if T < 1 or T > 100:
    exit()
if X < 1 or X > 100:
    exit()
print(T/X)
Buggy python submission (verdict: Runtime Error):
try:
    N, M = map(int, input().split())
    Xi = [int(x) for x in input().split()]

    if N < 1 or N > 10**5:
        exit()
    if M < 1 or M > 10**5:
        exit()
    if M != len(Xi):
        exit()
    for i in Xi:
        if Xi[i] < -10**5 or Xi[i] > 10**5:
            exit()
    
except ValueError:
    exit()



Fixed submission:
try:
    N, M = map(int, input().split())
    Xi = [int(x) for x in input().split()]

    if N < 1 or N > 10**5:
        exit()
    if M < 1 or M > 10**5:
        exit()
    if M != len(Xi):
        exit()
    for i in Xi:
        if i < -10**5 or i > 10**5:
            exit()
    Xi = sorted(Xi)

    a = []
    for i in range(M-1):
        a.append(Xi[i+1]-Xi[i])

    a = sorted(a, reverse=True)
    s = 0
    # print(a)
    for i in range(N-1):
        # print(a[0])
        a.pop(0)

    for i in a:
        s += abs(i)
    print(s)
except ValueError:
    exit()
except IndexError:
    print(0)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
if N < 1 or N > 100:
    exit()
if T < 1 or T > 1000:
    exit()

jugde = False
jugde_N = 100
maplist = {}
for i in range(N):
    ci,ti = map(int, input().split())
    if ci < 1 or ci > 1000:
        exit()
    if ti < 1 or ti > 1000:
        exit()
    if maplist.get(ci) == None:
        maplist[ci] = ti
for jN,jT in maplist.items():
    if jT <= T:
        if jN <= jugde_N:
            jugde = True
            jugde_N = jN
if jugde == False:
    print('TLE')
else:
    print(jugde_N)


Fixed submission:
N = int(input(""))

if N == 1:
    print('Hello World')
elif N == 2:
    A = int(input(""))
    B = int(input(""))
    print(A + B)

Buggy python submission (verdict: Runtime Error):
N = int(input(""))

if n == 1:
    print('Hello World')
elif n == 2:
    A= int(input("A"))
    B = int(input("B"))
    print(A + B)

Fixed submission:
N = int(input(""))

if N == 1:
    print('Hello World')
elif N == 2:
    A = int(input(""))
    B = int(input(""))
    print(A + B)
Buggy python submission (verdict: Runtime Error):
s = input()
sr = s.replace(s[0], '')
srr = sr.replace(sr[0], '')
if len(sr) == 2 and len(srr) == 0:
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()
sr = s.replace(s[0], '')
if len(sr) == 2 and sr.count(sr[0]) == 2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split())).sort()
i = int(n / 2)

print(d[i] - d[i - 1])

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
i = int(n / 2)

d.sort()
print(d[i] - d[i - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
i2p = {0:1}
p2i = {1:0}
cur = A[0]
i = 1
while True:
    i2p[i] = cur
    p2i[cur] = i
    if A[cur-1] in i2p.values():
        break
    cur = A[cur-1]
    i+=1
i = p2i[A[cur-1]]
num_loop = len(i2p) - i 
if K < i:
    print(i2p[K])
else:
    print(i2p[i+(K-i)%num_loop])

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

i2p = {0:1}
p2i = {1:0}
cur = A[0]
is_loop = {}
for i in range(N+1):
    is_loop[i] = False
i = 1
while True:
    i2p[i] = cur
    p2i[cur] = i
    is_loop[cur] = True
    if is_loop[A[cur-1]]:
        break
    cur = A[cur-1]
    i+=1
i = p2i[A[cur-1]]
num_loop = len(i2p) - i 
if K < i:
    print(i2p[K])
else:
    print(i2p[i+(K-i)%num_loop])

Buggy python submission (verdict: Time Limit Exceeded):
def serch(cur):
    if A[cur] == A[0]:
        return 

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

serch(A[1])

i2p = {
    0: 1
}
cur = A[0]

i = 1
remove_list = []
while True:
    i2p[i] = cur
    remove_list.append(cur)
    if A[cur-1] in i2p.values():
        break
    cur = A[cur-1]
    i+=1

for i in i2p.keys():
    if A[cur-1] == i2p[i]:
        break


num_loop = len(i2p) - i 

if K < i:
    print(i2p[K])
else:
    print(i2p[i+(K-i)%num_loop])

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

i2p = {0:1}
p2i = {1:0}
cur = A[0]
is_loop = {}
for i in range(N+1):
    is_loop[i] = False
i = 1
while True:
    i2p[i] = cur
    p2i[cur] = i
    is_loop[cur] = True
    if is_loop[A[cur-1]]:
        break
    cur = A[cur-1]
    i+=1
i = p2i[A[cur-1]]
num_loop = len(i2p) - i 
if K < i:
    print(i2p[K])
else:
    print(i2p[i+(K-i)%num_loop])

Buggy python submission (verdict: Time Limit Exceeded):
def serch(cur):
    if A[cur] == A[0]:
        return 

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

serch(A[1])

i2p = {
    0: 1
}
cur = A[0]

i = 1
remove_list = []
while True:
    i2p[i] = cur
    remove_list.append(cur)
    if A[cur-1] in i2p.values():
        break
    cur = A[cur-1]
    i+=1

for i in i2p.keys():
    if A[cur-1] == i2p[i]:
        break


num_loop = len(i2p) - i 

if K < i:
    print(i2p[K])
else:
    print(i2p[i+(K-i)%num_loop])

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

i2p = {0:1}
p2i = {1:0}
cur = A[0]
is_loop = {}
for i in range(N+1):
    is_loop[i] = False
i = 1
while True:
    i2p[i] = cur
    p2i[cur] = i
    is_loop[cur] = True
    if is_loop[A[cur-1]]:
        break
    cur = A[cur-1]
    i+=1
i = p2i[A[cur-1]]
num_loop = len(i2p) - i 
if K < i:
    print(i2p[K])
else:
    print(i2p[i+(K-i)%num_loop])
Buggy python submission (verdict: Runtime Error):
from math import sqrt

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

if sqrt(a)+sqrt(b)-sqrt(c) < 0:
    print('Yes')
else:
    print('No'

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

if c-(a+b) >= 0:
    if 4*a*b < (c-(a+b))**2:
        print('Yes')
    else:
        print('No')
else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

num_turn = 0

for i in range(Q):
    query = input()
    if query == '1':
        num_turn += 1
    else:
        _, f, c = query.split()
        f = int(f)
        if f == 1:
            if num_turn%2==0:
                S = c + S
            else:
                S = S + c
        else:
            if num_turn%2==0:
                S = S + c
            else:
                S = c + S

if num_turn%2==1:
    S = S[::-1]
print(S)

Fixed submission:
S = input()
Q = int(input())

num_turn = 0

front = []
end = []

for i in range(Q):
    query = input()
    if query == '1':
        num_turn += 1
    else:
        _, f, c = query.split()
        f = int(f)
        if f == 1:
            if num_turn%2==0:
                front.append(c)
            else:
                end.append(c)
        else:
            if num_turn%2==0:
                end.append(c)
            else:
                front.append(c)

S = list(S)
if num_turn%2==1:
    ans = end[::-1] + S[::-1] + front
else:
    ans = front[::-1] + S + end
print(''.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
# ans = 全通り - nCa - nCb
#     = 2^n - 1 - nCa - nCb

def pow(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def comb_num_mod(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

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

mod = (10**9) + 7

num_all = pow(2, n) - 1

nca = comb_num_mod(n, a, mod=mod)
ncb = comb_num_mod(n, b, mod=mod)

print(num_all - nca - ncb)

Fixed submission:
# ans = 全通り - nCa - nCb
#     = 2^n - 1 - nCa - nCb
def comb(n,r,mod=10**9+7):
    a=1
    b=1
    r = min(r,n-r)
    for i in range(r):
        a = a*(n-i)%mod
        b = b*(i+1)%mod
    return a*pow(b,mod-2,mod)%mod

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

mod = (10**9) + 7

num_all = pow(2, n, mod) - 1
nca = comb(n, a, mod=mod)
ncb = comb(n, b, mod=mod)

ans = num_all - nca - ncb
ans %= mod

print(ans)