Harryxun/stf_run huggingface dataset:
N,M =map(int,input().split())
A = [0]*(N*M*1000)
B = [0]*M
C = [0]*M
ans = int(0)

A = list(map(int, input().split()))
for i in range(M):
    B[i],C[i] = list(map(int,input().split()))
    for j in range(B[i]):
        A.append(C[i])

A.sort()

S = int(N)

for i in range(M):
    S +=B[i]

for i in range(S-1,S-N-1,-1):
    ans += A[i]

print(ans)

### FIXED CODE ###

from heapq import heappush, heappop

# input
N,M =map(int,input().split())
A = [0]*N
B = [0]*M
C = [0]*M

A = list(map(int, input().split()))
A.sort()
for i in range(M):
    B[i],C[i] = list(map(int,input().split()))


def solve():

    pairs = zip(C, B)
    sortedpairs = sorted(pairs, key=lambda x: x[0])
    for i in range(M):
        B[i]=sortedpairs[i][1]
        C[i]=sortedpairs[i][0]

    ansA=[0]*N
    for j in range(N):
        ansA[j] = A[j]

    p = int(0)
    j = int(0)
    while  j<N and M>=1+p :
        jd = int(0)
        if ansA[j] >= C[M - 1 - p]:
            break
        while  B[M-1-p]-jd>0 :
            if j==N : break
            if ansA[j]>=C[M-1-p] :
                break
            else:
                ansA[j]=C[M-1-p]
            jd +=1
            j +=1

        p +=1

    ans = int(0)
    for j in range(N):
        ans += ansA[j]

    print(ans)

solve()
X = int(input())]


DP = [0 for i in range(1000000)]
DP[0] = 1
a = [100, 101, 102, 103, 104, 105]
for i in a:
    for j in range(X):
        if DP[j] == 1:
            DP[j + i] = 1
print(DP[X])

### FIXED CODE ###

X = int(input())
import sys
q = X // 100
r = X % 100
if r >= 0 and r <= 5 * q:
    print(1)
    sys.exit()
print(0)
N,K=map(int,input().split())

num=[0]*(N)
for i in range(1,N+1):
    num[i%K]+=1
#print(num)
ans=0
for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        #print(a,b,c)
print(ans)

### FIXED CODE ###

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

num=[0]*(max(N+1,K))
for i in range(1,N+1):
    num[i%K]+=1
#print(num)
ans=0
for a in range(K):
    b=(K-a)%K#a=0なら0 a!=0ならk-aになる賢い手
    c=(K-a)%K
    if (b+c)%K!=0:
        continue
    else:
      	#print(a)
        ans+=num[a]*num[b]*num[c]
        #print(a,b,c)
print(ans)
from heapq import heapify,heappop,heappush
n,m=map(int,input().split())#n:num m:ticket
a=[-int(_) for _ in input().split()]
a=heapify(a)
for i in range(m):
	heappush(a,heappop//2)
print(sum(a)*-1)

### FIXED CODE ###

from heapq import heapify,heappop,heappush
n,m=map(int,input().split())#n:num m:ticket
a=[-int(_) for _ in input().split()]
heapify(a)
for i in range(m):
	num=heappop(a)*-1
	heappush(a,(num//2)*-1)
print(sum(a)*-1)
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a=ii()

if 65<= ord(a) <=90:
    print("A")
else:
    print("a")

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')

#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a=ss()

if 65<= ord(a) <=90:
    print("A")
else:
    print("a")
import sys
input = sys.stdin.readline

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

a_set=set()

for index in range(m):
    a_set.add(int(input()))

ans_list = []

ans_list = 0 * (n + 1)

for index in range(n + 1):
    if index == 0:
        ans_list[index] += 1
        continue
    if index == 1 and (index not in a_set):
        ans_list[index] += ans_list[index - 1]
        continue
    
    if index not in a_set:
        if (index - 1) not in a_set:
            ans_list[index] += ans_list[index - 1]
            ans_list[index] %= 1000000007
        if (index - 2) not in a_set:
            ans_list[index] += ans_list[index - 2]
            ans_list[index] %= 1000000007

print(ans_list[n])


### FIXED CODE ###

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

a_set=set()

for index in range(m):
    a_set.add(int(input()))

ans_list=[]

for index in range(n + 1):
    ans_list.append(0)

for index in range(n + 1):
    if index == 0:
        ans_list[index] += 1
        continue
    if index == 1 and (index not in a_set):
        ans_list[index] += ans_list[index - 1]
        continue
    
    if index not in a_set:
        if (index - 1) not in a_set:
            ans_list[index] += ans_list[index - 1]
            ans_list[index] %= 1000000007
        if (index - 2) not in a_set:
            ans_list[index] += ans_list[index - 2]
            ans_list[index] %= 1000000007

print(ans_list[n])
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

### FIXED CODE ###

n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)
n,a,b=map(int,input().split())

sum=0

for i in range(n+1):
    if a<=sum(map(int,str(i)))<=b:
        count+=i

print(sum)

### FIXED CODE ###

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

count=0

for i in range(n+1):
    if a<=sum(map(int,str(i)))<=b:
        count+=i

print(count)
from sys import stdin

n = int(input())
r = int(input())

if n < 11:
    a = r + 100 * (10-n)
else:
    a = r

print(n)


### FIXED CODE ###

from sys import stdin

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

if n < 10:
    print(r + 100 * (10-n))
else:
    print(r)
a,b = map(int,input().split(" "))
print(max([a+b,a-b,a*b])

### FIXED CODE ###

a,b = map(int,input().split(" "))
print(max([a+b,a-b,a*b]))
n,m=map(int,input().split())
b=[[int(x) for x in input().split()] for y in range(m)]
u=n*(n-1)//2

s=set()
a=[u]

for i in range(m-1,0,-1):
  x=y=-1
  for j in range(len(s)):
    if b[i][0] in s[j]:
      x = j
    if b[i][1] in s[j]:
      y = j
    if x!=-1 and y!=-1:
      break

  if x==-1 and y==-1:
    s.append(set((b[i][0],b[i][1])))
  elif y==-1:
    s[x].add(b[i][1])
  elif x==-1:
    s[y].add(b[i][0])
  elif x!=y:
    for k in range(len(s[y])):
      s[x].add(s[y].pop())
    s.pop(y)

  t=0
  for j in range(len(s)):
    t += (len(s[j])*(len(s[j])-1))//2
  a.append(u-t)
 
a.reverse()
for i in range(len(a)):
  print(a[i])


### FIXED CODE ###

n, m = map(int, input().split())
e = [[int(x) for x in input().split()] for _ in range(m)]

u = [-1]*(n+1)

def find(x):
  return x if u[x] < 0 else find(u[x])

t = n*(n-1)// 2
s = [t]

for i in range(m-1,0,-1):
  a = find(e[i][0])
  b = find(e[i][1])
  if a > b:
    a, b = b, a
  if a != b:
    t -= u[a]*u[b]
    u[a] += u[b]
    u[b] = a
  s.append(t)

for i in reversed(s):
  print(i)
a = len(str(N)) - 1
if str(N[a]) == 2 or str(N[a]) == 4 or str(N[a]) == 5 or str(N[a]) == 7 or str(N[a]) == 9:
  print("hon")
elif str(N[a]) == 0 or str(N[a]) == 1 or str(N[a]) == 6 or str(N[a]) == 8:
  print("pon")
elif str(N[a]) == 3:
  print("bon")

### FIXED CODE ###

Nin=input()

N=Nin[-1]

if N in "24579":
  print("hon")
elif N in "0168":
  print("pon")
else:
  print("bon")
K = int(input())
S = int(input())
if len(S) <= K:
  print(S)
else:
  print(S[:K]+"...")

### FIXED CODE ###

K = int(input())
S = input()
if len(S) <= K:
  print(S)
else:
  print(S[:K]+"...")
n = int(input())
x = list(map(int, input().split()))

min_energy = None

for p in range(x[-1]):
    energy = 0
    for x_i in x:
        energy += (x_i - p) ** 2
    if min_energy is None:
        min_energy = energy
    else:
        min_energy = min(energy, min_energy)

print(min_energy)


### FIXED CODE ###

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

if n >= 10:
    print(r)
else:
    print(r+100*(10-n))
L, R d = input().split()
counter=0
for i in range(R-L):
  num = i+L
  if num%d:
    counter+=1
print(counter)

### FIXED CODE ###


L, R ,d= map(int,input().split())
counter=0
for i in range(R+1-L):
  num = i+L
  if num%d == 0:
    counter+=1
print(counter)
n=int(input())
p = list(map(int, input().split()))
count=0
for i in range((n-2)
	if p[i]>p[i+1]>p[i+2] or p[i+2]>p[i+1]>p[i]:
    	count=count+1
print(count)

### FIXED CODE ###


n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
	if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
		ans += 1
print(ans)
a, b, c, d = map(int, input().split())
print(max(a * b, a * c, c * b))

### FIXED CODE ###

a, b, c = map(int, input().split())
print(min(a + b, a + c, c + b))
n=int(input())
s=input()
A=False
for i in range(n-1):
    if s[i]=='#':
        num=i
        A=True
        break
if A:
    moji=s[num:]
    lst=dict(Counter(moji).items())
    a=lst['#'];b=lst['.']

    if a==0 or b==0:
        print(0)
    else:
        if s[-1]=='#':
            print(min(a-1,b))
        else:
            print(min(a,b))
else:
    print(0)
 

### FIXED CODE ###

n=int(input())
s=input()
bres=0
wres=0
blst=[]
wlst=[]
for i in range(n):
    if s[i]=='#':
        bres+=1
    blst.append(bres)
for i in range(n-1,-1,-1):
    if s[i]=='.':
        wres+=1
    wlst.append(wres)
wlst=wlst[::-1]
ans=10**9
blst.insert(0,0)
wlst.insert(n,0)
for i in range(n+1):
    ans=min(blst[i]+wlst[i],ans)
print(ans)
import itertools
N,M = map(int,input().split())
A = []
X = [[0]]*M

for m in range(M):
  a,b = map(int,input().split())
  A.append([a,b])
  X[m] = X[m] + [a] + [b]


ans = []
XX = []
for _ in range(N-1):
  for x,v in itertools.product(X,A):   
    if x[-1] == v[0]:
      if v[1] in x:
        ans.append(x+[v[1]])
      else:
        XX.append(x + [v[1]])
    X = XX

if ans == []:
  print(-1)
else:
  n = m+2
  for a in ans:
    if n > len(a):
      n = len(a)
      ans_min = a[:-1]
  ans_min[0] = len(ans_min)-1
  print(ans_min)


### FIXED CODE ###

def main():
  from collections import deque
  n,m,*t=map(int,open(0).read().split())
  i=[0]*n
  o=[[]for _ in range(n)]
  for a,b in zip(*[iter(t)]*2):
    o[a-1]+=b-1,
    i[b-1]+=1
  q=deque(v for v,f in enumerate(i)if f<1)
  r=[]
  while q:
    v=q.popleft()
    r+=v,
    for w in o[v]:
      i[w]-=1
      if i[w]==0:q+=w,
  print(-(len(r)==n))
main()
N = int(input())
h = [i for i in map(int, input().split())]

def dp(i):
    if i==0:
        return 0
    elif i==1:
        return abs(h[1]-h[0])
    else:
        return min(dp(i-1)+abs(h[i]-h[i-1]), dp(i-2)+abs(h[i]-h[i-2]))

print(dp(N-1))

### FIXED CODE ###

N = int(input())
h = [i for i in map(int, input().split())]

dp = [0]*N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(N-2):
    dp[i+2] = min(dp[i]+abs(h[i+2]-h[i]), dp[i+1]+abs(h[i+2]-h[i+1]))
print(dp[-1])
N, S = map(str, input().split())
N = int(N)

ans = 0
str_list = list(S)

for i in range (len(str_list)-2):
  if(str_list[i] == "A"):
    if(str_list[i+1] == "B"):
      if(str[i+2] == "C"):
        ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
str_list = list(S)

for i in range (len(str_list)-2):
  if(str_list[i] == "A"):
    if(str_list[i+1] == "B"):
      if(str_list[i+2] == "C"):
        ans += 1

print(ans)
import math
n,m=map(int, input().split())
a=sorted(list(map(int, input().split())),reverse=True)
tot=0
rate=[0]*n
p=[0]*n

for i in range(n-1):
  rate[i]=math.log2(a[i]/a[i+1])
  
cur=0
while m>0:
  if rate[cur]>0:
    p[cur]+=1
    rate[cur]-=1
    m-=1
    if cur>0:
      rate[cur-1]+=1
      cur-=1
  else:
    cur+=1
  
for i in range(n):
  tot+=int(a[i]/(2**p[i]))
print(tot)

### FIXED CODE ###

import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))

for i in range(n):
    a[i]*=-1

heapq.heapify(a)
for _ in range(m):
    x=heapq.heappop(a)*(-1)
    x=x//2
    heapq.heappush(a,-x)

print(sum(a)*(-1))
a = int(input)
if a % 2 == 0:
  print(0.5)
else:
  print(((a+1)//2) / a)

### FIXED CODE ###

a = int(input())
if a % 2 == 0:
  print(0.5)
else:
  print(((a+1)//2) / a)
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

### FIXED CODE ###

import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
n,m,q = I2()
r = []
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
ans = []
import copy
def dfs(A):
    if len(A) == n+1:
        now = 0
        for i in range(q):
            if A[b[i]]-A[a[i]] == c[i]:now += d[i]
        ans.append(now)
        return
    A.append(A[-1])
    while (A[-1] <= m):
        dfs(copy.copy(A))
        A[-1] += 1
if __name__ == "__main__":
    for i in range(q):
        a[i],b[i],c[i],d[i] = I2()
    dfs([1])
    print(max(ans))
import sys
sys.setrecursionlimit(100000)
def anscestor(s, parent):
    ret = []
    if len(parent) == 0:
        return []
    else:
        r = parent[s]
        for el in r:
            ret.append(el)
            if len(an[el]) != 0:
                ret.append(an[el])
            else:
                ret.append(anscestor(el, parent))
    return ret


def check(l, parent):
    le = len(l)
    for i in range(le):
        a = l[i]
        ans = an[a]
        ans.append(a)
        if all(k in ans for k in l):
            return [a]


N, M = map(int, input().split())
nodes = [0]*N

parent = [[] for _ in range(N)]
an = [[] for _ in range(N)]


# 入力
for _ in range(N+M-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    nodes[b] += 1
    parent[b].append(a)

# 先祖を作る
for i in range(N):
    an[i] = anscestor(i, parent)

for i in range(N):
    if nodes[i] >= 2:
        parent[i] = check(parent[i], parent)


for i in range(N):
    if len(parent[i]) == 0:
        parent[i] = 0
    else:
        parent[i] = parent[i][0]+1

for i in parent:
    print(i)


### FIXED CODE ###

def topological_sort(V, E_in, E_from):
    '''
    V:N(node)
    E_from:
    E_in:
    '''

    # count num of pointed nodes for each nodes
    parent = [0]*V
    cnt = [0]*V
    Q = []
    for v in range(V):
        cnt[v] = len(E_in[v])
        if cnt[v] == 0:
            Q.append(v)

    while Q:
        del_node = Q.pop()
        for j in E_from[del_node]:
            cnt[j] -= 1
            if cnt[j] == 0:
                Q.append(j)
                parent[j] = del_node+1

    return parent


def main():
    N, M = map(int, input().split())
    E_in = [[] for _ in range(N)]
    E_from = [[] for _ in range(N)]
    for _ in range(N+M-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        E_from[a].append(b)
        E_in[b].append(a)

    ans = topological_sort(N, E_in, E_from)
    for s in ans:
        print(s)


if __name__ == '__main__':
    main()
input = input(“天気を入力：”)
items = {'Sunny': 'Cloudy', 'Cloudy':'Rainy', 'Rainy': 'Sunny'}
print( items[input] )

### FIXED CODE ###

input = input()
items = {'Sunny': 'Cloudy', 'Cloudy':'Rainy', 'Rainy': 'Sunny'}
print( items[input] )
def f(n):
  if n <= 1:
    return 1
  return f(n-1)*n

def h(n,m):
  return f(n+m-1)/f(n)/f(m-1)

s=int(input())

res = 0

pair = s//3

for i in range(1,pair+1):
  res += h(s-3*i,i)
print(res)
  

### FIXED CODE ###

def f(n):
  res = 1
  if n <= 1:
    return 1
  while n>1:
    res *= n
    n-=1
  return res
 
def h(n,m):
  return f(n+m-1)//f(n)//f(m-1)
 
s=int(input())
 
res = 0
 
pair = s//3
 
for i in range(1,pair+1):
  res += h(s-3*i,i)
print(res%(10**9+7))
from collections import Counter

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

C = Counter(A)
C = sorted(C.items())

cc = []
for a, b in C:
    cc.append([a, b])
C = cc

M = len(C)

left = 0
right = M - 1

while True:

    if C[left][1] < 2:
        for left in range(M):
            if C[left][1] > 1:
                break

    if C[right][1] < 2:
        for right in range(M):
            if C[M - right - 1][1] > 1:
                break

        right = M - right - 1

    if C[left][1] <= 1 and C[right][1] <= 1:
        break

    if left == right:
        if C[left][1] >= 3:
            C[left][1] -= 2
        else:
            C[left][1] -= 1
            for i in range(left + 1, M):
                if C[left + i][1] > 0:
                    C[left + i][1] -= 1
                    break
    else:
        C[left][1] -= 1
        C[right][1] -= 1


ans = 0
for a, b in C:
    ans += b

print(ans)


### FIXED CODE ###

from collections import Counter

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

C = Counter(A)
C = sorted(C.items())

cc = []
for a, b in C:
    cc.append([a, b])
C = cc

M = len(C)

left = 0
right = M - 1

while True:
    if C[left][1] < 2:
        p_left = left
        for left in range(p_left, M):
            if C[left][1] > 1:
                break

    if C[right][1] < 2:
        p_right = M - right - 1
        for right in range(M):
            if C[M - right - 1][1] > 1:
                break

        right = M - right - 1

    if C[left][1] <= 1 and C[right][1] <= 1:
        break

    if left == right:
        if C[left][1] >= 3:
            C[left][1] -= 2
        else:
            f = 0
            C[left][1] -= 1
            for i in range(left + 1, M):
                if C[i][1] > 0:
                    C[i][1] -= 1
                    f = 1
                    break

            if f == 0:
                for i in range(0, left):
                    if C[i][1] > 0:
                        C[i][1] -= 1

    else:
        C[left][1] -= 1
        C[right][1] -= 1


ans = 0
for a, b in C:
    ans += b

print(ans)
a, b = map(int, input().split())
if a <= 8 or b <= 8:
  print("Yay!")
elif:
  print(":(")


### FIXED CODE ###

a, b = map(int, input().split())
if a <= 8 and b <= 8:
  print("Yay!")
else:
  print(":(")
a, b = input().split()
a= int(a)
b = int(b)
if not len(a) <2;
 if not len(b) < 2;
  print(a*b)
else:
  print("-1")


### FIXED CODE ###

import sys
a, b = map(int, input().split())
k = range(1,10)
if a in k:
 if b in k:
  print(a*b)
  sys.exit()
 else:
  pass
print("-1")
def frog1(h):
    dp = [float('inf')]*3
    dp[0] = 0
    for i in range(1,len(h)):
        dp[i%3] = min([dp[(i-j)%3] + abs(h[i]-h[i-j]) for j in range(1,3)])
    return dp[(len(h)-1)%3]
    
n = raw_input()
vals = map(int, raw_input.split())

print(frog1(vals))

### FIXED CODE ###

def frog1(h):
    dp = [float('inf')]*3
    dp[0] = 0
    for i in range(1,len(h)):
        dp[i%3] = min([dp[(i-j)%3] + abs(h[i]-h[i-j]) for j in range(1,3)])
    return dp[(len(h)-1)%3]
    
n = input()
vals = list(map(int, input().split()))

print(frog1(vals))
a,b,c = map(int,input().split())

sum = a + b + c

if sum % 2 == 0:
  print(Yes)

else:
  print(No)
  


### FIXED CODE ###

li = sorted(list(map(int,input().split())))

a = li[0]
b = li[1]
c = li[2]

if a + b == c:
  print('Yes')

else:
  print('No')
S=input()
flag = True

for i in range(len(a)):
  if i%2==0 and S[i] == R:
    print('No')
    flag = False
    break
  elif i%2==1 and S[i] == L:
    print('No')
    flag = False
    break
if flag:
  print('Yes')
  	

### FIXED CODE ###

s=input()
flag=True
for i in range(len(s)):
  if i%2==1 and s[i]=="R":
    flag=False
    break
  elif i%2==0 and s[i]=="L":
    flag = False
    break
if flag:
  print('Yes')
else:
  print('No')
a = list(map(int,input().split()))

if a[1]<a[2]:
  print(0)
else:
  print(min(a[1],a[3])-max(a[0],a[2]))


### FIXED CODE ###

a = input()
if a[0] == a[2]:
  print("Yes")
else:
  print("No")
N,K = map(int,input().split())
PP = list(map(int,input().split()))


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum
            
print(ksum)
time3 = datetime.now()

       




### FIXED CODE ###

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


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum


print(mmax)
a,b =map(int, input().split)

if a <= 5 :
  print(0)
elif 5 < a <= 12 :
  print(b/2)
else :
  print(b)

### FIXED CODE ###

a,b = map(int,input().split())
 
if a <= 5 :
  print(0)
elif a <= 12 :
  print(int(b//2))
else :
  print(b)
import sys
n=10**5
p=[1]*n
p[0],p[1]=0,0
for i in xrange(2,int(n**0.5)+1):
    if p[i]==1:
        for j in xrange(i**2,n,i):
            p[j]=0
for i in xrange(2,n):
    p[i]+=p[i-1]
for line in sys.stdin.readlines():
    print p[int(line)]

### FIXED CODE ###

import sys
n=10**6
p=[1]*n
p[0],p[1]=0,0
for i in xrange(2,int(n**0.5)+1):
    if p[i]==1:
        for j in xrange(i**2,n,i):
            p[j]=0
for i in xrange(2,n):
    p[i]+=p[i-1]
for line in sys.stdin.readlines():
    print p[int(line)]