Harryxun/stf_run huggingface dataset:
n = int(input())
edges = [[] for _ in range(n)]
color = [0 for _ in range(n - 1)]
for e in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append((b - 1, e))
    edges[b - 1].append((a - 1, e))

def dfs(i, p, pcol):
    col = 1
    ret = 0
    for c, e in edges[i]:
        if c != p:
            if col == pcol:
                col += 1
            color[e] = col
            ret = max(ret, dfs(c, i, col))
            col += 1
    return max(ret, col - 1)

print(dfs(0, -1, -1))
for i in range(n - 1):
    print(color[i])

### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

n = int(input())
edges = [[] for _ in range(n)]
color = [0 for _ in range(n - 1)]
for e in range(n - 1):
    a, b = map(int, input().split())
    edges[a - 1].append((b - 1, e))
    edges[b - 1].append((a - 1, e))

def dfs(i, p, pcol):
    col = 1
    ret = 0
    for c, e in edges[i]:
        if c != p:
            if col == pcol:
                col += 1
            color[e] = col
            ret = max(ret, dfs(c, i, col))
            col += 1
    return max(ret, col - 1)

print(dfs(0, -1, -1))
for i in range(n - 1):
    print(color[i])
import numpy as np

h, w, k = map(int, input().split())
s = []
for i in range(h):
    string = input()
    temp = []
    for j in range(w):
        temp.append(int(string[j]))
    s.append(temp)

sum_s = [[0 for i in range(w)] for j in range(h)]
if s[0][0] == 1: sum_s[0][0] = 1
for j in range(1, w):
    sum_s[0][j] = sum_s[0][j-1] + s[0][j]
for i in range(1, h):
    sum_s[i][0] = sum_s[i-1][0] + s[i][0]
for i in range(1, h):
    for j in range(1, w):
        sum_s[i][j] = sum_s[i-1][j] + sum_s[i][j-1] - sum_s[i-1][j-1] + s[i][j]
sum_s = np.array(sum_s)

ans = 10**9
for i in range(2**(h-1)):
    bin_str = format(i, '0'+str(h-1)+'b')
    kouryo = []
    temp_s = sum_s[:]
    cnt = 0
    for j in range(h-1):
        if bin_str[j] == '1':
            cnt += 1
            kouryo.append(list(temp_s[j, :]))
            temp_s[j+1:, :] = temp_s[j+1:, :] - temp_s[j, :]
    kouryo.append(list(sum_s[h-1, :]))

    kouryo = np.array(kouryo)
    for j in range(1, w):
        if cnt >= 10**9: break
        for m in range(len(kouryo)):
            if cnt >= 10**9: break
            if kouryo[m, j] > k:
                kouryo[:, j:] = kouryo[:, j:] - kouryo[:, j-1]
                cnt += 1
                break
        for m in range(len(kouryo)):
            if kouryo[m, j-1] > k:
                cnt += 10**9
                break
    ans = min(ans, cnt)
print(ans)

### FIXED CODE ###

import numpy as np

h, w, k = map(int, input().split())
s = []
for i in range(h):
    string = input()
    temp = []
    for j in range(w):
        temp.append(int(string[j]))
    s.append(temp)

s_arr = np.array(s)

ans = 10**9
for i in range(2**(h-1)):
    bin_str = format(i, '0'+str(h-1)+'b')
    kouryo = np.array([[0 for _ in range(w)]])
    cnt = 0
    start = 0
    for j in range(h-1):
        if bin_str[j] == '1':
            cnt += 1
            kouryo = np.concatenate((kouryo, s_arr[start:j+1].sum(axis=0, keepdims=True)), axis=0)
            start=j+1
    kouryo = np.concatenate((kouryo, s_arr[start:].sum(axis=0, keepdims=True)), axis=0)

    if cnt > ans: continue
    if np.any(kouryo>k): continue

    wa = np.array([0 for _ in range(len(kouryo))])
    for j in range(w):
        wa += kouryo[:, j]
        if np.max(wa)>k:
            cnt += 1
            if cnt > ans: break
            wa = kouryo[:, j]
    ans = min(ans, cnt)
print(ans)
# -*- coding: utf-8 -*-
import sys
import copy

def main():
	num = int(input())
	
	clocks = []
	for _ in range(num):
		clock = int(input())
		clocks.append(clock)
		
	ans = 1
	for clock in clocks:
		ans = lcm(ans, clock)
	print(int(ans))
			
def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
def lcm(a, b):
	g = gcd(a, b)
	return a / g * b
	
if __name__ == "__main__":
	main()
	

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy

def main():
	num = int(input())
	
	clocks = []
	for _ in range(num):
		clock = int(input())
		clocks.append(clock)
		
	ans = 1
	for clock in clocks:
		ans = lcm(ans, clock)
	print(ans)
			
def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
def lcm(a, b):
	g = gcd(a, b)
	return a // g * b
	
if __name__ == "__main__":
	main()
import numpy as np
N=int(input())
A=np.empty((N))
A=input().split()
for i in range(N):
    A[i]=(int)(A[i])
for i in range(N):
    
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j=j-1
        A[j+1] = v
    for k in range(N):
        if k<N-1:
            print(A[k],end=" ")
        else:
            print(A[k])


### FIXED CODE ###

N=int(input())
A=[0 for i in range(N)]
A=input().split()
for i in range(N):
    A[i]=(int)(A[i])
for i in range(N):
    
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j=j-1
        A[j+1] = v
    for k in range(N):
        if k<N-1:
            print(A[k],end=" ")
        if k==N-1:
            print(A[k])
n=int(raw_input())
N=map(int,raw_input().split())
add=0
if sum(N)%n==0:
    a=sum(N)/n
else:
    a=sum(N)/n +1
for i in N:
    add+=(a-i)**2
print add

### FIXED CODE ###

n=int(raw_input())
print n*(n+1)/2
if __name__ == '__main__':
    a,b,c = raw_input().split(" ")
    a,b = b,a
    a,c = c,a
    stdout(a, b, c)

### FIXED CODE ###

if __name__ == '__main__':
    a,b,c = input().split(" ")
    a,b = b,a
    a,c = c,a
    print(a, b, c)
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)

### FIXED CODE ###

n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
    exit()
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)
import math
x, y = map(int, input().split())
c_up = (2*y-x)/3
c_do = (2*x-y)/3
if c_up.is_integer() and c_do.is_integer():
  c_up = int(c_up)
  c_do = int(c_do)
  pattern = math.factorial(c_up+c_do) / (math.factorial(c_up)*math.factorial(c_do))
  result = int(pattern % (7 + 10**9))
else:
  result = 0
print(result)


### FIXED CODE ###

def mod_comb(n, r, m):
  nn = n+1
  r = min(r, n-r)
  numer = 1
  denom = 1
  for i in range(1, r+1):
    numer = (numer * (nn - i)) % m
    denom = (denom * i) % m
  output = numer * pow(denom, m-2, m) % m
  return output

x, y = map(int, input().split())
if not (x <= 2*y and y <= 2*x):
  result = 0
else:
  c_up = (2*y-x)/3
  c_do = (2*x-y)/3
  if c_up.is_integer() and c_do.is_integer():
    c_up = int(c_up)
    c_do = int(c_do)
    result = mod_comb((c_up+c_do), c_up, 7+10**9)
  else:
    result = 0
print(result)
inn=int(input())
sizes = []
for i in range(inn):
  sizes.append(int(input())

ans = len(set(sizes))
print(ans)

### FIXED CODE ###

inn = int(input())
sizes = set()
for i in range(inn):
    sizes.add(int(input()))
ans = len(sizes)
print(ans)
s = str(input())


a, b = 0, 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        a, b = i+1, i+2
        break
    if i != len(s)-1:
        elif s[i] == s[i+2]:
            a, b = i+1, i+3
            break
        
if a == 0:
    print(-1, -1)
else:
    print(a, b)

### FIXED CODE ###

s = str(input())


a, b = 0, 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        a, b = i+1, i+2
        break
    elif i < len(s)-2:
        if s[i] == s[i+2]:
            a, b = i+1, i+3
            break
        
if a == 0:
    print(-1, -1)
else:
    print(a, b)
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)
d = [0] * 100001
for i in range(N):
    d[A[i]] = 1
for i in range(100000, 0, -1):
    d[i - 1] += d[i]

left = 0
right = A[0] * 2 + 1
while right - left > 1:
    mid = (left + right) // 2
    m = 0
    for i in range(N):
        m += d[max(0, mid - A[i])]
    if m >= M:
        left = mid
    else:
        right = mid

ans = 0
m = 0
for i in range(N):
    t = min(d[max(0, left - A[i])], M - m)
    ans += sum(A[:t]) + A[i] * t
    m += t
print(ans)


### FIXED CODE ###

from itertools import accumulate

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

A.sort(reverse=True)
d = [0] * (A[0] * 2 + 1)
for i in range(N):
    d[A[i]] += 1
d = list(accumulate(d[::-1]))[::-1]
S = list(accumulate([0] + A))

left = 0
right = A[0] * 2 + 1
while right - left > 1:
    mid = (left + right) // 2
    m = 0
    for i in range(N):
        m += d[max(0, mid - A[i])]
    if m >= M:
        left = mid
    else:
        right = mid

ans = 0
m = 0
for i in range(N):
    t = min(d[max(0, right - A[i])], M - m)
    ans += S[t] + A[i] * t
    m += t
ans += left * (M - m)
print(ans)
n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
p=[[] for i in range(n)]
for i in range(n):
    p[l[i][0]-1].append(l[i][1])
a=[]
b=[]
for i in range(n):
    if len(p[i])>0:
        mp=max(p[i])
        f=0
        for j in p:
            if f==0 and j==mp:
                a.append(j)
                f+=1
            else:
                b.append(j)
ans=len(a)*len(a)+sum(a)
if b:
    ans+=sum(b)
    b.sort()
    a.sort()
    i=0
    ai=0
    bi=0
    an=len(a)
    bn=len(b)
    while i<n-k:
        if ai<an and bi<bn:
            ap=a[ai]
            bp=b[bi]
            if ap+2*(an-ai-1)+1>=bp:
                bi+=1
                ans-=bp
            else:
                ans-=ap+2*(an-ai-1)+1
                ai+=1
        elif ai<an:
            ap=a[ai]
            ans-=ap+2*(an-ai-1)+1
            ai+=1
        elif bi<bn:
            ans-=b[bi]
            bi+=1
        i+=1
    print(ans)
else:
    a.sort(reverse=True)
    print(sum(a[:k])+k*k)

### FIXED CODE ###

n,k=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x: x[0]*1000000000000+x[1])
l.append([-1,-1])
a=[]
b=[]
for i in range(n):
    if l[i][0]==l[i+1][0]:
        b.append(l[i][1])
    else:
        a.append(l[i][1])
ans=len(a)*len(a)+sum(a)
#print(ans)
if len(b)>0:
    ans+=sum(b)
    b.sort()
    a.sort()
    i=0
    ai=0
    bi=0
    an=len(a)
    bn=len(b)
    while i<n-k:
        if ai<an and bi<bn:
            ap=a[ai]
            bp=b[bi]
            if ap+2*(an-ai-1)+1>=bp:
                bi+=1
                ans-=bp
            else:
                ans-=ap+2*(an-ai-1)+1
                ai+=1
        elif ai<an:
            ap=a[ai]
            ans-=ap+2*(an-ai-1)+1
            ai+=1
        elif bi<bn:
            ans-=b[bi]
            bi+=1
        i+=1
    print(ans)
else:
    a.sort(reverse=True)
    print(sum(a[:k])+k*k)
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        int N, A, B, ans = 0;
        cin >> N >> A >> B;
        rep(i, N + 1)
        {
                int t = i, cnt = 0;
                while (t > 0)
                {
                        cnt += t % 10;
                        t /= 10;
                }
                if (A <= cnt && cnt <= B)
                        ans += i;
        }
        cout << ans << endl;

        return 0;
}


### FIXED CODE ###

"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, readline().split())
ans = 0
for i in range(N + 1):
    s = 0
    t = i
    while t:
        s += t % 10
        t = t // 10

    if A <= s <= B:
        ans += i
print(ans)
n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)

if  is_broken[1]:
  dp[1],dp[2]=1,2
else:
  if is_broken[2]:
    dp[2]=1

if n>=2:
  for i in range(3,n+1):
    if i in broken:
      dp[i]=0
    
    elif  is_broken[i-1] and is_broken[i-2]:
      dp[i]=dp[i-1]+dp[i-2]
      dp[i]%=mod
    
    elif is_broken[i-1]:
      dp[i]=dp[i-1]
      dp[i]%=mod
    
    elif is_broken[i-2]:
      dp[i]=dp[i-2]
      dp[i]%=mod
    
    else:
      dp[i]=0
print(dp[n])


### FIXED CODE ###

n,m=map(int,input().split())
broken=[int(input()) for i in range(m)]
mod=10**9+7

is_broken=[True]*(n+1)
for i in range(m):
  is_broken[broken[i]]=False
   
dp=[0]*(n+1)
dp[0]=1
if is_broken[1]:
  dp[1]=dp[0]
  
for i in range(2,n+1):
    if is_broken[i]:
       dp[i]=dp[i-1]+dp[i-2]
       dp[i]%=mod
    else:
      dp[i]=0
      
print(dp[n])
n = int(input())
lsn = [input() for _ in range(n)]
m = int(input())
lsm = [input() for _ in range(m)]

from collections import defaultdict

d = defaultdict(str)

for i in lsn:
    d[i] += 1
for j in lsm:
    d[j] -= 1

cnt = 0
for k in d.values():
    if k > 0:
        cnt +=k

print(cnt)

### FIXED CODE ###

n = int(input())
lsn = [input() for _ in range(n)]
m = int(input())
lsm = [input() for _ in range(m)]
 
from collections import defaultdict
 
d = defaultdict(int)
 
for i in lsn:
    d[i] += 1
for j in lsm:
    d[j] -= 1
 
print(max(max(d.values()),0))
s,d = map(str, open(0).read().split())
ss = list(s)
dd = list(d)
a = 0
for i in range(ss):
  if(ss[i] == dd[i]):
    a += 1
    
print(a)

### FIXED CODE ###

s,d = map(str, open(0).read().split())
ss = list(s)
dd = list(d)
a = 0
for i in range(len(ss)):
  if(ss[i] == dd[i]):
    a += 1
    
print(a)
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
	a[i]=int(input())
	
def pattern(n):
	if n==0:
		return 1
	if n==1:
		return 1
	return pattern(n-1)+pattern(n-2)

def renzoku(m):
	total=0
	for i in range(m-1):
		if a[i]==a[i+1]-1:
			total=1
			break;
	return total
	
if renzoku(m):
	print(0)
	
elif m==0:
	print(pattern(n))
	
else:
	total=pattern(n-a[m-1]-1)*pattern(a[0]-1)
	for i in range(m-1):
		total*=pattern(a[i+1]-a[i]-2)
	print(total%1000000007)

### FIXED CODE ###

n,m=map(int,input().split())
dp=[-1 for i in range(n+1)] #dp[i]=はi段目
for i in range(m):
	a=int(input())
	dp[a]=0
dp[0]=1
if dp[1]<0:
	dp[1]=1
for i in range(2,n+1):
	if dp[i]<0:
		dp[i]=(dp[i-1]+dp[i-2])%1000000007
print(dp[n]%1000000007)
X, T = map(input().split())

R = X/T

print(R)

### FIXED CODE ###

T, X = [int(i) for i in input().split()]

print(T/X)
a = [int(i) for i in input().split(" ")]
b = max((a[2]-(a[0]-a[1]), 0)
print(b)


### FIXED CODE ###

a = [int(i) for i in input().split(" ")]
b = max(a[2]-(a[0]-a[1]), 0)
print(b)
s = input()
s_list = [s[_] for _ in range(len(s))]

dic = dict()
for c in s_list:
  if c in dic:
    dic[c] += 1
  else:
    dic[c] = 1

flg = True
for key in dic:
  if dic[key]%2 !- 0:
    flg = False
    break
    
if flg:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
s_list = [s[_] for _ in range(len(s))]

dic = dict()
for c in s_list:
  if c in dic:
    dic[c] += 1
  else:
    dic[c] = 1

flg = True
for key in dic:
  if dic[key]%2 != 0:
    flg = False
    break
    
if flg:
  print('Yes')
else:
  print('No')
l,r = map(int,input().split())

for i in range(l,r-1):
    for j in range(l+1,r):
        if i == l and j == l+1:
            ans = (i*j)%2019
        else:
            res = (i*j)%2019
            ans = min(ans,res)
print(ans)


### FIXED CODE ###

l,r = map(int,input().split())

if r - l >= 2018:
    print(0)
else:
    ans = 2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%2019)
    print(ans)
import sys

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

if a>=b:
  print(10)
else:
  print(0)
  


### FIXED CODE ###

import sys

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

if a>=b:
  print(10)
else:
  print(0)
n = int(input())
b = [*map(int, input().split())]
sum_a = b[0] + b[-1]
for i in range(1,n-1):
    sum_a += min(b[i],b[i-1])
print (sum_a)

### FIXED CODE ###

n = int(input())
b = list(map(int, input().split()))
a = [int(0) for i in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]
b.append(b[n-2])
for i in range(1,n-1):
    a[i] = min(b[i-1], b[i])
print(sum(a))
n = int(input())
h = list(map(int, input().split()))
xh = []
#print(n)
#print(h)

for i in range(len(h)-1):
  #print(h[i],h[i+1])
  counter = 0
  #print(i,"kaime",h[i],"wohantei")
  while h[i] >= h[i+1]:
    #print(h[i],">",h[i+1],"counter+1",counter+1)
    counter += 1
    #print(counter)
    i += 1
    #print(i,h[i])
    #print("tugiha",h[i],"to",h[i+1],"wohanteisimasu")
    if i == n-1:
      break
  #print("whilekaranukemasu",h[i],h[i+1])
  xh.append(counter)
print(max(xh))

### FIXED CODE ###

import math
n = int(input())
h = list(map(int, input().split()))
#print(n)
#print(h)
counter = 0
countMax = 0
for i in range(n-1):
  if h[i] >= h[i+1]:
    counter +=1
    countMax = max(counter,countMax)
  else:
    counter = 0
print(countMax)
N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i < 1:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] < B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))

### FIXED CODE ###

N = int(input())
B = [int(i) for i in input().split()]
A = [0]*N

for i in range(N):
    if i == 0:
        A[i] = B[0]
    else:
        if i < N-1:
            if B[i-1] <= B[i]:
                A[i] = B[i-1]
                A[i+1] = B[i]
            else:
                A[i] = B[i]
                # A[i+1] = B[i+1]
        else:
            A[i] = B[-1]
print(sum(A))
s = input()
smalls = "abcdefghijklmnopqrstuvwxyz".split()
def solve(s):
    count = 0
    if s[0] != "A":
        return False
    if s[1] not	in smalls:
	return False
    for char in s[2:]:
	if char	not in smalls:
            return False
	if char	== "C":
            count += 1
    if count !=	1:
	return False
    return True

if solve(s):
    print("AC")
else:
    print("WA")



### FIXED CODE ###

s = input()
smalls = "abcdefghijklmnopqrstuvwxyz"
def solve(s):
    count = 0
 
    if s[0] != "A":
        return False
 
    if s[1] not in smalls:
        return False
    for char in s[2:-1]:
        if char == "C":
            count += 1
            continue
 
        if char not in smalls:
            return False
    if count != 1:
        return False
    if s[-1] not in smalls:
	    return False
    return True
 
if solve(s):
    print("AC")
else:
    print("WA")
import math

A, B = map(int, input().strip().split())
print(A * B // math.gcd(A,B))

### FIXED CODE ###

import fractions

A, B = map(int, input().strip().split())
print(A * B // fractions.gcd(A,B))
D, N =map(int, input().split())
if N != 100:
  print(100**D*N)
else:
  print(100**d*101)
  

### FIXED CODE ###

D, N =map(int, input().split())
if N != 100:
  print(100**D*N)
else:
  print(100**D*101)
s = input()
q_number = int(input())
reverse_flag = 1
head = ""
tail = ""
for i in range(q_number):
  temp = input().split()
  if temp[0] == "1": 
    reverse_flag = reverse_flag * -1
  else:
    headstails = int(temp[1])*reverse_flag 
    if headstails == 1 or headstails == -2:
      head = temp[2] + head
    else:
      tail = tail + temp[2]
      
if reverse_flag == 1:
  print(head+s+tail)
else:
  print(tail[::-1]+s[::-1]+head[::-1])
        
       

### FIXED CODE ###

a = input()
if "A" in a and "B" in a:
  print("Yes")
else:
  print("No")
a,b,c=map(int,input().split())
print('No'ifa+b<c else'Yes')

### FIXED CODE ###

a,b,c=map(int,input().split())
print('No'if a+b<c else'Yes')
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,x) for(int i = 0; i < x; ++i)
using namespace std;

int n,ar[100001]={},dp[100001]={};

int solve(int x)
{
	if(x>=n-2) return dp[x];
	if(dp[x]==-1) dp[x]=min(abs(ar[x]-ar[x+1])+solve(x+1) , abs(ar[x]-ar[x+2])+solve(x+2));
	return dp[x];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	cin >> n;
	rep(i,n) cin >> ar[i];
	dp[n-2]=abs(ar[n-1]-ar[n-2]);
	rep(i,n-3) dp[i]=-1;
	cout << solve(0) <<nxt;
	return 0;
}

### FIXED CODE ###

import sys
I = lambda:map(int,sys.stdin.readline().split())
pr = lambda x:sys.stdout.write(f'{x}\n')
sys.setrecursionlimit(2000000001)

mn = lambda w,x,y,z: min(abs(w)+x,abs(y)+z)
n = ar = dp = 0

def solve(x):
	global n,ar,dp
	if x>=n-2: return dp[x]
	if dp[x] != -1: return dp[x]
	dp[x] = mn(ar[x]-ar[x+1], solve(x+1), ar[x]-ar[x+2], solve(x+2))
	# pr(f'{x} => {dp[x]}')
	return dp[x]

def main():
	global n,ar,dp
	n, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	# pr((n,ar,dp))
	pr(solve(0))

main()
a, b, c = map(int, input().split())
print(a + b[:1] + c)

### FIXED CODE ###

a, b, c = map(str, input().split())

print("A" + b[:1] + "C")
A = int(input())
if A % 2 == 0
   print(A)
  else:
    print(A // 2 + 1)


### FIXED CODE ###

num = int(input())
if num % 2 == 0:
   print(num // 2)
else:
   print(num // 2 + 1)
N, K = map(int, input().split())
arr = list(map(int,input().split()))
left = []
right = []
for i in arr:
    if i < 0:
        left.append(abs(i))
    else:
        right.append(i)
left.sort()
tmp = 0
count = 0
if len(right) >= K:
    tmp += right[K-1]
    i = 1
    while True:
        if len(left) < i or K-i-1 < 0:
            break
        tmp2 = right[K-i-1] + left[i-1] + min(right[K-i-1],left[i-1])
        i += 1
        if tmp2 < tmp:
            tmp = tmp2
else:
    tmp += right[-1]+left[K-len(right)-1]+min(right[-1],left[K-len(right)-1])
    i = 1
    while True:
        if K-len(right)-1+i >= K or -1-i < 1-K:
            break
        tmp2 = right[-1-i] + left[K-len(right)-1+i] + min(right[-1-i],left[K-len(right)-1+i])
        i += 1
        if tmp2 < tmp:
            tmp = tmp2
print(tmp)

### FIXED CODE ###

N, K = map(int, input().split())
arr = list(map(int,input().split()))
left = []
right = []
for i in arr:
    if i < 0:
        left.append(abs(i))
    else:
        right.append(i)
left.sort()
tmp = 0
count = 0
if len(right) == 0:
    print(left[K-1])
    exit()
if len(right) >= K:
    tmp += right[K-1]
    i = 1
    while True:
        if len(left) < i or K-i-1 < 0:
            break
        tmp2 = right[K-i-1] + left[i-1] + min(right[K-i-1],left[i-1])
        i += 1
        if tmp2 < tmp:
            tmp = tmp2
else:
    tmp += right[-1]+left[K-len(right)-1]+min(right[-1],left[K-len(right)-1])
    i = 1
    while True:
        if K-len(right)-1+i >= K or i >= len(right) or K-len(right)-1+i >= len(left)-1:
            break
        tmp2 = right[-1-i] + left[K-len(right)-1+i] + min(right[-1-i],left[K-len(right)-1+i])
        i += 1
        if tmp2 < tmp:
            tmp = tmp2
print(tmp)
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans =1
now = [1]
ed = set([1])

for i in range(n+1):
    if a[now[i]-1] ==2:
        break
    now.append(a[now[i]-1])
    ed = set(now)
    
t = len(now)-now.index(a[now[i]-1])
f = now.index(a[now[i]-1])


if k >= f + t:
    p = (k-f)%t
    k = f + p
    

print(now[k])

### FIXED CODE ###

import sys
n, k = map(int, input().split())
a = list(map(int, input().split())) 

visited = [None]*n
cur = 0
for i in range(k):
    if visited[cur] is None:
        visited[cur] = i
        cur = a[cur]-1
    else:
        break
else:
    print(cur+1)
    sys.exit()

k -= i
k %= i-visited[cur]

for i in range(k):
    cur = a[cur]-1

print(cur+1)