Harryxun/stf_run huggingface dataset:
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    min = sum(l[:])
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        if s < min:
            min = s
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < s < p2:
                d.add(s)
    d.add(min)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))

p = max(w)

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    n=2
    p1 = p
    p2 = None
    while(1):
        s = cndP(w,n,p1,p2)
        if not p2 == None:
            if s[0] > p2:
                print(p2)
                break
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            if(p2==None):
                p1 = i
        if (n == len(w)):
            print(p2)
            break
        n+=1

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
N = int(input())
# （１行読み込み→splitしてlist化→各要素に対して-1する）←を逆順にする（[::-1]）をN回繰り返す
A = [[x-1 for x in list(map(int, input().split()))][::-1] for i in range(N)]

def can_match(i, A, next_set):
    if not A[i]: # A[i]が空の場合
        return
    j = A[i][-1] # j = iさんの次の対戦相手

    if A[j][-1] == i: # jさんの次の対戦相手がiさんの場合（＝相思相愛の場合）
        if i < j: # 常に(小, 大)で格納する
            next_set.add((i,j))
        else: # 常に(小, 大)で格納する
            next_set.add((j,i))

# next_setの初期化
next_set = set() # setは集合を表す
for i in range(N):
    can_match(i, A, next_set)

# 試合できるか？何日かかるか？を判別する
day = 0
battle = 0
while next_set:
    day += 1
    current_set, next_set = next_set, set()
    for match in current_set:
        battle += 1
        del A[match[0]][-1]
        can_match(match[0], A, next_set)
        del A[1][-1]
        can_match(match[1], A, next_set)

if battle == N*(N-1)//2:
    print(day)
else:
    print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
# （１行読み込み→splitしてlist化→各要素に対して-1する）←を逆順にする（[::-1]）をN回繰り返す
A = [[x-1 for x in list(map(int, input().split()))][::-1] for i in range(N)]

def can_match(i, A, next_set):
    if not A[i]: # A[i]が空の場合
        return
    j = A[i][-1] # j = iさんの次の対戦相手

    if A[j][-1] == i: # jさんの次の対戦相手がiさんの場合（＝相思相愛の場合）
        if i < j: # 常に(小, 大)で格納する
            next_set.add((i,j))
        else: # 常に(小, 大)で格納する
            next_set.add((j,i))

# next_setの初期化
next_set = set() # setは集合を表す
for i in range(N):
    can_match(i, A, next_set)

# 試合できるか？何日かかるか？を判別する
day = 0
battle = 0
while next_set:
    day += 1
    current_set, next_set = next_set, set()
    for match in current_set:
        battle += 1
        del A[match[0]][-1]
        can_match(match[0], A, next_set)
        del A[match[1]][-1]
        can_match(match[1], A, next_set)

if battle == N*(N-1)//2:
    print(day)
else:
    print(-1)
= [-1]*n
li = []
flag = True

for i in range(m):
    a,b = map(int,input().split())
    if n == 1:
        if a == 1:
            L[0] = b
            break
        else:
            flag = False
    else:
        if (a in li) and L[a-1] != b:
            flag = False
            break
        elif a == 1 and b == 0:
            flag = False
            break
        else:
            L[a-1] = b
            li.append(a)
for i in range(n):
    if L[i] == -1:
        L[i] = 0
if flag:
    L = [str(x) for x in L]
    print("".join(L))
else:
    print(-1)

### FIXED CODE ###

n,m = map(int,input().split())
L = []
for i in range(m):
    L.append(list((map(int,input().split()))))

for i in range(1000):
    p = str(i)
    flag = False
    for j in range(m):
        if len(p) >= L[j][0]:
            if int(p[L[j][0]-1]) != L[j][1]:
                break
    else:
        if len(p) == n:
            flag = True

    if flag:
        print(i)
        exit()
print(-1)
A, B, C, D = map( int, input()split())
L = A + B
R = C + D

if( L < R):
  print('Right')
  
else:
  print('Left')

### FIXED CODE ###

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

if( L < R):
  print('Right')
  
elif(L == R):
  print('Balanced')
  
else:
  print('Left')
N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))

edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

q = queue.Queue()
for t in travels:
    q.put((
        0,
        (t,)
    ))

travels = R_LIST[:]

def dfs(cost,past):
    #print('aaa', past)
    if len(past) == len(travels):
        return cost
    
    ret = INT_MAX
    for t in travels:
        if t in past:
            continue
        
        if len(past) == 0:
            tmp_ret = dfs(0, [t])
            ret = min(ret, tmp_ret)
        else:
            next_cost = cost + shortest[past[-1]][t]
            if ret <= next_cost:
                continue

            next_past = past[:] + [t]
            tmp_ret = dfs(next_cost, next_past)
            ret = min(ret, tmp_ret)
        
    return ret

print(dfs(0, []))
            
      
        
        



### FIXED CODE ###

N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    
    
edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

rest = set(R_LIST[:])

import copy  
def dfs(cost,pre,rest):
    if len(rest) == 0:
        return cost
    
    ret = INT_MAX
    for r in rest:
        if pre == None:
            next_cost = 0
        else:
            next_cost = cost + shortest[pre][r]
        next_rest = copy.copy(rest)
        next_rest.remove(r)
        
        tmp_ret = dfs(next_cost, r, next_rest)
        ret = min(ret, tmp_ret)
        
    return ret
        
    

print(dfs(0, None, rest))
n = int(input())

ans = 0

l = list(range(1,n))
l.insert(0, n)

for i,x in enumerate(l):
    ans += x % (i+1)

print(ans)

### FIXED CODE ###

n = int(input())

print(n * (n-1) // 2)
N = int(input())
A = list(map(int,input().split()))
R = 0.0
for i in range(N):
  R += i**(-1)
print(1/R)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
R = 0.0
for i in range(N):
  R += A[i]**(-1)
print(1/R)
L, R = map(int, input().split())
m = 673
if R // m - (L - 1) // m != 0:
    print(0)
else:
    minnum = 1000
    Lmod = L % m
    Rmod = R % m
    for i in range(Lmod, Rmod+1):
        for j in range(i + 1, Rmod+1):
            #print(i, j, (i * j) % 2019)
            minnum = min(minnum, (i * j) % 2019)
    print(minnum)


### FIXED CODE ###

N, A, B = map(int, input().split())
sume = N * A
print(min(B, sume))
n, k = map(int, input().split())

t = []
d = k
while(True):
  d = d / 2
  t.append(d)
  if d <= 1:
    break
# print(t)

t2 = []
nn = 1+n if n < k else k
for i in range(1, nn):
  for j in range(len(t)):
    if i >= t[j]:
      t2.append(j+1)
      break
# print(t2)

t3 = [0.5]
for i in range(1, len(t2)+2):
  t3.append(t3[i-1]*0.5)
# print(t3)

r = 0
for t in t2:
  r += t3[t-1]
r /= n
if n >= k:
  r += (n-k+1) / n
print(r)

### FIXED CODE ###

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

r = 0
for i in range(1, 1+n):
  t = i
  p = 1.0
  while(True):
    if t >= k:
      r += p
      break
    t *= 2
    p *= 0.5
print(r/n)
N,x=map(int,input().split())
S = map(int,input().split())
pre,ans = 0,0
for i in range(N):
    tmp = pre+S[i]
    if tmp > x:
        ans += tmp-x
        S[i] -= tmp-x
    pre = S[i]
print(ans)

### FIXED CODE ###

N,x=map(int,input().split())
S = [int(i) for i in input().split()]
pre,ans = 0,0
for i in range(N):
    tmp = pre+S[i]
    if tmp > x:
        ans += tmp-x
        S[i] -= tmp-x
    pre = S[i]
print(ans)
from itertools import groupby
from statistics import median
from time import time
from sys import exit
import numpy as np

N = int(input())

line = ([(index, v) for index, v in enumerate(input())])


def types(line): return line[1]
def index(line): return line[0]


gp = groupby(sorted(line, key=types), types)

d = {}

for k, v in gp:
    indexes = np.array([i for i, value in v])
    d[k] = indexes

if 'R' not in d or 'G' not in d or 'B' not in d:
    print(0)
    exit()

delete = 0


for differ in range(1, N):
    for start in range(N):
        if start + differ*2 > N - 1:
            break

        i = line[start]
        j = line[start + differ]
        k = line[start + differ*2]

        if len({i[1], j[1], k[1]}) != 3:
            continue

        upper = max(i[0], j[0], k[0])
        lower = min(i[0], j[0], k[0])
        median_num = median([i[0], j[0], k[0]])
        if upper - median_num == median_num - lower:
            delete += 1

print(d['R'].size * d['G'].size * d['B'].size - delete)


### FIXED CODE ###

from itertools import groupby
from statistics import median
from sys import exit

N = int(input())

line = ([(index, v) for index, v in enumerate(input())])


def types(line): return line[1]
def index(line): return line[0]


gp = groupby(sorted(line, key=types), types)

d = {}

for k, v in gp:
    indexes = set([i for i, value in v])
    d[k] = indexes

if 'R' not in d or 'G' not in d or 'B' not in d:
    print(0)
    exit()

delete = 0


for differ in range(1, N):
    for start in range(N):
        if start + differ*2 > N - 1:
            break

        i = line[start]
        j = line[start + differ]
        k = line[start + differ*2]

        if len({i[1], j[1], k[1]}) != 3:
            continue

        upper = max(i[0], j[0], k[0])
        lower = min(i[0], j[0], k[0])
        median_num = median([i[0], j[0], k[0]])
        if upper - median_num == median_num - lower:
            delete += 1

print(len(d['R']) * len(d['G']) * len(d['B']) - delete)
H = int(input('H: '))
A = int(input('A: '))
 
if H%A == 0:
  x = H//A
  print(x)
else:
  x = (H//A)-1
  print(x)

### FIXED CODE ###

h,a=map(int,input().split())
if h%a==0:
  print(h//a)
else:
  print(h//a+1)
import math
def C():
    import math
    n= int(input())


    counter = 0
    for i in range(1,13):
        if int(26*(pow(26,i-1))/(26-1)) <= n < int(26*(pow(26,i))/(26-1)):
            counter = i
            break
    kekka = n - int(26*(pow(26,counter-1))/(26-1)) + 1
    syo = int(kekka/26)
    amari = kekka%26

    alplist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

    lists = []
    i = counter-1
    while i>= 0 :
        sho = int(kekka / pow(26,i))
        kekka = kekka - pow(26,i)*sho
        i -=1
        if i >= 0:
            lists.append(alplist[sho])
        else:
            lists.append(alplist[sho-1])


    print("".join(lists))


C()


### FIXED CODE ###


def C():
    import math
    n= int(input())

    counter = 0
    for i in range(1,13):
        if int(26*(pow(26,i-1))/(26-1)) <= n < int(26*(pow(26,i))/(26-1)):
            counter = i
            break
    kekka = n - int(26*(pow(26,counter-1))/(26-1))

    alplist=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

    kekkalist = []
    i = counter-1
    while i>= 0 :
        sho = int(kekka / pow(26,i))
        kekka = kekka - pow(26,i)*sho

        i -=1
        if i >= 0:
            kekkalist.append(alplist[sho])
        else:
            kekkalist.append(alplist[sho])


    print("".join(kekkalist))


C()
N = input()
a_list = [int(i) for i in input().split(' ')]
mod = 1000000007
 
sum = 0
for i in a_list:
  sum += i
 
for idx, i in enumerate(a_list[:-1]):
  sum -= a_list[idx]
  sum += i*sum
  
print(sum%mod)

### FIXED CODE ###

D,T,S = [int(i) for i in input().split(' ')]
 
if T*S >= D:
  print('Yes')
else:
  print('No')
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve(xx,a,b):
    if len(xx)==2:return [a,b]
    k=(a^b).bit_length()-1
    aa=[]
    bb=[]
    for x in xx:
        if x>>k&1==a>>k&1:aa.append(x)
        else:bb.append(x)
    mid=aa[0]
    if mid^1<<k==b:mid=aa[1]
    return solve(aa,a,mid)+solve(bb,mid^1<<k,b)

def main():
    popcnt=lambda x:bin(x).count("1")

    n,a,b=MI()
    if (popcnt(a)&1)^(popcnt(b)&1)==0:
        print("NO")
        exit()

    print(*solve(list(range(1<<n)),a,b))

main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    def parity_onebit(x):
        return bin(x).count("1") & 1

    def make_route(s, g, state):
        if state.count(-1) == 1:
            return [s, g]
        sep_dig = bin(s ^ g)[::-1].find("1")
        s_bit = (s >> sep_dig) & 1
        Lstate = state[:]
        Rstate = state[:]
        Lstate[sep_dig] = s_bit
        Rstate[sep_dig] = 1 - s_bit
        for i in range(16):
            ng = 0
            i_copy = i
            for sk in Lstate[::-1]:
                ng <<= 1
                if sk == -1:
                    ng += i_copy & 1
                    i_copy >>= 1
                else:
                    ng += sk
            ns = ng ^ (1 << sep_dig)
            if ng != s and parity_onebit(ng) != parity_onebit(s) and ns != g:
                break
        res = make_route(s, ng, Lstate)
        state[sep_dig] = 1 - s_bit
        res += make_route(ns, g, Rstate)
        return res

    n, s, g = map(int, input().split())
    if parity_onebit(s) == parity_onebit(g):
        print("NO")
        exit()
    ans=make_route(s, g, [-1] * n)
    print("YES")
    print(*ans)
    #print(*[format(a,"b").zfill(n) for a in ans])

main()
import numpy as np
import math
from functools import reduce

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

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

d = np.zeros(N, dtype=int)
for n in range(N):
    d[n] = x[n] - X

gcd = reduce(math.gcd, d)

# print(d)
print(gcd)


### FIXED CODE ###

import numpy as np
import math
from functools import reduce

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

def gcd(a: int, b: int): return gcd(b, a % b) if b else a

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

d = np.zeros(N, dtype=int)
for n in range(N):
    d[n] = x[n] - X

ret = abs(reduce(gcd, d))

# print(d)
print(ret)
import sys

input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    N, M = map(int, input().split())
    A = [0] * M
    for i in range(M):
        A[i] = int(input())

    is_ok = True
    for i in range(M - 1):
        if A[i] + 1 == A[i + 1]:
            is_ok = False
    if not is_ok:
        print(0)
        exit()

    broken = [False] * (N + 1)
    for a in A:
        broken[a] = True

    dp = [0] * (N + 1)
    dp[0] = 1
    dp[1] = 1 if A[0] != 1 else 0

    for i in range(2, N + 1):
        if broken[i]:
            dp[i] = 0
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % P
    
    ans = dp[N]
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

MOD = 10**9 + 7

N, M = [int(i) for i in input().strip().split()]
dirty_step_idxs = [0] * M
for i in range(M):
  dirty_step_idx = int(input())
  dirty_step_idxs[i] = dirty_step_idx

def fibonacci(n):
  # 0, 1, 1, 2, 3, 5, 8, ...
  a, b = 0, 1
  for i in range(n-1):
    a, b = b, a + b
  return a
  
if M == 0:
  res = fibonacci(N + 2)
else:
  res = 1
  now_step_idx = 0
  for i in range(M):
    n_step = dirty_step_idxs[i] - now_step_idx - 1
    if n_step == -1:
      res = 0
      break
    res *= fibonacci(n_step + 2)
    now_step_idx = dirty_step_idxs[i] + 1
  rest_steps = N - now_step_idx
  res *= fibonacci(rest_steps + 2) 
    
print(res % MOD)
import sys

while True:
    w = input()

    if not w.islower():
        continue

    if len(w) >= 100:
        continue

    for n_alpha in "abcdefghijklmnopqrstuvwxyz":
        count_alpha = w.count(n_alpha)
        if count_alpha % 2 == 1:
            print('No')
        else:
            print('Yes')
        break
    break

sys.exit()

### FIXED CODE ###

import string
w = input()
if all([w.count(low_alpha) % 2 == 0 for low_alpha in string.ascii_lowercase ]):
    print('Yes')
else:
    print('No')
# -*- coding: utf-8

x = map(int, raw_input(),split())
a = x[0]
b = x[1]

R = a*b
P = 2*a+2*b
A = str(R)+" "+str(P)

print(A)


### FIXED CODE ###


a = map(int, raw_input().split())

print('%s %d' % (a[0]*a[1], 2*a[0]+2*a[1]))
a,b,c = map(int,input().split())
if a == b:
	print(c)
elif a == c:
	print(b)
elif b == c:
	print(a)
	
a,b,c,d = map(int,input().split())
l = a + b
r = c + d
if l > r:
	print("Left")
elif l < r:
	print("Right")
elif l == r:
	print("Balanced")

### FIXED CODE ###

a,b,c,d = map(int,input().split())
l = a + b
r = c + d
if l > r:
	print("Left")
elif l < r:
	print("Right")
elif l == r:
	print("Balanced")
import math

A, B, N = map(int,input().split())
bst = -pow(10, 10)

for i in range(N+1):
    if((floor((A*i)/B) - A*floor(i/B)) > bst):
        bst = floor((A*i)/B) - A*floor(i/B)

print(bst)

### FIXED CODE ###

A,B,N = map(int, input().split())
p = min(N,B)

if p%B == 0:
    print(int(A*(p-1)//B))
else :
    print(int(A*(p)//B))
n = int(input(),10)
sort_list = list()

for i in range(0,n):
    sort_list.append(int(input(),10))

for i in range(1,n):
    
    for j in range(0,n):
        print(sort_list[j])
        if j is not n - 1:
            print(" ")
        else:
            print("\n")
    
    tmp = sort_list[i]
    j = i - 1
    while j >= 0 and sort_list[i] > v:
        sort_list[j+1] = sort_list[j]
        j = j - 1
    sort_list[j+1] = v




### FIXED CODE ###

import sys

n = input()
sort_list = list()

sort_list = map(int, raw_input().split())

for i in range(0,n):
    
    
    tmp = sort_list[i]
    j = i - 1
    while j >= 0 and sort_list[j] > tmp:
        sort_list[j+1] = sort_list[j]
        j = j - 1

    sort_list[j+1] = tmp


    for k in range(0,n):
        sys.stdout.write(str(sort_list[k]))
        if k is not n - 1:
            sys.stdout.write(" ")
        elif i is not n - 1:
            sys.stdout.write("\n")
            
print("")
c = []
for i in range(3):
  x,y,z = map(int, input().split())
  c.append([x,y,z])

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')

### FIXED CODE ###

c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))
a = c1[0]+c2[1]+c3[2]
b = c1[1]+c2[2]+c3[0]
c = c1[2]+c2[0]+c3[1]
d = c1[0]+c2[2]+c3[1]
e = c1[1]+c2[0]+c3[2]
f = c1[2]+c2[1]+c3[0]
if a==b==c==d==e==f:
  print('Yes')
else:
  print('No')
def get_cost(arr, n):
  if n == 1:
    return abs(arr[1] - arr[0])
  elif n == 0:
    return 0
  else:
    return min(
      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1),
      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2)
    )


N = int(input())
arr = [int(num) for num in input().split()]
print(get_cost(arr, N-1))

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

def get_cost(arr, n, dp):
  if dp[n] != float('inf'):
    return dp[n]
  if n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]
  elif n == 0:
    dp[0] = 0
    return dp[0]
  else:
    dp[n] = min(
      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1, dp),
      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2, dp)
    )
    return dp[n]


N = int(input())
arr = [int(num) for num in input().split()]
dp_arr = [float('inf')]*N
print(get_cost(arr, N-1, dp_arr))
#! /usr/bin/env python
# -*- coding: utf-8 -*-
def main():
    unko = raw_input()
    unko_ans = 0
    for i in range(3):
        if unko[i] == '1':
            unko_ans = unko_ans + 1
    print(unko_ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
def main():
    unko = raw_input()
    unko_ans = 0
    for i in range(3):
        if unko[i] == '1':
            unko_ans = unko_ans + 1
    print(unko_ans)
if __name__ == "__main__":
    main()
N = int(input())
A = int(input())

res = N%500
if A=>res:
	print("Yes")
else:
	print("No")


### FIXED CODE ###

N = int(input())
A = int(input())

res = N%500
if A >= res:
	print("Yes")
else:
	print("No")
a, b, c, d = map(int, input().split())
if (a + b) // 2 == a:
  print('Bad')
elif (b + c) // 2 == b:
  print('Bad')
elif (c + d) // 2 == c:
  print('Bad')
else:
  print('Good')


### FIXED CODE ###

a, b, c, d = map(int, list(input()))
if (a + b) / 2 == a:
  print('Bad')
elif (b + c) / 2 == b:
  print('Bad')
elif (c + d) / 2 == c:
  print('Bad')
else:
  print('Good')
N = int(input())

ans = 10**18

for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        b = N//i
        ans = min(ans, max( len(str(i)),  len(str(b))))
print(ans)

### FIXED CODE ###

A,B=map(int, input().split())
print(A+B) if (A+B) < 24 else print(A+B-24)
from collections import Counter

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

if N == 1:
    print(1)

pos.sort(reverse = True)

cnt = Counter()

for i in range(N):
    a,b = pos[i]
    for j in range(i+1,N):
        c,d = pos[j]
        t = (a - c, b - d)
        cnt[t] += 1

ans = N - cnt.most_common()[0][1]
print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
pos = [list(map(int,input().split())) for _ in range(N)]

if N == 1:
    print(1)
    exit()

pos.sort(reverse = True)

cnt = Counter()

for i in range(N):
    a,b = pos[i]
    for j in range(i+1,N):
        c,d = pos[j]
        t = (a - c, b - d)
        cnt[t] += 1

ans = N - cnt.most_common()[0][1]
print(ans)