Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

input = sys.stdin.readline
def main():
    n, c = map(int, input().split())
    stk = [list(map(int, input().split())) for i in range(n)]
    stk = sorted(stk, key=lambda x: x[0])

    ans = 1
    l = []
    heapify(l)
    heappush(l, [stk[0][1], stk[0][2]])
    for i in range(1, n):
        ll = []
        heapify(ll)
        size = len(l)
        for j in range(size):
            v = heappop(l)
            if stk[i][2] == v[1]:
                if stk[i][0] < v[0]:
                    heappush(ll, v)
            else:
                if stk[i][0] - 0.5 < v[0]:
                    heappush(ll, v)
        heappush(ll, stk[i][1:])
        l = ll
        ans = max(ans, len(l))
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

input = sys.stdin.readline
def main():
    n, c = map(int, input().split())
    stk = [tuple(map(int, input().split())) for i in range(n)]
    stk = sorted(stk, key=lambda x: x[0])

    ans = 1
    l = []
    # heapify(l)
    # heappush(l, (stk[0][1], stk[0][2]))
    l = [(stk[0][1], stk[0][2])]
    for i in range(1, n):
        ll = []
        #heapify(ll)
        for j in range(len(l)):
            # v = heappop(l)
            v = l[j]
            if stk[i][2] == v[1]:
                if stk[i][0] < v[0]:
                    # heappush(ll, v)
                    ll.append(v)
            else:
                if stk[i][0] - 0.5 < v[0]:
                    # heappush(ll, v)
                    ll.append(v)
        # heappush(ll, stk[i][1:])
        ll.append(stk[i][1:])
        l = ll
        ans = max(ans, len(l))
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import Counter
s = input()
s = s[::-1]

sum_list = [0]*(len(s)+1)
for i in range(1, len(s) + 1):
    sum_list[i] += sum_list[i-1] + int(s[i-1])*10**(i-1)
    
mod_s = [[] for _ in range(len(sum_list))]
mod_s[0] = 0
for i in range(1, len(sum_list)):
    mod_s[i] = sum_list[i] % 2019

c = Counter(mod_s)
ans = 0
for value in c.values():
    ans += value*(value-1)//2
print(ans)

### FIXED CODE ###

from collections import Counter
s = input()
n = len(s)
# 累積和の準備
sum_list = [0]*(n+1)  # s[0]は０であってほしいから配列数ひとつおおい
_10 = 1
for i in range(1, n + 1):
    sum_list[i] += (sum_list[i-1] + int(s[n-i])*_10 % 2019) % 2019  # ここでmodしておく
    _10 = _10*10 %2019
"""
(s[j]-s[i]/10**i)が区間の整数
区間の整数が2019で割り切れればよい
つまり、(s[j]-s[i]/10**i)≡0 (mod=2019)
ここで10**iと2019(素数)は互いに素なので、
10**iをかけて上の式はs[j]-s[i]≡0 (mod=2019)と同値
s[j]≡s[i] (mod=2019)となる。
"""
c = Counter(sum_list)
ans = 0

for key in c.keys():
    ans += c[key]*(c[key]-1)//2
print(ans)
### BUGGY CODE ###

A, B, K = map(int, input().split())
seisu = [i for i in range(A, B + 1)]
mitasu_seisu = []
for j in seisu[:K]:
    mitasu_seisu.append(j)
for k in seisu[-K:]:
    mitasu_seisu.append(k)
for l in sorted(list(set(mitasu_seisu))):
    print(l)


### FIXED CODE ###

A, B, K = map(int, input().split())
mitasu_seisu = []
for i in range(A, min(A + K, B)):
    mitasu_seisu.append(i)
for j in range(max(A, B - K + 1), B + 1):
    mitasu_seisu.append(j)
for k in sorted(set(mitasu_seisu)):
    print(k)
### BUGGY CODE ###

from functools import lru_cache
import sys
 
sys.setrecursionlimit(1000000)
 
N, W = list(map(int, input().split(" ")))
 
l = []
for i in range(N):
	w, v = list(map(int, input().split(" ")))
	l.append((w, v))
    
@lru_cache(maxsize=1000000)
def dp(i, score, remaining_weight):
	if (i < 0):
		return score
	if remaining_weight >= l[i][0]:
		# on / off
		return max([dp(i - 1, score + l[i][1], remaining_weight - l[i][0]), dp(i - 1, score, remaining_weight)])
	else:
		return dp(i-1, score, remaining_weight)
 
print(dp(N-1, 0, W))

### FIXED CODE ###

N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])
### BUGGY CODE ###

S = input()
num = 0
while(True):
    num += S.count("BW")
    S = S.replace("BW", "WB")
    if not "BW" in S:
        break
print(num)

### FIXED CODE ###

S = input()
indexes = [i for i, x in enumerate(S) if x == "W"]
print(sum([x-i for i, x in enumerate(indexes)]))
### BUGGY CODE ###

import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


# @lru_cache(size=None)
def slv(S, K):

    if len(S) <= 50:
        d = set([])
        for i in range(len(S)):
            for j in range(i + 1, len(S) + 1):
                d.add(S[i:j])

    # print('-----')

    import bisect
    S_ = [c for c in S]
    # S_.sort()
    idxs = []

    for k in sorted(set(S_)):
        # print('k', k)
        for i in range(len(S)):
            if S[i] == k:
                idxs.append(i)
        d = []

        for i in idxs:
            # print(i)
            for j in range(i + 1, len(S) + 1):
                if len(d) > K and d[-1] < S[i:j]:
                    break
                if S[i:j] not in d:
                    bisect.insort(d, S[i:j])
                    d = d[:K]
        if len(d) >= K:
            break
    # print(d)
    return sorted(d)[K - 1]


def main():
    S = read_str()
    K = read_int()
    S = [random.choice('abcdefghijklmnopqrstu') for _ in range(5000)]
    print(slv(S, K))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def slv(S, K):
    d = set([])
    for i in range(len(S)):
        for j in range(i + 1, i + 1 + K):
            d.add(S[i:j])

    return sorted(d)[K - 1]


def main():
    S = read_str()
    K = read_int()
    # K = 3
    # S = ''.join([random.choice('abcdefghijklmnopqrstu') for _ in range(5000)])
    print(slv(S, K))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import math
import bisect
import sys
input = sys.stdin.readline

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

XH=[[0,0] for _ in range(N)]
for i in range(N):
    x,h=map(int,input().split())
    XH[i][0]=x
    XH[i][1]=h
    
XH.sort()

X=[0]*N
for i in range(N):
    X[i]=XH[i][0]


#bの倍数の中でaを超える最小
def calc(a,b):
    return math.ceil(a/b)*b

ans=0
for i in range(N):
    if XH[i][1]>0:
        bom=X[i]+D
        Lb=i
        Rb=bisect.bisect_right(X,bom+D)
        ans+=XH[i][1]//A
        if XH[i][1]%A!=0:
            ans+=1
        dam=calc(XH[i][1],A)
        for j in range(Lb,Rb):
            XH[j][1]-=dam
        
print(ans)
    
    
    
    





### FIXED CODE ###

import math
import bisect
import sys
input = sys.stdin.readline

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

XH=[[0,0] for _ in range(N)]
for i in range(N):
    x,h=map(int,input().split())
    XH[i][0]=x
    XH[i][1]=h
    
XH.sort()

X=[0]*N
for i in range(N):
    X[i]=XH[i][0]



ans=0
S=[0]*(N+1)#累積和


for i in range(N):
    if S[i]<XH[i][1]:
        bom=X[i]+D
        Lb=i
        Rb=bisect.bisect_right(X,bom+D)
        num=(XH[i][1]-S[i])//A
        if (XH[i][1]-S[i])%A!=0:
            num+=1
        ans+=num
        dam=num*A
        #imosで遅延
        S[Lb]+=dam
        S[Rb]-=dam
    S[i+1]+=S[i]
        
print(ans)
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,W = IL()
w = []
v = []

for i in range(N):
  a,b = IL()
  w.append(a)
  v.append(b)

dp = [[0]*(W+1)] + [[None]*(W+1) for i in range(N)]

for i in range(N):
  for j in range(W+1):
    if w[i] <= j:
      dp[i+1][j] = max(dp[i][j-w[i]]+v[i], dp[i][j])
    else:
      dp[i+1][j]=dp[i][j]
      
print(dp[N][W])

### FIXED CODE ###

N,W = list(map(int,input().split()))
w = [0]
v = [0]

for i in range(N):
  a,b = list(map(int,input().split()))
  w.append(a)
  v.append(b)
  
# dp[i][w] = v
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1,N+1):
  for j in range(1,W+1):
    if j < w[i]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i])  # max(iの品を使わない時, iの品を使う時)

print(dp[N][W])
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(i+1)
flag = 1
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i] < a[i-1]:
            a[i],a[i-1] = a[i-1],a[i]
            b[i],b[i-1] = b[i-1],b[i]
            flag = 1
print(' '.join(map(str,b)))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n):
    b[a[i]-1] = i + 1
print(' '.join(map(str,b)))
### BUGGY CODE ###

n=int(input())
mx=10**18
z=1

a=[int(i) for i in input().split()]
for i in a:
    z*=i

if(z>mx)    : z=-1
print(z)



### FIXED CODE ###

n=int(input())
mx=10**18
z=1

a=[int(i) for i in input().split()]
for i in a:
    if i==0:
        print(0)
        quit()

for i in a:
    z*=i
    if z>mx:    z=-1
    if z==-1:   break

if z>mx or z<0   : z=-1
print(z)
### BUGGY CODE ###

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


Con = 10**18
ans = functools.reduce(lambda a,b: a*b,A)
print(ans if ans<=Con else "-1")

### FIXED CODE ###

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

Con = 10**18

ans = 1
if A.__contains__(0):
    print(0)
else:
    for i in A:
        if ans <=Con:
            ans*=i
        else:
            break
    print(ans if ans<=Con else "-1")
### BUGGY CODE ###

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

D = []
d = 1
while M >= N * d:
	if M % d == 0:
		D.append(d)
	d += 1

maxg = 1
for d in D:
	if (M - d * (N - 1)) % d == 0:
		maxg = max(maxg, d)

print(maxg)

### FIXED CODE ###

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

def divisible(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors

div = divisible(M)

div = [d for d in div if d <= M / N]

print(max(div))
### BUGGY CODE ###

#-*-coding:utf-8-*-

def main():
    A, B, C, X, Y = list(map(int, input().split()))

    dp = [[0 for i in range(Y+1)] for j in range(X+1)]


    
    for i in range(X+1):
        for j in range(Y+1):
            if i == 0 and j > 0:
                dp[i][j] = min(dp[i][j-1]+B, dp[i][j-1]+2*C)
            elif i > 0 and j == 0:
                dp[i][j] = min(dp[i-1][j]+A, dp[i-1][j]+2*C)
            elif i > 0 and j > 0:
                dp[i][j] = min(dp[i-1][j]+A, dp[i-1][j]+2*C, dp[i][j-1]+B, dp[i][j-1]+2*C, dp[i-1][j-1]+2*C)
    
    #for i  in range(X+1):
        #print(dp[i])
        
    print(dp[-1][-1])
                




if __name__ == '__main__':
    main()

### FIXED CODE ###

#-*-coding:utf-8-*-

def main():
    A, B, C, X, Y = list(map(int, input().split()))

    ABset = 2 * C
    min_price = 0

    #ABsetのほうがA,Bを個別に買うより安い場合
    if ABset <= A + B:
        if X >= Y:
            min_price += ABset * Y
            min_price += min(A * (X - Y), ABset * (X - Y))
        if X < Y:
            min_price += ABset * X
            min_price += min(B * (Y - X), ABset * (Y - X))
    else:
        min_price += A * X + B * Y

    print(min_price)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import collections


n, p = map(int, input().split())
s = input()

if p == 2:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 2 == 0:
            ret = ret + i + 1
    print(ret)
elif p == 5:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 5 == 0:
            ret = ret + i + 1
    print(ret)
else:
    c_list = [0] * n
    for i in range(len(s)):
        c_list[i] = int(s[-i-1:]) % p
    c_list.append(0)
    counter = [0] * p
    for i in c_list:
        counter[i] += 1
    ret = 0
    for item in counter:
        if item >= 2:
            ret = ret + (item * (item - 1) // 2)
    print(ret)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n, p = map(int, input().split())
s = input()

if p == 2:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 2 == 0:
            ret = ret + i + 1
    print(ret)
elif p == 5:
    ret = 0
    for i in range(len(s)):
        if int(s[i]) % 5 == 0:
            ret = ret + i + 1
    print(ret)
else:
    c_list = [0] * n
    power = 1
    for i in range(len(s)):
        c_list[i] = (c_list[i-1] + (int(s[-i-1]) * power)) % p
        power *= 10
        power = power % p
    c_list.append(0)
    counter = [0] * p
    for i in c_list:
        counter[i] += 1
    ret = 0
    for item in counter:
        if item >= 2:
            ret = ret + (item * (item - 1) // 2)
    print(ret)
### BUGGY CODE ###

import sys
from math import sqrt

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
bucket_size = int(sqrt(n))
for i in range(q):
    l, r = map(int, input().split())
    LR.append((l // bucket_size, r, l, i))
LR.sort()
# print(LR)

num = 0
count = [0] * (n + 1)


def add_num(idx):
    global num
    c = C[idx]
    if not count[c]:
        num += 1
    count[c] += 1


def del_num(idx):
    global num
    c = C[idx]
    count[c] -= 1
    if not count[c]:
        num -= 1


# 開区間[nl,nr)で考える
nl, nr = 0, 0
ans = [0] * (q)
preb = -1
for i in range(q):
    b, r, l, idx = LR[i]
    l -= 1
    if preb != b:
        nl, nr = 0, 0
        num = 0
        count = [0] * (n + 1)
    # print(nl, nr, l, r)
    # 区間を広げる時
    while nl > l:
        nl -= 1
        add_num(nl)
    while nr < r:
        add_num(nr)
        nr += 1
    # 区間を狭める時
    while nl < l:
        del_num(nl)
        nl += 1
    while nr > r:
        nr -= 1
        del_num(nr)
    # print("a", num, "idx", idx, "LR", (l, r))
    # print("c", count)
    ans[idx] = num


print(*ans, sep="\n")



### FIXED CODE ###

import sys

input = sys.stdin.buffer.readline
n, q = map(int, input().split())
C = list(map(int, input().split()))
LR = []
for i in range(q):
    l, r = map(int, input().split())
    LR.append((l, r, i))
LR.sort(key=lambda x: x[1])


BIT = [0] * (n + 1)


def update(idx, val):
    while idx <= n:
        BIT[idx] += val
        idx += idx & (-idx)


def query(idx):
    res = 0
    while idx > 0:
        res += BIT[idx]
        idx -= idx & (-idx)
    return res


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


def func(idx):
    temp = C[idx]
    if pos[temp] == -1:
        pos[temp] = idx + 1
        update(idx + 1, 1)
    else:
        pre = pos[temp]
        pos[temp] = idx + 1
        update(pre, -1)
        update(idx + 1, 1)


ans = [0] * (q)
idx = 0
for i in range(q):
    l, r, ans_num = LR[i]
    # l,rは0-indexに戻す
    l -= 1
    r -= 1
    while idx < r + 1:  # rになるまで増やす
        if idx < n:  # n超えないように注意
            func(idx)
            idx += 1
        else:
            break
    res = 0
    res += query(r + 1)
    if l > 0:
        res -= query(l)
    ans[ans_num] = res

print(*ans, sep="\n")
### BUGGY CODE ###

import heapq


k = int(input())
dist = [float("inf")] * k
q = []
heapq.heappush(q, (1, 1))

while q:
    n, c = heapq.heappop(q)
    if dist[n] <= c:
        continue
    dist[n] = c

    if dist[(n+1) % k] > c + 1:
        heapq.heappush(q, ((n + 1) % k, c + 1))
    if dist[(n*10) % k] > c:
        heapq.heappush(q, ((n * 10) % k, c))

print(dist[0])

### FIXED CODE ###

import heapq


def small_multiple(k):
    # kの倍数で各桁の総数が最も小さくなるような、各桁の総数
    dist = [float("inf")] * k
    q = []
    # kで割った余りが1になるような最小の数は1
    heapq.heappush(q, (1, 1))

    while q:
        n, c = heapq.heappop(q)
        if dist[n] <= c:
            continue
        dist[n] = c

        if dist[(n + 1) % k] > c + 1:
            heapq.heappush(q, ((n + 1) % k, c + 1))
        if dist[(n * 10) % k] > c:
            heapq.heappush(q, ((n * 10) % k, c))

    print(dist[0])


def main():
    k = int(input())
    small_multiple(k)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import math

def is_prime_num(in_num):
    cnt = 0
    if in_num == 2:
        return True
    elif in_num <= 1:
        return False
    elif in_num % 2 == 0:
        return False
    else:
        max_num = int(math.sqrt(in_num)+1)
        for j in range(3, max_num, 2):
            if in_num % j == 0:
                cnt = cnt + 1
                break
                    
        if cnt == 0:
            #?´???°
            return True
        else:
            return False

while True:
    try:
        n = int(input())
        prime_cnt = 0

        for i in range(2, n+1):
            if is_prime_num(i):
                #?´???°
                prime_cnt = prime_cnt + 1
                

        print(str(prime_cnt))
    except:
        break
    

### FIXED CODE ###

#init
max_num = 1000000
is_prime_num = [True for i in range (max_num+1)]

#0, 1 --- not prime number
is_prime_num[0] = False
is_prime_num[1] = False
end = int(max_num ** .5)

for i in range(2, end+1):
    if is_prime_num[i]:
        for j in range(i*i, max_num+1, i):
            is_prime_num[j] = False


while True:
    try:
        n = int(input())
        prime_cnt = 0
        for i in range(1, n+1):
            if is_prime_num[i]:
                prime_cnt = prime_cnt + 1
                   
   
        print(str(prime_cnt))
    except:
        break
### BUGGY CODE ###

def digits_of (n): # nの桁の数字のリストを出力する関数｡ nは自然数
    digits = [] # nの桁の数字を入れるリスト
    while n != 0:
        r = n % 10 # 10で割った余り
        digits.append(r) # リストに加える
        n = n // 10 # nを10で割った整数に置き換える
    return digits

def is_multiple_of_9 (n): # nは自然数
    sum = 0 # 各桁の数字の合計をもとめる
    for i in digits_of (n):
        sum += i
    return sum % 9 == 0 # もし合計が9の倍数ならTrue, そうでないならFalse
  
n = int(input())

print('Yes' if is_multiple_of_9 (n) == True else 'No')

### FIXED CODE ###

n = list(map(int,input()))

s = sum(n)

if s % 9 == 0:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def topological_sort(graph):
  in_cnt = {k:0 for k in nodes}
  for x in nodes:
    for y in graph[x]:
      in_cnt[y] += 1
  ret = []
  q = deque([i for i in nodes if not in_cnt[i]])
  while q:
    x = q.popleft()
    ret.append(x)
    for y in graph[x]:
      in_cnt[y] -= 1
      if not in_cnt[y]:
        q.append(y)
  if [i for i in nodes if in_cnt[i]]:
    return None
  return ret

N = int(input().strip())
from itertools import combinations
nodes = list(combinations(range(N), 2))
graph = {i:set() for i in nodes}
for x in range(N):
  l = list(map(int,input().split()))
  y = l[0]-1
  prev = (min(x,y),max(x,y))
  for y in l[1:]:
    y -= 1
    now = (min(x,y),max(x,y))
    graph[prev].add(now)
    prev = now

ans = topological_sort(graph)
if not ans:
  print(-1)
else:
  d = {i:1 for i in nodes}
  for x in ans:
    for y in graph[x]:
      d[y] = max(d[x]+1,d[y])
  print(max(d[i] for i in nodes))

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input().strip())
M = N*(N-1)//2

graph = [[] for i in range(M)]
in_cnt = [0 for i in range(M)]
for x in range(1,N+1):
  l = list(map(int,input().split()))
  y = l[0]
  b,s = max(x,y),min(x,y)
  prev = (b-1)*(b-2)//2+s-1
  for y in l[1:]:
    b,s = max(x,y),min(x,y)
    now = (b-1)*(b-2)//2+s-1
    graph[prev].append(now)
    in_cnt[now] += 1 
    prev = now

d = [1 for k in range(M)]
q = [i for i in range(M) if not in_cnt[i]]

if not q:
  print(-1)
  exit()
ans = 0
while q:
  x = q.pop()
  for y in graph[x]:
    d[y] = max(d[y],d[x]+1)
    ans = max(ans,d[y])
    in_cnt[y] -= 1
    if not in_cnt[y]:
      q.append(y)
if [i for i in range(M) if in_cnt[i]]:
  print(-1)
  exit()

print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000100)
n = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

ans = []
def frog(pnt, pos):
    if pos ==n-1:
        ans.append(pnt)
    elif pos ==n-2:
        frog(pnt + abs(H[pos+1]-H[pos]), pos+1)
    else:
        frog(pnt + abs(H[pos+1]-H[pos]), pos+1)
        frog(pnt + abs(H[pos+2]-H[pos]), pos+2)
        
frog(0, 0)
print(min(ans))

### FIXED CODE ###

import sys
n = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

P =[0 for _ in range(n)]
P[1] = abs(H[1]-H[0])
for pos in range(2, n):
    a = abs(H[pos]-H[pos-1])
    b = abs(H[pos]-H[pos-2])
    P[pos] = min((P[pos-1] + a), (P[pos-2] + b))

print(P[n-1])