Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a_list = [int(i) for i in input().split()]

for i in range(1, N + 1):
    print(sum(a == i for a in a_list[i - 1:]))


Fixed submission:
from collections import defaultdict

N = int(input())
a_dict = defaultdict(int)
for i in input().split():
    a_dict[int(i)] += 1

for i in range(1, N + 1):
    print(a_dict[i])
Buggy python submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print(f"{A} {B} {C}")


Fixed submission:
A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print("%s %s %s" % (A, B, C))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    K = int(input())
    if K <= 9:
        print(K)

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()


Fixed submission:
from collections import deque

def main():
    K = int(input())
    if K <= 9:
        print(K)
        return

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
    K = int(input())
    if K <= 0:
        print(K)

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

main()


Fixed submission:
from collections import deque

def main():
    K = int(input())
    if K <= 9:
        print(K)
        return

    que = deque(range(1,10))
    # print(que)
    cnt = 9
    while True:
        x = que.popleft()
        mod = x % 10

        if mod != 0:
            que.append(10 * x + mod - 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

        que.append(10 * x + mod)
        # print(que)
        cnt += 1
        if cnt == K:
            print(que[-1])
            return

        if mod != 9:
            que.append(10 * x + mod + 1)
            # print(que)
            cnt += 1
            if cnt == K:
                print(que[-1])
                return

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

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

def comb(n, k):
    return int(factorial(n) / factorial(k) / factorial(n-k))

res = comb(M, 2) + comb(N, 2)

print(res)

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

def factorial(n):
    p = 1
    for i in range(n, 0, -1):
        p *= i
    return p


def comb(n, k):
    return factorial(n) // (factorial(k) * factorial(n-k))


res = comb(M, 2) + comb(N, 2)

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

for q in range(1, Q+1):
    query = input()
    if query[0] == "1":
        S = "".join(reversed(S))
    else:
        T, F, C = query.split()
        if F == "1":
            S = C + S
        else:
            S += C

print(S)

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

rev = False
l, r = "", ""

for _ in range(Q):
    query = input()
    if query[0] == "1":
        rev = not rev
    else:
        T, F, C = query.split()
        if F == "1":
            if rev:
                r += C
            else:
                l = C + l
        else:
            if rev:
                l = C + l
            else:
                r += C

res = l + S + r
if rev:
    res = res[::-1]

print(res)
Buggy python submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split(" "))

a = list(map(int, input().split(" ")))
heapq._heapify_max(a)

for _ in range(m):
    largest = heapq._heappop_max(a)
    heapq.heappush(a, largest // 2)

print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split(" "))

a = [- int(i) for i in input().split(" ")]
heapq.heapify(a)

for _ in range(m):
    largest = heapq.heappop(a)
    heapq.heappush(a, int(largest / 2))

print(- sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split(" "))

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

for _ in range(m):
    max_ix = a.index(max(a))
    a[max_ix] //= 2

print(sum(a))

Fixed submission:
import heapq

n, m = map(int, input().split(" "))

a = [- int(i) for i in input().split(" ")]
heapq.heapify(a)

for _ in range(m):
    largest = heapq.heappop(a)
    heapq.heappush(a, int(largest / 2))

print(- sum(a))
Buggy python submission (verdict: Runtime Error):
def takahashi_cal(m: int, d: int) -> int:
    res = 0
    for mm in range(1, m + 1):
        for dd in range(1, d + 1):
            d1 = dd % 10
            d10 = dd // 10
            if any([d1 < 2, d10 < 2]):
                continue
            if d1 * d10 == mm:
                res += 1
    return res
  
  m, d = input().split(" ")
  print(takahashi_cal(m, d))

Fixed submission:
def takahashi_cal(m: int, d: int) -> int:
    res = 0
    for mm in range(1, m + 1):
        for dd in range(1, d + 1):
            d1 = dd % 10
            d10 = dd // 10
            if any([d1 < 2, d10 < 2]):
                continue
            if d1 * d10 == mm:
                res += 1
    return res
    
m, d = input().split(" ")
print(takahashi_cal(int(m), int(d)))
Buggy python submission (verdict: Runtime Error):
X = int(input())

if X in range(400,600):
  print(8)
elif X in range(600,800)
  print(7)
elif X in range(800,1000)
  print(6)
elif X in range(1000,1200)
  print(5)
elif X in range(1200,1400)
  print(4)
elif X in range(1400,1600)
  print(3)
elif X in range(1600,1800)
  print(2)
elif X in range(1800,1900)
  print(1)

Fixed submission:
X = int(input())

if X in range(400,600):
  print(8)
elif X in range(600,800):
  print(7)
elif X in range(800,1000):
  print(6)
elif X in range(1000,1200):
  print(5)
elif X in range(1200,1400):
  print(4)
elif X in range(1400,1600):
  print(3)
elif X in range(1600,1800):
  print(2)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(a=n//1000)

Fixed submission:
print((1000-(int(input())%1000))%1000)
Buggy python submission (verdict: Runtime Error):
def remove_fwhite(S):
    fwhite = 0
    for fw in S:
        if fw == '.':
            fwhite += 1
        else:
            break
    return fwhite

def remove_fblack(S):
    fblack = 0
    for fb in S[::-1]:
        if fb == '#':
            fblack += 1
        else:
            break
    return fblack

def count_stone(S):
    black = 0
    white = 0
    for stone in S:
        if stone == '#':
            black += 1
        else:
            white += 1
    print(min(black,white))

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


fw = remove_fwhite(S)
fb = remove_fblack(S)
#print('fw:')
#print(fw)
#print('fb:')
#print(fb)
#print(S[fw:N-fb])
if fw == 0 or fb == 0:
    count_stone(S)
elif fw == N:
    print('0')
else:
    count_stone(S[fw:N-fb])


Fixed submission:
def check_between(a,b,c):
    if  (b < c) and (c < a) :
        print('Yes')
    elif (a < c) and (c <b) :
        print('Yes')
    else:
        print('No')

a, b, c = map(int, input().split())
check_between(a,b,c)
Buggy python submission (verdict: Runtime Error):
def check_max_coin(a,b):
  max_coin = 0
  for i in range(1:3):
    if a < b :
      max_coin += b 
    else:
      max_coin += a      
  print(max_coin)
  
a, b = map(int, input().split())
check_max_coin(a,b)

Fixed submission:
def check_max_coin(a,b):
  max_coin = 0
  for i in range(1,3):
    if a < b :
      max_coin += b 
      b-=1 
    else:
      max_coin += a  
      a-=1    
  print(max_coin)
  
a, b = map(int, input().split())
check_max_coin(a,b)
Buggy python submission (verdict: Runtime Error):
def age_check(age):
  if age ==3:
    print('YES')
  else age == 5:
    print('YES')
  else age == 7:
    print('YES')
  else:
    print('NO')

age = input()

age_check(age) 


Fixed submission:
def age_check(age):
  if age == 3 or age == 5 or age == 7:
    print('YES')
  else:
    print('NO')
 
age = int(input())
 
age_check(age)

Buggy python submission (verdict: Runtime Error):
def age_check(age):
    if age ==3:
        print('YES')
    else age == 5:
        print('YES')
    else age == 7:
        print('YES')
    else:
        print('NO')

age = input()

age_check(age) 

Fixed submission:
def age_check(age):
  if age == 3 or age == 5 or age == 7:
    print('YES')
  else:
    print('NO')
 
age = int(input())
 
age_check(age)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
    a_i = conb.count(0)
    b_i = conb.count(1)
    c_i = conb.count(2)
    
    if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
        f = True

if f:
    print("Yes")
else:
    print("No")

Fixed submission:
import itertools

a, b, c = map(int, input().split(" "))
k = int(input())
f = False
for conb in list(itertools.combinations_with_replacement([0, 1, 2], k)):
    a_i = conb.count(0)
    b_i = conb.count(1)
    c_i = conb.count(2)
    
    if (a * (2 ** a_i) < b * (2 **b_i)) and (b * (2 ** b_i) < c * (2 ** c_i)):
        f = True

if f:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
in = int(input())
print(int(in % 1000))

Fixed submission:
pyment = int(input())
if pyment % 1000 == 0:
    print(0)
else:
    print(1000 - int(pyment % 1000))
Buggy python submission (verdict: Runtime Error):
n = input()
a = input()
b = input()

output = ""

for s, t in zip(a, b):
    output += a
    output += b
print(output)

Fixed submission:
n = input()
a, b = input().split(" ")
output = ""
for s, t in zip(a, b):
    output += s
    output += t
print(output)
Buggy python submission (verdict: Runtime Error):
n = input()
renga = list(map(int, input().split(" ")))

ni = 1
remains = 0

for r in renga:
    if ni == r:
        ni += 1
        remains += 1
if ni == 1:
    print(-1)
else:
    print(renga - remains)

Fixed submission:
n = input()
renga = list(map(int, input().split(" ")))

ni = 1
remains = 0

for r in renga:
    if ni == r:
        ni += 1
        remains += 1
if ni == 1:
    print(-1)
else:
    print(len(renga) - remains)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = input_ints()
    A = input_int_list_in_line()

    hyouten = 1

    for i in range(K):
        hyouten *= A[i]
    
    for i in range(N-K):
        new_hyouten = hyouten / A[i] * A[i+K]

        if hyouten < new_hyouten:
            print('Yes')
        else:
            print('No')
        
        hyouten = new_hyouten



def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


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


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


Fixed submission:
def main():
    N, K = input_ints()
    A = input_int_list_in_line()

    for i in range(N-K):
        if A[i] < A[i+K]:
            print('Yes')
        else:
            print('No')


def input_ints():
    line_list = input().split()

    if len(line_list) == 1:
        return int(line_list[0])
    else:
        return map(int, line_list)


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


def input_int_tuple_list(n: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


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

for i in range(5):
  if l[i] == 0
    print(i + 1)

Fixed submission:
l = list(map(int, input().split()))
     
for i in range(5):
  if l[i] == 0:
    print(i + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

num_list = list(map(int, input().split()))
     
num = 1
     
for i in num_list:
    num *= i
    
    if num == 0:
        break

if num > 1000000000000000000:
    num = -1

print(num)

Fixed submission:
def product(list):
    num = 1

    if any([i == 0 for i in num_list]):
        print(0)
        return
     
    for i in num_list:
        num *= i
        if num > 1000000000000000000:
            num = -1
            break

    print(num)


N = int(input())

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

product(num_list)

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

num_list = list(map(int, input().split()))
     
num = 1
     
for i in num_list:
    num *= i
    
    if num == 0:
        break

if num > 1000000000000000000:
    num = -1
    break

print(num)

Fixed submission:
def product(list):
    num = 1

    if any([i == 0 for i in num_list]):
        print(0)
        return
     
    for i in num_list:
        num *= i
        if num > 1000000000000000000:
            num = -1
            break

    print(num)


N = int(input())

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

product(num_list)

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

num_list = list(map(int, input().split()))
     
num = 1
     
for i in num_list:
    num *= i
     
if num > 10**18:
    num = -1
     
print(num)

Fixed submission:
def product(list):
    num = 1

    if any([i == 0 for i in num_list]):
        print(0)
        return
     
    for i in num_list:
        num *= i
        if num > 1000000000000000000:
            num = -1
            break

    print(num)


N = int(input())

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

product(num_list)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
     
T.pop(-1)
     
if S == T:
  print('Yes')
else:
  print('No')

Fixed submission:
S = input()
T = input()
     
if S == T[:-1]:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

T.pop(len(T) - 1)

if S == T:
  print('Yes')
else:
  print('No')

Fixed submission:
S = input()
T = input()
     
if S == T[:-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
A, B, C, K = int(input()), int(input()), int(input()), int(input())

if A >= K:
  print(K)
elif A + B >= K:
  print(A)
else:
  print(A - (K - A - B))

Fixed submission:
A, B, C, K = map(int , input().split())

if A >= K:
  print(K)
elif A + B >= K:
  print(A)
else:
  print(A - (K - A - B))
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())

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

V = [list(map(int, input().split())) for i in range(M)]

count = 0

dic = {}

for i in range(1, N):
  dic[i] = set()

for hen in V:
  dic[hen[0]].add(hen[1])
  dic[hen[1]].add(hen[0])

print(sum(all([H[i] > hs for hs in dic[i]]) for i in range(N)))

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

H = list(map(int, input().split()))
H.insert(0, 0)

V = [list(map(int, input().split())) for i in range(M)]

count = 0

dic = {}

for i in range(1, N+1):
  dic[i] = set()

for hen in V:
  dic[hen[0]].add(hen[1])
  dic[hen[1]].add(hen[0])

print(sum(all([H[i] > H[hs] for hs in dic[i]]) for i in range(1, N+1)))

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

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

V = [list(map(int, input().split())) for i in range(M)]

count = 0

dic = {}

for i in range(1, N):
  dic[i] = set()

for hen in V:
  dic[hen[0]].add(hen[1])
  dic[hen[1]].add(hen[0])

print(sum(all([H[i] > hs for hs in dic[i]]) for i in N))

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

H = list(map(int, input().split()))
H.insert(0, 0)

V = [list(map(int, input().split())) for i in range(M)]

count = 0

dic = {}

for i in range(1, N+1):
  dic[i] = set()

for hen in V:
  dic[hen[0]].add(hen[1])
  dic[hen[1]].add(hen[0])

print(sum(all([H[i] > H[hs] for hs in dic[i]]) for i in range(1, N+1)))

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

H = [int(input()) for i in range(N)]

V = [list(map(int, input().split())) for i in range(M)]

count = 0

dic = {}

for i in range(1, N):
  dic[i] = set()

for hen in V:
  dic[hen[0]].add(hen[1])
  dic[hen[1]].add(hen[0])

print(sum(all([H[i] > hs for hs in dic[i]]) for i in N))

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

H = list(map(int, input().split()))
H.insert(0, 0)

V = [list(map(int, input().split())) for i in range(M)]

count = 0

dic = {}

for i in range(1, N+1):
  dic[i] = set()

for hen in V:
  dic[hen[0]].add(hen[1])
  dic[hen[1]].add(hen[0])

print(sum(all([H[i] > H[hs] for hs in dic[i]]) for i in range(1, N+1)))
Buggy python submission (verdict: Runtime Error):
import sys

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

for i in range(A, B + 1):
  if i % K == 0:
    print('OK')
    sys.exit()
	
print('NG')


Fixed submission:
import sys

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

for i in range(A, B + 1):
  if i % K == 0:
    print('OK')
    sys.exit()
	
print('NG')

Buggy python submission (verdict: Runtime Error):
K = input()
A, B = map(int, input().split())

for i in range(A, B + 1):
  if i % K == 0:
    print('OK')
    exit()
	
print('NG')

Fixed submission:
import sys

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

for i in range(A, B + 1):
  if i % K == 0:
    print('OK')
    sys.exit()
	
print('NG')
Buggy python submission (verdict: Runtime Error):
N = int(input())

if N % 2 != 0:
    print('0')
else:
    count = 0
    i = 1
    while True:
        dif = (N // 2) // (5 ** i)
        count += dif
        if dif == 0:
            break

        i += 1

print(count)


Fixed submission:
N = int(input())

if N % 2 != 0:
    print('0')
else:
    count = 0
    i = 1

    while True:
        dif = (N // 2) // (5 ** i)
        count += dif
        if dif == 0:
            break

        i += 1

    print(count)
Buggy python submission (verdict: Runtime Error):
def main():
    N = input_int()
    S = input()

    print(len(rec(S)))


def rec(s):
    if len(s) <= 1:
        return s

    i = 0

    while i + 1 in range(len(s)) and s[i] == s[i+1]:
        i += 1

    return s[0] + rec(s[i+1:])


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


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


main()


Fixed submission:
def main():
    N = input_int()
    S = input()

    validitylist = [False] * N
    validitylist[0] = True

    for i in range(1, N):
        if S[i-1] != S[i]:
            validitylist[i] = True
    
    print(len([i for i in validitylist if i is True]))



def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


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


main()

Buggy python submission (verdict: Runtime Error):
def main():
    N = input_int()
    S = input()

    print(len(rec(S)))


def rec(s):
    if len(s) <= 1:
        return s

    i = 0

    while i + 1 in range(len(s)) and s[i] == s[i+1]:
        i += 1

    return s[0] + rec(s[i+1:])


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


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


main()


Fixed submission:
def main():
    N = input_int()
    S = input()

    validitylist = [False] * N
    validitylist[0] = True

    for i in range(1, N):
        if S[i-1] != S[i]:
            validitylist[i] = True
    
    print(len([i for i in validitylist if i is True]))



def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


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


main()

Buggy python submission (verdict: Runtime Error):
def main():
    N = input_int()
    S = input()

    print(len(rec(S)))
    print(rec(S))


def rec(s):
    if len(s) <= 1:
        return s

    i = 0

    while i + 1 in range(len(s)) and s[i] == s[i+1]:
        i += 1

    return s[0] + rec(s[i+1:])


def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


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


main()


Fixed submission:
def main():
    N = input_int()
    S = input()

    validitylist = [False] * N
    validitylist[0] = True

    for i in range(1, N):
        if S[i-1] != S[i]:
            validitylist[i] = True
    
    print(len([i for i in validitylist if i is True]))



def input_int():
    return int(input())


def input_int_tuple():
    return map(int, input().split())


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


main()
Buggy python submission (verdict: Runtime Error):
N = input()
print(N ** 3)

Fixed submission:
N = int(input())
print(N ** 3)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [-1].extend(list(map(int, input().split()))) # たべた料理
B = [-1].extend(list(map(int, input().split()))) # 料理の満足度
C = [-1].extend(list(map(int, input().split()))) # i -> i+1ボーナス

manzoku = 0

for i in range(1, N+1):
  manzoku += B[A[i]]
  if A[i-1] + 1 == A[i]:
    manzoku += C[A[i-1]]

print(manzoku)

Fixed submission:
N = int(input())
A = [-1]
A.extend(list(map(int, input().split()))) # たべた料理
B = [-1]
B.extend(list(map(int, input().split()))) # 料理の満足度
C = [-1]
C.extend(list(map(int, input().split()))) # i -> i+1ボーナス

manzoku = 0

for i in range(1, N+1):
    manzoku += B[A[i]]
    if A[i-1] + 1 == A[i]:
        manzoku += C[A[i-1]]

print(manzoku)
Buggy python submission (verdict: Runtime Error):
def main():
    N = input_ints()
    h = input_int_list_in_line()

    DP = [0] * N

    DP[1] = abs(h[0] - h[1])

    for i in range(2, N):
        one_hop = abs(h[i] - h[i - 1])
        two_hop = abs(h[i] - h[i - 2])

        if DP[i - 1] + one_hop < DP[i - 2] + two_hop:
            DP[i] += DP[i - 1] + one_hop
        else:
            DP[i] += DP[i - 2] + two_hop

    print(DP[-1])


def input_int():
    return int(input())


def input_ints():
    return map(int, input().split())


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


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


Fixed submission:
def main():
    N = input_int()
    h = input_int_list_in_line()

    DP = [0] * N

    DP[1] = abs(h[0] - h[1])

    for i in range(2, N):
        one_hop = abs(h[i] - h[i - 1])
        two_hop = abs(h[i] - h[i - 2])

        if DP[i - 1] + one_hop < DP[i - 2] + two_hop:
            DP[i] += DP[i - 1] + one_hop
        else:
            DP[i] += DP[i - 2] + two_hop

    print(DP[-1])


def input_int():
    return int(input())


def input_ints():
    return map(int, input().split())


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


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()