Harryxun/stf_run huggingface dataset:
#import sys
#input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    alledge.append((a-1,b-1))
if n==2:
    print(0)
    exit()


def f(x,y,c):
    c += 1
    for e in edge[x]:
        if e == y:
            continue
        if c > d:
            used[e] = 1
        f(e,x,c)


if k % 2 == 0:
    d = k//2
    res = []
    for i in range(n):
        used = [0]*n
        f(i,-1,0)
        res.append(sum(used))
    print(min(res))
else:
    d = (k-1)//2
    res = []
    for e1 in alledge:
        used = [0]*n
        f(e1[0],e1[1],0)
        f(e1[1],e1[0],0)
        res.append(sum(used))
    print(min(res))


### FIXED CODE ###

import sys
#input = sys.stdin.readline
n,k = map(int,input().split())
edge = [[] for i in range(n)]
alledge = []
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    alledge.append((a-1,b-1))

def f(x,y,c):
    global tmp
    c += 1
    for e in edge[x]:
        if e == y:
            continue
        if c > d:
            tmp +=1
        f(e,x,c)

sys.setrecursionlimit(4100000)

if k % 2 == 0:
    d = k//2
    ass = 2001
    for i in range(n):
        tmp = 0
        f(i,-1,0)
        ass = min(ass,tmp)
    print(ass)
else:
    d = (k-1)//2
    ass = 2001
    for e1 in alledge:
        tmp = 0
        f(e1[0],e1[1],0)
        f(e1[1],e1[0],0)
        ass = min(ass,tmp)
    print(ass)
t=int(input())
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif b>d:
    print("No")
  elif c>b:
    print("Yes")
  else:
    if b-gcd(b,d)+a%gcd(b,y)>c:
      print("No")
    else:
      print("Yes")

### FIXED CODE ###

t=int(input())
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif b>d:
    print("No")
  elif c>b:
    print("Yes")
  else:
    if b-gcd(b,d)+a%gcd(b,d)>c:
      print("No")
    else:
      print("Yes")
s = str(input())
odd = ['R', 'U', 'D]
even = ['L', 'U', 'D']
tmp = 0

for i in range(len(s)):

    if i%2!=0 and s[i] in odd:
       tmp += 1
    elif i%2==0 and s[i] in even:
        tmp += 1

print('Yes' if tmp==len(s) else 'No')

### FIXED CODE ###

s = str(input())
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
tmp = 0

for i in range(len(s)):
    if i%2==0 and s[i] in odd:
        tmp += 1
    elif i%2!=0 and s[i] in even:
        tmp += 1

print('Yes' if tmp==len(s) else 'No')
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
m = map(int, raw_input().split())

def solve(i, m):
 if i == m:
  return true
 if i > n:
  return false
 res = solve(i + 1, m) || solve(i + 1, m - A(i))
 return res
 
for j in range(0, q-1):
 if m == solve(j, m(j)):
  print "yes"
 else:
  print "no"

### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
m = map(int, raw_input().split())

def solve(i, m):
 if m == 0:
  return True
 if i >= n or m > sum(A):
  return False
 res = solve(i+1, m) or solve(i+1, m-A[i])
 return res

for j in range(0, q):
 if solve(0, m[j]):
  print 'yes'
 else:
  print 'no'
def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for b in name:
		if i, b in enumerate(boin[:-1]):
			c += name[i+1]
	
	return c

while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length):
		s = set([name[:i] for name in names])
		if len(set) == n:
			print i
			break

### FIXED CODE ###


def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for i, b in enumerate(name[:-1]):
		if b in boin:
			c += name[i+1]
	
	return c

	
while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		#print tmp
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length+1):
		s = set([name[:min(i, len(name))] for name in names])
		if len(s) == n:
			print i
			n = 0
			break
			
	if n != 0:
		print -1
from collections import deque
import sys
n = int(input())
if n == 1:
    print('a')
    sys.exit()

q = deque([])
q.append((1, '1'))
cur = 1
while cur != n:
    num = len(q)
    j = 0
    while j < num:
        a, b = q.popleft()
        for i in range(1, a+2):
            q.append((i, b + str(i)))
        j += 1
    cur += 1

d = dict()
for i in range(1, n+1):
    d[str(i)] = chr((i-1) + 97)

for i in range(len(q)):
    a, b = q.popleft()
    print(b.translate(str.maketrans(d)))


### FIXED CODE ###

from collections import deque
import sys
n = int(input())
if n == 1:
    print('a')
    sys.exit()

q = deque([])
q.append((1, 'a', '1'))
cur = 1
while cur != n:
    num = len(q)
    j = 0
    while j < num:
        a, b, c = q.popleft()
        for i in range(1, max(map(int, list(c)))+2):
            q.append((i, b + chr(96+i), c + str(i)))
        j += 1
    cur += 1

for i in range(len(q)):
    a, b, c = q.popleft()
    print(b)
l = raw_input().split()
N = int(l[0])
K = int(l[1])
count = 0
numbers = list(range(1, N+1))
while True:
    if len(numbers) >= K:
        numbers.pop(0)
        count = count + 1
    else:
        print(count)
        break


### FIXED CODE ###

t = input()
l = t.split(" ")
N = int(l[0])
K = int(l[1])
count = 0
numbers = list(range(1, N+1))
while True:
    if len(numbers) >= K:
        numbers.pop(0)
        count = count + 1
    else:
        print(count)
        break
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=0
            else:
                right_max = max(Arr[i+1:])
    
        print(right_max)
    
    if i == N-1:
        return
    
    left_max=max(n,left_max)
    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))


### FIXED CODE ###

N = int(input())
Arr = [int(input()) for i in range(N)]

left_max=0
right_max=max(Arr)

for i in range(N):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=left_max
                
            else:
                right_max = max(Arr[i+1:])

        print(right_max)

    if i == N-1:
        break
    left_max=max(n,left_max)
w, a, b = map(int, input().split())
if b >=  a+w:
   print(b-a-w)
elif b+w<= a:
   print(a-b-w)
else:
   print(0)

### FIXED CODE ###

n = int(input())
p = 1
for i in range(1, n+1):
   p = p * i
   p = p % (10**9+7)
print(p)
n=int(input())
a=[int(input()) for i in range(n)]
s=sum(a)
ans=round(s/n)
count=0
for i in range(n):
    count+=(a[i]-ans)**2
print(count)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ave=round(sum(a)/n)
a=[(x-ave)**2 for x in a]
print(sum(a))
k = int(input())
a,b = map(int, input().sprit())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)

    


### FIXED CODE ###

k = int(input())
a,b = map(int,input().split())
ans = 'NG'
for i in range(a,b+1) :
  if i%k == 0 : 
    ans = 'OK'

print(ans)
n =(int)(input().split())
ans=0
for i in range(n):
  if i*i <= n:
    ans =i
print(ans)

### FIXED CODE ###

n=(int)(input())
ans =1
for i in range(n):
  for j in range(n):
    p=j+2
    if i**p <=n:
      ans=max(ans,i**p)
    else:
      break
print(ans)
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
ans=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(int(ans))
else:
    for i in range(max_A):
        j=max_A-i
        if lines[j]>=4:
            if long_line>0:
                ans=j*long_line
                break
            else:
                ans=j*j
                break
        elif lines[j]>=2:
            if long_line>0:
                ans=j*long_line
                break
            else:
                long_line=j
print(int(ans))


### FIXED CODE ###

#ABC071C
N=int(input())
A=list(map(int,input().split()))
A_sorted=sorted(A,reverse=True)
long_line=0
lines=1
for i in range(N-1):
    if A_sorted[i]==A_sorted[i+1]:
        lines+=1
    if A_sorted[i]!=A_sorted[i+1] or i==N-2:
        if lines>=4:
            if long_line>0:
                print(long_line*A_sorted[i])
                exit()
            else:
                print(pow(A_sorted[i], 2))
                exit()
        elif lines>=2:
            if long_line>0:
                print(long_line * A_sorted[i])
                exit()
            else:
                long_line=A_sorted[i]
        lines=1
print(0)
import math

N, X = [int(n) for n in input().split()]
xs = [int(n) - X for n in input().split()]

if len(xs) > 1:
    m = min(xs)
    xs = [n - m for n in xs]
    g = math.gcd(xs[0], xs[1])
    for n in xs[2:]:
        g = math.gcd(g, n)
    print(g)
else:
    print(xs[0])


### FIXED CODE ###

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

N, X = [int(n) for n in input().split()]
xs = [int(n) for n in input().split()]

xs.append(X)

m = min(xs)
xs = [n - m for n in xs]
g = gcd(max(xs[0], xs[1]), min(xs[0], xs[1]))
for n in xs[2:]:
    g = gcd(max(g, n), min(g, n))
print(g)
n, m = map(int,input())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i], s[i] = map(str, input().split())
for i in range(m):
    p[i] = int(p[i])

ans1 = 0
ans2 = 0

aclis = [0] * n
walis = [0] * n



for i in range(m):
    if s[i] == 'AC':
        aclis[p[i]] = True
        ac += 1

    if aclis[p[i]] == 0:
        walis[p[i]] += 1
ans1 = aclis.count('True')

for i in range(n):
    if aclis[i] == True:
        ans2 += walis[i]

print(ans1, ans2)

### FIXED CODE ###

n, m = map(int,input().split())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i], s[i] = map(str, input().split())
for i in range(m):
    p[i] = int(p[i])

ans1 = 0
ans2 = 0

aclis = [0] * (n+1)
walis = [0] * (n+1)


for i in range(m):
    if s[i] == 'AC':
        aclis[p[i]] = 1



    elif aclis[p[i]] == 0 and s[i] == 'WA':
        walis[p[i]] += 1
ans1 = aclis.count(1)
#print(aclis)
#print(walis)

for i in range(n+1):
    if aclis[i] == 1:
        ans2 += walis[i]


print(ans1, ans2)
a = int(input())
b = int(input())

x = b//(a-1)

print(x)


### FIXED CODE ###

import math
A, B = list(map(int, input().split()))
print(math.ceil((B-1)/(A-1)))
n = int(input())
a = list(map(int, input().split()))
candidate = []
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    if dd[k] >= 2:
        candidate.append(int(k))
candidate.sort(reverse=True)
if len(candidate) < 2:
    print(0)
else:
    print(candidate[0] * candidate[1])

### FIXED CODE ###

import collections
dd = collections.defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
candidate = []
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    if dd[k] >= 2:
        candidate.append(int(k))
    if dd[k] >= 4:
        candidate.append(int(k))
candidate.sort(reverse=True)
if len(candidate) < 2:
    print(0)
else:
    print(candidate[0] * candidate[1])
a = input()
res = a // 2
if a % 2 > 0:
  res += 1
print(res)

### FIXED CODE ###

a = int(input())
res = a // 2
if a % 2 > 0:
  res += 1
  
print(res)
s = input()
k = int(input())
l = len(s)
print(sorted(set(s[i:j] for i, j in combinations(range(l+1), 2) if j - i <= k))[k-1])

### FIXED CODE ###

from itertools import*
s = input()
k = int(input())
l = len(s)
print(sorted(set(s[i:j] for i, j in combinations(range(l+1), 2) if j - i <= k))[k-1])
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

### FIXED CODE ###

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

kill = 0

if A[0] >= B[0]:
  kill += B[0]
  B[0] = 0
else:
  kill += A[0]
  B[0] -= A[0]

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

if A[N] <= B[N-1]:
  kill += A[N]
else:
  kill += B[N-1]

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

### FIXED CODE ###

a,b = map(int, input().split())
print("Even") if (a * b) % 2 == 0 else print("Odd")
n = int(input())
a = sorted(map(int,input().split()))
print(a[n-1]-a[0])

### FIXED CODE ###

n = int(input())
if n % 2 == 0:
	print(n)
else:
  	print(n*2)
N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

for j in range(1,N):
    for i in range(max(0,j-K),j):
        dp[j] = min(dp[j],dp[i] + abs(H[j]-H[i]))
print(dp[-1])

### FIXED CODE ###

def func():
    N, K = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    
    dp = [0]*N
    for i in range(1, N):
        L = []
        for j in range(max(0, i-K), i):
            L.append(dp[j] + abs(H[i] - H[j]))
        dp[i] = min(L)

    print(dp[-1])
    
if __name__=="__main__":
    func()
import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = {i:i for i in range(0, n+1)}
sizes = {i:1 for i in range(0, n+1)}

hd = collections.Counter()

adj = collections.defaultdict(set)

def f(parent, u):
	if parent[u] != u: 
		parent[u] = f(parent, parent[u])
	return parent[u]

for a,b in friendships:
	if a != b:
		pa,pb = f(parent, a), f(parent, b)
		
		adj[a].add(b)
		adj[b].add(a)

		if pa != pb:
			parent[pb] = pa
			sizes[pa] += sizes[pb]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1
"""
hd[u] = k
u has k disses in its connected component
"""

print ' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1)  for u in range(1, n+1)])

### FIXED CODE ###

import collections

n,m,k = map(int,raw_input().split(' '))

friendships = [map(int, raw_input().split(' ')) for _ in range(m)]
disses = [map(int, raw_input().split(' ')) for _ in range(k)]

parent = {i:i for i in range(0, n+1)}
sizes = {i:1 for i in range(0, n+1)}

hd = collections.Counter()

adj = collections.defaultdict(set)

def f(parent, u):
	if parent[u] != u: 
		parent[u] = f(parent, parent[u])
	return parent[u]

for a,b in friendships:
	if a == b: continue

	pa,pb = f(parent, a), f(parent, b)
	
	adj[a].add(b)
	adj[b].add(a)

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in disses:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1
"""
hd[u] = k
u has k disses in its connected component
"""

print ' '.join([str(sizes[f(parent,u)] - len(adj[u]) - hd[u] - 1)  for u in range(1, n+1)])
#ABC 072 C
N=int(input())
A=[int(j) for j in input().split()]
cnt=[0]*(10**5)
for a in A:
    cnt[a]+=1
    cnt[a+1]+=1
    cnt[a+2]+=1
print(max(cnt))

### FIXED CODE ###

#ABC 072 C
N=int(input())
A=[int(j) for j in input().split()]
cnt=[0]*(10**6)
for a in A:
    cnt[a]+=1
    cnt[a+1]+=1
    cnt[a+2]+=1
print(max(cnt))
import sys

# N: コマ数
# M: 地点数

# N,M,*X = map(int, open(0).read().split())

# コマ数が地点数以上の場合、各地点にコマを配置できる
# よって 0 回の移動で目的を達成できる
if N >= M:
    print(0)
    sys.exit()

X.sort()
ans = []
for i in range(M-1):
    ans.append(abs(X[i+1] - X[i]))

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

### FIXED CODE ###

import sys

# N: コマ数
# M: 地点数

N,M,*X = map(int, open(0).read().split())

# コマ数が地点数以上の場合、各地点にコマを配置できる
# よって 0 回の移動で目的を達成できる
if N >= M:
    print(0)
    sys.exit()

X.sort()
ans = []
for i in range(M-1):
    ans.append(abs(X[i+1] - X[i]))

ans.sort(reverse=True)
print(X[-1] - X[0] - sum(ans[:N-1]))
N = input()
print(((N + 1) // 2) / N)

### FIXED CODE ###

N = int(input().strip())
print(((N + 1) // 2) / N)
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

digit = max(s)

ans = []

for i in range(10 ** digit + 1,10 ** (digit + 1)):
    num = str(i)
    flg = 0
    for j in range(m):
        if num[s[j]-1] == str(c[j]):
            flg = 1
        else:
            flg = 0
            break
    if flg == 1:
        ans.append(i)

if ans:
    print(min(ans))
else:
    print(-1)

### FIXED CODE ###

n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    val1,val2 = map(int,input().split())
    s.append(val1)
    c.append(val2)

for i in range(1000):
    if len(str(i)) == n:
        flg = True
        for j in range(m):
            if int(str(i)[s[j] - 1]) != c[j]:
                    flg = False
        if flg:
            print(i)
            break
if not flg:
    print(-1)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

import itertools

n = int(input())
abli = [tuple(map(int, input().split())) for i in range(n)]

leftsum = sum(map(lambda x: x[0], abli))
rightsum = sum(map(lambda x: x[1], abli))

maxminel = max(enumerate(abli), key=lambda x: 10**10*min(x[1])+max(x[1]))
maxminmax = max(abli[maxminel[0]])
del abli[maxminel[0]]
flattenli = list(itertools.chain.from_iterable(abli))
flattenli.sort()
tmpans = sum(flattenli[:n])
if flattenli[n] > maxminmax:
    tmpans = tmpans-flattenli[n]+maxminmax


print(min(leftsum, rightsum, tmpans))


### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC028 C
"""

from operator import itemgetter

n = int(input())
abli = []
for i in range(n):
    a, b = map(int, input().split())
    abli.append((a, i, 0))
    abli.append((b, i, 1))

abli.sort(key=itemgetter(0))
tmpans0 = sum(map(itemgetter(0), abli[:n]))
aiset = set([i for x, i, aorb in abli[:n] if not aorb])
biset = set([i for x, i, aorb in abli[:n] if aorb])
flag = bool(set.intersection(aiset, biset))


y, j, arob2 = abli[n]
z, k, arob3 = abli[n+1]

if flag:
    tmpans = tmpans0
else:
    min1 = y-max([x for x, i, aorb in abli[:n] if j != i])
    min2 = z-max([x for x, i, aorb in abli[:n] if j == i])
    tmpans = tmpans0 + min(min1, min2)

leftsum = sum([aa for aa, i, aorb in abli if not aorb])
rightsum = sum([bb for bb, i, aorb in abli if aorb])

print(min(leftsum, rightsum, tmpans))
n = raw_input()
a = map(int raw_input().split())
print "min(a) max(a) sum(a)"

### FIXED CODE ###

n = raw_input()
a = map(int, raw_input().split())
print ("%d %d %d") % (min(a), max(a), sum(a))
inp = input().split(" ")
N = int(inp[0])
R = int(inp[1])
if N >= 10:
    iner_r = R
else:
    iner_r  = R + 100*(10-N)
return iner_r

### FIXED CODE ###

n,r= map(int,input().split())
if n >= 10:
    print(r)
else:
    r  = r + 100*(10-n)
    print(r)
N = int(input())
L = list(map(int, input().split()))

L.sort()
#print(L)

count = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        L_ = L[j+1:]
        #print(L[i] + L[j], ">", L_, "?")
        key = len(L_) // 2
        #print("init key", key)
        past_key = 0
        n = 2
        while key and N > key:
            n *= 2
            if L[i] + L[j] > L_[key]:
                key += round(len(L_) / n)
            elif L[i] + L[j] <= L_[key]:
                #print(n, round(key / n))
                key -= round(len(L_) / n)
            
            if past_key == key:
                break
            else:
                past_key = key
            #print("next key", key)
            
        if L[i] + L[j] > L_[key]:
            count += key + 1
            

print(count)

### FIXED CODE ###

def fnt(arr,n): 
  
     
     
     
    count = 0
  
     
    for i in range(0,n-2): 
  
         
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
             
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
             
            if(k>j): 
                count += k - j - 1
  
    return count
 
 
n=int(input())
arr=input()
arr=arr.split()
arr=list(map(int,arr))
arr.sort()
print(fnt(arr,n))
c = 0
s.append("U")

for i in range(-(-l//2)):
    d = 2*i
    if s[d] == "L":
        print("No")
        c = 1
        break
    if s[d+1] == "R":
        print("No")
        c = 1
        break
if c == 0:
    print("Yes")

### FIXED CODE ###

S = input()
l = len(S)
s = list(S)
c = 0
s.append("U")

for i in range(-(-l//2)):
    d = 2*i
    if s[d] == "L":
        print("No")
        c = 1
        break
    if s[d+1] == "R":
        print("No")
        c = 1
        break
if c == 0:
    print("Yes")
s,c = map(int,input().split())

if s<c/2:
    c_s = (c-2*s)//4
    sc = s
    print(c_s+sc)
else:
    sc = (min(s,c//2)
    print(sc)

### FIXED CODE ###

s,c = map(int,input().split())
if s<c/2:
    print((c-2*s)//4+s)
else:
    print(min(s,c//2))
import math
r=int(input())
x=r*math.pi
print(str("{:.6f}".format(r*x)+' '+str("{:.6f}".format(2*x))))

### FIXED CODE ###

from math import pi
r=float(input())
print("{} {}".format(r*r*pi,2*r*pi))
import sys
sys.setrecursionlimit(500000)
N, Q = map(int, input().split())
g = [[] for i in range(N)] 
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

plus_list = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    plus_list[p-1] += x

ans = [0] * N
def dfs(v, p):
    ans[v] = plus_list[v] + ans[p]
    for i in range(len(g[v])):
        x = g[v][i]
        if x != v:
            dfs(x, v)

dfs(0, -1)
print(*ans)

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def dfs(fr, now, num):
    global graph, addsum, ans
    tmp = num + addsum[now]
    for a in graph[now]:
        if a == fr:
            continue
        dfs(now, a, tmp)
    ans[now] = tmp


def main():
    global graph, addsum, ans
    N, Q = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a -= 1; b -= 1
        graph[a].append(b)
        graph[b].append(a)
    addsum = [0]*N
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        addsum[p] += x
    
    ans = [0]*N
    dfs(-1, 0, 0)

    print(*ans)


if __name__ == "__main__":
    main()
import numpy as np
 
n = int(input())
hh = np.array([])
for i in range(n):
    hh.append(input())
 
for i in range(len(hh)-1):
   if hh[i] < hh[i+1]:
       hh[i+1] -= 1
np.diff(hh-1, n=1)
 
minus = [i for i in np.diff(hh-1, n=1) if i < 0]
 
if len(minus) > 0:
    print('No')
else:


### FIXED CODE ###

import numpy as np
 
n = int(input())
h = list(map(int, input().split()))
 
h = np.array(h)
 
for i in range(len(h)-1):
   if h[i] < h[i+1]:
       h[i+1] -= 1
np.diff(h-1, n=1)
 
minus = [i for i in np.diff(h-1, n=1) if i < 0]
 
if len(minus) > 0:
    print('No')
else:
    print('Yes')
S=input()
K=int(input())
S2 = S*2
tmp=0
tmp2=0
for i in range(1,S):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,S2):
    if S2[i-1]==S2[i]:
        S2[i]="0"
        tmp2 += 1
print(tmp+(tmp2-tmp)*(K-1))

### FIXED CODE ###

S=list(input())
K=int(input())
S2 = S*2
tmp=0
tmp2=0

if all([S[i] == S[0] for i in range(1,len(S))]):
    print((len(S)*K)//2)
    exit()
for i in range(1,len(S)):
    if S[i-1]==S[i]:
        S[i]="0"
        tmp += 1

for i in range(1,len(S2)):
    if S2[i-1]==S2[i]:
        S2[i]="0"
        tmp2 += 1

print(tmp+(tmp2-tmp)*(K-1))