Harryxun/stf_run huggingface dataset:
def resolve():
    (N, M) = list(map(int, input().split(" ")))
    As = [int(input()) for i in range(M)]
    mems = [False] * (N+1)

    def rec(target):
        if target in As:
            return 0
        
        if target == 1:
            return 1
        
        if target == 2:
            return 2 if 1 not in As else 1

        if not mems[target]:
            one = rec(target-1)
            two = rec(target-2)
            mems[target] = one + two
        
        return mems[target]
    
    print(rec(N)%1000000007)

if '__main__' == __name__:
    resolve()

### FIXED CODE ###

def resolve():
    (N, M) = list(map(int, input().split(" ")))
    As = [int(input()) for i in range(M)]
    As.sort()

    cnts = [False] * (N+1)
    ptr = 0
    for i in range(N+1):
        c = 0
        if ptr < len(As) and i == As[ptr]:
            c = 0
            ptr = ptr + 1
        elif i == 0:
            c = 1
        elif i == 1:
            c = 1
        elif i == 2:
            c = 2 if 1 not in As else 1
        else:
            c = (cnts[i-2] + cnts[i-1])%1000000007
        cnts[i] = c

    print(cnts[N])

if '__main__' == __name__:
    resolve()
import sys
sys.setrecursionlimit(100001)
 
# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)
 
memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
[ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
print(mmm)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100001)

def gcd(b, s):
    return s if b % s == 0 else gcd(s, b % s)

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
if len(sumnl) == 1:
    print(sumnl[0])
else:
    print(max([sumnl[-2]] + [gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)] + [sumrl[1]]))
# coding:utf-8
n = int(input())
h = list(map(int, input().split()))
counter = 1

#一番西がもっとも高い山ならその時点で終了
if max(h) == h[0]:
    print(counter)
else:
    for i in range(n):
        print(h[0:i+1])
        h_max = max(h[0:i+1])
        if (h[i] >= h_max) and (h[i] > h[0]):
            #print(h[i])
            counter += 1
    print(counter)


### FIXED CODE ###

#coding:utf-8
a, b = map(int, input().split())

aa = 2*a - 1
ab = a + b
bb = 2*b - 1

print(max(aa, ab, bb))
import sys

w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
    lines = sys.stdin.readline().rstrip()
    if not lines:
		break	
    words = lines.split( " " )
    for i in range( len( words ) ):
    	if w == words[i].lower():    		
			cnt += 1			
print( cnt )

### FIXED CODE ###

import sys

w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
	lines = sys.stdin.readline().rstrip()
	if not lines:
		break
	for s in lines.split( " " ):
		if w == s.lower():
			cnt = cnt + 1	

print( cnt )
from math import factorial
N, K = map(int, input().split())
for i in range(K):
    a = factorial(N-K+1) / factorial(i+1) / factorial(N-K+1 - (i+1))
    b = factorial(K-1) / factorial(i) / factorial(K-1 - i)

    print((a*b) % (10**9+7))

### FIXED CODE ###

from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under % (10 ** 9 + 7)

N, K = map(int, input().split())
for i in range(K):
    if N-K+1 >= i + 1 and K-1 >= i:
        # a = factorial(N-K+1) / factorial(i+1) / factorial(N-K+1 - (i+1))
        a = cmb(N-K+1, i + 1)
        # b = factorial(K-1) / factorial(i) / factorial(K-1 - i)
        b = cmb(K-1, i)
        print((a*b) % (10**9+7))
    else:
        print(0)
K,N = map(int,input().split())
now = -10**9
for i in range(N):
  if i == N-1:
    if K-A[N-1]+A[i]>now:
      now = K-A[N-1]+A[i]
  else:
    if A[i+1]-A[i] > now:
      now = A[i+1]-A[i]
print(K-now)

### FIXED CODE ###

K,N = map(int,input().split())
A = list(map(int,input().split()))
now = K-A[N-1]+A[0]
for i in range(N-1):
  if A[i+1]-A[i] > now:
    now = A[i+1]-A[i]
print(K-now)
A, B = map(int,input().split())

# ABが互いにそなら答えは１

ans = 0
import math

if math.gcd(A,B) == 1:
  ans = 1
else:
  # 公約数を求める
  cdlist =[]

  for i in range(1, min(A,B) + 1):
    if A % i == 0 and B % i == 0:
      cdlist.append(i)

  # print(cdlist)

  for i,cd1 in enumerate(cdlist):
    for cd2 in cdlist[i+1:]:
      # print(cd1,cd2)
      if math.gcd(cd1,cd2) == 1:
        ans += 1

print(ans)



### FIXED CODE ###

# 素因数分解
def prime_factorize(n):
    a = []
    # ２で割れなくなるまで割る
    while n % 2 == 0:
        a.append(2)
        n //= 2
    # 奇数で割り続けていく
    # 本当は素数で割り続けていくのが良い
    f = 3
    # 二乗して超えたら終了
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    # 最後の一つ
    if n != 1:
        a.append(n)
    return a
    
A, B = map(int, input().split())
A_list = set(prime_factorize(A))
B_list = set(prime_factorize(B))

print(len(A_list & B_list) + 1)
x,y,z,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ls = [0]*(len(A)*len(B))
for i in range(len(A)):
    for j in range(len(B)):
        ls[(i*len(B))+j] = A[i] + B[j]
ls.sort(reverse = True)
ls = ls[:k]
check_ls = []
for i in range(len(C)):
    for j in range(len(ls)):
        check_ls.append(C[i] + ls[j])
check_ls.sort(reverse = True)
for i in range(k):
    print(check_ls[i])

### FIXED CODE ###

ls = [int(input()) for i in range(5)]
k = int(input())
boo = False
for i in range(5):
    for j in range(5):
        if abs(ls[i] - ls[j]) > k:boo = True
if boo:print(':(')
else:print('Yay!')
a=input()
a.replace(9,8)
a.replace(1,9)
a.replace(8,1)
print(a)

### FIXED CODE ###

a=input()
print(a.replace("1","8").replace("9","1").replace("8","9"))
l=[]

def detain(n,a,b,c,l):
    
    n,a,b,c=map(int,input().split())
    for i in range(n):
        li=int(input())
        l.append(li)
    return


detain(n,a,b,c,l)
d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)        
        

### FIXED CODE ###

l=[]
n,a,b,c=map(int,input().split())
for i in range(n):
    li=int(input())
    l.append(li)

d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10+sum(d)
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)
a, b, c = int(input())

if (a + b + c) == 19:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a, b, c = (int(x) for x in input().split())

if (a + b + c) == 17:
  print("YES")
else:
  print("NO")
def powerDX(n, r, mod):
  if r == 0: return 1
  if r%2 == 0:
    return powerDX(n*n % mod, r//2, mod) % mod
  if r%2 == 1:
    return n * powerDX(n, r-1, mod) % mod
 
def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * powerDX(denom, mod-2, mod) % mod
 
ans = power(2, n, mod) - 1
ans -=  combination(n, a, mod)
ans -=  combination(n, b, mod)
ans += 3*mod
ans %= mod
print(ans)

### FIXED CODE ###

n, a, b = map(int, input().split())
mod = 10**9 + 7

def powerDX(n, r, mod):
  if r == 0: return 1
  if r%2 == 0:
    return powerDX(n*n % mod, r//2, mod) % mod
  if r%2 == 1:
    return n * powerDX(n, r-1, mod) % mod

def combination(n, r, mod=10**9+7):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * powerDX(denom, mod-2, mod) % mod

ans = powerDX(2, n, mod) - 1
ans -=  combination(n, a, mod)
ans -=  combination(n, b, mod)
ans += 3*mod
ans %= mod
print(ans)
A = int(input())
B = int(input())
C = int(input())
X = int(input())
 
counter = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if(500*a + 100*b + 50*c == X):
                counter += 1
print(counter)

### FIXED CODE ###

X = int(input())
A = int(input())
B = int(input())

print((X-A) % B)
N = input()
S = input()

n = str.count('ABC')
print(n)

### FIXED CODE ###

N = input()
S = input()

n = S.count('ABC')
print(n)
import math
pi=format(:.5,math.pi)
r=input()
print("{} {}".format(2*r*pi,r*r*pi))


### FIXED CODE ###

import math
pi=math.pi
r=float(input())
print("{:.5f} {:.5f}".format(r*r*pi,2*r*pi))
n = int(input())
pos=[]
for i in range(n):
  x,y,h = map(int, input().split())
  pos.append([x,y,h])

def solve():
  for cx in range(101):
    for cy in range(101):
      res=[]
      edge=[]
      for i in range(n):
        x=pos[i][0]
        y=pos[i][1]
        h=pos[i][2]
        H = h+abs(x-cx)+abs(y-cy)
        if h == 0:
          if x == cx+H or x == cx-H or y == cy+H or y == cy-H:
            res.append(H)
        else:
          res.append(H)
      if len(set(res)) ==1:
        return [cx,cy,res[0]]
cx,cy,h=solve()
print(cx,cy,h)

### FIXED CODE ###

n = int(input())
pos=[]
for i in range(n):
  x,y,h = map(int, input().split())
  pos.append([x,y,h])

pos = sorted(pos, key=lambda x: x[2])
tx,ty,th = pos[-1]
def solve():
  for cx in range(101):
    for cy in range(101):
      H = th+abs(tx-cx)+abs(ty-cy)
      for x,y,h in pos:
        if h != max(H-abs(x-cx)-abs(y-cy), 0):
          break
      else:
        return(cx,cy,H)

cx,cy,H=solve()
print(cx,cy,H)
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, Y, A, B, C = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)
    q = sorted(list(map(int, input().split())), reverse=True)
    r = sorted(list(map(int, input().split())), reverse=True)

    ans = 0
    i = 0 # pのindex
    j = 0 # qのindex
    k = 0 # rのindex
    for l in range(X):
        if p[i] >= r[k] or k == C:
            ans += p[i]
            i += 1
        else:
            ans += r[k]
            k += 1

    for l in range(Y):
        if q[j] >= r[k] or k == C:
            ans += q[j]
            j += 1
        else:
            ans += r[k]
            k += 1
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, Y, A, B, C = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)
    q = sorted(list(map(int, input().split())), reverse=True)
    r = sorted(list(map(int, input().split())), reverse=True)

    now = sum(p[:X]) + sum(q[:Y])
    ans = now
    i = X-1
    j = Y-1

    for k in range(min(C,X+Y)):
        if i < 0:
            now += r[k]-q[j]
            j -= 1
        elif j < 0:
            now += r[k]-p[i]
            i -= 1
        elif p[i] < q[j]:
            now += r[k]-p[i]
            i -= 1
        else:
            now += r[k]-q[j]
            j -= 1
        ans = max(ans,now)
    print(ans)

if __name__ == "__main__":
    main()
a = input()
b = input()
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a,b = map(int, input().split())
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
def gcd_list(l):
    if len(l)>=2:
        m = l[0]
        n = l[1]
        g = gcd(m,n)
        l_new = [g] + l[2:]
        return (gcd_list(l_new))
    else:
        return l[0]
    
N = int(input())
A_list = [int(i) for i in input().split()]
ans = gcd_list(A_list)
print(ans)

### FIXED CODE ###

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
def gcd_list(l):
    g = l[0]
    for i in l[1:]:
        g = gcd(g,i)


    return g
    
N = int(input())
A_list = [int(i) for i in input().split()]
ans = gcd_list(A_list)
print(ans)
inputStr = raw_input().split(' ')
a = int(inputStr[0])
b = int(inputStr[1])
c = int(inputStr[2])
if a < b & b < c:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

inputStr = input().split(' ')
a = int(inputStr[0])
b = int(inputStr[1])
c = int(inputStr[2])
if a < b & b < c:
  print("Yes")
else:
  print("No")
#!/usr/bin/env python3
import sys


def solve(K: int, S: str):
    if (len(S) <= K):
        print(S)
    else:
        print(S[0:K], "...", sep='')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    mod = N % 10
    if mod in [2, 4, 5, 7, 9]:
        print("hon")
    elif mod in [0, 1, 6, 8]:
        print("pon")
    else:
        print("bon")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()
class Node:
    def __init__(self):
        self.num = None
        self.parent = None
        self.children = list()
        self.added = 0
        self.count = None
    def __repr__(self):
        return f'Node({self.num})'
    def calc_count(self):
        if self.num==1:
            self.count = self.added
            return
        if self.parent.count is None:
            self.parent.calc_count()
        self.count = self.parent.count + self.added

(n,q),*abpx = [list(map(int, s.split())) for s in open(0)]

ab,px = abpx[:n-1],abpx[n-1:]

from collections import defaultdict,deque
d = defaultdict(Node)

for a,b in ab:
    d[a].num = a
    d[b].num = b
    d[b].parent = d[a]
    d[a].children.append(d[b])

for p,x in px:
    d[p].added += x

dq = deque([d[1]])

while dq:
    cur = dq.popleft()
    if cur.children:
        dq.extend(cur.children)
    cur.calc_count()

print(*list(d[i].count for i in range(1,n+1)))

### FIXED CODE ###

(n,q),*abpx = [list(map(int, s.split())) for s in open(0)]
ab,px = abpx[:n-1],abpx[n-1:]

from collections import defaultdict, deque
add = defaultdict(int)

for p,x in px:
    add[p] += x

links = defaultdict(set)

for a,b in ab:
    links[a].add(b)
    links[b].add(a)

passed = set()

dq = deque()
dq.append((0,1))

ans = {}

while dq:
    to_add, cur = dq.popleft()
    tmp = to_add + add[cur]
    ans[cur] = tmp
    for nx in links[cur]:
        links[nx].remove(cur)
        dq.append((tmp, nx))

print(*(ans[i] for i in range(1,n+1)))
import fractions
N = int(input())
print(2 * N / gcd(2,N))

### FIXED CODE ###

import fractions
N = int(input())

print(2*N if N%2==1 else N)
(a,b)=map(int,input().split())
if a*b%2==0:
  print(偶数)
else
  print(奇数)

### FIXED CODE ###

(a,b)=map(int,input().split())
if a*b%2==0:
  print("Even")
else:
  print("Odd")
N=int(input())

H=list(map(int , input().split()))
cnt = 0
for i in range(len(H)):
  if max(H[0:i]==H[i]):
    cnt +=1
    
print(cnt)

### FIXED CODE ###

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

cnt = 0
for i in range(len(H)):
    if (max(H[0:i+1]) == H[i]):
        cnt += 1

print(cnt)
n=int(input())
w=list(map(int,input().split()))
ans=100000000;
s1=0
s2=0
 
for i in range(n):
    s1 += sum(w[:i+1])
    s2 += sum(w[i+1:])
            
    if abs(s1-s2) < ans:
        ans = abs(s1-s2)
    
print(ans)

### FIXED CODE ###

p, q, r =(int(i) for i in input().split())
ans1=p+q
ans2=q+r
ans3=p+r

if ans1<=ans2 and ans1<=ans3:
    print(ans1)
elif ans2<= ans1 and ans2 <= ans3:
    print(ans2)
else:
    print(ans3)
x=input()
print(x*x*x)

### FIXED CODE ###

x = int(input())
print(x**3)
def check(s,cnt):
    if ('ABC' in s):
        s=s.replace('ABC','BCA',1)
        cnt+=1
        check(s,cnt)
    else :
        print(cnt)

s=input()
cnt=0
(check(s,cnt))


### FIXED CODE ###

s=input()
n=0
c=0
i=0
while i<len(s):
  if s[i]=="A":
    c+=1
  elif s[i:i+2]=="BC":
    n+=c
    i+=1
  else:
    c=0
  i+=1
print(n)
N = int(input())
print(N ＊＊ 3)


### FIXED CODE ###

N = int(input())
print(N ** 3)
x = int(raw_input())
x = "{0.hours}:{0.minutes}:{0.seconds}".format(relativedelta(seconds=x))
print(x)


### FIXED CODE ###

x = int(raw_input())
m = x/60
h = m/60
m = m%60
s = x%60
print(str(h)+":"+str(m)+":"+str(s))
n = int(input())
a = list(map(int, input()))
 
money = 1000
for i in range(n-1):
  if a[i] < a[i+1]:
    money += (a[i+1]-a[i]) * (money//a[i])
print(money)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
money = 1000
for i in range(n-1):
  if a[i] < a[i+1]:
    money += (a[i+1]-a[i]) * (money//a[i])
print(money)
while True:
    a,b = map(int, input().split()
    if a ==0 and b == 0: break
    if a > b:
        c = a
        a = b
        b = c
    print("{} {}".format(a,b))



### FIXED CODE ###

while True:
    a,b = map(int, input().split())
    if (a,b) == (0,0) :
        break
    elif a > b:
        c = a
        a = b
        b = c
    print("{} {}".format(a,b))
s=input()
w=(Sunny,Cloudy,Rainy,Sunny)
n=w.index(s)
print(w[n+1])

### FIXED CODE ###

s=input()
w=('Sunny','Cloudy','Rainy','Sunny')
n=w.index(s)
print(w[n+1])
already = [False] * 200000
n = int(input())
a = list(map(int, input().split()))
for x in a:
    if already[x]:
        print("NO")
        break
    already[x] = True
else:
    print("YES")


### FIXED CODE ###

already = {}
n = int(input())
a = list(map(int, input().split()))
for x in a:
    if already.get(x):
        print("NO")
        break
    already[x] = True
else:
    print("YES")
ip = input()

ans = ip / 3
print(int(ans))

### FIXED CODE ###

ip = int(input())

ans = ip / 3
print(int(ans))
a = input("a:")
b = input("b:")
c = input("c:")

print(int(int(a)*int(b)/2))


### FIXED CODE ###

AB,BC,CA = map(int,input().split())
print(int(AB*BC/2))
lists=[]
for i n range(5):
  nums=int(input())
  lists.append(nums)
dis=int(input())
lists=sorted(lists)
if lists[-1]-lists[0]<=dis:
  print("Yay!")
else:
  print(":(")

### FIXED CODE ###

lists=[]
for i in range(5):
  nums=int(input())
  lists.append(nums)
dis=int(input())
lists=sorted(lists)
if lists[-1]-lists[0]<=dis:
  print("Yay!")
else:
  print(":(")
import sys

# 再帰上限の変更(デフォルトは1000)
sys.setrecursionlimit(10 ** 100)

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

# XがわかればYがわかるので、あるAiがわかったときどこまでわかるか?をグラフにしてDFSで探索

graph = [[]for i in range(N + 1)]

seen = [0] * (N + 1)

for X, Y, Z in XYZ:
    graph[X].append(Y)
    graph[Y].append(X)


def dfs(a):
    if seen[a] == 1:
        return
    else:
        seen[a] = 1
        for i in graph[a]:
            dfs(i)


ans = 0

for i in range(1, N + 1):
    if seen[i] == 1:
        continue
    else:
        dfs(i)
        ans += 1

print(ans)


### FIXED CODE ###

import sys

# 再帰上限の変更(デフォルトは1000)
# 大きくしすぎるとREするらしい
sys.setrecursionlimit(10 ** 9)

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

# XがわかればYがわかるので、あるAiがわかったときどこまでわかるか?をグラフにしてDFSで探索

graph = [[]for i in range(N + 1)]

seen = [0] * (N + 1)

for X, Y, Z in XYZ:
    graph[X].append(Y)
    graph[Y].append(X)


def dfs(a):
    if seen[a] == 1:
        return
    else:
        seen[a] = 1
        for i in graph[a]:
            dfs(i)


ans = 0

for i in range(1, N + 1):
    if seen[i] == 1:
        continue
    else:
        dfs(i)
        ans += 1

print(ans)
S = input()
T = input()
ev = [0] * (len(S) - len(T))
for i in range(len(S) - len(T)):
  commit = 0
  for j in range(len(T)):
    if S[i + j] == T[j]:
      commit += 1
  ev[i] = commit

ev.sort(reverse=True)
print(len(T) - ev[0])

### FIXED CODE ###

S = input()
T = input()
ev = []
for i in range(len(S) - len(T) + 1):
  commit = 0
  for j in range(len(T)):
    if S[i + j] == T[j]:
      commit += 1
  ev.append(commit)

ev.sort(reverse=True)
print(len(T) - ev[0])
n=input()
if s[0]==7: 
	print("Yes")
if s[1]==7:
    print("Yes")
if s[2]==7:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n=input()
if (n[0]=='7' or n[1]=='7' or n[2]=='7'):
    print("Yes")
else:
    print("No")
import math
x = int(input())
y = int(math.pow(x, 1/5))
x - (y)**5 = z
print(x, y)

### FIXED CODE ###

x = int(input())
for a in range(200, -200, -1):
  for b in range(-200, 200, 1):
    if x==a**5-b**5:
      print(a, b)
      exit()
a,b,c = map(int.input().split())
if a=b=c:
  print(1)
elif (a=b or b=c or a=c):
  print(2)
else:
  print(3)


### FIXED CODE ###

a,b,c = map(int,input().split())
if a==b and b==c:
  print(1)
elif a==b or b==c or a==c:
  print(2)
else:
  print(3)
def sub():
    N = int(input())
    hs = [int(e) for e in input().split()]

    def optimal_value(a_index):
        if a_index >= N - 1:
            return 0

        buf = [optimal_value(a_index + 1) + abs(hs[a_index + 1] - hs[a_index])]
        if a_index < N - 2:
            buf.append(optimal_value(a_index + 2) + abs(hs[a_index + 2] - hs[a_index]))

        return min(buf)

    print(optimal_value(0))


sub()


### FIXED CODE ###

def sub():
    N = int(input())
    hs = [int(e) for e in input().split()]
    optimal_values = [None for _ in range(N)]
    optimal_values[0] = 0
    for i in range(1, N):
        if i > 1:
            a = optimal_values[i - 1] + abs(hs[i] - hs[i - 1])
            b = optimal_values[i - 2] + abs(hs[i] - hs[i - 2])
            optimal_values[i] = min(a, b)
        else:
            optimal_values[i] = optimal_values[i - 1] + abs(hs[i] - hs[i - 1])
    print(optimal_values[-1])


sub()