Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
 
for i in range(Q):
    Que = input().split()
 
    if Que[0] == '1':
        S = S[::-1]
 
    if Que[0] == '2':
        if Que[1] == '1':
            S = Que[2] + S
        
        if Que[1] == '2':
            S = S + Que[2]
 
print(S)

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

A=""
Z=""
AZFlag = 0
for i in range(Q):
    Que = input().split()

    if Que[0] == '1':
        if AZFlag == 0:
            AZFlag = 1
            continue

        if AZFlag == 1:
            AZFlag = 0
            continue

    if Que[0] == '2':
        if Que[1] == '1' and AZFlag == 0:
            A = Que[2]+A
            continue

        if Que[1] == '1' and AZFlag == 1:
            Z = Z+Que[2]
            continue
        
        if Que[1] == '2' and AZFlag == 0:
            Z = Z+Que[2]
            continue

        if Que[1] == '2' and AZFlag == 1:
            A = Que[2]+A
            continue


if AZFlag == 0:
    print(A+S+Z)
if AZFlag == 1:
    print(Z[::-1]+S[::-1]+A[::-1])

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

for i in range(Q):
    Que = input().split()

    if Que[0] == '1':
        S = S[::-1]

    if Que[0] == '2':
        if Que[1] == '1':
            S = Que[2] + S
        
        if Que[1] == '2':
            S = S + Que[2]

print(S)


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

A=""
Z=""
AZFlag = 0
for i in range(Q):
    Que = input().split()

    if Que[0] == '1':
        if AZFlag == 0:
            AZFlag = 1
            continue

        if AZFlag == 1:
            AZFlag = 0
            continue

    if Que[0] == '2':
        if Que[1] == '1' and AZFlag == 0:
            A = Que[2]+A
            continue

        if Que[1] == '1' and AZFlag == 1:
            Z = Z+Que[2]
            continue
        
        if Que[1] == '2' and AZFlag == 0:
            Z = Z+Que[2]
            continue

        if Que[1] == '2' and AZFlag == 1:
            A = Que[2]+A
            continue


if AZFlag == 0:
    print(A+S+Z)
if AZFlag == 1:
    print(Z[::-1]+S[::-1]+A[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))

ans=10**10
for i in range(2*10**5):
  tmp=0
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp

print(ans)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
 
ans=10**10
for i in range(0,101):
  tmp=0
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp
 
print(ans)

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

ans=10**10
for i in range(N):
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp

print(ans)

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
 
ans=10**10
for i in range(0,101):
  tmp=0
  for x in X:
    tmp += (i - x)**2
  
  if ans>=tmp:
    ans=tmp
 
print(ans)
Buggy python submission (verdict: Runtime Error):
S, T = input().split()
A, B = input().split()
U = input()

if U == S:
  print(A-1)
else:
  print(B-1)

Fixed submission:
S, T = input().split()
A, B = list(map(int,input().split()))
U = input()
 
if U == S:
  print("{} {}".format(A-1,B))
else:
  print("{} {}".format(A,B-1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(N):
    if i == 0:
        ans += 1
        continue

    if P[i] <= min(P[:i]):
        ans += 1

print(ans)


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

ans = 0
n_p = 0
for i in range(N):
    if i == 0:
        ans += 1
        n_p = P[0]
        continue

    if P[i] <= n_p:
        ans += 1

    if n_p > P[i]:
        n_p = P[i]
        

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

def main():
    N, M = map(int, input().split())

    if M == 0:
        print('0 0')
        sys.exit()


    p_S = []
    for i in range(M):
        p_S.append(input().split())

    uniq_ps = np.unique(p_S, axis=0)
    


    ac = 0
    wa = 0
    for arr in uniq_ps:
        if arr[1] == 'AC':
            ac += 1
        else:
            wa += 1

    print(ac, wa)

main()




Fixed submission:
import sys

def main():
    N, M = list(map(int,input().split()))
    p_S = [None] * M

    wa_cnt = [0] * N
    ac_flags = [0] * N

    for i in range(M):
        p_S[i] = list(input().split())
        p_S[i][0] = int(p_S[i][0])

    wa_ans, ac_ans = 0, 0

    for j in p_S:
        if j[1] == 'WA':
            wa_cnt[j[0] - 1] += 1

        if j[1] == 'AC' and ac_flags[j[0] - 1] == 0:
            wa_ans += wa_cnt[j[0] - 1]
            ac_ans += 1
            ac_flags[j[0] - 1] = 1


    print(ac_ans, wa_ans)

main()
Buggy python submission (verdict: Runtime Error):
import sys
import math

def main():
    A, B = map(int, input().split())

    print(int(A * B / math.gcd(A, B)))

main()


Fixed submission:
import sys
from fractions import gcd

def main():
    A, B = map(int, input().split())

    print(int(A * B / gcd(A, B)))

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    A, B = map(int, input().split())

    for i in range(1, 9999900000):
        if(i%A==0 and i%B==0):
            print(i)
            sys.exit()
main()


Fixed submission:
import sys
from fractions import gcd

def main():
    A, B = map(int, input().split())

    print(int(A * B / gcd(A, B)))

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
    N = int(input())
    a = list(map(int, input().split()))
    num = 0
    blocks = 0

    while True:
        flag=0
        num += 1

        try:
            i = a.index(num)
            blocks += i
            del a[:i+1]
            flag=1

        except:
            if(num==1):
                print('-1')
                sys.exit()
        if(flag==0):
            blocks += len(a)
            print(blocks)
            sys.exit()

main()

Fixed submission:
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 1

    for i in a:
        if(i==num):
            num += 1

    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
    N = int(input())
    a = list(map(int, input().split()))
    num = 0
    blocks = 0

    while True:
        flag=0
        num += 1
        for i in range(0, len(a)):
            if(num==a[i]):
                blocks += i
                del a[:i+1]
                flag=1
                break


        if(flag==0):
            if(num==1):
                print('-1')
                sys.exit()

            blocks += len(a)
            print(blocks)
            sys.exit()

main()

Fixed submission:
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 1

    for i in a:
        if(i==num):
            num += 1

    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    delsum = 0

    i = 1
    while True:
        try:
            point = a.index(i)

        except ValueError:
            if(i==1):
                print('-1')
                sys.exit()

            delsum += len(a)-i+1
            print(delsum)
            sys.exit()

        delsum += point-(i-1)

        del a[i-1:point]

        i+=1

    print('-1')

main()

Fixed submission:
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 1

    for i in a:
        if(i==num):
            num += 1

    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    delsum = 0

    i = 1
    while True:
        try:
            point = a.index(i)

        except ValueError:
            if(i==1):
                print('-1')
                sys.exit()

            delsum += len(a)-i+1
            print(delsum)
            sys.exit()

        delsum += point-(i-1)

        del a[i-1:point]

        i+=1

    print('-1')

main()

Fixed submission:
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 1

    for i in a:
        if(i==num):
            num += 1

    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')

main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  S = list(input())
  
  sum = 0
  for i in range(0,int(len(S)//2)):
    if S[i]!=S[len(S)-i-1):
    	sum+=1
               
  print(sum)
               
main()

Fixed submission:
import sys
 
def main():
  S = list(input())
  
  sum = 0
  for i in range(0,int(len(S)//2)):
    if S[i]!=S[len(S)-i-1]:
    	sum+=1
               
  print(sum)
               
main()
Buggy python submission (verdict: Runtime Error):
import sys
import math

def main():
    N = int(input())
    N_x = 100*N
    for x in range(N_x-50, N_x+50):
        if(x%108==0):
            print(x//108)
			sys.exit()
    print(":(")

main()

Fixed submission:
import sys

def main():
    N=int(input())

    for x in range(50001):
        if(int(x*1.08)==N):
            print(x)
            sys.exit()

    print(":(")
main()

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

def main():
    N = int(input())
    N_x = 100*N
    for x in range(N_x-50, N_x+50):
        if(x%108==0):
            print(x//108)
			sys.exit()
    print(":(")

main()

Fixed submission:
import sys

def main():
    N=int(input())

    for x in range(50001):
        if(int(x*1.08)==N):
            print(x)
            sys.exit()

    print(":(")
main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

def main():
    N = int(input())



    for a in reversed(range(1, int(math.sqrt(N))+1)):
        b = a
        while True:
            if a * b == N:
                print(a + b - 2)
                sys.exit()

            if a * b > N:
                break

            b += 1

main()

Fixed submission:
import sys
import math

def main():
    N = int(input())

    for a in reversed(range(1, int(math.sqrt(N))+1)):
        if N % a == 0:
            print(int(a + N/a - 2))
            sys.exit()

main()
Buggy python submission (verdict: Runtime Error):
S = str(input())
if(S=="Sunny"):
    print("Cloudy")
else if(S=="Cloudy"):
    print("Rainy")
else if(S=="Rainy"):
    print("Sunny")
else:
    exit()

Fixed submission:
S = str(input())
if(S=="Sunny"):
    print("Cloudy")
elif(S=="Cloudy"):
    print("Rainy")
elif(S=="Rainy"):
    print("Sunny")
else:
    exit()
Buggy python submission (verdict: Runtime Error):
import sys

A, B =map(int, input().split())
count = 1

if(A>=B):
    print('1')
    sys.exit()

B-=A
while True:
    B-=(A-1)
    if(B<=0):
        print(count)
        sys.exit()
    count+=

Fixed submission:
import sys

A, B =map(int, input().split())
x = 0

if(B==1):
    print('0')
    sys.exit()

while True:
    if(A+(A-1)*x>=B):
        print(x+1)
        sys.exit()
    x+=1
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
x = A+B
y = A-B
z = A*B

if(x>y and x>z):
    print(x)

elif(y>x and y>z):
    print(y)

elif(z>x and z>y):
    print(z)

else:
    exit()
~

Fixed submission:
A, B = map(int, input().split())
x = A+B
y = A-B
z = A*B

if(x>=y>=z or x>=z>=y):
    print(x)
elif(y>=x>=z or y>=z>=x):
    print(y)
else:
    print(z)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = int(input())

    Ss = []
    for x in range(N):
        Ss.append(sorted(input()))

    ans = 0
    for i in range(0, N-1):
        ans += Ss[i+1:N].count(Ss[i])

    print(ans)

main()

Fixed submission:
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    N = int(input())

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(input()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
 
def main():
    N = int(input())
 
    Ss = []
    for x in range(N):
        Ss.append(sorted(input()))
 
    ans = 0
    for i in range(0, N-1):
        for j in range(i+1, N):
            if Ss[i] == Ss[j]:
                ans += 1
 
    print(ans)
 
main()

Fixed submission:
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    N = int(input())

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(input()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = int(input())

    Ss = []
    for x in range(N):
        Ss.append(sorted(input()))

    ans = 0
    for i in range(0, N-1):
        for j in range(i+1, N):
            if Ss[i] == Ss[j]:
                ans += 1

    print(ans)

main()

Fixed submission:
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    N = int(input())

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(input()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]


    for j in range(N):
        if j == 0:
            print(max(A[1:]))

        elif j == N-1:
            print(max(A[:N-1]))

        else:
            print(max(max(A[:j]), max(A[j+1:])))


main()

Fixed submission:
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
 
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
 
    for j in range(N):
        if j == 0:
            print(max(A[1:]))
 
        elif j == N-1:
            print(max(A[:N-1]))
 
        else:
            print(max(max(A[:j]), max(A[j+1:])))
 
 
main()

Fixed submission:
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    N = int(input())
    A = [int(input()) for i in range(N)]

    for j in range(N):
        if j == 0:
            print(max(A[1:]))

        elif j == N-1:
            print(max(A[:N-1]))

        else:
            print(max(max(A[:j]), max(A[j+1:])))


main()

Fixed submission:
import sys

def main():
    N = int(input())
    A = [int(sys.stdin.readline()) for i in range(N)]
    anoA = sorted(A)
    mA = max(A)

    for j in range(N):
        if mA == A[j]:
            print(anoA[-2])

        else:
            print(mA)


main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    d = list(map(int, input().split()))
    mind = min(d)
    maxd = max(d)

    ans = 0
    for i in range(mind, maxd):
        n = sum(x > i for x in d)
        if n == N // 2:
            ans += 1


    print(ans)


main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    d = list(map(int, input().split()))
    sod = sorted(d)


    print(sod[int(N/2)] - sod[int(N/2)-1])


main()
Buggy python submission (verdict: Runtime Error):
S = list(map(str, input()))

if(S[0]==S[1] or S[1]==S[2] or S[2]==S[3]):
  print("Bad")
else:
  print(Good)

Fixed submission:
S = list(map(str, input()))
 
if(S[0]==S[1] or S[1]==S[2] or S[2]==S[3]):
  print("Bad")
else:
  print("Good")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import math

def main():
    A, B, C, D = list(map(int, input().split()))
    lcm = C * D / math.gcd(C, D)

    Ac = int(A/C)
    if A % C == 0:
        Ac-=1

    Bc = int(B/C)
    cnum = Bc - Ac

    Ad = int(A/D)
    if A % D == 0:
        Ad-=1

    Bd = int(B/D)
    dnum =Bd - Ad

    Alcm = int(A/lcm)
    if A % lcm == 0:
        Alcm-=1

    Blcm = int(B/lcm)
    lcmnum = Blcm - Alcm

    print(B - A + 1 - (cnum + dnum - lcmnum))

main()

Fixed submission:
import sys

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a



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



def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)

    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(input())
s[k]=chr(ord(s[k])+32)

print(*s,sep='')

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=chr(ord(s[k-1])+32)

print(*s,sep='')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N, M = map(int, input().split())

    AB = [0] * N
    for i in range(N):
        AB[i] = list(map(int, input().split()))

    AB = sorted(AB)

    have = 0
    price = 0
    while M != have:
        AB[0][1] -= 1
        price += AB[0][0]
        have += 1

        if AB[0][1] == 0:
            del AB[0]


    print(price)

main()

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N, M = map(int, input().split())

    AB = [0] * N
    for i in range(N):
        AB[i] = list(map(int, input().split()))

    AB = sorted(AB)

    have = 0
    price = 0
    while M != have:
        AB[0][1] -= 1
        price += AB[0][0]
        have += 1

        if AB[0][1] == 0:
            del AB[0]


    print(price)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

def main():
    S  = list(map(int, input()))

    del_cnt = 0
    while True:
        mark = []
        now_p = 0
        now_S = len(S)
        while now_S-1 > now_p:
            if S[now_p] == S[now_p + 1]:
                now_p += 1
            else:
                mark.extend([now_p,now_p+1])
                del_cnt += 1
                now_p += 2

        S = dellist(S, mark)
        if not mark:
            break

        mark = []

    print(del_cnt * 2)

main()

Fixed submission:
import sys

def main():
    S  = list(map(int, input()))
    o = S.count(0)
    l = S.count(1)

    print(min(o, l) * 2)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    S  = list(map(int, input()))

    del_cnt = 0
    while True:
        now_S = len(S)
        for i in range(now_S - 1):
            if S[i] != S[i+1]:
                del S[i:i+2]
                del_cnt += 1
                break
        done_S = len(S)

        if now_S == done_S:
            break

    print(del_cnt * 2)

main()

Fixed submission:
import sys

def main():
    S  = list(map(int, input()))
    o = S.count(0)
    l = S.count(1)

    print(min(o, l) * 2)

main()
Buggy python submission (verdict: Runtime Error):
import fractions 

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

ans = 0
for i in range(N):
  if i == 0:
    ans = A[0]
    continue

  ans = gcd(ans,A[i])
  
print(ans)

Fixed submission:
import fractions 

N = int(input())
A = list(map(int,input().split()))
 
ans = 0
for i in range(N):
  if i == 0:
    ans = A[0]
    continue
 
  ans = fractions.gcd(ans,A[i])
  
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))

    if M == 1:
        print('0')
        exit()

    if N == 1:
        print(X[M] - X[0])
        exit()

    X = sorted(X)

    kukan = []
    for i in range(1, M):
        kukan.append(X[i]-X[i-1])

    kukan = sorted(kukan, reverse=True)

    jogai = 0
    for j in range(N-1):
        jogai += kukan[j]

    print(X[M-1] - X[0] - jogai)

main()

Fixed submission:
import sys

def main():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))

    if N >= M:
        print('0')
        exit()

    X = sorted(X)

    kukan = []
    for i in range(1, M):
        kukan.append(X[i]-X[i-1])

    kukan = sorted(kukan, reverse=True)

    jogai = 0
    for j in range(N-1):
        jogai += kukan[j]

    print(X[M-1] - X[0] - jogai)

main()

Buggy python submission (verdict: Runtime Error):
import sys

def main():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))

    if M == 1:
        print('0')
        exit()

    X = sorted(X)

    kukan = []
    for i in range(1, M):
        kukan.append(X[i]-X[i-1])

    kukan = sorted(kukan, reverse=True)

    jogai = 0
    for j in range(N-1):
        jogai += kukan[j]

    print(X[M-1] - X[0] - jogai)

main()

Fixed submission:
import sys

def main():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))

    if N >= M:
        print('0')
        exit()

    X = sorted(X)

    kukan = []
    for i in range(1, M):
        kukan.append(X[i]-X[i-1])

    kukan = sorted(kukan, reverse=True)

    jogai = 0
    for j in range(N-1):
        jogai += kukan[j]

    print(X[M-1] - X[0] - jogai)

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

dp = [None]*n

for i in range(n):
  if i == 0:
    dp[i] = 0

  if i == 1:
    dp[1] = abs(h[1] - h[0])

  dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
  
  
print(dp[n-1])

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
 
dp = [None]*n
 
for i in range(n):
  if i == 0:
    dp[0] = 0
    continue
    
  if i == 1:
    dp[1] = abs(h[1] - h[0])
    continue
    
  dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
  
  
print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
 
dp = [float('inf')]*n
 
for i in range(n):
  if i == 0:
    dp[0] = 0
    continue
    
  for j in range(0 if i-k < 0 else i-k,i):
    dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
  
  
print(dp[n-1])

Fixed submission:
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
 
dp = [float('inf')]*n
 
for i in range(n):
  if i == 0:
    dp[0] = 0
    continue
    
  for j in range(0 if i-k < 0 else i-k,i):
    dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
  
  
print(dp[n-1])