peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
from itertools import combinations_with_replacement as comb

n,m,q = map(int, input().split(' '))
lis = [list(map(int, input().split())) for _ in range(q)]
tes = comb(range(1,m+1),n)
res = 0
for i in tes:
    te = 0
    for a,b,c,d in lis:
        if c == i[b-1] - i[a-1]:
            te += d
    res = max(te,res)
print(res)
# Judge status: Wrong Answer
N = int(input())
A = []
for _ in range(N):
    A.append(int(input())-1)

ans = -1
push = 1
for i in range(N+1):
    light = A[push]
    push = light
    if light == 2:
        ans = i+1
        break
print(ans)
# Judge status: Wrong Answer
a,b=map(int,input().split())

def prime_factorization(n):
  if n==1:
    return []
  else:
    i=2
    ans=[]
    for j in range(2,int(n**0.5+1)):
      if n%j==0:
        n//=j
        ans.append(j)
        while n%j==0:
          n//=j
    return ans

A=prime_factorization(a)
B=prime_factorization(b)

ans=0
for _a in A:
  if B.count(_a):
    ans+=1
print(ans+1)
# Judge status: Accepted
n, m = map(int, input().split())

if m < 2:
    print(0)
    exit()

ans = 0
tmp = min(n, m // 2)
ans += tmp
n -= tmp
m -= tmp * 2

ans += m // 4

print(ans)
# Judge status: Wrong Answer
a, b, c, d = map(int, input().split())
table = [0] * 101

for i in range(a, b+1):
    table[i] += 1

for j in range(c, d+1):
    table[j] += 1

print(table.count(2)-1)
# Judge status: Accepted
abc=sorted(list(map(int,input().split())),reverse=True)
print(sum(abc)+abc[0]*9)
# Judge status: Wrong Answer
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = sum(A)
num = 0
for i in range(M):
    B = max(A)
    num += B - B // 2
print(sum)
# Judge status: Accepted
def pay_check(N):
  for i in range(N//4 + 1):
    for j in range(N//7 + 1):
      if (N == 4*i + 7*j):
        print('Yes')
        return
  print('No')
pay_check(int(input()))
# Judge status: Accepted
import itertools


X = int(input())

u = -1000
A = []
while u < 1000:
    A.append(u)
    u += 1
AA = list((itertools.product(A, repeat=2)))
for a,b in AA:
    if a**5-b**5 == X:
        print(a,b)
        break
# Judge status: Accepted
x = int(input())
if (x >= 30):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
q,h,s,d=map(int,input().split())
n=int(input())
if 2*q<h:
  h=2*q
if 2*h<s:
  s=2*h
if 2*s<d:
  d=2*s
print(n//2*d+n%2*s)
# Judge status: Accepted

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

answer = 0
K= (A+B)/2

if A!= B and (A+B)%2 == 0 and (A-K)*(B-K)<0:
	print(int(K))
else:
  	print("IMPOSSIBLE")
# Judge status: Accepted
c=[list(map(int,input().split())) for _ in range(3)]
if c[0][0]-c[1][0]==c[0][1]-c[1][1]==c[0][2]-c[1][2] and c[0][0]-c[2][0]==c[0][1]-c[2][1]==c[0][2]-c[2][2]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
A,B = map(int,input().split())
if A>8 or B>8:
    print(":(")
else:
    print("Yay!")
# Judge status: Accepted
H,W=map(int,input().split())
if H==1 or W==1:
    print(1)
    exit()
if (H*W)%2==0:
    print(int(H*W/2))
else:
    ans=((H//2+1)*(W//2+1))+((H-(H//2+1))*(W//2))
    print(ans)
# Judge status: Accepted
def main():
    s, t = input(), input()

    if s in t + t:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n, m = map(int, input().split())
if n <= 2*m:
    ans = n + (m - 2*n)//4
else:
    ans = m // 2
print(ans)
# Judge status: Accepted
s = [input() for i in range(1)] 
s0 = int(s[0])
t = [input() for i in range(s0)]
ac_count=0
wa_count=0
tle_count=0
re_count=0

for j in range(s0):
    s1 = t[j]
    if s1 == "AC":
        ac_count+=1
    if s1 == "WA":
        wa_count+=1
    if s1 == "TLE":
        tle_count+=1
    if s1 == "RE":
        re_count+=1
print("AC x ",ac_count)
print("WA x ",wa_count)
print("TLE x ",tle_count)
print("RE x ",re_count)
# Judge status: Accepted
n,y = map(int, input().split())

def Otoshidama(n):
    for i in range(0, y//10000 + 1):
        for j in range(0, (y - 10000*i)//5000 + 1):
            h = y - 10000*i - 5000*j
            if h%1000 == 0 and h >= 0 and i + j + h//1000 == n:
                return str(i) + " " + str(j) + " " + str(h//1000)
    return "-1 -1 -1"

print(Otoshidama(n))
# Judge status: Accepted
n = int(input())
s = [0]*n
for i in range(n):
    s[i] = int(input())
s.sort()
ans = sum(s)
if all(i%10==0 for i in s):
    print(0)
    exit(0)
else:
    for i in s:
        if ans%10==0 and i%10!=0:
            ans -= i
print(ans)
# Judge status: Accepted
import itertools
x = int(input())

for i in range(500):
	for j in range(500):
		if i**5 + j**5 == x:
			print (i,-j)
			exit()
		if i**5 - j**5 == x:
			print (i,j)
			exit()
# Judge status: Accepted
n, a, b, c, d = map(int, input().split())
s = input()
if "##" in s[a:max(c,d)]:
	print ("No")
	exit()

if c > d:
	if "..." not in s[max(0,b-2):min(d+1,n)]:
		print ("No")
		exit()
print ("Yes")
# Judge status: Wrong Answer
from collections import defaultdict
s = input()
t = input()
n = len(s)

d = defaultdict(str)

for i in range(n):
    if d[t[i]] == "":
        d[t[i]] = s[i]
    elif d[t[i]] != s[i]:
        print("No")
        exit()
print("Yes")
# Judge status: Accepted
n , m = map(int, input().split())
food = [0] * m
data = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    for j in range(1, data[i][0] + 1):
        food[data[i][j] - 1] += 1

ans = 0
for i in range(m):
    if food[i] == n:
        ans += 1

print(ans)
# Judge status: Accepted
n, k = (int(i) for i in input().split())
s = input()

print(s[:k-1] + s[k-1].lower() + s[k:])
# Judge status: Accepted

s = input()
ans = 0
for i in range(len(s)):
    count = 0
    for j in range(i,len(s)):
        if s[j] in "ACGT":
            count += 1
        else:
            break
    if count >= ans:
        ans = count
print(ans)
# Judge status: Wrong Answer
n,k = map(int,input().split())

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

hl = sorted(hl)
if n <= k:
    print(0)
elif k == 0:
    print(sum(hl))
else:
    print(sum(hl[n-k:]))
# Judge status: Accepted
N = int(input())
A = []
B = []

for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

ctr = 0

for i in reversed(range(N)):
    if (A[i] + ctr) % B[i] == 0: continue
    ctr += B[i] - ((A[i] + ctr) % B[i])

print(ctr)
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(1,len(p)-1):
  if p[i]>p[i-1] and p[i]<=p[i+1]:
    cnt+=1
    
  elif p[i]<=p[i-1] and p[i]>p[i+1]:
    cnt+=1
    
print(cnt)
# Judge status: Accepted
a, b = map(str, input().split())

ab = a+b
ab = int(ab)

for i in range(320):
    if ab == i**2:
        print("Yes")
        exit()

print("No")
# Judge status: Accepted
s = str(input())
a = 200000
z = 0
for i in range(len(s)):
    if s[i] == "A":
        a = min(a, i)
    elif s[i] == "Z":
        z = max(z, i)

print(z - a + 1)
# Judge status: Accepted
from fractions import gcd

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

L = [0] * (N + 1)
R = [0] * (N + 1)

for i in range(N):
  L[i+1] = gcd(L[i], A[i])
  R[N-i-1] = gcd(R[N-i], A[N-1-i])

ans = 0
for i in range(N):
  ans = max(ans, gcd(L[i], R[i+1]))

print(ans)
# Judge status: Wrong Answer
h, m, h2, m2, k = map(int, input().split())
print(12*h2+m2-(12*h+m+k))
# Judge status: Accepted
#import sys
#input = sys.stdin.readline
Q = 10**9+7
def main():
    N = int( input())
    ans = pow(10, N, Q) - pow(9, N, Q)*2 + pow(8, N, Q)
    print( ans%Q)
if __name__ == '__main__':
    main()
# Judge status: Accepted
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a += [a[i]+A[i]]
for i in range(m):
    b += [b[i]+B[i]]

ans, i = 0, m
for j in range(n+1):
    if a[j] > k:
        break
    while b[i] > k-a[j]:
        i -= 1
    ans = max(ans, i+j)
print(ans)
# Judge status: Accepted
A, B = map(int, input().split())
if A%3==0 or B%3==0 or (A+B)%3==0:
  print('Possible')
else:
  print('Impossible')
# Judge status: Wrong Answer
a, b, c = map(int,input().split())

if b - (a * c) > 0:
    print(c)

elif b - (a * c) < 0:
    print(b // a)

elif a > b :
    print(0)
# Judge status: Accepted
from itertools import groupby as gb
n=int(input())
s=sorted(input())
ans=1
mod=10**9+7
for i,x in gb(s):
  ans=ans*(len(list(x))+1)%mod
print(ans-1)
# Judge status: Wrong Answer
n = int(input())
d = list(map(int, input().split()))

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

if l[0] != 1:
    print(0)
    exit()

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)
# Judge status: Accepted
N=int(input())
S=[list(map(str,input().split())) for _ in range(N)]
for row in S:
    row[1]=int(row[1])
SS=sorted(S)
ins=0
ans=list()
tmp=0
for i in SS:
    if i[0]==tmp:
        ans.insert(ins,i)
    else:
        ins=len(ans)
        ans.append(i)
        tmp=i[0]
for j in ans:
    print(S.index(j)+1)
# Judge status: Wrong Answer
Q, H, S, D = map(int, input().split())
N = int(input())
x = N % 2
y = N // 2
arr = [4*Q*x, 2*H*x, S*x]
arr1 = [8*Q*y, 4**H*y, 2*S*y, D*y]
#if N % 2 == 0:
#  arr.append(int(0.5*D*N))
#else:
#  arr.append(int(0.5*D*(N-1)+ min(S, 2*H, 4*Q)))
   
print(min(arr) + min(arr1))
# Judge status: Wrong Answer
N = int(input())

x = 800 * N
y = (N % 15) * 200

print(x - y)
# Judge status: Accepted
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

while m > 0:
    a_max = heapq.heappop(a)
    if a_max == 0:
        break
    heapq.heappush(a, (-1)*(-a_max // 2))
    m -= 1
print(sum(a)*(-1))
# Judge status: Wrong Answer
n=int(input())
m=round(n/float(1.08))
if int(m*float(1.08))==n:
  print(m)
else:
  print(':(')
# Judge status: Wrong Answer
s = int(input())
seen = {s}
i = 1
while s>1:
    if s%2==0:
        s //= 2
    else:
        s = 3*s+1
    i += 1
    if s in seen:
        print(i)
        break
    seen.add(s)
else:
    print(i+1)
# Judge status: Accepted
a = int(input())
count = 0
for i in range(a + 1):
  if len(str(i)) % 2 == 1:
    count += 1
print(count - 1)
# Judge status: Wrong Answer
s = 6
w = 9
S = int(s)
W = int(w)
if S<=W:
  print("unsafe")
else:
  print("safe")
# Judge status: Wrong Answer
s = input()
count = {"N":0, "W":0, "S":0, "E":0}
for i in s:
    count[i] += 1

if count["N"] == count["S"] and count["W"] == count["E"]:
    print("Yes")

else:
    print("No")
# Judge status: Accepted
X,N = map(int,input().split())
if N>0:
    p_set = set(map(int,input().split()))
else:
    p_set = set()
min_dist_xp = 1000
for p in reversed(range(0,102)):
    if p not in p_set:
        dist_xp = abs(X-p)
        if dist_xp<=min_dist_xp:
            min_dist_xp = dist_xp
            ans = p
print(ans)
# Judge status: Accepted
from operator import itemgetter

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

BC.sort(key = itemgetter(1),reverse=True)

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
A += change
A.sort(reverse=True)
answer = sum(A[:N])
print(answer)
# Judge status: Wrong Answer
n = int(input())
count = 0
for i in range(n):
  d1, d2 = map(int, input().split())
  if count > 2:
    break
  elif d1 == d2:
    count += 1
  else:
    count == 0
if count > 2:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N,M=map(int,input().split())
    X=sorted(list(map(int,input().split())))



    l=sorted([X[i+1]-X[i] for i in range(M-1)], reverse=True)

    print(X[-1]-X[0]-sum(l[:N-1]))




resolve()
# Judge status: Accepted
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
bests = [1] * n
for k in range(m):
    a, b = list(map(int, input().split()))
    if h[a -1] > h[b - 1]:
        bests[b - 1] = 0
    elif h[a -1] < h[b - 1]:
        bests[a - 1] = 0
    else:
        bests[a - 1] = 0
        bests[b - 1] = 0
print(sum(bests))
# Judge status: Wrong Answer
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.pop(0)
for i in range(n-1):
  x=list(map(int,input().split()))
  x.pop(0)
  for j in a:
    if j not in x:
      a.remove(j)
print(len(a))
# Judge status: Wrong Answer
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n,d=map(int,stdin.readline().split())
print(math.ceil(n/(d+d)))
# Judge status: Accepted
n = int(input())
S = input()
#右にある白，左にある黒
cnt = [0]*(n+1)
white = S.count(".")
black = 0
cnt[0] = white
for i in range(n):
    if S[i] == ".":
        white -= 1
    else:
        black += 1
    cnt[i+1] = black + white
print(min(cnt))
# Judge status: Wrong Answer
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = []
for i in range(N):
    C.append(B[i]-A[i])

c_1 = sum([i for i in C if i > 0])
c_2 = sum([i for i in C if i < 0])

if c_1 >= c_2*-2:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n = int(input())
s = input()
l = s.rfind(')')

cntl, cntr = 0, 0
s2 = 0
flag = 0
for i in range(l + 1):
    if s[i] == '(':
        cntl += 1
    else:
        cntr += 1

if cntl <= cntr:
    s1 = '(' * (max((cntr - cntl), 0))
    print(s1, end='')
else:
    s2 = ')' * (max((cntl - cntr), 0))
    flag = 1

print(s, end='')
r1 = ')' * (max((n - l - 1), 0))
print(r1, end='')

if flag:
    print(s2)
# Judge status: Wrong Answer
s=input()
a=753
ans=999
for i in range(len(s)-3):
  n=int(s[i:i+2])
  tmp=abs(a-n)
  if tmp<ans:
    ans=tmp
print(ans)
# Judge status: Accepted
l = sorted(list(map(int,input().split())))
ans = [5,5,7]
print("YES" if l == ans else "NO")
# Judge status: Accepted
#coding:utf-8

n = int(input())
mtrx = [[0 for _ in range(10)] for _ in range(10)]

for i in range(1, n + 1):
    num = str(i)
    s = int(num[0]) - 1
    e = int(num[-1]) - 1

    mtrx[s][e] += 1
    
sumv = 0
for i in range(10):
    for j in range(10):
        sumv += mtrx[i][j] * mtrx[j][i]
print(sumv)
# Judge status: Accepted
S=input()
if(len(S)%2==0):
  for i in range(len(S)//2):
    if(S[2*i]!="h" or S[2*i+1]!="i"):
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")
# Judge status: Accepted
X, Y = map(int, input().split())
a = X / Y
if a == int(a):
    ans = -1
else:
    ans = X
print(ans)
# Judge status: Accepted
x, y = map(int, input().split())
print(x if x%y else -1)
# Judge status: Accepted
n=int(input())
a = [0]*(20000)
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            if i**2+j**2+k**2 >= n:
                break
            a[i**2+j**2+k**2+i*j+j*k+i*k]+=1
for i in range(1,n+1):
    print(a[i])
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))

min = None
for y in range(-100, 101):
    sum = 0
    for x in a:
        sum += abs(x - y) ** 2
    if min is None or min > sum:
        min = sum

print(min)
# Judge status: Wrong Answer
import itertools

N, L = map(str, input().split())
P = list(map(str, input().split()))

U = itertools.combinations_with_replacement(list(set([str(i) for i in range(10)])-set(P)),10-len(P))
K = str()
for i in U:
    K = ''.join(i)
    if K>=N:
        print(K)
        break
# Judge status: Wrong Answer
N,*V=map(int,open(0).read().split())
A=sorted(V)
for n in range(N-1):
    print(A)
    A=sorted([(A[0]+A[1])/2,]+A[2:])
print(A[0])
# Judge status: Wrong Answer
inputs = map(int, input().split(" "))

is_denied = False
for i in inputs:
  if i % 2 ==0:
    if i % 3 != 0 and i % 5 != 0:
      is_denied = True
      
if is_denied:
  print("DENIED")
else:
  print("APPROVED")
# Judge status: Wrong Answer
a, b = map(int,input().split())
num = [a%2019]
num.append(b%2019)

for i in range(a + 1,b):
  if(max(num) > (i % 2019)):
    num.append(i%2019)
    num.remove(max(num))
  elif(i % 2019 == 0):
    print(0)
    break

print(num[0] * num[1])
# Judge status: Wrong Answer
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    if N%2 == 0:
        print(abs(sum(A[:N//2]) - sum(A[N//2:])))
    else:
        if A[0] <= A[-1]:
            print(abs(sum(A[:(N+1)//2]) - sum(A[(N+1)//2:])))
        if A[0] > A[-1]:
            print(abs(sum(A[:(N-1)//2]) - sum(A[(N-1)//2:])))
resolve()
# Judge status: Accepted
n, l = map(int, input().split())
s = sorted([input() for i in range(n)])

print("".join(s))
# Judge status: Wrong Answer
K = int(input())
A, B = map(int, input().split())
for i in range(A,B+1):
  if i%K == 0:
    print('OK')
  else:
    print('NG')
# Judge status: Accepted
X = input()
ans = len(X)
c = 0

for x in X:
    if x == 'S':
        c += 1
    else:
        if c > 0:
            ans -= 2
            c -= 1
print(ans)
# Judge status: Wrong Answer
a, b, c, d = map(int, input().split())
if abs(b - a) <= d and abs(c - b) <= d:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
a,b = map(int,input().split())
print(a,b)
# Judge status: Accepted
N = int(input())

mod = 10**9+7
ans = pow(10, N, mod) - ((pow(9, N, mod) * 2) - pow(8, N, mod))
ans %= mod
print(ans)
# Judge status: Accepted
N = int(input())

ans = N - 1
for i in range(1, int(N**0.5) + 10):
    if N % i == 0:
        j = N // i
        ans = min(ans, i + j - 2)

print(ans)
# Judge status: Accepted
L,R,d =map(int,input().split())
if L%d == 0:
  print(R//d - L//d + 1)
else:
  print(R//d - L//d)
# Judge status: Accepted
N, K = map(int, input().split())
A = N % K
B = abs((N % K)-K)
print(min(A, B))
# Judge status: Accepted
print("NYOE S"[input() in "753"::2])
# Judge status: Accepted
a, b = map(int, input().split())
print(a if b >= a else a-1)
# Judge status: Wrong Answer
N=int(input())
s=[int(input()) for i in range(N)]
num=sum(s)

if num%10!=0:
    print(num)
else:
    for i in range(N):
        s=sorted(s)
        if s[i]%10==0:
            continue
        else:
            print(num-s[i])
            break
    print(0)
# Judge status: Accepted
n = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
	for j in range(1,105):
		for k in range(1,105):	
			v = i*i+j*j+k*k+i*j+j*k+k*i;
			if v<10050:
				ans[v]+=1
for i in range(n):
	print(ans[i+1])
# Judge status: Wrong Answer
import numpy as np

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

ze = np.ones((W + 1, H + 1))

for i in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        ze[:x, :] = 0
    elif a == 2:
        ze[x + 1:, :] = 0
    elif a == 3:
        ze[:, :y] = 0
    elif a == 4:
        ze[:, y + 1:] = 0

print(np.sum(ze))
# Judge status: Accepted
N = int(input())
a_s = list(map(int, input().split()))

a_s.sort(reverse=True)
Alice = a_s[0::2]
Bob = a_s[1::2]
print(sum(Alice) - sum(Bob))
# Judge status: Accepted
h,w = (int(x) for x in input().split())


num  = 1
if h != 1 and w != 1:
    num = ((w // 2) + (w % 2))*( (h // 2) + ( h% 2) ) + ((w // 2) + (w % 2)-(w%2))*( (h // 2) + (h%2) -(h%2)) 
print(num)
# Judge status: Accepted
N=int(input())
A=[int(i) for i in input().split()]
plus=0
minus=0
ans=1
for i in range(N-1):
    plus += A[i]<A[i+1]
    minus += A[i]>A[i+1]
    if plus and minus:
        ans += 1
        plus = 0
        minus = 0
print(ans)
# Judge status: Accepted
x,y=map(int,input().split())
res = 0
if 0<=x<=y:
    res = y-x
elif 0<y<x:
    res = x-y+2
elif y==0 and x>0:
    res = x+1
elif y==0 and x<0:
    res = abs(x)
elif x==0 and y>0:
    res = y
elif x==0 and y<0:
    res = abs(y)+1
elif x<0<y:
    res = abs(x+y)+1
elif y<0<x:
    res = abs(x+y)+1
elif x<=y<=0:
    res = y-x
elif y<x<=0:
    res = x-y+2
print(res)
# Judge status: Wrong Answer
N = int(input())

C = input()

if N % 2 == 0:
  mid = N//2
else:
  mid = N//2+1

Wcount = C.count("W", 0, mid)
print(Wcount)
# Judge status: Wrong Answer
N = int(input())

for i in range(1, N):
  if i ** 2 > N:
    print((i - 1) ** 2)
    exit()
# Judge status: Accepted
n = int(input())
h = list(map(int,input().split()))

dp = [float("inf")]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(1,n-1):
    dp[i+1] = min(dp[i]+abs(h[i+1]-h[i]),dp[i-1]+abs(h[i+1]-h[i-1]))
print(dp[n-1])
# Judge status: Wrong Answer
#ABC055

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

print((m-2*n)//4+n)
# Judge status: Accepted
x,y=map(int,input().split())
ans=1
while 2*x<=y:
    ans+=1
    x*=2
print(ans)
# Judge status: Accepted
K, N = list(map(int,input().split()))
A = list(map(int,input().split()))
d = [A[i+1]-A[i] for i in range(N-1)]
de = K - A[N-1] + A[0]
d.append(de)
D = sorted(d)
dis = 0
for i in range(N-1):
  dis += D[i]
print(dis)
# Judge status: Accepted
# coding: utf-8
# Your code here!

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

if a >= b : 
    num_large = a
    num_small = str(b)
else : 
    num_large = b
    num_small = str(a)

print(num_small * num_large)
# Judge status: Accepted
import itertools
import math
X=int(input())
arr=[]
arr2=[]
arr3=[]
for i in range(0,640):
    arr.append(i**5)
    arr.append(-i**5)
l=itertools.combinations_with_replacement(arr,2)
for i in l:
    arr2.append(i[0]-i[1])
    arr3.append([i[0],i[1]])
ans=arr3[arr2.index(X)]
print(int(math.pow(abs(ans[0]), 1/5))*(1 if ans[0]>=0 else -1), int(math.pow(abs(ans[1]), 1/5))*(1 if ans[1]>=0 else -1))
# Judge status: Accepted
n=int(input())
s = [[0,0,0]]
for i in range(n):
    s.append(list(input().split()))

for i in range(1,len(s)):
    dt=int(s[i][0])-int(s[i-1][0])
    dx=int(s[i][1])-int(s[i-1][1])
    dy=int(s[i][2])-int(s[i-1][2])

    if dt<abs(dx)+abs(dy):
        print("No")
        exit()

    if (dx+dy)%2!=dt%2:
        print("No")
        exit()

print("Yes")
# Judge status: Accepted
N,M,X = map(int,input().split())
arr = []
for i in range(N):
    arr.append(list(map(int,input().split())))
cost = 10**9 + 7
for k in range(2**N):
    c = 0
    t = [0]*M
    for i in range(N):
        if (k >> i)%2 :
            c += arr[i][0]
            for j in range(M):
                t[j] += arr[i][j+1]
    if sum(x>=X for x in t) == M:
        cost = min(cost,c)
print(cost if cost < 10**9 + 7 else -1)
# Judge status: Accepted
a,b,k=map(int,input().split())
c=min(a,b)+1
ct=0
while ct <k:
  c=c-1
  if a%c==0 and b%c==0:
    ct+=1

  
print(c)
# Judge status: Accepted
n=int(input())-1
m=n;i=0;lst=[]
while m>=0:
    i+=1;k=m;m-=26**i
    k
while k>0:
    lst.append(k%26)
    k//=26
for j in range(i-len(lst)):
    lst.append(0)
print(''.join([chr(b+97) for b in lst][::-1]))
# Judge status: Accepted
import math

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


D =A[0]**2+A[1]**2-2*A[0]*A[1]*math.cos(math.radians(30*A[2]-5.5*A[3]))

print(math.sqrt(D))
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

A = sorted(A)[::-1]
a = []
ng = 9999999
for i in range(N-1):
    if i != ng:
        if A[i] == A[i+1]:
            a.append(A[i])
            ng = i+1
            if len(a) == 2:
                break

ans = 0
if len(a) == 2:
    ans = a[0] * a[1]
else:
    ans = 0

print(ans)
# Judge status: Accepted
s = input()
k = int(input())
ans = '1'
for i in range(k):
    if s[i] != '1':
        ans = s[i]
        break

print(ans)
# Judge status: Accepted
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()] 

a.sort(reverse = True)
tmp = []
i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        tmp.append(a[i])
        i += 2
    else:
        i += 1
if len(tmp) >= 2:
    print(tmp[0] * tmp[1])
else:
    print(0)
# Judge status: Wrong Answer
n, k = map(int, input().strip().split(" "))
h = list(map(int, input().split(" ")))

dp = [10**5] * n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], abs(h[i]-h[i+j])+dp[i])
        else:
            break
print(dp[n-1])
# Judge status: Accepted
n = int(input())
ans = 0
for i in range(1, n+1):
    if i%3==0 and i%5==0: continue
    elif i%3==0: continue
    elif i%5==0: continue
    ans+=i
print(ans)