Harryxun/stf_run huggingface dataset:
from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) or i1<=len(D1):
        if D0[i0][0]!=D1[i1][0] or (i0==len(D0) and i1==len(D1)):
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D[i0+1][1]>D[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1



### FIXED CODE ###

from collections import defaultdict
d0 = defaultdict(int)
d1 = defaultdict(int)
N=int(input())
v=list(map(int,input().split()))
for i in range(N):
    if i%2==0:
        d0[v[i]]+=1
    else:
        d1[v[i]]+=1
D0=sorted(d0.items(), key=lambda x:x[1],reverse=True)
D1=sorted(d1.items(), key=lambda x:x[1],reverse=True)
if (D0[0][1]+D1[0][1])==len(v) and D0[0][0]==D1[0][0]:
    print(len(v)//2)
else:
    i0=0
    i1=0
    while i0<=len(D0) or i1<=len(D1):
        if D0[i0][0]!=D1[i1][0]:
            print(len(v)-D0[i0][1]-D1[i1][1])
            break
        else:
            if D0[i0][1]>D1[i1][1]:
                i1+=1
            elif D0[i0][1]<D1[i1][1]:
                i0+=1
            else:
                if (len(D0)-1-i0)>0 and (len(D1)-1-i1)>0:
                    if D0[i0+1][1]>D1[i1+1][1]:
                        i0+=1
                    else:
                        i1+=1
                elif (len(D0)-1-i0)==0 :
                    i1+=1
                elif (len(D1)-1-i1)==0:
                    i0+=1
l = int(input())
 
word = input()
 
counter = 0
for i in range(len(word)):
  if len(word[i:]) >= 3:
    if word[i:i+3] == 'abc':
      counter += 1
      
print(counter)

### FIXED CODE ###

numbers = input().split(' ')
a = int(numbers[0])
b = int(numbers[1])

if a*500 >= b:
  print("Yes")
else:
  print("No")
S=list(input().split(""))
 
T=list(input().split(""))
 
if S==T-(T-S):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

S=list(input())
 
T=list(input())
Judge = True 
 
for i in range(len(S)):
  if S[i]==T[i]:
    continue
  else:
    Judge = False

if Judge:
  print("Yes")
else:
  print("No")
a,b,k = map(int, input().split())

l = []

greatest = a

if(b > a):
  greatest = b
  
for i in range(1, greatest):
  if(a % i == 0 and b % i == 0):
    l.append(i)

if(len(l) == 0):
  if(a == b):
    l.append(1)
    
print(str(l[len(l) - int(k)]))

### FIXED CODE ###

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

if( (b / a) >= c):
  print(c)
else:
  print(str(int(b/a)))
n = input()
if n[0]=1:
  n[0]=9
else:
  n[0]=1
if n[1]=1:
  n[1]=9
else:
  n[1]=1
if n[2]=1:
  n[2]=9
else:
  n[2]=1

print(n)

### FIXED CODE ###

n = input()
a = ""
for i in range(len(n)):
  if n[i]=="1":
    a +="9"
  else:
    a +="1"
print(a)
import sys
from collections import defaultdict

input = sys.stdin.readline

N = int(input())
G = defaultdict(list)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
res = [None] * N


def dfs(v, p, c):
    if res[v] is not None:
        return
    res[v] = c
    for u, w in G[v]:
        if u == p:
            continue
        if w % 2 == 0:
            dfs(u, v, c)
        else:
            dfs(u, v, 1 - c)


dfs(0, -1, 0)
for x in res:
    print(x)


### FIXED CODE ###

import sys
from collections import defaultdict

sys.setrecursionlimit(100000)
input = sys.stdin.readline

N = int(input())
G = defaultdict(list)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
res = [None] * N


def dfs(v, c):
    res[v] = c
    for u, w in G[v]:
        if res[u] is not None:
            continue
        if w % 2 == 0:
            dfs(u, c)
        else:
            dfs(u, 1 - c)


dfs(0, 0)
for x in res:
    print(x)
//words = ['dream', 'dreamer', 'erase', 'eraser']
words = ['dream', 'erase', 'aser*', 'er', 'as']
s = input()
for word in words:
  s = s.replace(word, '*')
s = s.replace('*', '')
if len(s) == 0:
  print('YES')
else:
  print('NO')



### FIXED CODE ###

er = ["dreamer", "eraser"]
noter = ["dream", "erase"]
words = er + noter
s = input()
while len(s) > 0:
  flag = True
  for word in words:
    if s.endswith(word):
      s = s[:-len(word)]
      flag = False
  if flag:
    print("NO")
    exit()
print("YES")
import sympy
x=int(input())
print sympy.nextprime(x)

### FIXED CODE ###

x = int(input())
while any(x % i < 1 for i in range(2, x)): 
    x += 1
print(x)
from math import floor as f
a = input().split()
print(f(int(a[0]) * (int(float(a[1] * 100))) / 100))

### FIXED CODE ###

from math import floor as f
a = input().split()
a[0] = int(a[0])
a[1] = int("".join(a[1].split(".")))

print(a[0] * a[1] // 100)
import sysinput = sys.stdin.readline

s = input()
t = input()

dp = [[0 for _ in range(len(s) + 10)] for _ in range(len(s) + 10)]

for i in range(1, len(s)):
    for l in range(1, len(t)):
        if s[i - 1] == t[l - 1]:
            dp[i][l] = max(max(dp[i - 1][l - 1] + 1, dp[i][l - 1]), dp[i - 1][l])
        else:
            dp[i][l] = max(dp[i][l - 1], dp[i - 1][l])
length = dp[len(s) - 1][len(t) - 1]
if length == 0:
    print("")
else:
    ans = ''
    i = len(s) - 1
    l = len(t) - 1
    while i > 0 and l > 0:
        if dp[i][l] == dp[i - 1][l - 1] + 1:
            ans = s[i - 1] + ans
            i -= 1
            l -= 1
        elif dp[i-1][l] == dp[i][l]:
            i -= 1
        elif dp[i][l-1] == dp[i][l]:
            l -= 1
    print(ans)


### FIXED CODE ###

import sys
import math
from collections import deque
import copy

input = sys.stdin.readline

s = input()
t = input()

dp = [[0 for _ in range(len(t) + 10)] for _ in range(len(s) + 10)]

for i in range(1, len(s)):
    for l in range(1, len(t)):
        if s[i - 1] == t[l - 1]:
            dp[i][l] = max(max(dp[i - 1][l - 1] + 1, dp[i][l - 1]), dp[i - 1][l])
        else:
            dp[i][l] = max(dp[i][l - 1], dp[i - 1][l])
length = dp[len(s) - 1][len(t) - 1]
if length == 0:
    print("")
else:
    ans = ''
    i = len(s) - 1
    l = len(t) - 1
    while i > 0 and l > 0:
        if dp[i-1][l] == dp[i][l] and i >= 1:
            i -= 1
        elif dp[i][l-1] == dp[i][l] and l >= 1:
            l -= 1
        else:
            ans = s[i - 1] + ans
            i -= 1
            l -= 1
    print(ans)
A=[[int(x) for x in inout().split()]for i in range(3)]
n=int(input())
b=list(map(int,input().split()))
for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
    elif A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[2][0] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit()
print('No')

### FIXED CODE ###

A=[[int(x) for x in input().split()]for i in range(3)]
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
 
for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[2][0] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit() 
print('No')
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
count =0
while B != A: 
    if max(B) < max(A):
        count =-1
        break
    i = B.index(max(B))
    if i+1 >= N:
        B[i] = B[i] - B[0] - B[i-1]
    else:
        B[i] = B[i] - B[i+1] - B[i-1]
    count += 1
    
print(count)

### FIXED CODE ###

S = input()
count = 1
strings = []
strings.append(S[0])
stack = ''
for s in S[1:]:
    stack += s
    if strings[-1] == stack:
        continue
    else:
        strings.append(stack)
        stack = ''
        count+=1    

print(count)
N = int(input())
A=[int(i) for i in input().split()]

B = [0 for i in range(len(A))]
for i in A:
    B[i] =B[i] + 1

for i in range(B):
    print(i)

### FIXED CODE ###

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

B = [0 for i in range(N)]
for i in A:
    B[i-1] =B[i-1] + 1

for i in B:
    print(i)
h, w = map(int, input().split())
s = []
for i in range(h):
    s_ = input()
    s.append(s_)

for i in range(h):
    for j in range(w):
        if s[j][i] == '#':
            if j + 1 < w and s[i][j+1] == '#':
                continue
            if j - 1 >= 0 and s[i][j-1] == '#':
                continue
            if i + 1 < h and s[i+1][j] == '#':
                continue
            if i - 1 >= 0 and s[i-1][j] == '#':
                continue
            print('No')
            exit()

print('Yes')

### FIXED CODE ###

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

for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            if j + 1 < h and s[j+1][i] == '#':
                continue
            if j - 1 >= 0 and s[j-1][i] == '#':
                continue
            if i + 1 < w and s[j][i+1] == '#':
                continue
            if i - 1 >= 0 and s[j][i-1] == '#':
                continue
            print('No')
            exit()

print('Yes')
N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in A:
  ans *= i
  if ans > 1e18:
  	print(-1)
    return
  
if ans > 1e18:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

def solve():
  ans = 1
  if 0 in A:
    return 0
  for i in A:
    ans *= i
    if ans > 1e18:
      return -1
  return ans


N = int(input())
A = list(map(int, input().split()))
print(solve())
n = int(input())
v = [int(i) for i in input().split()]

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

### FIXED CODE ###

from collections import Counter
def main(n,v):
    # n = int(input())
    # v = list(map(int, input().split()))
    odd = Counter(v[0::2]).most_common(2) + [(0, 0)]
    even = Counter(v[1::2]).most_common(2) + [(0, 0)]

    n_half = int(n / 2)

    if (len(odd) == 1 and len(even) == 1) and odd[0][0] == even[0][0]:
        ans = n_half
    elif odd[0][0] == even[0][0]:
        ans = min(n_half - odd[0][1] + n_half - even[1][1],\
                n_half - odd[1][1] + n_half - even[0][1])
    else:
        ans = n_half - odd[0][1] + n_half - even[0][1]

    print(ans)
    return 0

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    main(n,v)
a,p=map(int,input().split())
s=a*3
reuslt=(p+s)//2

print(result)

### FIXED CODE ###

a,p=map(int,input().split())
result=(p+(a*3)) // 2
print(result)
import sys
input = sys.stdin.readline
from heapq import *
def min_cost_flow_dijkstra(E, s, t, f):
    NN = 2 * N + 6
    G = [[] for _ in range(NN)]
    for a, b, cap, c in E:
        G[a].append([b, cap, c, len(G[b])])
        G[b].append([a, 0, -c, len(G[a])-1])
    prevv = [-1] * NN
    preve = [-1] * NN
    h = [0] * NN
    res = 0
    while f > 0:
        dist = [1<<100] * NN
        dist[s] = 0
        q = []
        heappush(q, s)
        while h:
            di, v = q.pop()
            if dist[v] < di: continue
            for i, (b, _cap, c, r) in enumerate(G[v]):
                if _cap > 0 and dist[b] > dist[v] + c + h[v] - h[b]:
                    dist[b] = dist[v] + c + h[v] - h[b]
                    prevv[b] = v
                    preve[b] = i
                    heappush(q, (dist[b], b))
        
        
        if dist[t] == 1<<100:
            return -1
        for v in range(NN):
            h[v] += dist[v]
        
        d = f
        v = t
        while v != s:
            d = min(d, G[prevv[v]][preve[v]][1])
            v = prevv[v]
        f -= d
        res += d * h[t]
        v = t
        while v != s:
            G[prevv[v]][preve[v]][1] -= d
            G[v][G[prevv[v]][preve[v]][3]][1] += d
            v = prevv[v]
    return res

E = []
N = int(input())
su = 0
INF = 1 << 31
for i in range(N):
    x, y, cnt = map(int, input().split())
    E.append((2*N+4, i, cnt, 0))
    E.append((i, 2*N, cnt, x + y + INF))
    E.append((i, 2*N+1, cnt, x - y + INF))
    E.append((i, 2*N+2, cnt, - x + y + INF))
    E.append((i, 2*N+3, cnt, - x - y + INF))
    su += cnt

for i in range(N):
    x, y, cnt = map(int, input().split())
    E.append((i+N, 2*N+5, cnt, 0))
    E.append((2*N, i+N, cnt, - x - y + INF))
    E.append((2*N+1, i+N, cnt, - x + y + INF))
    E.append((2*N+2, i+N, cnt, x - y + INF))
    E.append((2*N+3, i+N, cnt, x + y + INF))

print(su * INF * 2 - min_cost_flow(E, 2*N+4, 2*N+5, su))

### FIXED CODE ###

from networkx import*
N = int(input())
G = MultiDiGraph()
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(i, demand = -c)
    G.add_weighted_edges_from([(i, -1, x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -2, x - y)], capacity = c)
    G.add_weighted_edges_from([(i, -3, -x + y)], capacity = c)
    G.add_weighted_edges_from([(i, -4, -x - y)], capacity = c)
for i in range(N):
    x, y, c = map(int, input().split())
    G.add_node(N + i, demand = c)
    G.add_weighted_edges_from([(-1, N + i, -x - y)], capacity = c)
    G.add_weighted_edges_from([(-2, N + i, -x + y)], capacity = c)
    G.add_weighted_edges_from([(-3, N + i, x - y)], capacity = c)
    G.add_weighted_edges_from([(-4, N + i, x + y)], capacity = c)

print(-min_cost_flow_cost(G))
s = input()
t = input()

ans = 10000

for i in range(len(s) - len(t) + 1):
    score = 0
    U = [i:i + len(t)]
    for j in range(len(t)):
        if U[j] != t[j]:
            score += 1
    ans = min(ans, score)

print(ans)

### FIXED CODE ###

s = input()
t = input()

ans = 10000

for i in range(len(s) - len(t) + 1):
    score = 0
    U = s[i:i + len(t)]
    for j in range(len(t)):
        if U[j] != t[j]:
            score += 1
    ans = min(ans, score)

print(ans)
(k,n),*a = [list(map(int,i.split())) for i in open(0)]
a.append(a[0]+k)
print(k - min(a[i+1]-a[i] for i in range(n)))

### FIXED CODE ###

(k,n),(*a,) = [list(map(int,i.split())) for i in open(0)]
a.append(a[0]+k)
print(k - max(a[i+1]-a[i] for i in range(n)))
D = input()

if D == "25"
	print("Christmas")
elif D == "24"
	print("Christmas Eve")
elif D == "23"
	print("Christmas Eve Eve Eve")

### FIXED CODE ###

D = int(input())
 
if D == 25:
	print("Christmas")
elif D == 24:
	print("Christmas Eve")
elif D == 23:
	print("Christmas Eve Eve")
elif D == 22:
	print("Christmas Eve Eve Eve")
n = int(input())
as = list(map(int,input().split()))

ans = 1

for i in as:
    ans *= i
    ans = min(i, 10*18+1)
    if ans == 10**18+1:
        print(-1)

else:
    print(ans)


### FIXED CODE ###

x, y = map(int, input().split())

for a in range(x+1):
    b = x - a
    if a*2 + b*4 == y:
        print('Yes')
        break
else:
    print('No')
N, X = map(int, input().split())
l = list(map(int, input().split()))
d = 0
answer = 0
for i in range(N+1):
    if d <= X:
        answer += 1
        d += l[i]
    else:
        break
print(answer)

### FIXED CODE ###

import itertools
N, X = map(int, input().split())
l = list(map(int, input().split()))
l.insert(0,0)
l_acc = list(itertools.accumulate(l))
answer = [x for x in l_acc if x<=X]
print(len(answer))
a,b=map(int,input().split())
    if a*b%2==0:print("Even")
    else:print("Odd")

### FIXED CODE ###

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

n = int(input())

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b); eid[a].append(i)
    to[b].append(a); eid[b].append(i)

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])

### FIXED CODE ###

"""dfs"""

n = int(input())
import sys
sys.setrecursionlimit(10**6)

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b); eid[a].append(i)
    to[b].append(a); eid[b].append(i)

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])
n,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[[0 for i in range(10**5)] for i in range(c)]
for i in range(n):
  for j in range(l[i][0],l[i][1]+1):
    L[l[i][2]-1][j]=1
ans=[]
for i in range(10**5):
  ct=0
  for j in range(c):
    ct+=L[j][i]
    ans.append(ct)
print(max(ans))

### FIXED CODE ###

n,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[[0 for i in range(10**5+1)] for i in range(c)]
for i in range(n):
  for j in range(l[i][0],l[i][1]+1):
    L[l[i][2]-1][j]=1
ans=[]
for i in range(10**5+1):
  ct=0
  for j in range(c):
    ct+=L[j][i]
    ans.append(ct)
print(max(ans))
D,N = map(int,input().split())
ans = []
for i in range(10000000):
  if i%(100**D) == 0:
    ans.append(i)
    if len(ans) == N
print(ans[N])


### FIXED CODE ###

import sys
d,n = map(int,input().split())
num = 100**d
if n == 100:
  print(101*num)
  sys.exit()
if d == 0:
  print(n)
else:
  print((100**d)*n)
n = int(input())
tastes = list(map(lambda x:int(x), input().split()))

ans = 0

while len(tastes)>0:
    x = tastes[0]
    del tastes[0]
    for y in tastes:
        ans += x * y
            
print(ans)


### FIXED CODE ###

a, b = list(map(lambda x: int(x), input().split()))

ans = max(0, a - (2*b))

print(ans)
S = int(input())
h = 46979 / 3600
m = 179 / 60
s = 46979 % 60
pirnt(h, m, s, sep=':')

### FIXED CODE ###

S = int(input())
h = S // 3600
m = S % 3600 // 60
s = S % 3600 % 60
print(h,m,s,sep=':')
# -*- coding:utf-8 -*-

from collections import defaultdict

N, Q = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N-1)]
px = [tuple(map(int, input().split())) for _ in range(Q)]

parent_map = {b: a for a, b in ab}
child_map = defaultdict(list)
for parent, child in ab:
    child_map[parent].append(child)

operation_map = defaultdict(int)
for p, x in px:
    operation_map[p] += x

counter = [0] * N


def count(parent_no, parent_counter):
    for child_no in child_map[parent_no]:
        child_count = parent_counter + operation_map[child_no]
        counter[child_no-1] = child_count
        count(child_no, child_count)


counter[0] = operation_map[1]
count(1, counter[0])

print(' '.join(map(str, counter)))


### FIXED CODE ###

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

from collections import defaultdict

N, Q = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N-1)]
px = [tuple(map(int, input().split())) for _ in range(Q)]

parent_map = {b: a for a, b in ab}
child_map = defaultdict(list)
for parent, child in ab:
    child_map[parent].append(child)

operation_map = defaultdict(int)
for p, x in px:
    operation_map[p] += x

counter = [0] * N

counter[0] = operation_map[1]
stack = list(child_map[1])
node_no = 0
while True:
    try:
        node_no = stack.pop()
    except IndexError:
        break

    parent_no = parent_map[node_no]
    counter[node_no - 1] = counter[parent_no - 1] + operation_map[node_no]
    stack += list(child_map[node_no])

print(' '.join(map(str, counter)))
N = int(input())
h_s = list(map(int, input().split()))+[0]*10
# print(h_s)
dp = [float("inf")]*(N+10)
dp[0] = 0

for i in range(N):
    for j in range(1, 3):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h_s[i]-h_s[i+j]))

print(dp[N-1])

### FIXED CODE ###

N, K = map(int, input().split())
h_s = list(map(int, input().split()))+[0]*K
# print(h_s)
dp = [float("inf")]*(N+K)
dp[0] = 0
 
for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h_s[i]-h_s[i+j]))
 
print(dp[N-1])
def f2(n):
    c = len(n)-1
    nn = n[1:]
    s = c*(c-1)//2 * 9*9 
    s += c * (int(n[0])-1)*9
    s += (len(nn)-1)*9 + int(nn[0])
    return s

n = input()
k = int(input())

if k == 1:
    print((len(n)-1)*9 + int(n[0]))
if k == 2:
    print(f2(n))

if k == 3:
    c = len(n)-1
    nn = n[1:]
    s = c*(c-1)*(c-2)//(3*2) * 9*9*9
    s += (int(n[0])-1) * c*(c-1)//2 * 9*9 
    s += f2(nn)
    print(s)

### FIXED CODE ###

def f2(n):
    c = len(n)-1
    nn = n[1:]
    s = c*(c-1)//2 * 9*9 
    s += c * (int(n[0])-1)*9
    nn = str(int(nn))
    s += (len(nn)-1)*9 + int(nn[0])
    return s

n = input()
k = int(input())

if k == 1:
    print((len(n)-1)*9 + int(n[0]))
if k == 2:
    if len(n) >= 2:
        print(f2(n))
    else:
        print(0)
        
if k == 3:
    if len(n) >= 3:
        c = len(n)-1
        nn = n[1:]
        nn = str(int(nn))
        s = c*(c-1)*(c-2)//(3*2) * 9*9*9
        s += (int(n[0])-1) * c*(c-1)//2 * 9*9 
        if len(nn) >= 2:
            s += f2(nn)
        print(s)
    else:
        print(0)
n=int(input())
p=[int(input()) for i in range(n)]
print(sum(p)+max(p//2))

### FIXED CODE ###

n=int(input())
p=[int(input()) for i in range(n)]
print(sum(p)-max(p)//2)
a,b=map(int,input().split())
if (a+b)%2===0:
    print((a+b)//2)
else("IMPOSSIBLE")


### FIXED CODE ###

a,b=map(int,input().split())
if (a+b)%2==0:
    print((a+b)//2)
else:
    print("IMPOSSIBLE")
n = int(input())
s = input()

ans = 'Yes'

for i in ((n // 2) - 1):
    if s[i] != s[i + (n // 2)]:
        ans = 'No'

print(ans)
        
        


### FIXED CODE ###

n = int(input())
s = input()

ans = 'Yes'

if n % 2 != 0:
    ans = 'No'
    
for i in range(n // 2):
    if s[i] != s[i + (n // 2)]:
        ans = 'No'

print(ans)
from math import gcd

n = int(input())


def lcm(a, b):
    return a * b // gcd(a, b)


ans = 1
for _ in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(ans)


### FIXED CODE ###

from fractions import gcd

n = int(input())


def lcm(a, b):
    return a * b // gcd(a, b)


ans = 1
for _ in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(ans)
in = list(map(int, input().split()))
s = sum(in)
if s>21:
  print('burst')
else:
  print('win')

### FIXED CODE ###

nums = [int(e) for e in input().split()]

s = sum(nums)
if s>21:
  print('bust')
else:
  print('win')