Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

ans = S.count('R') * S.count('G') * S.count('B')

SN = []

for s in S:
    if s == 'R': SN.append(-1)
    elif s == 'G': SN.append(0)
    else: SN.append(1)

rem2 = ['RRR', 'GGG', 'BBB']

count = 0
for i in range(1, N-1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass
        elif SN[left] + SN[index] + SN[right] == 0 :
            count+= 1
        
        left -= 1
        right += 1

print(ans-count)


Fixed submission:
#!/usr/bin/env python3

MOD = 10**9
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)
    return divisors

N = int(input())
S = input()


ans = S.count('R') * S.count('G') * S.count('B')

SN = []

for s in S:
    if s == 'R': SN.append(-1)
    elif s == 'G': SN.append(0)
    else: SN.append(1)

rem2 = ['RRR', 'GGG', 'BBB']

count = 0
for i in range(1, N-1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass
        elif SN[left] + SN[index] + SN[right] == 0 :
            count+= 1
        
        left -= 1
        right += 1

print(ans-count)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

count = 0
ans = S

for i in range(Q):
    T = input().split()
    if len(T)==1:
        count+=1
        continue

    if count%2==0:
        if T[1] == '1': ans = T[2] + ans
        else: ans += T[2]
    else:
        if T[1] == '1': ans += T[2]
        else: ans = T[2] + ans

if count%2==0:
    print(ans)
else:
    print(ans[::-1])


Fixed submission:
#!/usr/bin/env python3
S = input()
Q = int(input())

count = True
ans = S

ireru_mae = ''
ireru_usiro = ''
for i in range(Q):
    T = input().split()
    if len(T)==1:
        count = not(count)
        ans = ireru_mae + ans + ireru_usiro
        ireru_mae = ''
        ireru_usiro = ''
        continue

    if count:
        if T[1] == '1': ireru_mae = T[2] + ireru_mae
        else: ireru_usiro += T[2]
    else:
        if T[1] == '1': ireru_usiro += T[2]
        else: ireru_mae = T[2] + ireru_mae

ans = ireru_mae + ans + ireru_usiro
if count:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
S = input()
Q = int(input())

count = 0
ans = S

for i in range(Q):
    T = input().split()
    if len(T)==1:
        count+=1
        continue

    if count%2==0:
        if T[1] == '1': ans = T[2] + ans
        else: ans += T[2]
    else:
        if T[1] == '1': ans += T[2]
        else: ans = T[2] + ans

if count%2==0:
    print(ans)
else:
    print(ans[::-1])


Fixed submission:
#!/usr/bin/env python3
S = input()
Q = int(input())

count = True
ans = S

ireru_mae = ''
ireru_usiro = ''
for i in range(Q):
    T = input().split()
    if len(T)==1:
        count = not(count)
        ans = ireru_mae + ans + ireru_usiro
        ireru_mae = ''
        ireru_usiro = ''
        continue

    if count:
        if T[1] == '1': ireru_mae = T[2] + ireru_mae
        else: ireru_usiro += T[2]
    else:
        if T[1] == '1': ireru_usiro += T[2]
        else: ireru_mae = T[2] + ireru_mae

ans = ireru_mae + ans + ireru_usiro
if count:
    print(ans)
else:
    print(ans[::-1])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
N, M = map(int, input().split())

n = {}
exs = {}

for i in range(M):
    n[i+1] = 0
    exs[i+1]=0

f = True

for i in range(M):
    s, c = map(int, input().split())
    exs[s] += 1
    if exs[s] == 1 or c==n[s]:
        n[s] = c
    else:
        f = False
        break
ans = ''
if f:
    for k,v in n.items():
        ans += str(v)
else:
    print(-1)
    exit()

if int(ans) > 0:
    print(ans)
else:
    print(-1)





Fixed submission:
#!/usr/bin/env python3

N, M = map(int, input().split())


sc = []
for i in range(M):
    s, c = map(int, input().split())
    sc.append([s,c])


sc = sorted(sc)
if N == 1: start = 0
else: start = 10 ** (N-1)
end = 10 ** N

ans = -1
for i in range(start, end):
    si = str(i)
    f = True
    for j in range(M):
        if si[sc[j][0]-1] != str(sc[j][1]):
            f = False
            break
    if f:
        ans = i
        break

    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

array = []
index = 0

for i in range(len(P)-K+1):
    s = sum(P[i:i+K])
    if s >= index:
        index = s
        array = P[i:i+K]


ans = 0
for i in range(K):
    s = array[i]*(array[i]+1)/2
    ans += s / array[i]

print(ans)




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


kitaiti = {}

k = 1.0
for i in range(1, 1001):
    kitaiti[i] = k
    k += 0.5

index = 0

for i in range(K):
    index += kitaiti[P[i]]

s = index
ans = index

for i in range(1, len(P)-K+1):
    s = index - kitaiti[P[i-1]] + kitaiti[P[i+K-1]]
    if s > ans: ans = s
    index = s
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

array = []
index = 0

for i in range(len(P)-K+1):
    if sum(P[i:i+K]) >= index:
        index = sum(P[i:i+K])
        array = P[i:i+K]


ans = 0
for i in range(K):
    s = 0
    for j in range(1, array[i]+1):
        s += j
    ans += s / array[i]

print(ans)




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


kitaiti = {}

k = 1.0
for i in range(1, 1001):
    kitaiti[i] = k
    k += 0.5

index = 0

for i in range(K):
    index += kitaiti[P[i]]

s = index
ans = index

for i in range(1, len(P)-K+1):
    s = index - kitaiti[P[i-1]] + kitaiti[P[i+K-1]]
    if s > ans: ans = s
    index = s
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(N):
    f = True
    for j in range(i, -1, -1):
        if P[i] > P[j]:
            f = False
            break
    if f == True: ans += 1


print(ans)


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

ans = 1
index = P[0]

for i in range(1, N):
    if index > P[i]:
        index = P[i]
        ans += 1


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

if N%2==1:
    print(0)
    exit()
elif N==0 or N==2:
    print(0)
    exit()

M = (N//2)//2
two = (N//2) + M*(M+1)//2

go = 0

go_dict = {}
for i in range(10, N+1, 10):
    index = i
    cnt = 0
    while index % 5==0:
        if (index//5) in go_dict:
            cnt += go_dict[index//5]+1
            break
        else:
            index /= 5
            cnt+=1
    go_dict[i] = cnt
    go += cnt


print(min(two, go))


Fixed submission:
#!/usr/bin/env python3

N = int(input())

if N % 2 == 1:
    print(0)
else:
    ret = 0
    for i in range(1, 27):
        ret += N // (2*5**i)


    print(ret)

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

if N%2==1:
    print(0)
    exit()
elif N==0 or N==2:
    print(0)
    exit()

index = 1
ans = 0
for i in range(2, N+1, 2):
    s = str(i)
    index2 = index
    if int(s[len(s)-1:len(s)]) == 0:
        ans += 1
    else:
        index2 *= int(s[len(s)-1:len(s)])
        s2 = str(index2)
        if int(s2[len(s2)-1:len(s2)]) == 0:
            ans += 1
        else:
            index = index2


print(ans)


Fixed submission:
#!/usr/bin/env python3

N = int(input())

if N % 2 == 1:
    print(0)
else:
    ret = 0
    for i in range(1, 27):
        ret += N // (2*5**i)


    print(ret)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

S = input()
K = int(input())

A = []
cnt = 1
C = []
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        cnt += 1
    else:
        C.append([S[i-1], cnt])
        cnt = 1
C.append([S[i], cnt])

ans = 0
S2 = []
for c in C:
    ans += (c[1])//2
    if c[1] == 1:
        S2.append(False)
    else:
        for _ in range(c[1]):
            S2.append(True)

ans *= K

ans2 = 0
if S[0] == S[-1]:
    if S2[-1] == False:
        ans2 += 1

print(ans + ans2*(K-1))


Fixed submission:
#!/usr/bin/env python3

S = input()
K = int(input())

if len(S) == 1:
    print(K//2)
    exit()

A = []
cnt = 1
C = []
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        cnt += 1
    else:
        C.append([S[i-1], cnt])
        cnt = 1
C.append([S[i], cnt])

ans = 0
if len(C) == 1:
    print((C[0][1]*K) // 2)
    exit()
else:
    for c in C:
        ans += c[1] // 2

ans *= K

ans2 = 0
if S[-1] == S[0]:
    ans2 = ((C[0][1]+C[-1][1])//2 - C[0][1]//2 - C[-1][1]//2) * (K-1)
print(ans + ans2)
Buggy python submission (verdict: Runtime Error):
N = int(input)
ans = (1/2) * (N-1) * (N)
print(int(ans))


Fixed submission:
N = int(input())
ans = (N-1) * (N) //2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1,N+1):
    ans += i
print(ans-N)


Fixed submission:
N = int(input())
ans = (N-1) * (N) //2
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1,N+1):
    ans += i
print(ans-N)


Fixed submission:
N = int(input())
ans = (N-1) * (N) //2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
a = int(input())
s = input()

if a>=3200: print(s)
else: print 'red'


Fixed submission:
a = int(input())
s = input()

if a>=3200: print(s)
else: print('red')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

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

print(ans)


Fixed submission:
import collections
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))

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

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ss = set(s)
ans = 0

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

print(ans)


Fixed submission:
import collections
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))

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

s = [sorted(list(input())) for i in range(N)]
count = []
while len(s)>0:
    c = 0
    cc = []
    for i in range(0,len(s)):
        if s[0]==s[i]:
            c += 1
            cc.append(i)
    count.append(c)
    if len(cc)==0: cc.append(0)
    for i in cc[::-1]:
        del s[i]

ans = 0

for i in count:
    ans += (1/2)*i*(i-1)

print(int(ans))


Fixed submission:
import collections
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))

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

s = [sorted(list(input())) for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1, N):
        f = True
        for k in range(10):
            if s[i][k]!=s[j][k]:
                f = False
                break
        if f: ans+=1

print(ans)


Fixed submission:
import collections
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))

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

s = [sorted(list(input())) for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1, N):
        if s[i]==s[j]:
            ans+=1

print(ans)


Fixed submission:
import collections
N = int(input())

s = [sorted(list(input())) for i in range(N)]

for i in range(N):
    s[i] = ''.join(s[i])

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if c-(a-b)>0:
    print(c-(a-b))
else:
    print(0

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

if c-(a-b)>0:
    print(c-(a-b))
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, D = map(int, input().split())

ans = 0
for i in range(A, B+1):
    if i%C!=0 and i%D!=0:
        ans+=1

print(ans)


Fixed submission:
#!/usr/bin/env python3

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())

N = B - A + 1

g = lcm(C,D)
C_ = B//C - (A-1)//C
D_ = B//D - (A-1)//D
CD_ = B//g - (A-1)//g
ans = N - C_ - D_ + CD_
print(ans)
Buggy python submission (verdict: Runtime Error):
def move(now, goal, m):
    global rlt
    if m==goal:
        rlt += 1
        return

    if m>goal: return

    move(m, goal, m+1)
    move(m, goal, m+2)


N, M = map(int, input().split())

A = [int(input()) for i in range(M)]

for i in range(1, len(A)):
    if A[i]-A[i-1]==1:
        print(0)
        exit()

ans = 0

m = []
now = 0
rlt = 0
for a in A:
    move(now, a-1, now+1)
    move(now, a-1, now+2)
    m.append(rlt)
    rlt = 0

now = A[len(A)-1]+1
move(now, N, now+1)
move(now, N, now+2)
m.append(rlt)

ans = 1

for i in m:
    ans *= i

print(ans%1000000007)



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

oks = [True]*(N+1)

for i in range(M):
    a = int(input())
    oks[a] = False

dp = [0]*(N+1)

dp[0]=1
if oks[1]==True: dp[1] = 1

for i in range(2, N+1):
    if oks[i]==True:
        dp[i] = (dp[i-1] + dp[i-2]) % (1e9+7)

print(int(dp[N]))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

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


n = int(input())

a = (list(map(int, input().split())))

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
#L = [0 for i in range(n+1)]
#R = [0 for i in range(n+1)]
L = [0]
R = [0]
for i in range(1,n+1):
    L.append(gcd(L[i-1], a[i-1]))

for i in range(n)[::-1]:
    R.append(gcd(R[i+1], a[i]))

#m = [0 for i in range(n)]
m = []
for i in range(n):
    m.append(gcd(L[i], R[i+1]))

print(max(m))


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

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

tt=t+0.5

print((int)(tt/a)*b)
Buggy python submission (verdict: Runtime Error):

a = (list(map(int, input().split())))

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

for i in range(n)[::-1]:
    R[i] = gcd(R[i+1], a[i])

m = []

for i in range(n):
    m.append(gcd(L[i], R[i+1]))

print(max(m))


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

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


n = int(input())

a = (list(map(int, input().split())))

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

for i in range(n)[::-1]:
    R[i] = gcd(R[i+1], a[i])

m = [0 for i in range(n)]

for i in range(n):
    m[i] = gcd(L[i], R[i+1])

print(max(m))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


x = raw_input()


count = []
c = 0
for s in x:
    a = is_acgt(s)
    if a == 0:
        count.append(c)
        c = 0
    else:
        c += 1


print max(count)


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


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


x = raw_input()


count = []
c = 0
for s in x:
    a = is_acgt(s)
    if a == 0:
        count.append(c)
        c = 0
        continue
    else:
        c += 1

    count.append(c)

if len(count)==0:
    print 0
    exit()
print max(count)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
N, M = map(int, raw_input().split())

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count
    if count == M: break

print(yen)


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n, m = map(int, raw_input().split())

dic = {} # yen: many

for i in range(n):
    a, b = map(int, raw_input().split())
    if a in dic: dic[a] += b
    else: dic.update({a:b})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v < m-count:
        yen += k*v
        count += v
    else:
        yen += k*(m-count)
        count += m-count
        print yen
        break
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import functools
import math
n = input()
monster = list(map(int,input().split()))

gcd = functools.reduce(math.gcd, monster)
print(gcd)


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

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

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


if n==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if n==2:print(element)
    else:
        for i in range(2,n):
            element=gcd(element,x[i])
        print(element)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n = input()
monster = list(map(int,input().split()))

print(gcd_list(monster))


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

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

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


if n==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if n==2:print(element)
    else:
        for i in range(2,n):
            element=gcd(element,x[i])
        print(element)
Buggy python submission (verdict: Runtime Error):
d = input().split()
print(float(d[0])/d[1])

Fixed submission:
d = input().split()
print(float(int(d[0]))/int(d[1]))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def dp(index, cos):
    if index == N-1:
        #cost.append(cos)
        return cos

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))
    
    cost.append(d)
    return 10**9



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

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))



Fixed submission:
#!/usr/bin/env python3



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

dp = [float('inf') for i in range(N+1)]

dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



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

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))



Fixed submission:
#!/usr/bin/env python3



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

dp = [float('inf') for i in range(N+1)]

dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



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

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))



Fixed submission:
#!/usr/bin/env python3



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

dp = [float('inf') for i in range(N+1)]

dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



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

cost = []

dp(0, 0)

print(min(cost))



Fixed submission:
#!/usr/bin/env python3



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

dp = [float('inf') for i in range(N+1)]

dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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

if N <=K:
    print(abs(H[0]-H[-1]))
    exit()


dp = [float('inf') for _ in range(N+K+1)]

dp[0] = 0

for i in range(1, K+1):
    dp[i] = abs(H[0] - H[i])

for i in range(N):
    for j in range(i+1, i+K+1):
        if j < N:
            dp[j] = min(dp[i] + abs(H[i]-H[j]), dp[j])

print(dp[N-1])



Fixed submission:
#!/usr/bin/env python3
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float('inf') for i in range(N+K+1)]


if K>=N:
    print(abs(H[0]-H[-1]))
    exit()


dp[0] = 0
for i in range(1, K+1):
    dp[i] = abs(H[i]-H[0])


for i in range(0, N):
    for j in range(i+1, i+K+1):
        if j < N:
            dp[j] = min(dp[i] + abs(H[i] - H[j]), dp[j])
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

N, W = map(int, input().split())

weight = []
value = []

for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

#dp = [[0]*110]*11010
#dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
dp=[[0 for _ in range(110)] for _ in range(11010)]


for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])


Fixed submission:
#!/usr/bin/env python3

N, W = map(int, input().split())

weight = []
value = []

for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

#dp = [[0]*110]*11010
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
#dp=[[0 for _ in range(110)] for _ in range(11010)]


for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])