Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
s=0
a=list(map(int,input().split()))
c=collections.Counter(a)
for i in  c.keys():
  if c.values(i)>i:
    s+=c.values(i)-i
  elif c.values(i)<i:
    s+=c.values(i)
print(s)
    
    

Fixed submission:
import collections
N=int(input())
s=0
a=list(map(int,input().split()))
c=collections.Counter(a)
for i in  c.keys():
  if c[i]>i:
    s+=c[i]-i
  elif c[i]<i:
    s+=c[i]
print(s)
Buggy python submission (verdict: Runtime Error):
N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if i!=N:
    if p[i]==i+1:
      s=p[i+1]
      p[i]=s
      p[i+1]=i+1
      t+=1
  else:
    if p[i]==i+1:
      u=p[i-1]
      p[i]=u
      p[i-1]=i+1
      t+=1
print(t)


Fixed submission:
N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if i!=N-1:
    if p[i]==i+1:
      s=p[i+1]
      p[i]=s
      p[i+1]=i+1
      t+=1
  else:
    if p[i]==i+1:
      u=p[i-1]
      p[i]=u
      p[i-1]=i+1
      t+=1
print(t)

Buggy python submission (verdict: Runtime Error):
N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if p[i]==i+1:
    s=p[i+1]
    p[i]=s
    p[i+1]=i+1
    t+=1
print(t)

Fixed submission:
N=int(input())
p=list(map(int,input().split()))
t=0
for i in range(N):
  if i!=N-1:
    if p[i]==i+1:
      s=p[i+1]
      p[i]=s
      p[i+1]=i+1
      t+=1
  else:
    if p[i]==i+1:
      u=p[i-1]
      p[i]=u
      p[i-1]=i+1
      t+=1
print(t)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
u=0
for i in range(M):
  a,b=list(map(int,input().split()))
for i in range(M):
  if a[i]==1:
    s=b[i]
    idxlist=[]
    for idx,val in enumerate(a):
      if val==s:
        idxlist.append(idx)
    for j in idxlist:
      if b[j]!=N:
        u+=1
if u==len(idxlist):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Fixed submission:
N,M=map(int,input().split())
x=[]
for i in range(M):
  a,b=map(int,input().split())
  if a==1:
    x.append(b)
  if b==N:
    x.append(a)
l=len(x)
if len(set(x))==l:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[]
B=[]
for i in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
u=0
k=A.count(1)
for i in range(M):
  if A[i]==1:
    s=B[i]
    t=A.index(B[i])
    if B[t]!=N:
      u+=1
if u==k:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Fixed submission:
N,M=map(int,input().split())
x=[]
for i in range(M):
  a,b=map(int,input().split())
  if a==1:
    x.append(b)
  if b==N:
    x.append(a)
l=len(x)
if len(set(x))==l:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(M):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
u=0
k=A.count(1)
for i in range(M):
  if A[i]==1:
    s=B[i]
    t=A.index(B[i])
    if B[t]!=N:
      u+=1
if u==k:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

    





Fixed submission:
N,M=map(int,input().split())
x=[]
for i in range(M):
  a,b=map(int,input().split())
  if a==1:
    x.append(b)
  if b==N:
    x.append(a)
l=len(x)
if len(set(x))==l:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=(s*i)%MOD
t=1
for i in range(2,M+1):
  t=(t*j)%MOD
if abs(N-M)>1:
  print(0)
  exit()
if abs(N-M)==1:
  print((s*t)%MOD)
else:
  print((2*s*t)%MOD)
  

Fixed submission:
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=(s*i)%MOD
t=1
for i in range(2,M+1):
  t=(t*i)%MOD
if abs(N-M)>1:
  print(0)
  exit()
if abs(N-M)==1:
  print((s*t)%MOD)
else:
  print((2*s*t)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=s*i
t=1
for j in range(2,M+1):
  t=t*j
if abs(N-M)>=2:
  print(0)
if abs(N-M)==1:
  print((s*t)%MOD)
if N==M:
  print((2*s*t)%MOD)

Fixed submission:
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=(s*i)%MOD
t=1
for i in range(2,M+1):
  t=(t*i)%MOD
if abs(N-M)>1:
  print(0)
  exit()
if abs(N-M)==1:
  print((s*t)%MOD)
else:
  print((2*s*t)%MOD)

Buggy python submission (verdict: Runtime Error):
N.M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=s*i
t=1
for j in range(2,N+1):
  t=t*j
if N-1==M:
  print((s*t)%MOD)
if N==M-1:
  print((s*t)%MOD)
if N==M:
  print((2*s*t)%MOD)
else:
  print(0)

Fixed submission:
N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=(s*i)%MOD
t=1
for i in range(2,M+1):
  t=(t*i)%MOD
if abs(N-M)>1:
  print(0)
  exit()
if abs(N-M)==1:
  print((s*t)%MOD)
else:
  print((2*s*t)%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
S=[]
for i in range(N):
  a,b=map(int,input().split())
  for i in range(b):
    S.append(a)
S=sorted(S)
print(S[K-1])

Fixed submission:
N,K=map(int,input().split())
S={}
for i in range(N):
  a,b=map(int,input().split())
  if a in S:
    S[a]+=b
  else:
    S[a]=b
T=sorted(S.items())
count=0
for i in range(len(T)):
  count+=T[i][1]
  if count>=K:
    print(T[i][0])
    break
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=map(int, input().strip())

res=0
tres=0
prev=-1
for ai in a:
  if (prev<ai):
    res=max(res, tres)
    tres=0
  else:
    tres+=1
print(res)

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

res=0
tres=0
prev=-1
for ai in a:
  if (prev<ai):
    res=max(res, tres)
    tres=0
  else:
    tres+=1
  prev=ai
res=max(res, tres)
print(res)
Buggy python submission (verdict: Runtime Error):
n = input()
print((n-1)*n/2)

Fixed submission:
n = int(input().strip())
print(((n-1)*n)//2)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())

a = list()
for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a, reverse=True)

for i in range(n):
    index = a_sorted.index(a[i])
    if a[i] == a_sorted[0]:
        print(a_sorted[1])
        continue

    print(a_sorted[0])


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())

a = list()
for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sorted[0]:
        print(a_sorted[1])
        continue

    print(a_sorted[0])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
ans = 1

check = True
zero = False

for i in a:
    ans = ans*i

    if i==0:
        zero = True
        break;

    if ans>1000000000000000000:
        check = False
        break;




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 1

check = True
zero = False

for i in range(0,n):
    if a[i]==0:
        zero = True
        break;




for i in range(0,n):
    ans = ans*a[i]

    if ans>1000000000000000000:
        check = False
        break;




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 1

check = True
zero = False

for i in a:
    ans = ans*i

    if i==0:
        zero = True

    if ans>1000000000000000000:
        check = False




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 1

check = True
zero = False

for i in range(0,n):
    if a[i]==0:
        zero = True
        break;




for i in range(0,n):
    ans = ans*a[i]

    if ans>1000000000000000000:
        check = False
        break;




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 1

check = True
zero = False

for i in a:
    ans = ans*i

    if i==0:
        zero = True

    if ans>1000000000000000000:
        check = False




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 1

check = True
zero = False

for i in range(0,n):
    if a[i]==0:
        zero = True
        break;




for i in range(0,n):
    ans = ans*a[i]

    if ans>1000000000000000000:
        check = False
        break;




if zero:
    print(0)
else:
    if check:
        print(ans)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if c>a and c<b:
    print("Yes")
else:
    print("No")

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



if a[2]>a[0] and a[2]<a[1]:
    print("Yes")
elif a[1]<a[2] and a[2]<a[0]:
    print("Yes")
else:
    print("No")

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

if c>a and c<b:
    print("Yes")
else:
    print("No")

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



if a[2]>a[0] and a[2]<a[1]:
    print("Yes")
elif a[1]<a[2] and a[2]<a[0]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
human_num, train_value, taxi_num = tuple(int(i) for i in input().split(""))
print(min(train_value * human_num, taxi_num))

Fixed submission:
human_num, train_value, taxi_num = tuple(int(i) for i in input().split(" "))
print(min(train_value * human_num, taxi_num))
Buggy python submission (verdict: Runtime Error):
cord = list(input())
cord_len = len(cord)
for i in range(cord - 1):
    if cord[i] == cord[i + 1]:
        print("Bad")
        break
else:
    print("Good")


Fixed submission:
cord = list(input())
cord_len = len(cord)
for i in range(cord_len - 1):
    if cord[i] == cord[i + 1]:
        print("Bad")
        break
else:
    print("Good")
Buggy python submission (verdict: Runtime Error):
num = int(input())
weight_list = [int(i) for i in input().split(" ")]
ans_condinate = []
for i in range(num):
    ans_condinate.append(abs(sum(weight_list[:i + 1]) - sum(weight_list[i + 1:])))
print(min(ans_condinate))
a

Fixed submission:
num = int(input())
weight_list = [int(i) for i in input().split(" ")]
ans_condinate = []
for i in range(num):
    ans_condinate.append(abs(sum(weight_list[:i + 1]) - sum(weight_list[i + 1:])))
print(min(ans_condinate))
Buggy python submission (verdict: Runtime Error):
ID_num, gate_num = tuple([int(i) for i in input().split(" ")])
min_list = []
max_list = []
for i in range(gate_num):
  	min_ID, max_ID = tuple([int(i) for i in input().split(" ")])
    min_list.append(min_ID)
    max_list.append(max_ID)
print(min(max_list) - max(min_list) + 1)

Fixed submission:
ID_num, gate_num = tuple([int(i) for i in input().split(" ")])
min_list = []
max_list = []
for i in range(gate_num):
    min_ID, max_ID = tuple([int(i) for i in input().split(" ")])
    min_list.append(min_ID)
    max_list.append(max_ID)
M = min(max_list)
m = max(min_list)
if M >= m:
    print(min(max_list) - max(min_list) + 1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
ID_num, gate_num = tuple([int(i) for i in input().split(" ")])
min_list = []
max_list = []
for i in range(gate_num):
  	min_ID, max_ID = tuple([int(i) for i in input().split(" ")])
    min_list.append(min_ID)
    max_list.append(max_ID)
print(min(max_list) - max(min_list))

Fixed submission:
ID_num, gate_num = tuple([int(i) for i in input().split(" ")])
min_list = []
max_list = []
for i in range(gate_num):
    min_ID, max_ID = tuple([int(i) for i in input().split(" ")])
    min_list.append(min_ID)
    max_list.append(max_ID)
M = min(max_list)
m = max(min_list)
if M >= m:
    print(min(max_list) - max(min_list) + 1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        try:
            if i[1] > num_list[0]:
            num_list.pop(0)
            ans_list.append(i[1])
            else:
                break_is = 1
                break
        except IndexError:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))


Fixed submission:
def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        try:
            if i[1] > num_list[0]:
                num_list.pop(0)
                ans_list.append(i[1])
            else:
                break_is = 1
                break
        except IndexError:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))

Buggy python submission (verdict: Runtime Error):
def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        if i[1] > num_list[0]:
            num_list.pop(0)
            ans_list.append(i[1])
        else:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))


Fixed submission:
def index_1_sumall(list):
    return list[1]


n, m = tuple(int(i) for i in input().split(" "))
num_list = [int(i) for i in input().split(" ")]
num_list.sort()
change_list = []
ans_list = []
for j in range(m):
    change_list.append([int(i) for i in input().split(" ")])
change_list.sort(key=index_1_sumall, reverse=1)
break_is = 0
for i in change_list:
    for j in range(i[0]):
        try:
            if i[1] > num_list[0]:
                num_list.pop(0)
                ans_list.append(i[1])
            else:
                break_is = 1
                break
        except IndexError:
            break_is = 1
            break
    if break_is:
        break
num_list.append(0)
print(sum(num_list) + sum(ans_list))
Buggy python submission (verdict: Runtime Error):
a = [int(i) for i in input().split("")]
if a[0] == a[1]:
    print(2 * a[0])
else:
    print(2 * max(a) - 1)

Fixed submission:
a = [int(i) for i in input().split(" ")]
if a[0] == a[1]:
    print(2 * a[0])
else:
    print(2 * max(a) - 1)
Buggy python submission (verdict: Runtime Error):
n, x = int(input())
if x <= n*500:
    print("Yes")
else:
    print("No")

Fixed submission:
n, x = map(int, input().split())
if x <= n*500:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s = 0
now = As[0]
for a in As:
    if a<now:
        s += now - a
    else:
        now = a
        
print(s)

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

s = 0
now = As[0]
for a in As:
    if a<now:
        s += now - a
    else:
        now = a
        
print(s)
Buggy python submission (verdict: Runtime Error):
ng = -1
# 完食時間の最大はA=10**6, F=10**6の時。
ok = 10**12+1

def isok(x):
    # 最大の完食時間がxになるように修行する
    # その場合の修行回数の合計を求める
    # そしてそれがK回以下ならTrueを返す
    cnt = 0
    for a, f in zip(a_list,f_list):
        aprime = x // f
        cnt += max(a - aprime,0)
        
        if cnt > K:
            return False
    return True

while abs(ok-ng)>1:
    x = (ok+ng) // 2
    
    if isok(x):
        # train_cntが限界より多い場合、目指す最大の完食時間が短すぎる
        # よって完食時間を増やすべき
        # Kに等しい場合ももしかしたらもっといい
        ok = x
    else:
        ng = x
        
    print(ok,ng, train_cnt)

        
print(ok)

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

a_list.sort()
f_list.sort(key=lambda x :-x)

ng = -1
# 完食時間の最大はA=10**6, F=10**6の時。
ok = 10**12+1

def isok(x):
    # 最大の完食時間がxになるように修行する
    # その場合の修行回数の合計を求める
    # そしてそれがK回以下ならTrueを返す
    cnt = 0
    for a, f in zip(a_list,f_list):
        aprime = x // f
        cnt += max(a - aprime,0)
        
        if cnt > K:
            return False
    return True

while abs(ok-ng)>1:
    x = (ok+ng) // 2
    
    if isok(x):
        # train_cntが限界より多い場合、目指す最大の完食時間が短すぎる
        # よって完食時間を増やすべき
        # Kに等しい場合ももしかしたらもっといい
        ok = x
    else:
        ng = x
        
        
print(ok)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

s_list = list(S)

modified = "mdf"

def solve():
    # その単語に1種類の文字しかなければ、合計の文字数を2で割捨てした数
    if len(set(s_list)) == 1:
        return (len(s_list * K))//2
    
    cnt = 1
    cnt_list = []
    for i in range(len(S)-1):
        if s_list[i] == s_list[i+1]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    
    # 最後の対応
    # cnt = 1の時、最後は1文字だけ
    # cnt >= 2の時、最後は同じ文字が続いてる
    cnt_list.append(cnt)
    
    # 最初と最後が同じ時は最初と最後を足したやつを作る必要。
    head = cnt_list[0]
    tail = cnt_list[-1]
    body = cnt_list[1:-1]
    
    if s_list[0] == s_list[-1]:
        head_tail = cnt_list[0] + cnt_list[-1]
        return head//2 + tail//2 + (sum(body)//2)*K + (head_tail//2)*(K-1)
    else:
        return (head//2 + tail//2 + sum(body)//2) * K

result = solve()

print(result)

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

s_list = list(S)

modified = "mdf"

def solve():
    # その単語に1種類の文字しかなければ、合計の文字数を2で割捨てした数
    if len(set(s_list)) == 1:
        return (len(s_list)*K)//2
    
    cnt = 1
    cnt_list = []
    for i in range(len(s_list)-1):
        if s_list[i] == s_list[i+1]:
            cnt += 1
        else:
            cnt_list.append(cnt)
            cnt = 1
    
    # 最後の対応
    # cnt = 1の時、最後は1文字だけ
    # cnt >= 2の時、最後は同じ文字が続いてる
    cnt_list.append(cnt)
    
    # 最初と最後が同じ時は最初と最後を足したやつを作る必要。
    head = cnt_list[0]
    tail = cnt_list[-1]
    body = cnt_list[1:-1]
    
    def body_change_cnt(body):
        cnt = 0
        for b in body:
            cnt += b//2
        return cnt
    
    if s_list[0] == s_list[-1]:
        head_tail = cnt_list[0] + cnt_list[-1]
        return head//2 + tail//2 + body_change_cnt(body)*K + (head_tail//2)*(K-1)
    else:
        return (head//2 + tail//2 + body_change_cnt(body)) * K

result = solve()

print(result)
Buggy python submission (verdict: Runtime Error):
s_list = list(input())

length = len(s_list)

def func(idx,past):
    if idx==length:
        return 0
    if idx>length:
        return -1
    
    if s_list[idx] == past:
        return func(idx+2,s_list[idx:idx+2]) + 1
    else:
        return func(idx+1,s_list[idx])+1

print(func(0,""))

Fixed submission:

import sys
sys.setrecursionlimit(1000000)
s_list = list(input())
length = len(s_list)

def func(idx,past):
    if idx==length:
        return 0
    if idx>length:
        return -1
    
    if s_list[idx] == past:
        return func(idx+2,s_list[idx:idx+2]) + 1
    else:
        return func(idx+1,s_list[idx])+1

print(func(0,""))
Buggy python submission (verdict: Runtime Error):
S = int(input())

x2 = 10**9
y2 = 1

quotient = S//(10**9)
mod = S%(10**9)

if mod != 0:
    x3 = quotient+1
    y3 = -(mod-10**9)
else:
    x3 = quotient
    y3 = mod
    
print(f"0 0 {x2} {y2} {x3} {y3}")

Fixed submission:
S = int(input())

x2 = 1
y2 = 10**9

quotient = S//(10**9)
mod = S%(10**9)

if mod != 0:
    x3 = quotient+1
    y3 = -(mod-10**9)
else:
    x3 = quotient
    y3 = mod
    
print(" ".join(map(str,[0,0,x2,y2,x3,y3])))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

dp = [float('inf')]*n
for i in range(n):
    x = bisect.bisect_right(dp,-a[i])
    dp[x] = -a[i]
c = dp.count(float('inf'))
print(n-c)

Fixed submission:
import bisect
n = int(input())
a = [int(input()) for _ in range(n)]

dp = [float('inf')]*n
for i in range(n):
    x = bisect.bisect_right(dp,-a[i])
    dp[x] = -a[i]
c = dp.count(float('inf'))
print(n-c)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

print(4 + math.ceil(N/min(A,B,C,D,E)))

Fixed submission:
import math
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

print(4 + math.ceil(N/min(A,B,C,D,E)))
Buggy python submission (verdict: Runtime Error):
from math import gcd

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

A,B,K = map(int, input().split())

gcd_num = gcd(A,B)

divisor = make_divisors(gcd_num)

print(divisor[-K])

Fixed submission:
def gcd(x,y):
    if x%y==0:
        return y
    else:
        return gcd(y, x%y)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

A,B,K = map(int, input().split())

gcd_num = gcd(A,B)

divisor = make_divisors(gcd_num)

print(divisor[-K])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)
N = int(input())
h_list = list(map(int,input().split()))

costs = [None for _ in range(N)]

def func(stone_num):
    if stone_num == 0:
        return 0
    if stone_num == 1:
        return func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num])
    return min(
        func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num]),
        func(stone_num-2) + abs(h_list[stone_num-2] - h_list[stone_num])
    )

print(func(N-1))

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

costs = [None for _ in range(N)]

for i in range(N):
    if i == 0:
        cost = 0
    elif i == 1:
        cost = costs[i-1] + abs(h_list[i-1] - h_list[i])
    else:
        cost = min(
            costs[i-1] + abs(h_list[i-1] - h_list[i]),
            costs[i-2] + abs(h_list[i-2] - h_list[i])
        )
    costs[i] = cost

print(costs[-1])

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

costs = [None for _ in range(N)]

def func(stone_num):
    if stone_num == 0:
        return 0
    if stone_num == 1:
        return func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num])
    return min(
        func(stone_num-1) + abs(h_list[stone_num-1] - h_list[stone_num]),
        func(stone_num-2) + abs(h_list[stone_num-2] - h_list[stone_num])
    )

print(func(N-1))

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

costs = [None for _ in range(N)]

for i in range(N):
    if i == 0:
        cost = 0
    elif i == 1:
        cost = costs[i-1] + abs(h_list[i-1] - h_list[i])
    else:
        cost = min(
            costs[i-1] + abs(h_list[i-1] - h_list[i]),
            costs[i-2] + abs(h_list[i-2] - h_list[i])
        )
    costs[i] = cost

print(costs[-1])