Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = list(map(int, input().split()))


find = False
# 2こめ
for i, x in enumerate(li[1:]):
    result = [li[0]]
    
    result.append(x)
    not_used = li[1:]
    not_used.pop(i)
    
    # 3こめ~
    for j in range(n - 2):
#         print(result)
        nex = result[-1]^result[-2]
#         print(nex, not_used)
        if nex in not_used:
            idx = not_used.index(nex)
            result.append(nex)
            not_used.pop(idx)
        else:
            break
    if len(result) != n:
        continue
    else:
        print("Yes")
        find = True
        break

if not find:
    print("No")
        
        

Fixed submission:
import numpy as np
n = int(input())
li = np.array(list(map(int, input().split())))

if np.count_nonzero(li) == 0:
    print("Yes")
elif len(li)%3 != 0:
    print("No")
else:
    li = sorted(li)
    li0 = li[:n//3]
    li1 = li[n//3:n//3*2]
    li2 = li[n//3*2:]
    if (li0 == li0[0]).all() and (li1 == li1[0]).all() and (li2 == li2[0]).all() and ((li0[0]^li1[0]) == li2[0] or (li0[0]^li1[0]) == li2[0] or (li0[0]^li1[0]) == li2[0]):
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

t = sorted(t)[::-1]
biggest = t[0]
for i in range(biggest, 10**18+1, biggest):
    ok = True
    for j in t[1:]:
        if i%j != 0:
            ok = False
            break
    if ok == True:
        break
    
print(i)
            

Fixed submission:
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))
    
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

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

result = 1
for i in range(n):
    result = lcm(result, t[i])
    
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
# E = 0.5 * (np.eye(n) + np.eye(n, n, 1) + np.eye(n, n, -n + 1))
vec = (-1) ** np.arange(n)
print(' '.join([str(int(np.dot(np.roll(vec, i), a))) for i in range(n)]))

Fixed submission:
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
# E = 0.5 * (np.eye(n) + np.eye(n, n, 1) + np.eye(n, n, -n + 1))
vec = (-1) ** np.arange(n)
b = np.zeros(n)
b[0] = np.dot(vec, a)
b[1] = np.dot(np.roll(vec, 1), a)
for i in range(2, n):
    sgn = (-1) ** (i % 2)
    b[i] = b[i - 2] - 2 * (a[i - 2] - a[i - 1])
print(' '.join([str(int(i)) for i in b]))
Buggy python submission (verdict: Runtime Error):
class Burg:
    def __init__(self):
        self.lv = [None] * 51
        self.lv[0] = 1
        # self.string = ''

    def make_burg(self, n):
        if n == 0:
            return 'P'
        else:
            if self.lv[n] is None:
                tmp = self.make_burg(n - 1)
                self.lv[n] = 'B' + tmp + 'P' + tmp + 'B'
            return self.lv[n]


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

gen = Burg()
string = gen.make_burg(n)
div = string[:x]
print(div.count('P'))

Fixed submission:
class Burg:
    def __init__(self):
        self.lv = [2**(i+1) - 1 for i in range(51)]

    def make_burg(self, n, m):
        if n == 0:
            return 1, m - 1
        num = 4 * 2**n - 3
        if num <= m:
            return self.lv[n], m - num
        if m <= 1:
            return 0, 0
        a, b = self.make_burg(n - 1, m - 1)
        if b <= 1:
            return a + b, 0
        c, d = self.make_burg(n - 1, b - 1)
        return a + c + 1, max(0, d - 1)

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

gen = Burg()
print(gen.make_burg(n, x)[0])
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
num_tap = 0
output = 0
if b == 1:
  print(0)
else:
  for i in range(30):
  output += 1
  if i == 0:
    num_tap += a
  else:
    num_tap += a-1
  if num_tap >= b:
    break
  print(output)

Fixed submission:
a, b = map(int, input().split())
num_tap = 0
output = 0
if b == 1:
  print(0)
else:
  for i in range(30):
    output += 1
    if i == 0:
      num_tap += a
    else:
      num_tap += a-1
    if num_tap >= b:
      break
  print(output)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(list(map(deno, np.arange(1,N+1)))) / N
print(pro)

Fixed submission:
N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(map(deno, range(1,N+1))) / N
print(pro)
Buggy python submission (verdict: Runtime Error):
n = int(input())

ans_list = [100*x+10*x+x for x in range(10)]

for v in ans_list:
    if v > n:
        ans = v
        break
        
print(ans)

Fixed submission:
n = int(input())

ans_list = [100*x+10*x+x for x in range(10)]

for v in ans_list:
    if v >= n:
        ans = v
        break
        
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

for i in range(len(s)):
    if int(s[i]) != 1:
        ans = int(s[i])
        break
        
print(ans)

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

import numpy as np

ind = np.inf

for i in range(len(s)):
    if int(s[i]) != 1:
        ind = i
        ans = int(s[i])
        break
if ind >= k:
    ans = 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
x = int(input())
import math
flag = False
for i in range(x):
    ans = x - i
    for j in range(2,x):
        b = math.pow(ans, 1/j)
        if b % 1 == 0:
            flag = True
            break
        elif b < 1:
            break
    if flag:
        break
print(ans)

Fixed submission:
a, b, c, d = map(int,input().split(" "))
ans = "No"
if abs(c-a) <= d:
    ans = "Yes"
elif abs(b-a) <= d and abs(c-b) <= d:
    ans = "Yes"
print(ans)
Buggy python submission (verdict: Runtime Error):
date=input()
yr=slice(int[0:4])
mn=slice(int[5:7])
dy=slice(int[8:10])
if yr <2019:
  print("Heisei")
elif yr >2019:
  print("TBD")
else:
  if mn<4:
    print("Heisei")
  elif mn>4:
    print("TBD")
  else:
    print("Heisei")

Fixed submission:
yr,mn,dy=map(int,input().split('/'))
if yr <2019:
  print("Heisei")
elif yr >2019:
  print("TBD")
else:
  if mn<4:
    print("Heisei")
  elif mn>4:
    print("TBD")
  else:
    print("Heisei")
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if n*a>b:
  print(b)
else n*a<=b:
  print(n*a)

Fixed submission:
n,a,b=map(int,input().split())
ans=min(n*a,b)
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y=map(input().split())
s="ABCDEF"
for i in range(0,6):
  if s[i]==x:
    x=int(i)
  if s[i]==y:
    y=int(i)
if x>y:
  print(">")
elif x<y:
  print("<")
else:
  print("=")

Fixed submission:
x,y=input().split()
s="ABCDEF"
for i in range(0,6):
  if s[i]==x:
    x=int(i)
  if s[i]==y:
    y=int(i)
if x>y:
  print(">")
elif x<y:
  print("<")
else:
  print("=")
Buggy python submission (verdict: Time Limit Exceeded):
n  = int(input())
arr = [int(i) for i in input().split()]
arr.sort()

works= lambda a,b,c : (a<(b+c)) and (b<(a+c)) and (c<(b+a))

total = 0

for i in range(n):
    aI = arr[i]
    for j in range(i+1,n):
        aJ = arr[j]
        for k in range(j+1,n):
            if works(arr[k],aI,aJ):
                total+=1
            else:
                break

print(total)


Fixed submission:
n  = int(input())
arr = [int(i) for i in input().split()]
arr.sort()

total = 0

for i in range(n-2):
    aI = arr[i]
    k = i + 2
    
    for j in range(i+1,n):
        mySum = aI+arr[j]

        while (k<n) and arr[k]<mySum:
            k+=1
            
        if k>j:
            total+= k-j-1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
n  = int(input())
arr = [int(i) for i in input().split()]
arr.sort()

works= lambda a,b,c : (a<(b+c)) and (b<(a+c)) and (c<(b+a))

total = 0

for i in range(n):
    aI = arr[i]
    for j in range(i):
        aJ = arr[j]
        for k in range(j):
            if works(arr[k],aI,aJ):
                total+=1

print(total)


Fixed submission:
n  = int(input())
arr = [int(i) for i in input().split()]
arr.sort()

total = 0

for i in range(n-2):
    aI = arr[i]
    k = i + 2
    
    for j in range(i+1,n):
        mySum = aI+arr[j]

        while (k<n) and arr[k]<mySum:
            k+=1
            
        if k>j:
            total+= k-j-1

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
ni,ki = [int(i) for i in input().split()]
arri = [int(i) for i in input().split()]

dif = lambda x,y: abs(x-y)

def getRes(arr,n,k):
    dp = [0]*n
    for i in range(1,n):
        H = arr[i]
        dp[i] = min([dp[j]+dif(arr[j],H) for j in range(max(0,i-k),i)])
    return dp[-1]

print(getRes(arri,ni,ki))


Fixed submission:
ni,ki = [int(i) for i in input().split()]
arri = [int(i) for i in input().split()]
    
def getRes(arr,n,k):
    dp = [0]*n
    for i in range(1,n):
        H = arr[i]
        dp[i] = min([dp[j]+abs(arr[j]-H) for j in range(max(0,i-k),i)])
    return dp[-1]

print(getRes(arri,ni,ki))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]

dif = lambda x,y: abs(x-y)

dp = [0]*n

for i in range(1,n):
    H = arr[i]
    dp[i] = min([dp[j]+dif(arr[j],H) for j in range(max(0,i-k),i)])

print(dp[-1])


Fixed submission:
ni,ki = [int(i) for i in input().split()]
arri = [int(i) for i in input().split()]
    
def getRes(arr,n,k):
    dp = [0]*n
    for i in range(1,n):
        H = arr[i]
        dp[i] = min([dp[j]+abs(arr[j]-H) for j in range(max(0,i-k),i)])
    return dp[-1]

print(getRes(arri,ni,ki))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]

dif = lambda x,y: abs(x-y)

dp = [0,dif(arr[0],arr[1])]

for i in range(2,n):
    H = arr[i]
    minCost = min([dp[j]+dif(arr[j],H) for j in range(max(0,i-k),i)])
    dp.append(minCost)

print(dp[-1])


Fixed submission:
ni,ki = [int(i) for i in input().split()]
arri = [int(i) for i in input().split()]
    
def getRes(arr,n,k):
    dp = [0]*n
    for i in range(1,n):
        H = arr[i]
        dp[i] = min([dp[j]+abs(arr[j]-H) for j in range(max(0,i-k),i)])
    return dp[-1]

print(getRes(arri,ni,ki))

Buggy python submission (verdict: Runtime Error):
n,k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]

dif = lambda x,y: abs(x-y)

dp = [0,dif(arr[0],arr[1])]

for i in range(2,n):
    minCost = 10000
    H = arr[i]
    for j in range(i-k,i):
        cost = dp[j]+dif(arr[j],H)
        if cost<minCost:
            minCost = cost
    dp.append(minCost)

print(dp[-1])


Fixed submission:
ni,ki = [int(i) for i in input().split()]
arri = [int(i) for i in input().split()]
    
def getRes(arr,n,k):
    dp = [0]*n
    for i in range(1,n):
        H = arr[i]
        dp[i] = min([dp[j]+abs(arr[j]-H) for j in range(max(0,i-k),i)])
    return dp[-1]

print(getRes(arri,ni,ki))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict


class Solution:
    def main(self):
        N, M = map(int, input().split())
        L = []
        R = []
        cards = set(list(range(1, N+1)))
        for _ in range(M):
            l, r = map(int, input().split())
            cands = set(list(range(l, r+1)))
            cards = cards & cands
        print(len(cards))


if __name__ == '__main__':
    Solution().main()

Fixed submission:
from collections import defaultdict


class Solution:
    def main(self):
        N, M = map(int, input().split())
        L = []
        R = []
        cards = set(list(range(1, N+1)))
        left = 1
        right = N
        for _ in range(M):
            l, r = map(int, input().split())
            if right < l or r < left:
                print(0)
                return 0

            left = max(l, left)
            right = min(r, right)
        else:
            print(right-left+1)
            return


if __name__ == '__main__':
    Solution().main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from heapq import heappush, heappop, heapify

class Solution:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))
        heapify(A)
        for _ in range(M):
            b, c = map(int, input().split())
            for _ in range(b):
                v = A[0]
                if v < c:
                    heappop(A)
                    heappush(A, c)
                else:
                    break
        print(sum(A))


if __name__ == '__main__':
    Solution().main()

Fixed submission:
from collections import defaultdict
from heapq import heappush, heappop, heapify, heapreplace
from random import randint

class Solution:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))
        # A = list(range(100000))
        A = sorted(A)
        BC = []
        for _ in range(M):
            b, c = map(int, input().split())
            BC.append((b, c))
        # BC *= 100000
        BC = sorted(BC, key=lambda x: -x[1])
        idx = 0
        for i in range(M):
            # print(A)
            b, c = BC[i]
            for j in range(b):
                if idx >= N or A[idx] >= c:
                    break
                else:
                    A[idx] = c
                    idx += 1

        print(sum(A))


if __name__ == '__main__':
    Solution().main()
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
R, G, B = sorted([R, G, B])[::-1]

r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while r*R + g*G <= N:
    b = (N - r*R - g*G)/B
    if b == int(b):
      counter += 1
      g += 1
  r += 1
print(counter)

Fixed submission:
R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R
r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R

r = 0
while r * R <= N:
  g = 0
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Fixed submission:
R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R
r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
# R, G, B = sorted([R, G, B])
r = 0
while r * R <= N:
  g = 0
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Fixed submission:
R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R
r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
counter = 0
r = 0
while r * R <= N:
  g = 0
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b >= 0 and b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)

Fixed submission:
R, G, B, N = map(int, input().split())
counter = 0
if R < G:
  R, G = G, R
if G < B:
  G, B = B, G
if R < G:
  R, G = G, R
r = 0
while r * R <= N:
  g = 0
  if B == 1:
    counter += (N - r*R)//G + 1
    r += 1
    continue
  while g * G <= N:
    b = (N - r*R - g*G)/B 
    if b < 0:
      break
    elif b == int(b):
      counter += 1
    g += 1
  r += 1
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, k = map(int, input().split())
S = input()
blocks = [(k, len(list(v))) for k, v in itertools.groupby(S)]
res = 0
i = 0
if blocks[i][0] == '0':
  res = max(res, sum([b[1] for b in blocks[i:i+2*k]]))
  i += 1

while i < len(blocks):
  res = max(res, sum([b[1] for b in blocks[i:i+2*k+1]]))
  i += 2
print(res)


Fixed submission:
import itertools
 
_, k = map(int, input().split())
S = input()
blocks = [(key, len(list(v))) for key, v in itertools.groupby(S)]
res = 0
i = 0
if blocks[i][0] == '0':
  res = max(res, sum([b[1] for b in blocks[i:i+2*k]]))
  i += 1

crr = sum([b[1] for b in blocks[i:i+2*k+1]])
res = max(res, crr)
while i+2*k + 2 < len(blocks):
  i += 2
  crr = crr + blocks[i+2*k-1][1] + blocks[i+2*k][1]
  crr = crr - blocks[i-1][1] - blocks[i-2][1]
  res = max(res, crr)

crr = sum([b[1] for b in blocks[-2*k:]])
res = max(res, crr)
print(res)

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

n, k = map(int, input().split())
S = input()
blocks = [(k, len(list(v))) for k, v in itertools.groupby(S)]
res = 0
for i in range(len(blocks)):
  if blocks[i][0] == '0':
    res = max(res, sum([b[1] for b in blocks[i:i+2*k]]))
  else:
    res = max(res, sum([b[1] for b in blocks[i:i+2*k+1]]))
print(res)

Fixed submission:
import itertools
 
_, k = map(int, input().split())
S = input()
blocks = [(key, len(list(v))) for key, v in itertools.groupby(S)]
res = 0
i = 0
if blocks[i][0] == '0':
  res = max(res, sum([b[1] for b in blocks[i:i+2*k]]))
  i += 1

crr = sum([b[1] for b in blocks[i:i+2*k+1]])
res = max(res, crr)
while i+2*k + 2 < len(blocks):
  i += 2
  crr = crr + blocks[i+2*k-1][1] + blocks[i+2*k][1]
  crr = crr - blocks[i-1][1] - blocks[i-2][1]
  res = max(res, crr)

crr = sum([b[1] for b in blocks[-2*k:]])
res = max(res, crr)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    l_i, r_i = map(int, input().split())
    l.append(l_i)
    r.append(r_i)

ac_flag = [0] * len(S)

for i in range(len(S)-1):
    if S[i: i + 2] == 'AC':
        ac_flag[i] = 1

for i in range(Q):
    print(sum(ac_flag[l[i]-1:r[i]-1]))


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

c = [0] * N

for i in range(N-1):
    if S[i:i+2] == 'AC':
        c[i+1] = c[i] + 1
    else:
        c[i+1] = c[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r-1] - c[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
def ac_count(s):
    cnt = 0
    for i in range(len(s)-1):
        if s[i:i+2] == 'AC':
            cnt += 1
    return cnt


N, Q = map(int, input().split())
S = input()
l = []
r = []
for i in range(Q):
    l_i, r_i = map(int, input().split())
    l.append(l_i)
    r.append(r_i)

for i in range(Q):
    print(ac_count(S[l[i]-1:r[i]]))


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

c = [0] * N

for i in range(N-1):
    if S[i:i+2] == 'AC':
        c[i+1] = c[i] + 1
    else:
        c[i+1] = c[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r-1] - c[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

import sys
sys.setrecursionlimit(10 ** 7)

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

@lru_cache(maxsize=None)
def rec(n):
  # print(n)
  if n == 1:
    return 0
  elif n == 2:
    return abs(h[1]-h[0])
  else:
    return min(rec(n-1)+abs(h[n-1]-h[n-2]), rec(n-2)+abs(h[n-1]-h[n-3]))

print(rec(N))

Fixed submission:
from functools import lru_cache

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

cost = [None] * N
cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2, N):
  cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]))
print(cost[N-1])
# print(cost)

"""
@lru_cache(maxsize=None)
def rec(n):
  # print(n)
  if n == 1:
    return 0
  elif n == 2:
    return abs(h[1]-h[0])
  else:
    return min(rec(n-1)+abs(h[n-1]-h[n-2]), rec(n-2)+abs(h[n-1]-h[n-3]))

print(rec(N))
"""

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

import sys
sys.setrecursionlimit(10000)

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

@lru_cache(maxsize=None)
def rec(n):
  # print(n)
  if n == 1:
    return 0
  elif n == 2:
    return abs(h[1]-h[0])
  else:
    return min(rec(n-1)+abs(h[n-1]-h[n-2]), rec(n-2)+abs(h[n-1]-h[n-3]))

print(rec(N))

Fixed submission:
from functools import lru_cache

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

cost = [None] * N
cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2, N):
  cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]))
print(cost[N-1])
# print(cost)

"""
@lru_cache(maxsize=None)
def rec(n):
  # print(n)
  if n == 1:
    return 0
  elif n == 2:
    return abs(h[1]-h[0])
  else:
    return min(rec(n-1)+abs(h[n-1]-h[n-2]), rec(n-2)+abs(h[n-1]-h[n-3]))

print(rec(N))
"""

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

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

@lru_cache(maxsize=None)
def rec(n):
  # print(n)
  if n == 1:
    return 0
  elif n == 2:
    return abs(h[1]-h[0])
  else:
    return min(rec(n-1)+abs(h[n-1]-h[n-2]), rec(n-2)+abs(h[n-1]-h[n-3]))

print(rec(N))

Fixed submission:
from functools import lru_cache

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

cost = [None] * N
cost[0] = 0
cost[1] = abs(h[1]-h[0])
for i in range(2, N):
  cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]))
print(cost[N-1])
# print(cost)

"""
@lru_cache(maxsize=None)
def rec(n):
  # print(n)
  if n == 1:
    return 0
  elif n == 2:
    return abs(h[1]-h[0])
  else:
    return min(rec(n-1)+abs(h[n-1]-h[n-2]), rec(n-2)+abs(h[n-1]-h[n-3]))

print(rec(N))
"""
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if s[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if s[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res = w[i] + e[i]

print(min(res))


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

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if s[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if s[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res[i] = w[i] + e[i]

print(min(res))

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

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if S[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if S[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res = w[i] + e[i]

print(min(res))


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

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if s[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if s[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res[i] = w[i] + e[i]

print(min(res))

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

result = 10e6

for i in range(n):
    a = s[:i]
    b = s[i+1:]
    result = min(result, a.count('W') + b.count('E'))

print(result)


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

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if s[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if s[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res[i] = w[i] + e[i]

print(min(res))