Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = input().split()
A = input().split()
a = []

if int(N[0]) >= 2 and int(N[0]) <= 200000:
  n = int(N[0])
  for i in range(n):
    if int(A[i]) >= 1 and int(A[i]) <= 2020202020:
      a.append(int(A[i]))

right = 0
left = 0
cnt = 0
herf = 0

for i in range(n):
  cnt += a[i]
herf = int(cnt/2)
for i in range(n):
  left += a[i]
  if left > herf:
    left -= a[i]
    right = cnt - left
    break
print(abs(left-right))







Fixed submission:
num = input().split()
nums = []
for i in num:
  nums.append(int(i))
#print(nums)
price = [300000, 200000, 100000]
result = []

#2 3 4 5 6
for i in nums:
  if int(i) > 3:
    result.append(0)
  else:
    result.append(price[i-1])
value = result[0] + result[1]
if value == 600000:
  print("1000000")
else:
  print(value)

Buggy python submission (verdict: Runtime Error):
def fun(x):
  if x==1:
    return 300000
  elif x==2:
    return 200000
  elif x==3:
    return 100000
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
su=0
if a==b==1:
    su+=400000
su+=fun(a)
su+=fun(b)
print(su)


Fixed submission:
def fun(x):
    if x==1:
        return 300000
    elif x==2:
        return 200000
    elif x==3:
        return 100000
    else:
        return 0
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
su=0
if a==b==1:
    su+=400000
su+=fun(a)
su+=fun(b)
print(su)

Buggy python submission (verdict: Runtime Error):
def fun(x):
  if x==1:
    return 300000
  elif x==2:
    return 200000
  elif x==3:
    return 100000
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
sum+=fun(a)
sum+=fun(b)
print(sum)


Fixed submission:
def fun(x):
    if x==1:
        return 300000
    elif x==2:
        return 200000
    elif x==3:
        return 100000
    else:
        return 0
s=input()
s=s.split()
a=eval(s[0])
b=eval(s[1])
su=0
if a==b==1:
    su+=400000
su+=fun(a)
su+=fun(b)
print(su)
Buggy python submission (verdict: Time Limit Exceeded):
alen = input()
ai = input()
alen,ai = int(alen), [int(i) for i in ai.split(" ")]
print(sum([sum([1 if k==0 else 0 for k in [sum(ai[i:j]) for j in range(i+1,alen+1)]]) for i in range(alen)]))


Fixed submission:
a=int(input())
b=list(map(int, input().split(" ")))
c=0
d=0
e={0:1}
for i in b:
 c+=i
 d+=e.get(c,0)
 e[c]=e.get(c,0)+1

print(d)
Buggy python submission (verdict: Runtime Error):
sum = 0
for i in map(int, input().split()):
    if i==1:
        sum += 300000
    elif i==2:
        sum+200000
    elif i==3:
        sum += 100000
if sum == 600000:
    sum += 400000
print(s)

Fixed submission:
s = 0
for i in map(int, input().split()):
    if i==1:
        s+=300000
    elif i==2:
        s+=200000
    elif i==3:
        s+=100000
if s==600000:
    s=1000000
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
NKQ= input().split(" ")
N = int(NKQ[0])
K = int(NKQ[1])
Q = int(NKQ[2])
LIST = []

for i in range(0, N):
    LIST.append(K)

for i in range(0, Q):
    offset = int(input()) - 1
    for o in range(0, N):
        if o != offset:
            LIST[o] -= 1
        else:
            pass
        
for i in LIST:
    if i >= 1:
        print("Yes")
    else:
        print("No")
    

Fixed submission:
NKQ= input().split(" ")
N = int(NKQ[0])
K = int(NKQ[1])
Q = int(NKQ[2])
LIST = []

for i in range(0, N):
    LIST.append(K)

for i in range(0, Q):
    offset = int(input()) - 1
    LIST[offset] += 1
        
for i in LIST:
    if i - Q >= 1:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
NM = input().split(" ")
A_LIST = input().split(" ")
A = []
for i in A_LIST:
    A.append(int(i))

N = int(NM[0])
M = int(NM[1])

#.sort()
for i in range(0, M):
    m = max(A)
    n = A.index(m)
    m = m // 2
    A[n] = m
S = 0
for i in A:
    S += i
print(S)

Fixed submission:
import heapq

NM =input().split(" ")
A_LIST = input().split(" ")
N = int(NM[0])
M = int(NM[1])

A = []
for i in A_LIST:
    heapq.heappush(A, -1 * int(i))
    
for i in range(0, M):
    m = heapq.heappop(A)
    m = -1 * m
    m = m // 2
    heapq.heappush(A, -1 * m)

S = 0    
for i in A:
    S += (-1 * i)

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
NM = input().split(" ")
A_LIST = input().split(" ")
A = []
for i in A_LIST:
    A.append(int(i))

N = int(NM[0])
M = int(NM[1])

A.sort()
for i in range(0, M):
    if A[N-1] >= A[N-2]:
        m = A[N-1]
        m = m // 2
        A[N-1] = m
    elif A[N-2] >= A[N-3]:
        m = A[N-2]
        m = m // 2
        A[N-2] = m
        A.sort()
S = 0
for i in A:
    S += i
print(S)

Fixed submission:
import heapq

NM =input().split(" ")
A_LIST = input().split(" ")
N = int(NM[0])
M = int(NM[1])

A = []
for i in A_LIST:
    heapq.heappush(A, -1 * int(i))
    
for i in range(0, M):
    m = heapq.heappop(A)
    m = -1 * m
    m = m // 2
    heapq.heappush(A, -1 * m)

S = 0    
for i in A:
    S += (-1 * i)

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
NM = input().split(" ")
A_LIST = input().split(" ")
A = []
for i in A_LIST:
    A.append(int(i))

N = int(NM[0])
M = int(NM[1])

A.sort()
for i in range(0, M):
    m = max(A)
    m = m // 2
    A[N-1] = m
    if m >= max(A):
        pass
    else:
        A.sort()
S = 0
for i in A:
    S += i
print(S)

Fixed submission:
import heapq

NM =input().split(" ")
A_LIST = input().split(" ")
N = int(NM[0])
M = int(NM[1])

A = []
for i in A_LIST:
    heapq.heappush(A, -1 * int(i))
    
for i in range(0, M):
    m = heapq.heappop(A)
    m = -1 * m
    m = m // 2
    heapq.heappush(A, -1 * m)

S = 0    
for i in A:
    S += (-1 * i)

print(S)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H_list = input().split(" ")
max_count = 0

for i in range(0, N):
    S = int(H_list[i])
    count = 0
    for j in range(i + 1, N):
        if S >= int(H_list[j]):
            S = int(H_list[j])
            count += 1
        else:
            break
    if max_count < count:
        max_count = count
    if max_count >= N - i:
        break
print(max_count)


Fixed submission:
S_list = input()
T_list = input()
count = 0

for i in range(0, 3):
  if S_list[i] == T_list[i]:
    count += 1
  else:
    pass
  
print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
H_list = input().split(" ")
H_LIST = []

for i in range(0, N):
    H_LIST.append(int(H_list[i]))
 
max_count = 0

for i in range(0, N):
    S = H_LIST[i]
    count = 0
    for j in range(i + 1, N):
        if S >= H_LIST[j]:
            S = H_LIST[j]
            count += 1
        else:
            pass
    if max_count < count:
        max_count = count

print(max_count)


Fixed submission:
S_list = input()
T_list = input()
count = 0

for i in range(0, 3):
  if S_list[i] == T_list[i]:
    count += 1
  else:
    pass
  
print(count)

Buggy python submission (verdict: Runtime Error):
AB = input().split(" ")
A = int(AB[0])
B = int(AB[1])

kuti = 1
count = 0 #tap

while kuti < B:
  kuti -= 1
  kuti += A
  count += 1

print(count)
  

Fixed submission:
S_list = input()
T_list = input()
count = 0

for i in range(0, 3):
  if S_list[i] == T_list[i]:
    count += 1
  else:
    pass
  
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
lis = list(map(int,input().split()))

m = min(lis)
lis.remove(min(lis))
m_2 = min(lis)
lis.remove(min(lis))
v = (m + m_2) / 2   

for i in range(0, N - 1):
    v = (v + min(lis)) / 2
    lis.remove(min(lis))

print(v)
    
    

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

m = min(lis)
lis.remove(min(lis))
m_2 = min(lis)
lis.remove(min(lis))
v = (m + m_2) / 2   

for i in range(0, N - 2):
    v = (v + min(lis)) / 2
    lis.remove(min(lis))

print(v)
Buggy python submission (verdict: Runtime Error):
lis = input(" ")

K = int(lis[0])
X = int(lis[1])

mini = X - (K - 1)
maxm = X + (K - 1)
list_a = []
for i in range(0, (K - 1) * 2 + 1):
    list_a.append(str((X - (K - 1)) + i))

print(" ".join(list_a))

Fixed submission:
lis = input().split(" ")

K = int(lis[0])
X = int(lis[1])

mini = X - (K - 1)
maxm = X + (K - 1)
list_a = []
for i in range(0, (K - 1) * 2 + 1):
    list_a.append(str((X - (K - 1)) + i))

print(" ".join(list_a))
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
count = 0
if(N==1):
    print("Yes")
else:
    for i in range(N-1):
        if(H[i+1]-H[i]==-1):
            count +=1
            if(count==1):
                H[i]=H[i]-1
        elif(H[i]>H[i+1]):
            count +=1
    print(count)
    if(count<=1):
        print("Yes")
    else:
        print("No")


Fixed submission:
a, b, c= (int(i) for i in input().split())  

cap=a-b
c=c-cap
if(c>0):
    print(c)
else:
    print("0")
Buggy python submission (verdict: Runtime Error):
keta = (len(n))
max = int(keta/2)+1

count = 0
t = int(n)
if(keta%2==0):
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
else:
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
    t = t - 10**(keta-1)
    count += t
    count +=1
print(count)

Fixed submission:
import math
n = str(input()) 
keta = (len(n))
max = int(keta/2)+1

count = 0
t = int(n)
if(keta%2==0):
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
else:
    for i in range(1,max):
        count += 9*10**((2*(i-1)))
    t = t - 10**(keta-1)
    count += t
    count +=1
print(count)
Buggy python submission (verdict: Runtime Error):
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  s.sort()
  S.append(s)
S.sort()
S.append(["z" for i in range(11)])
cont=0
for i in range(n-1):
  t=1
  while S[i]==S[i+t]:
    cont+=1
    t+=1
print(cont)

Fixed submission:
a,b=map(int,input().split())
c=[a+b, a-b, a*b]
m=max(c)
print(m)
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N = 10**5:
  print("90909")
elif N >= 10**4:
  resid=N-10**4+1
  print(str(9+900+resid))
elif N >= 10**3:
  print("990")
elif N >= 10**2:
  resid=N-10**2+1
  print(str(9+resid))
elif N >= 10:
  print("9")
else:
  print(str(N))

Fixed submission:
N=int(input())
if N == 10**5:
  print("90909")
elif N >= 10**4:
  resid=N-10**4+1
  print(str(9+900+resid))
elif N >= 10**3:
  print("909")
elif N >= 10**2:
  resid=N-10**2+1
  print(str(9+resid))
elif N >= 10:
  print("9")
else:
  print(str(N))
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int, input().split()))
h=reversed(h)
a=0
for i in range(length(h)-1):
  if h[i]+1 < h[i+1]:
    a+=1
    break
  elif h[i]+1==h[i+1]:
    h[i+1]=h[i+1]-1
  else:
    pass
if a==0:
  print("Yes")
else:
  print("No")
  

Fixed submission:
n=int(input())
h=list(map(int, input().split()))
h.reverse()
a=0
for i in range(len(h)-1):
  if h[i]+1 < h[i+1]:
    a+=1
    break
  elif h[i]+1==h[i+1]:
    h[i+1]=h[i+1]-1
  else:
    pass
if a==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,a,b=int(input().strip().split())

if n*a>=b:
  print(b)
else:
  print(n*a)

Fixed submission:
n,a,b=input().strip().split()
n,a,b=[int(n),int(a),int(b)]

if n*a>b:
  print(b)
else:
  print(n*a)

Buggy python submission (verdict: Runtime Error):
n,a,b=int(input().strip().split)

train=n*a
taxi=b

fare=min(taxi,train)

print(str(fare))

Fixed submission:
n,a,b=input().strip().split()
n,a,b=[int(n),int(a),int(b)]

if n*a>b:
  print(b)
else:
  print(n*a)
Buggy python submission (verdict: Time Limit Exceeded):
L,R=map(int, input().strip().split())

d=2018
for i in range(R-L+1):
  a=L+i
  for j in range(R-a):
    b=a+j+1
    c=(a*b)%2019
    if c<d:
      d=c
print(d)

Fixed submission:
L,R=map(int, input().strip().split())

d=2018
for i in range(min(R-L,2019)):
  a=L+i
  for j in range(min(R-a,2019)):
    b=a+j+1
    c=(a*b)%2019
    if c<d:
      d=c
print(d)
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
S = input()
partS = []
for _ in range(q):
    l, r = map(int, input().split())
    partS .append(S[l - 1:r])
for i in range(q):
    print(partS[i].count("AC"))


Fixed submission:
n, q = map(int, input().split())
s = input()
count = [0]*n
for i in range(1, n):
    count[i] = count[i-1]
    if s[i - 1: i + 1] == "AC":
        count[i] += 1

for i in range(q):
    l, r = map(int, input().split())
    print(count[r-1]-count[l-1])
Buggy python submission (verdict: Runtime Error):
s = [*input()]
t = [*input()]
s.sort()
t.sort()
t.reverse()
print("Yes" if s < t else "No")


Fixed submission:
S = input()
T = input()
s = list(S)
t = list(T)
s.sort()
t.sort()
t.reverse()
print("Yes" if s < t else "No")
Buggy python submission (verdict: Runtime Error):
s = raw_input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))


Fixed submission:
s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
import operator

# def check_cycle

N, = map(int, sys.stdin.readline().rstrip().split(" "))
As = list(map(int, sys.stdin.readline().rstrip().split(" ")))
Bs = list(map(int, sys.stdin.readline().rstrip().split(" ")))
AB_sorted = list(sorted(zip(As, Bs), key=operator.getitem(1)))
As_original = list(map(operator.getitem(0), AB_sorted))
As.sort()

A_reserve_dict = {}
last_reserve = None
for i in range(len(As)):
    if As[i] > Bs[i]:
        print("No")
        break
else:
    for i in range(len(As)):
        if As[i] == As_original[i]: # すでに一致してる = 1回減らせる
            print("Yes")
            break
    else:
        for i in range(len(As)-1):
            if As[i+1] <= Bs[i]: # i と i+1はどちらでもいい = 1回減らせる
                print("Yes")
                break
        else:
            print("No")
exit(0)

# Fails
# 1 2 3
# 2 3 1

# Fails
# 1 2 3 4
# 3 4 2 1


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
import operator
import numpy

def check_cycle(i_pair):
    i_orig_sorted_dict = {i_orig: i_sort for i_orig, i_sort in i_pair}
    cycle_dict = {}
    for i_orig, i_sort in i_pair:
        i_current = i_orig
        while True:
            if not i_current in cycle_dict:
                cycle_dict[i_current] = i_orig
            else:
                break
            i_current = i_orig_sorted_dict[i_current]
    return len(numpy.unique(list(cycle_dict.values())))


N, = map(int, sys.stdin.readline().rstrip().split(" "))
As = list(map(int, sys.stdin.readline().rstrip().split(" ")))
Bs = list(map(int, sys.stdin.readline().rstrip().split(" ")))
AB_sorted = list(sorted(zip(As, Bs), key=operator.itemgetter(1)))
Bs = list(map(operator.itemgetter(1), AB_sorted))
As_original = list(map(operator.itemgetter(0), AB_sorted))
A_i_pair = [(i_orig, i_sort) for i_sort, (i_orig, value) in enumerate(sorted(enumerate(As_original), key=operator.itemgetter(1)))]
As.sort()

# print(Bs)
# print(As_original)
# print(As)

A_reserve_dict = {}
last_reserve = None
for i in range(len(As)):
    if As[i] > Bs[i]:
        print("No")
        break
else:
    # for i in range(len(As)):
    #     if As[i] == As_original[i]:  # すでに一致してる = 1回減らせる
    #         print("Yes")
    #         break
    if check_cycle(A_i_pair) >= 2:
        print("Yes")
    else:
        for i in range(len(As) - 1):
            if As[i + 1] <= Bs[i]:  # i と i+1はどちらでもいい = 1回減らせる
                print("Yes")
                break
        else:
            print("No")
exit(0)

# Fails
# 1 2 3
# 2 3 1

# Fails
# 1 2 3 4
# 3 4 2 1
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections


def fib(n):
    return int((1 / math.sqrt(5)) * (math.pow((1 + math.sqrt(5)) / 2, n) - math.pow((1 - math.sqrt(5)) / 2, n)))


# for i in range(10):
#     print(fib(i))

N, M = map(int, sys.stdin.readline().rstrip().split(" "))
As = []
for i in range(M):
    a, = map(int, sys.stdin.readline().rstrip().split(" "))
    As.append(a)
As.append(N+1)
result = 1
current = 0
for a in As:
    diff = a - current - 1
    if diff == -1:
        print(0)
        exit(0)
    # 1: 1
    # 2: 2
    # 3: 3C0 + 2C1 = 3
    # 4: (1,1,1,1) (1,1,2) (1, 2, 1) (2, 1, 1), (2, 2): 4C4 + 3C1 + 2C2 = 1+ 3 + 1 = 5
    # 5: 5C0 + 4C1 + 3C2 = 1 + 4 + 3 = 8
    # 6: 6C0 + 5C1 + 4C2 + 3C3 = 1+5+6+1 = 13
    # 7: 7C0 + 6C1 + 5C2 + 4C3 = 1+6+10+4 = 21
    # print(current, a, fib(diff+1))
    result *= fib(diff+1)
    result %= 1000000007
    # print("res", result)
    current = a + 1
print(result)
exit(0)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections


fib_list=[1, 1]
for i in range(10**5):
    fib_list.append(fib_list[-1] + fib_list[-2])

# def fib(n):
#     return int((1 / math.sqrt(5)) * (math.pow((1 + math.sqrt(5)) / 2, n) - math.pow((1 - math.sqrt(5)) / 2, n)))

def fib(n):
    return fib_list[n-1]


# for i in range(-10, 10):
#     print(fib(i))

N, M = map(int, sys.stdin.readline().rstrip().split(" "))
As = []
for i in range(M):
    a, = map(int, sys.stdin.readline().rstrip().split(" "))
    As.append(a)
As.append(N+1)
result = 1
current = 0
for a in As:
    diff = a - current - 1
    if diff < 0:
        print(0)
        exit(0)
    # 1: 1
    # 2: 2
    # 3: 3C0 + 2C1 = 3
    # 4: (1,1,1,1) (1,1,2) (1, 2, 1) (2, 1, 1), (2, 2): 4C4 + 3C1 + 2C2 = 1+ 3 + 1 = 5
    # 5: 5C0 + 4C1 + 3C2 = 1 + 4 + 3 = 8
    # 6: 6C0 + 5C1 + 4C2 + 3C3 = 1+5+6+1 = 13
    # 7: 7C0 + 6C1 + 5C2 + 4C3 = 1+6+10+4 = 21
    # print(current, a, fib(diff+1))
    result *= fib(diff+1)
    result %= 1000000007
    # print("res", result)
    current = a + 1
print(result)
exit(0)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N,M = map(int, sys.stdin.readline().rstrip().split(" "))
Lmax, Rmin = 0, N
for _ in range(M):
    L, R = map(int, sys.stdin.readline().rstrip().split(" "))
    Lmax = max(L, Lmax)
    Rmin = min(R, Rmin)
assert Rmin >= Lmax
print(Rmin - Lmax + 1)
exit(0)

Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, M = map(int, sys.stdin.readline().rstrip().split(" "))
Lmax, Rmin = 0, N
for _ in range(M):
    L, R = map(int, sys.stdin.readline().rstrip().split(" "))
    Lmax = max(L, Lmax)
    Rmin = min(R, Rmin)
if Rmin >= Lmax:
    print(Rmin - Lmax + 1)
else:
    print(0)
exit(0)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**8

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

ans = solve(costs + [INF] * 2)
assert ans < INF
print(ans)
exit(0)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**10

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

ans = solve(costs + [INF] * 2)
assert ans < INF
print(ans)
exit(0)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**8

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

print(solve(costs + [INF] * 2))
exit(0)

        


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
INF = 10**10

N, = map(int, sys.stdin.readline().rstrip().split(" "))
costs = map(int, sys.stdin.readline().rstrip().split(" "))


def solve(costs):
    dp = [0] + [INF for _ in costs]
    for i in range(len(costs)-2):
        dp[i+1] = min(dp[i+1], dp[i] + abs(costs[i+1] - costs[i]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(costs[i+2] - costs[i]))
    #print(dp)
    return dp[-4]

ans = solve(costs + [INF] * 2)
assert ans < INF
print(ans)
exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import copy

N, K = list(map(int, sys.stdin.readline().rstrip().split()))
data = []
for _ in range(N):
    A, B = list(map(int, sys.stdin.readline().rstrip().split()))
    # print(A)
    # print(bin(A)[2:])
    data.append([list(reversed(bin(A)[2:])), B])

ans = 0


def lower(x, y):
    if(len(x) > len(y)):
        return False
    for xx, yy in zip(x, y):
        if (xx == "1" and yy == "0"):
            return False
    else:
        return True


Nstr = list(reversed(bin(K)[2:]))
subNstrs = [Nstr]
for i in range(len(Nstr)):
    if Nstr[i] == "0":
        continue
    subNstr = copy.deepcopy(Nstr)
    subNstr[i] = "0"
    for j in range(i):
        subNstr[j] = "1"
    subNstrs.append(subNstr)


for subNstr in subNstrs:
    subans = 0
    for A, B in data:
        # print(A, subNstr, lower(A, subNstr))
        if(lower(A, subNstr)):
            subans += B
    # print(subNstr, subans)
    ans = max(subans, ans)

print(ans)

exit(0)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import copy

N, K = list(map(int, sys.stdin.readline().rstrip().split()))
data = []
for _ in range(N):
    A, B = list(map(int, sys.stdin.readline().rstrip().split()))
    data.append([A, B])

ans = 0


def lower(x, y):
    if(x > y):
        return False
    # print(bin(x), bin(y), bin(x|y), bin((x | y) ^ y))
    if((x | y) ^ y) == 0:
        return True
    else:
        return False


Nstr = list(reversed(bin(K)[2:]))
subNs = [K]
for i in range(len(Nstr)):
    if Nstr[i] == "0":
        continue
    subNstr = copy.deepcopy(Nstr)
    subNstr[i] = "0"
    for j in range(i):
        subNstr[j] = "1"

    realstr = ""
    for s in reversed(subNstr):
        realstr += s
    subNs.append(int(realstr, 2))


for subNstr in subNs:
    subans = 0
    for A, B in data:
        # print(A, subNstr, lower(A, subNstr))
        if(lower(A, subNstr)):
            subans += B
    # print(subNstr, subans)
    ans = max(subans, ans)

print(ans)

exit(0)