Harryxun/stf_run huggingface dataset:
N = int(input())
A =  []
l1 = input().split()
for i in l1:
    A.append(int(i))
B = []
l2 = input().split()
for i in l2:
    B.append(int(i))
if sum(A) < sum(B):
    print(-1)
else:
    z = 0
    ar1 = []
    ar2 = []
    for i in range(N):
        if A[i] < B[i] :
            ar1.append(B[i] - A[i])
        if A[i] > B[i]:
            ar2.append(A[i] - B[i])
    ar1.sort(reverse = True)
    ar2.sort(reverse = True)
    b = 0
    for a in ar1:
        while a > ar2[b]:
            ar2[b] = 0
            a -= ar2[b]
            b += 1
        ar2[b] -= a
        ar2.sort(reverse = True)
        if a == ar1[-1] and ar2[b] != 0:
            z = 1
    ans = 0
    for i in ar2:
        if i == 0:
            z +=1
    ans = len(ar1) + z
    print(ans)

### FIXED CODE ###

l1  = input().split(" ")
ar = []
for i in l1:
  ar.append(int(i))
d = {1:0,9:0,7:0,4:0}
for i in ar:
  for j in d:
    if  i == j:
      d[j] = 1
con = True
for  i in d:
  if d[i] == 0:
    con = False
    print("NO")
    break
if con:
  print("YES")
import sys
import itertools

class Treasure:
    def __init__(self, value, weight):
        self.value = value
        self.weight = weight


def solv(treasures, w_limit):
    comb = t_combinations(treasures)
    ts = filter(lambda x: t_sum_weight(x) <= w_limit, comb)
    max_value = max(map(lambda x: t_sum_value(x), ts))
    ts2 = filter(lambda x: t_sum_value(x) == max_value, ts)
    if len(ts2) == 1:
        return (ts2[0].value, ts2[0].weight)
    else:
        rt = rightest(ts2)
        return (t_sum_value(rt), t_sum_weight(rt))


def t_combinations(t):
    l = len(t)
    r = []
    for x in range(1, l+1):
        for y in itertools.combinations(t, x):
            r.append(y)
    return r


def t_sum_weight(t):
    return sum(map(lambda x: x.weight, t))


def t_sum_value(t):
    return sum(map(lambda x: x.value, t))


def rightest(ts):
    return reduce(lambda a, b: take_right(a, b), ts)


def take_right(a, b):
    if t_sum_weight(a) <= t_sum_weight(b):
        return a
    else:
        return b


case = 0

while True:
    weight_limit = int(sys.stdin.readline())
    case += 1
    if weight_limit == 0:
        exit()
    n = int(sys.stdin.readline())
    treasures = []
    for i in range(n):
        v, w = map(int, sys.stdin.readline().split(','))
        treasures.append(Treasure(v, w))
    value, weight = solv(treasures, weight_limit)
    print 'Case ' + str(case) + ':'
    print value
    print weight

### FIXED CODE ###


import sys
import itertools


class Treasure:
    def __init__(self, value, weight):
        self.value = value
        self.weight = weight



def solv(treasures, w_limit):
    dp = []
    dp.append(0)
    for n in range(w_limit):
        dp.append(-1)
    for i in treasures:
        for j in range(w_limit - i.weight, -1, -1):
            if dp[j] >= 0:
                dp[j + i.weight] = max(dp[j + i.weight], dp[j] + i.value)
    p = 0
    q = 0
    for i in range(w_limit + 1):
        if dp[i] > p:
            p = dp[i]
            q = i
    return (p, q)






case = 0

while True:
    weight_limit = int(sys.stdin.readline())
    case += 1
    if weight_limit == 0:
        exit()
    n = int(sys.stdin.readline())
    treasures = []
    for i in range(n):
        v, w = map(int, sys.stdin.readline().split(','))
        treasures.append(Treasure(v, w))
    value, weight = solv(treasures, weight_limit)
    print 'Case ' + str(case) + ':'
    print value
    print weight
O=list(input())
E=list(input())
F=[]
j=0
k=0
for i in range(0,len(O)+len(E)):
    F.append('0')
while j<(len(O)+len(E)):
    if j%2==0:
        F[j]=E[j//2]
    else:
        F[j] = O[j//2]
    j=j+1
F= ''.join([str(elem) for elem in F])
print(F)

### FIXED CODE ###

a = input()
b = input()

if(len(a) > len(b)):
    for i in range(len(b)):
        print(a[i],b[i],sep="",end="")
    print(a[i+1:])
else:
    for i in range(len(a)):
        print(a[i],b[i],sep="",end="")
    print(b[i+1:])
N=int(imput())
for i in range(3):
    if (N%10)==7:
        break
    N=N//10
if N!=0:
    print("yes")
else:
    print("No")


### FIXED CODE ###

N=int(input())
for i in range(3):
    if (N%10)==7:
        break
    N=N//10
if N!=0:
    print("Yes")
else:
    print("No")
N = int.input()
if N % 1000 == 0:
  print(0)
else:
  print(1000-(N%1000))



### FIXED CODE ###

N = int(input())
if N % 1000 == 0:
  print(0)
else:
  print(1000-(N%1000))
import math
A,B,C,D=map(int,input().split())

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//math.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)


### FIXED CODE ###

import fractions

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

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//fractions.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)
x = [int(input()) for i in range(3)]
print('Hello World' if x[0]==1 else x[1]+x[2])

### FIXED CODE ###

n = int(input())
if n == 1:
    print('Hello World')
else:
    a = int(input())
    b = int(input())
    print(a+b)
MOD = 10**9 + 7
INF = 10**20
I = lambda:list(map(int,input().split()))
from collections import defaultdict as dd
from math import gcd

s = input()
n = len(s)
ans = 0
for i in range(n//2):
    ans += (s[i] != s[n-i])
print(ans)

### FIXED CODE ###


MOD = 10**9 + 7
INF = 10**20
I = lambda:list(map(int,input().split()))
from collections import defaultdict as dd

s = input()
n = len(s)
ans = 0
for i in range(n//2):
    ans += (s[i] != s[n-i-1])
print(ans)
N, K = map(int,input().split())
S = list(input())

mxl = []
Sl = []
c = 0
if S[0] == "0":
  Sl.append(0)
for i in range(N-1):
  c += 1
  if S[i] != S[i+1]:
    Sl.append(c)
    c = 0
if S[N-1] == "0":
  c += 1
  Sl.append(c)
  Sl.append(0)
else:
  c += 1
  Sl.append(c)

Kl = K*2+1

if len(Sl) ==1:
  mxl.append(Sl[0])

for i in range(0,len(Sl)+1-Kl,2):
  mxl.append(sum(Sl[i:Kl+i]))

print(max(mxl))


### FIXED CODE ###

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

mxl = []
Sl = []
c = 0
if S[0] == "0":
  Sl.append(0)
for i in range(N-1):
  c += 1
  if S[i] != S[i+1]:
    Sl.append(c)
    c = 0
if S[N-1] == "0":
  c += 1
  Sl.append(c)
  Sl.append(0)
else:
  c += 1
  Sl.append(c)

Kl = K*2+1

Ru = [0 for i in range(len(Sl)+1)]

if len(Sl) ==1:
  mxl.append(Sl[0])
else:
  for i in range(1,len(Sl)+1):
    Ru[i] = Ru[i-1]+Sl[i-1] 
  mxl.append(Ru[min(Kl,len(Ru)-1)])
  
for i in range(2,min(len(Sl)+1-Kl,len(Ru)-1),2):
  mxl.append(Ru[Kl+i]-Ru[i])

print(max(mxl))
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
a, b = tuple(li())
div, mod = divmod(b, a)
if mod == 0:
    return a + b
else:
    return b - a


### FIXED CODE ###

import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
a, b = tuple(li())
div, mod = divmod(b, a)
if mod == 0:
    print(a + b)
else:
    print(b - a)
N = int(input())
like_rabbits_list = list(map(int, input().split()))

sum_of_pairs = 0
for i,rabbit in enumerate(like_rabbits_list):
    if like_rabbits_list[rabbit - 1] == (i+1):
        sum_of_pairs += 1

print (int(sum_of_pairs / 2))

### FIXED CODE ###

code_festival = input()

code = code_festival[:4]
festival = code_festival[4:]

code_festival = code + " " + festival
print (code_festival)
n,m = map(int,input().split())
l = [ i for i in input().split() if i>m]
print(len(l))

### FIXED CODE ###

n,k = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
print(len([i for i in l if i>=k]))
s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))

### FIXED CODE ###

import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
import collections
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    s = collections.deque(list(input()))
    q = int(input())
    count = 0
    for i in range(q):
        tfc = list(input().split())
        if tfc[0]=='1':
            count = abs(count - 1)
        else:
            t,f,c = tfc
            if count:
                if f=='1':
                    s.append(c)
                else:
                    s.appendleft(c)
            else:
                if f=='1':
                    s.appendleft(c)
                else:
                    s.append(c)
    if count:
        t = []
        for i in range(len(s)):
            t.append(s.pop())
        print(''.join(t))
    else:
        print(''.join(s))
    return

if __name__=='__main__':
    main()
T = input()
for i in range(len(T)):
    if T[i]=='?':
        if T[i-1]=='P':
            T=T.replace('?','D',1)
        elif T[i+1]=='D':
            T=T.replace('?','P',1)
        elif T[i+1]=='?':
            T=T.replace('??','PD',1)
        else:
            T.replace('?','D',1)
print(T)

### FIXED CODE ###

T=input()
T=T.replace('?','D')
print(T)
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p = sorted(p)
q = sorted(q)
r = sorted(r)
P = A - X
Q = B - Y
R = C - 1
found = True
for i in range(C+1):
    if R < 0:
        break
    if P < A:
        if (r[C-i-1] >= p[P]):
            if (q[Q] >= p[P]):
                P += 1
                R -= 1
            elif Q < B:
                if r[C-i-1] > q[Q]:
                    Q += 1
                    R -= 1
                else:
                    break
            else:
                break
        elif Q < B:
            if r[C-i-1] > q[Q]:
                Q += 1
                R -= 1
            else:
                break
        else:
    elif Q < B:
        if r[C-i-1] > q[Q]:
                Q += 1
                R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))

### FIXED CODE ###

X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p = sorted(p)
q = sorted(q)
r = sorted(r)
P = A - X
Q = B - Y
R = C - 1
found = True
for i in range(C+1):
    if R < 0:
        break
    if P < A:
        if (r[C-i-1] >= p[P]):
            if Q < B:
                if (q[Q] >= p[P]):
                    P += 1
                    R -= 1
                elif r[C-i-1] > q[Q]:
                    Q += 1
                    R -= 1
                else:
                    break
            else:
                P += 1
                R -= 1
        elif Q < B:
            if r[C-i-1] > q[Q]:
                Q += 1
                R -= 1
            else:
                break
        else:
            break
    elif Q < B:
        if r[C-i-1] > q[Q]:
            Q += 1
            R -= 1
        else:
            break    
    else:
        break
print(sum(p[P:])+sum(q[Q:])+sum(r[R+1:]))
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(float, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
R, G, B, N = MAP()
ans = 0
 
for r in range(N//R + 1):
	for g in range((N-r*R)//G + 1):
		if (N - R*r - G*g) // B == 0:
			ans += 1
		
print(ans)

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

R, G, B, N = MAP()
ans = 0
for i in range(N//R+1):
	r = i
	for j in range((N-R*r)//G + 1):
		g = j
		b = (N - R*r - G*g) / B
		if b == b//1 and 0 <= b:
			ans += 1

print(ans)
from collections import deque

s = input()

ns = ""

for s_i in s:
    if s_i != "x":
        ns += s_i

if ns != ns[::-1]:
    print(-1)
    exit()

if len(ns) % 2 == 1:
    cnt = -1
    for i,s_i in enumerate(s):
        if s_i != "x":
            cnt += 1
        if cnt == len(ns)//2:
            note = i
            break
    left = deque(s[:note][::-1] + "@")
    right = deque(s[note+1:] + "@")
else:
    cnt = -1
    f = 1
    for i,s_i in enumerate(s):
        if s_i != "x":
            cnt += 1
        if cnt == len(ns)//2 - 1 and f:
            l = i
            f = 0
        if cnt == len(ns)//2:
            r = i
            break
    left = deque(s[:l][::-1] + "@")
    right = deque(s[r+1:] + "@")

ans = 0

while left or right:
    if left[0] == right[0]:
        left.popleft()
        right.popleft()
    elif left[0] == "x":
        left.popleft()
        ans += 1
    elif right[0] == "x":
        right.popleft()
        ans += 1

print(ans)

### FIXED CODE ###

from collections import deque

s = input()

ns = ""

for s_i in s:
    if s_i != "x":
        ns += s_i

if ns != ns[::-1]:
    print(-1)
    exit()

if ns == "":
    print(0)
    exit()

if len(ns) % 2 == 1:
    cnt = -1
    for i,s_i in enumerate(s):
        if s_i != "x":
            cnt += 1
        if cnt == len(ns)//2:
            note = i
            break
    left = deque(s[:note][::-1] + "@")
    right = deque(s[note+1:] + "@")
else:
    cnt = -1
    f = 1
    for i,s_i in enumerate(s):
        if s_i != "x":
            cnt += 1
        if cnt == len(ns)//2 - 1 and f:
            l = i
            f = 0
        if cnt == len(ns)//2:
            r = i
            break
    left = deque(s[:l][::-1] + "@")
    right = deque(s[r+1:] + "@")

ans = 0

while left or right:
    if left[0] == right[0]:
        left.popleft()
        right.popleft()
    elif left[0] == "x":
        left.popleft()
        ans += 1
    elif right[0] == "x":
        right.popleft()
        ans += 1

print(ans)
n = int(input())
x = input().split()
x_int = [int(i) for i in x]
y = list(range(n))

for i in range(n):
     y[-i-1] = x_int[i]
for i in y:
    print('{} 'format(i),end = '')
print()

### FIXED CODE ###

n = int(input())
x = input().split()
x_int = [int(i) for i in x]
y = list(range(n))

for i in range(n):
     y[-i-1] = x_int[i]
y_str = [str(i) for i in y]
print(' '.join(y_str))
a,b,c=map(int,input().split(' '))
if sum(a.b.c) >=22:
    print('bust')
else:
    print('win')

### FIXED CODE ###

a=list(map(int,input().split(' ')))
if sum(a) >=22:
    print('bust')
else:
    print('win')
%%time
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(a, b, c)
print(ans)

### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

comb_count = {1:1, 2:3, 3:6}
k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            ans += gcd(a, b, c) * comb_count[len(set([a, b, c]))]
print(ans)
n = int(input())
lst = [input() for _ in range(n)]

counter_lst = []
counter_num = [0] * n
for i in range(n):
    a = Counter(lst[i])
    if a in counter_lst:
        m = counter_lst.index(a)
        counter_num[m] += 1
        counter_lst.append(0)
    else:
        counter_lst.append(a)
        counter_num[i] = 1
    
res = 0
for i in counter_num:
    if i > 0:
        res += i * (i-1) // 2
print(res)

### FIXED CODE ###

n = int(input())
lst = [input() for _ in range(n)]

dic = dict()
res = 0
for i in range(n):
    sorted_string = "".join(sorted(lst[i]))
    if sorted_string in dic:
        dic[sorted_string] += 1
        res += dic[sorted_string]
    else:
        dic[sorted_string] = 0
    
print(res)
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim());
  const B = input[1].trim().split(' ').map(Number);
  
  let cnt = N-1;
  let ret = 0;
  let tmp = 0;
  for(let i=0; i<cnt; i++){
    if(i===0){
      ret += B[i];
      tmp = B[i]
      continue;
    } 

    if(tmp < B[i]){
      ret += B[i];
      ret += tmp - B[i];
    } else {
      ret += B[i];
    }
    tmp = B[i];
  }
  ret += tmp;
  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

### FIXED CODE ###

import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    B = il()
    ret = B[len(B) - 1] + B[0]
    for n in range(N - 2):
        ret += min(B[n+1], B[n])
    print(ret)


if __name__ == '__main__':
    main()
H = int(input())

def Test(m):
    if m == 1:
        return 1
    else:
        return 2 * Test(m/2) + 1

ans = Test(H)

print(ans)

### FIXED CODE ###

H = int(input())

def f(x):
    if x == 1:
        return 1
    else:
        return 2 * f(int(x/2)) + 1

ans = f(H)

print(ans)
A = []
A = list(map(int, input().split()))
s,m,l = A.sort()
count = 0
difs = l-s
difm = l-m
count += difs//2 + difm//2
if difs%2 == 0 and difm%2 == 0:
  print(count)
elif difs%2 == 0 and difm%2 == 1:
  count += 2
  print(count)
else:
  count += 1
  print(count)
  


### FIXED CODE ###

A = [int(i) for i in input().split()]
A.sort()
s,m,l = A
count = 0
ls = l-s
lm = l-m
count += ls//2
count += lm//2
if ls%2 == 0 and lm%2 == 0:
  print(count)
  exit()
elif ls%2 == 1 and lm%2 == 1:
  count += 1
  print(count)
else:
  count += 2
  print(count)
a=int(input().split(" "))
a1,a2,a3=int(a[0]),(a[1]),int(a[2])
ans="No"
if a1!=a2 and (a1==a3 or a2==a3):
  ans="Yes"
if a1!=a3 and (a1==a2 or a2==a3):
  ans="Yes"
if a2!=a3 and (a1==a2 or a1==a3):
  ans="Yes"

### FIXED CODE ###

a=input().split(" ")
a1,a2,a3=int(a[0]),int(a[1]),int(a[2])
ans="No"
if a1!=a2 and (a1==a3 or a2==a3):
  ans="Yes"
if a1!=a3 and (a1==a2 or a2==a3):
  ans="Yes"
if a2!=a3 and (a1==a2 or a1==a3):
  ans="Yes"
  
print(ans)
def gcd(a, b):
    if b == 1:
        return 1
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

def lcm(A, n):
    if n == 2:
        return A[0]*A[1] // gcd(A[0], A[1])
    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
    a = lcm(A, n-1)
    return a* A[n-1] // gcd(a, A[n-1])

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
#a.sort(reverse = True)
ans = lcm(a, n)
print(str(ans))

### FIXED CODE ###

def gcd(a, b):
    if b == 1:
        return 1
    # a > b　を仮定
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

#def lcm(A, n):
#    if n == 2:
#        return A[0]*A[1] // gcd(A[0], A[1])
#    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
#    a = lcm(A, n-1)
#    return a* A[n-1] // gcd(a, A[n-1])

n = int(input())
#a = []
T1 = int(input())
for i in range(n-1):
    T2 = int(input())
    T1 = T1*T2 // gcd(T1, T2)
    #a.append(int(input()))
#a.sort(reverse = True)
#ans = lcm(a, n)
print(str(T1))
N = int(input())
h = list(map(int,input().split()))

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

print(f(N))


### FIXED CODE ###

def memoize(f):
    cache={}
    def helper(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]
    return helper

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

import sys
sys.setrecursionlimit(1000000)

@memoize
def f(n):
    if n==1:
        return 0
    elif n==2:
        return abs(h[1]-h[0])
    elif n==3:
        return abs(h[2]-h[0])
    else:
        return min(f(n-1)+abs(h[n-1]-h[n-2]),f(n-2)+abs(h[n-1]-h[n-3]))

print(f(N))
kuku= [1, 2, 3, 4, 5, 6, 7, 8, 9]
c = 0

for a in kuku:
    for b in kuku:
        if a*b == N:
            c+=1
if c>=1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N = int(input())
kuku= [1, 2, 3, 4, 5, 6, 7, 8, 9]
c = 0

for a in kuku:
    for b in kuku:
        if a*b == N:
            c+=1
if c>=1:
    print('Yes')
else:
    print('No')
s = input()
ans_set = []

for i in range(len(s)):
    x = abs(int(s[i:i+3])-753)
    ans_set[i] = x
ans = min(ans_set)
print(ans)

### FIXED CODE ###

s = input()
ans_set = [0] * len(s)

for i in range(len(s)):
    x = abs(int(s[i:i+3])-753)
    ans_set[i] = x
ans = min(ans_set)
print(ans)
n,k = map(int,input().split())

A = list(map(int,input().split()))
t = 0
c = 0
ans = [0] * n
L = []
for _ in range(k):
    if ans[t] == 1:
        t += k%c
        t %= n
        t = L[t]
        break
    else:
        ans[t] = 1
        L.append(t)
        t = A[t]-1
        c += 1
print(t+1)

### FIXED CODE ###

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

A = list(map(int,input().split()))
t = 0
c = 0
ans = [0] * n
L = []
s = 0
for _ in range(k):
    if ans[t] == 1:
        n = len(L) - L.index(t)
        temp = (k-c)%n
        t = L[L.index(t):][temp]
        break
    else:
        ans[t] = 1
        L.append(t)
        t = A[t]-1
        c += 1
print(t+1)
while True:
    H, W = [int(i) for i in input ().split()]
    if H == W == 0:
        break

    for h in range(h):
        for w in range(w):
            print('#', end='')

        print()
    
    print()

### FIXED CODE ###

while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0:
        break

    for h in range(H):
        for w in range(W):
            print('#', end='')

        print()

    print()
a,b=input().split()
print("=" if a==b elif a>b ">" else "<")

### FIXED CODE ###

a,b=input().split()
print("=" if a==b else "<" if a<b else ">")
A=int(input())
B=int(input())
if(A==1 and B==2):
  answer==3
elif(A==2 and B==3):
  answer==1
elif(A==3 and B==1):
  answer==2
print(answer)


### FIXED CODE ###

A=int(input())
B=int(input())
if(A==1 and B==2):
  answer=3
elif(A==1 and B==3):
  answer=2
elif(A==2 and B==3):
  answer=1
elif(A==2 and B==1):
  answer=3
elif(A==3 and B==1):
  answer=2
elif(A==3 and B==2):
  answer=1
print(answer)