Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N, K = inputIntList()
    h = inputIntList()
    h.extend([0] * K)
    dp = [float("inf") for _ in range(N + K)]
    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            if abs(h[i] - h[i + k]) + dp[i] < dp[i + k]:
                dp[i + k] = abs(h[i] - h[i + k]) + dp[i]
        # print(dp)
    return dp[N - 1]


if __name__ == "__main__":
    print(main())


Fixed submission:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N, K = inputIntList()
    h = inputIntList()
    h.extend([0] * K)
    dp = [float("inf") for _ in range(N + K)]
    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            if abs(h[i] - h[i + k]) + dp[i] < dp[i + k]:
                dp[i + k] = abs(h[i] - h[i + k]) + dp[i]
        # print(dp)
    return dp[N - 1]


if __name__ == "__main__":
    print(main())
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    act = []
    for i in range(N):
        act.append(inputIntList())
    act.append([0, 0, 0])
    dp = [0 for _ in range(N + 1)]
    for i in range(N):
        dp[i + 1] = dp[i] + max(act[i])
        act[i + 1][np.argmax(act[i])] = 0
        # print(np.argmax(act[i]))

    return dp[-1]


if __name__ == "__main__":
    print(main())


Fixed submission:
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    act = [inputIntList() for _ in range(N)]
    act.append([0, 0, 0])
    dp = [[0 for _ in range(3)] for _ in range(N + 1)]
    dp[0] = act[0]
    for i in range(1, N + 1):
        for j in range(3):
            dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + act[i][j]
            # print(dp)

    return max(dp[-1])


if __name__ == "__main__":
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy as np


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N, capacity = inputIntList()
    w = [0 for _ in range(N)]
    v = [0 for _ in range(N)]
    for i in range(N):
        w[i], v[i] = inputIntList()

    dp = [[0 for _ in range(capacity + 1)] for _ in range(N + 1)]
    for i in range(N):
        for j in range(capacity + 1):
            if j < w[i]:
                dp[i + 1][j] = dp[i][j]
            else:

                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j])
            # print(dp)

    return dp[N][capacity]


if __name__ == "__main__":
    print(main())


Fixed submission:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N, capacity = inputIntList()
    w = [0 for _ in range(N)]
    v = [0 for _ in range(N)]
    for i in range(N):
        w[i], v[i] = inputIntList()

    dp = [[0 for _ in range(capacity + 1)] for _ in range(N + 1)]
    for i in range(N):
        for j in range(capacity + 1):
            if j < w[i]:
                dp[i + 1][j] = dp[i][j]
            else:

                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j])
            # print(dp)

    return dp[N][capacity]


if __name__ == "__main__":
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
val = list(map(int, input().split()))
N = int(input())
price = [v / (2 ** i)  for i, v in enumerate(val)]
sortedIndex = []
sortedPrice = sorted(price)
price2 = price.copy()
for p in sortedPrice:
    sortedIndex.append(price2.index(p))
    price2[price2.index(p)] = -1

temp = 0
ans = 0
for i in sortedIndex:
    while N > temp:
        if(N < temp + 0.25 * (2 ** i)):
            break
        temp += 0.25 * (2 ** i)
        ans += val[i]
    
print (ans)


Fixed submission:
val = list(map(int, input().split()))
N = int(input())
price = [v / (2 ** i)  for i, v in enumerate(val)]
sortedIndex = []
sortedPrice = sorted(price)
price2 = price.copy()
for p in sortedPrice:
    sortedIndex.append(price2.index(p))
    price2[price2.index(p)] = -1

temp = 0
ans = 0
for i in sortedIndex:
    size  = (0.25 * (2 ** i))
    times = int(N / size)
    # print (size, times)
    N -= size * times
    ans += val[i] * times
# for i in sortedIndex:
#     while N > temp:
#         if(N < temp + 0.25 * (2 ** i)):
#             break
#         temp += 0.25 * (2 ** i)
#         ans += val[i]

print (ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
usa = list(map(int, input().split()))
flag = [0 for x in range(N)]
count = 0
for i, j in enumerate(usa):
    if(flag[i]):
        continue
    if(usa[j-1]-1 == i):
        count+=1
        flag[usa[j - 1]] = 1

print (count)


Fixed submission:
N = int(input())
usa = list(map(int, input().split()))
flag = [0 for x in range(N)]
count = 0
for i, ai in enumerate(usa):
    if(flag[i]):
        continue
    if(usa[ai-1]-1 == i):
        count+=1
        flag[ai - 1] = 1

print (count)
Buggy python submission (verdict: Time Limit Exceeded):
NK=input().split()
N=int(NK[0])
K=int(NK[1])
Hlis=list(map(int,input().split()))
ans=0

if K>=N:
    print(0)
else:
    for i in range(N-K):
        mini=Hlis.index(min(Hlis))
        ans+=Hlis[mini]
        Hlis.pop(mini)
    print(ans)

Fixed submission:
NK=input().split()
N=int(NK[0])
K=int(NK[1])
Hlis=list(map(int,input().split()))
ans=0

if K>=N:
    print(0)
else:
    Hlis.sort()
    for i in range(N-K):
        ans+=Hlis[i]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
NK=input().split()
N=int(NK[0])
K=int(NK[1])
Hlis=list(map(int,input().split()))
ans=0

if K>=N:
    print(0)
else:
    for i in range(N-K):
        ans+=Hlis[Hlis.index(min(Hlis))]
        Hlis[Hlis.index(min(Hlis))]=10**9
    print(ans)


Fixed submission:
NK=input().split()
N=int(NK[0])
K=int(NK[1])
Hlis=list(map(int,input().split()))
ans=0

if K>=N:
    print(0)
else:
    Hlis.sort()
    for i in range(N-K):
        ans+=Hlis[i]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
NK=input().split()
N=int(NK[0])
K=int(NK[1])
Hlis=list(map(int,input().split()))

if K>=N:
    print(0)
else:
    for i in range(K):
        Hlis[Hlis.index(max(Hlis))]=0
    print(sum(Hlis))



Fixed submission:
NK=input().split()
N=int(NK[0])
K=int(NK[1])
Hlis=list(map(int,input().split()))
ans=0

if K>=N:
    print(0)
else:
    Hlis.sort()
    for i in range(N-K):
        ans+=Hlis[i]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a_lis=list(map(int,input().split()))

output=""

for i in range(n):
    output+=str(1+a_lis.index(i+1))+" "

print(output)


Fixed submission:
n=int(input())
a_lis=list(map(int,input().split()))
lis = sorted(range(n), key=lambda k: a_lis[k])
for i in range(n):
    lis[i]=str(lis[i]+1)
print(' '.join(lis))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = input().split()
counter = 0
for i in range(N):
    k = i+1
    for j in range(k):
        if int(P[i]) > int(P[j]):
            break
    if (i == j ):
        counter += 1
print(counter)


Fixed submission:
N = int(input())
P = input().split()
counter = 0
m = N
for p in P:
    if int(m) >= int(p):
        counter +=1
        m = p
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = input().split()
check_counter = 0
counter = 0
for i in range(N):
    k = i+1
    for j in range(k):
        if int(P[i]) <= int(P[j]):
            check_counter += 1
        else:
            break
    if (k == check_counter):
        counter += 1
    check_counter = 0
print(counter)

Fixed submission:
N = int(input())
P = input().split()
counter = 0
m = N
for p in P:
    if int(m) >= int(p):
        counter +=1
        m = p
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = input().split()
check_counter = 0
counter = 0
for i in range(N):
    k = i+1
    for j in range(k):
        if int(P[i]) <= int(P[j]):
            check_counter += 1
    if (k == check_counter):
        counter += 1
    check_counter = 0
print(counter)

Fixed submission:
N = int(input())
P = input().split()
counter = 0
m = N
for p in P:
    if int(m) >= int(p):
        counter +=1
        m = p
print(counter)
Buggy python submission (verdict: Runtime Error):
n = int(input())                                                                    s = input()                                                                                                                                                             print(s.count('ABC'))

Fixed submission:
n = int(input())
s = input()                                                                                                                                                             
print(s.count('ABC'))
Buggy python submission (verdict: Runtime Error):
 a,b=map(int,input().split())#標準入力を行う
  print(a % b)

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

if n % k == 0:
	print('0')
else :
	print('1')

Buggy python submission (verdict: Runtime Error):
A, B = map(int, raw_input().split())
print(A % B)

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

if n % k == 0:
	print('0')
else :
	print('1')
Buggy python submission (verdict: Runtime Error):
a,b = int(input())

if a*b % 2 == 0:
  print('Even')
else a*b % 2 == 1:
  print("Odd")

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")
Buggy python submission (verdict: Runtime Error):
date = input()

print(date.replace(date[4:],2018))

Fixed submission:
date = input()
print(date.replace(date[:4],'2018'))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split(" ")))
result = []

for i in range(1,N+1):
  stu = A.index(i) + 1
  result.append(stu)

print(" ".join(map(str,result)))


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

sorted_result = sorted(J , key=lambda i: +A[i])
print(" ".join(map(str,sorted_result)))
Buggy python submission (verdict: Runtime Error):
num = int(input())
V = list(input().split(" "))
C = list(input().split(" "))
result = 0

for i in range(num):
    Vi = int(V[i])
    Ci = int(C[i])
    if Vi <= Ci:
        continue
    result += (Vi - Ci )

print(result)


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

num = int(T/A)

print(num*B)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce

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

def read_float_n():
    return list(map(float, input().split()))

NM=read_int_n()
A=read_float_n()
A=list(set(A)) ##重複した要素を削除し、新たなリストを生成

##2で何回割れるかをcountする
def power2(n): ##参考：https://note.nkmk.me/python-prime-factorization/
  m=0
  while n % 2 == 0:
    m+=1
    n //= 2
  return m

a=[]
a_2=power2(A[0])

for i in range(NM[0]):
  if power2(A[i])==a_2:
    a.append(A[i]*0.5)

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

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

lcm=lcm_list(a)

amari=NM[1]/lcm #50までは15,30,45の3つ

print(int(round(amari/2))) #3つうち奇数を切り上げ

Fixed submission:
from fractions import gcd
from functools import reduce

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

def read_float_n():
    return list(map(float, input().split()))

NM=read_int_n()
A=read_float_n()
A=list(set(A)) ##重複した要素を削除し、新たなリストを生成

##2で何回割れるかをcountする
def power2(n): ##参考：https://note.nkmk.me/python-prime-factorization/
  m=0
  while n % 2 == 0:
    m+=1
    n //= 2
  return m

#####2で奇数回割り切れる場合のみのflag
flag=0

a=[]
a_2=power2(A[0])

for i in range(len(A)): ###len(A) ###### A[0]をa=[]にappendする
  if power2(A[i])==a_2:
    a.append(int(A[i]*0.5)) ########## floatをintに直す
  else:
    flag=1

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

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)  
  
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

if flag==0:
  lcm=lcm_list(a)
  amari=NM[1]/lcm #50までは15,30,45の3つ
  amari=(amari+1)//2 #3つのうち奇数を切り上げ
  ########roundは偶数への丸め(0.5は1になる):https://note.nkmk.me/python-round-decimal-quantize/
  ########四捨五入するならdecimalモジュールのquantize('.01')
  #Decimal(i).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
  print(int(amari)) 
else:
  print(0)
#print(flag,amari,NM[1],lcm,a,A)
Buggy python submission (verdict: Runtime Error):
n=int(input())
List = [int(i) for i in input().split()]
ans=0
for i in range(n):
  for j in range(i):
    a+=List[i]*List[j]
print(ans)

Fixed submission:
n=int(input())
List = [int(i) for i in input().split()]
a=0
for i in range(n):
  for j in range(i):
    a+=List[i]*List[j]
print(a)
Buggy python submission (verdict: Runtime Error):
t=str(input())
k=int(input())
L = len(t)
tmp = t[0]
n = 0 #change
flag = 0
for i in range(1,L):
  if flag==1:
    flag=0
  elif t[i]==tmp:# and flag==0:
    n+=1
    flag=1  
  tmp=t[i]
ans=k*n

if t[0]==t[-1] and t[-2]!=t[-1]:
  ans+=k-1
print(ans)

Fixed submission:
t=str(input())
k=int(input())
L = len(t)
tmp = t[0]
n = 0 #change
flag = 0
for i in range(1,L):
  if flag==1:
    flag=0
  elif t[i]==tmp:
    n+=1
    flag=1  
  tmp=t[i]
ans=k*n
if L>2:
  if t[0]==t[-1] and flag==0:
    u = t[0]+t
    tmp = u[0]
    m = 0 #change
    flag = 0
    for i in range(1,L+1):
      if flag==1:
        flag=0
      elif u[i]==tmp:
        m+=1
        flag=1  
      tmp=u[i]
    if m!=n: 
      ans+=k-1

if t.count(t[0])==L:
  ans=(k*L)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1,n):
  ans += i%(i+1)
print(ans)

Fixed submission:
n = int(input())
print(int((n)*(n-1)//2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = [int(i) for i in input().split()] # input:"1 2 3 4 5"
ans = 0
for i in range(n-1):
  for j in range(i,n-1):
    delta = h[j]-h[i]
    if h[j+1]+1<h[i]:
        ans = 1
        break
    elif h[j+1]+1==h[i]:
        h[i]-=1
        break
if ans == 1:
  print('No')
elif sorted(h)==h:
  print('Yes')
else:
  print('No')


Fixed submission:
n = int(input())
h = [int(i) for i in input().split()] # input:"1 2 3 4 5"

#2019/08/08とき直し
#次のマスの高さを１高くすることができるようにする
ans = 'Yes'
for i in range(n-1):
  if h[i]>h[i+1]+1:
    ans = 'No'
    break
  elif h[i]==h[i+1]+1:
    h[i+1]+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = [int(i) for i in input().split()] # input:"1 2 3 4 5"
ans = 0
for i in range(n-1):
  for j in range(i,n-1):
    delta = h[j]-h[i]
    if h[j+1]+1<h[i]:
        ans = 1
        break
    elif h[j+1]+1==h[i]:
        h[i]-=1
        break
if ans == 1:
  print('No')
elif sorted(h)==h:
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()] # input:"1 2 3 4 5"

#2019/08/08とき直し
#次のマスの高さを１高くすることができるようにする
ans = 'Yes'
for i in range(n-1):
  if h[i]>h[i+1]+1:
    ans = 'No'
    break
  elif h[i]==h[i+1]+1:
    h[i+1]+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
#print(L)
M=0
ans = set(range(L[M][0],L[M][1]+1))
for M in range(m):
  a=set(range(L[M][0],L[M][1]+1))
  ans = a&ans
  #print(ans)
print(len(list((ans))))


Fixed submission:
import numpy as np
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
list = np.asarray(L)

MAX=np.max(list,axis=0)
MIN=np.min(list,axis=0)

ans = MIN[1]-MAX[0]+1
if ans>0:
  print(MIN[1]-MAX[0]+1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
#print(L)
M=0
ans = set(range(L[M][0],L[M][1]+1))
for M in range(m):
  a=set(range(L[M][0],L[M][1]+1))
  ans = a&ans
  #print(ans)
print(len(list((ans))))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
list = np.asarray(L)

MAX=np.max(list,axis=0)
MIN=np.min(list,axis=0)

ans = MIN[1]-MAX[0]+1
if ans>0:
  print(MIN[1]-MAX[0]+1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
#print(L)
M=0
ans = set(list(range(L[M][0],L[M][1]+1)))
for M in range(m):
  a=set(list(range(L[M][0],L[M][1]+1)))
  ans = a&ans
  #print(ans)
print(len(list((ans))))

Fixed submission:
import numpy as np
n,m=map(int,input().split())
L=[list(map(int,input().split())) for i in range(m)]
list = np.asarray(L)

MAX=np.max(list,axis=0)
MIN=np.min(list,axis=0)

ans = MIN[1]-MAX[0]+1
if ans>0:
  print(MIN[1]-MAX[0]+1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
4 3
CABA

Fixed submission:
a,b=map(int,input().split())
b=b-1
s=input()
print(s[0:b].upper()+s[b].lower()+s[b+1:].upper())
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N =map(int,input().split())
ans=0
for r in range(N//R +1):
  for g in range(N//G +1):
    n = N-r*R-g*G
    
    if n>=0:
      if n%B==0:

        ans+=1

print(ans)

Fixed submission:
R,G,B,N =map(int,input().split())
ans=0
for r in range(N//R +1):
  for g in range(N//G +1):
    n = N-r*R-g*G
    
    if n>=0:
      if n%B==0:

        ans+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import numpy as np

n = int(input())
a =[int(i) for i in input().split()] 

A = 0
for i in range(n):
  aa = np.asarray(a)
  a_del = np.delete(a, i, 0)
  List = list(a_del)
  
  G = reduce(gcd,List)
  #print(G)
  A = max(A,G)
print(A)

Fixed submission:
from fractions import gcd
n = int(input())
a = [int(x) for x in input().split(' ')]

L=[0]
for i in range(n):
  L.append(gcd(L[i],a[i]))

R=[0]
for i in range(n):
  R.append(gcd(R[i],a[n-i-1]))
  
M=[0]
for i in range(n):
  M.append(gcd(L[i],R[n-i-1]))
  
print(max(M))
Buggy python submission (verdict: Runtime Error):
N=int(input())
b=[int(i) for i in input().split()]
a = [0]*N
def dfs(x,n,a): #n桁のx
  if x == []: #Goalで終了
    return True
    
  for xlen in range(min(len(x),9))[::-1]:
    if x[xlen] == xlen+1:
      a[n] = xlen+1
      xx = copy.copy(x)
      xx.pop(xlen)
      return dfs(xx, n-1, a)

  if a[n] == 0:
      return False
if dfs(b,N-1,a):
  for i in range(N):
    print(a[i])
else:
  print(-1)

Fixed submission:
import copy
N=int(input())
b=[int(i) for i in input().split()]
 
c = copy.copy(b) #コピーを行う
a = [0]*N
a_n = N-1
 
for n in range(N)[::-1]:#N桁
  for i in range(len(c))[::-1]:#大きい数字からcheck
    if c[i]==i+1:#iが9を超えても成立する
      a[a_n] = c.pop(i)
      #print(c,len(c))
      a_n = a_n-1
      break#このbreakに気づかなかったので、2を取り除いたあとに1も取り除いてしまった
 
if n-1 != a_n:
  print(-1)
  exit()
else:
  for i in range(N):
    print(a[i])
Buggy python submission (verdict: Time Limit Exceeded):
ans = 0
A,B = map(int,input().split())
for i in range(A,B+1):
  ans = ans ^ i
print(ans)

Fixed submission:
A,B = map(int,input().split())
def xor(n):
  m = 0
  if n % 4 == 0:
    m = n
  elif n % 4 == 1:
    m = 1
  elif n % 4 == 2:
    m = n + 1
  return m
a = xor(A-1)
b = xor(B)
print(a ^ b)
Buggy python submission (verdict: Runtime Error):
import numpy as np
a,b,q = list(map(int, input().split()))

s  = [int(input()) for i in range(a)]
t  = [int(input()) for i in range(b)]
x  = [int(input()) for i in range(q)]

S = np.asarray(s)
T = np.asarray(t)
X = np.asarray(x)

st = np.zeros([a,b])
for i in range(a):
  for j in range(b):
    st[i][j] = abs(s[i]-t[j])

ans = np.zeros(q)
for k in range(q):
  #sを探す
  SX= np.abs(S-X[k])
  min_SX = min(SX)
  i = np.argmin(SX)
  #tを探す
  TX = np.abs(T-X[k])
  j = np.argmin(TX)
  min_TX = min(TX)
  #sが近い->そのsに近いtを探す
  ans[k] = min(min_SX + min(st[i]), min_TX + min(st.T[j]))
  print(int(ans[k]))

Fixed submission:
import bisect #bisectの典型的問題
a,b,q = map(int, input().split())

s  = [int(input()) for i in range(a)]
t  = [int(input()) for i in range(b)]

INF=10**18
s=[-INF]+s+[INF] #グリッド系の問題では、配列外を探索しないように
t=[-INF]+t+[INF]
x  = [int(input()) for i in range(q)]
for i in range(q):
  xi = x[i] #xを一気に読み込まなくてもfor loopの中の方が良い
  si = bisect.bisect_right(s, xi)
  ti = bisect.bisect_right(t, xi)
  ans=INF
  
  for S in [s[si-1], s[si]]:
    for T in [t[ti-1], t[ti]]:
      SX = abs(S-xi)
      TX = abs(T-xi)
      ST = abs(S-T)
      ans = min(ans, SX+ST, TX+ST)
  print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
import math
GCD_i=A[0]
for i in range(len(A)):
  GCD_i = math.gcd(GCD_i,A[i])
print(GCD_i)

Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))
GCD_i=A[0]
for i in range(len(A)):
  GCD_i = fractions.gcd(GCD_i,A[i])
print(GCD_i)
Buggy python submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)
 
@lru_cache(maxsize = None)

N = int(input())
hlist = list(map(int, input().split()))
 
#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))
 
print(dp(N-1))

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]

def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(cost[n-1]+abs(hlist[n]-hlist[n-1]), cost[n-2]+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i]=dp(i)
print(cost[-1])

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

#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))

print(dp(N-1))

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]

def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(cost[n-1]+abs(hlist[n]-hlist[n-1]), cost[n-2]+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i]=dp(i)
print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]
cost[0] = 0
cost[1] = abs(hlist[1] - hlist[0])
#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  #print(n)
  if n==0: return cost[0]
  elif n==1: return cost[1]
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i] = dp(i)
print(cost[-1])

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]

def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(cost[n-1]+abs(hlist[n]-hlist[n-1]), cost[n-2]+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i]=dp(i)
print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]
cost[0] = 0
cost[1] = abs(hlist[1] - hlist[0])
#再帰
"""
def function(n)
if 終了条件 return 初項
return function(n-1)を処理したもの
"""
def dp(n):
  #print(n)
  if n==0: return cost[0]
  if n==1: return cost[1]
  else: return min(dp(n-1)+abs(hlist[n]-hlist[n-1]), dp(n-2)+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i] = dp(i)
print(cost[-1])

Fixed submission:
N = int(input())
hlist = list(map(int, input().split()))
cost = [-1 for _ in range(N)]

def dp(n):
  if n==0: return 0
  if n==1: return abs(hlist[1] - hlist[0])
  else: return min(cost[n-1]+abs(hlist[n]-hlist[n-1]), cost[n-2]+abs(hlist[n]-hlist[n-2]))

for i in range(N):
  cost[i]=dp(i)
print(cost[-1])