peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
ss = {i:list(input()) for i in "abc"}
x = ss['a'].pop(0)
while True:
  if not ss[x]:
    print(x.upper())
    break
  else:
    x = ss[x].pop(0)
# Judge status: Accepted
import sys

h, w = list(map(int, input().split()))

if h == 1 or w == 1:
    print(1)
    sys.exit()

print(int((h * w + 1)/2))
# Judge status: Accepted
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    k, n = map(int, readline().rstrip().split())
    A = sorted(list(map(int, readline().rstrip().split())))
    maxA = k + A[0] - A[n-1]
    for i in range(n-1):
        a = abs(A[i+1] - A[i])
        maxA = max(maxA, a)
    print(k - maxA)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n,m,k = map(int, input().split())

for i in range(n):
    for j in range(m):
        if j*(n-i) + i*(m-j) == k:
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
#b
s = input()
v = input()
ans = 0
for i in range(len(s)-len(v)+1):
    count = 0
    for j in range(len(v)):
        if s[i+j] == v[j]:
            count += 1
    if count > ans:
        ans = count
print(len(v) - ans)
# Judge status: Wrong Answer
N = int(input())
B = [int(i) for i in input().split()]

res = 0
for i in range(N-2):
  res += min(B[i], B[i+1])
res += B[-1]

print(res)
# Judge status: Accepted
text = str(input())
cnt = 0

for i in text:
    if i == "5":
        cnt += 1
    if i == "7":
        cnt += 2

if cnt == 4:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
import collections


N = int(input())
a = list(map(int,input().split()))

A = 0
for i in a:
    A = A^i

for i in a:
    print(i^A)
# Judge status: Wrong Answer
n = int(input())
b = list(map(int,input().split()))
a = [-1]*n
a[0] = a[1] = b[0]
a[-1:] = b[-1:]
for i in range(n-3):
    a[i+2] = min(b[i+1],b[i+2])
print(sum(a))
# Judge status: Accepted
A,B=map(int,input().split())
if A+B>=24:
  print(A+B-24)
else:
  print(A+B)
# Judge status: Wrong Answer
H, N = map(int, input().split())
dp = [[float("inf") for i in range(H+1)] for j in range(N+1)]

dp[0][0] = 0

for i in range(N):
  a, b = map(int, input().split())
  
  for j in range(H):
    dp[i+1][j] = min(dp[i][j], dp[i+1][j])

    # if j-a >= 0:
      # dp[i+1][j] = min(dp[i][j], dp[i+1][j-a] + b)
    dp[i+1][min(j+a, H)] = min(dp[i+1][min(j+a, H)], dp[i+1][j] + b)


print(dp[N][H])
# Judge status: Wrong Answer
P,Q,R = map(int,input().split())

if P + R <= P + Q and P + R <= R + Q:
   answer = P + R
elif P + Q <= P + R and P + Q <= R + Q:
	answer = P + Q
elif R + Q <= P + R and R + Q <= R + Q:
	answer = P + Q
  
print(answer)
# Judge status: Wrong Answer
n=int(input())
li=list(map(int,input().split()))
ans=1
if 0 in li:
    print('-1')
    import sys
    sys.exit()
    
for l in li:
    ans*=l
    #print(ans)
    if ans > 10**18:
        print('-1')
        break
else:
    print(ans)
# Judge status: Wrong Answer
if __name__ == '__main__':
    tmp = int(input())
    l = [2, 1]
    ans = 0
    for i in range(tmp - 1):
        ans = l[i] + l[i + 1]
        l.append(ans)
    print(ans)
# Judge status: Accepted
# C - Lower
def main():
    n = int(input())
    h = list(map(int, input().split()))
    cnt = 0
    ans = []

    if n == 1:
        print(0)
        exit()
    for i in range(n-1):
        if h[i] >= h[i+1]:
            cnt += 1
            if i == n-2:
                ans.append(cnt)

        else:
            ans.append(cnt)
            cnt = 0
    print(max(ans))


if __name__ ==  "__main__":
    main()
# Judge status: Wrong Answer
import math
a, b, c = map(int, input().split())
rt_ab = math.sqrt(a*b)
if a + b + 2*rt_ab < c:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, m=map(int, input().split())
a=[int(input()) for i in range(m)]
mod=10**9 +7
dp=[1]*(n+1)
dp[0]=1
dp[1]=1

for i in range(m):
    dp[a[i]] = 0

for i in range(2, n+1):
    
    if dp[i] > 0:
        dp[i]=(dp[i-1]+dp[i-2])%mod

print(dp[n])
# Judge status: Wrong Answer
N, R = map(int, input().split())
if N < 10:
    a = 100 * (10^N)
else:
    a = 0
print(a + R)
# Judge status: Accepted
n = int(input())
ans = (10 ** n - 9 ** n * 2 + 8 ** n) % (10 ** 9 + 7)
print(ans)
# Judge status: Wrong Answer
import sys
from collections import defaultdict
from collections import deque

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

graph = defaultdict(list)

for _ in range(m):
    a, b = map(lambda x: int(x), input().split())
    graph[a].append(b)
    graph[b].append(a)

q = deque([1])
cnt = 0

while q and cnt < 2:
    cnt += 1
    node = q.popleft()
    after = graph[node]

    for a in after:
        if a == n:
            print("POSSIBLE")
            sys.exit()
        q.append(a)

print("IMPOSSIBLE")
# Judge status: Accepted
import numpy as np
a,b=map(str,input().split())
ab=int(a+b)
ab_sqrt=np.sqrt(ab)
if(int(ab_sqrt)==ab_sqrt):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
k,n=map(int, input().split())
a=list(map(int, input().split()))
ans = a[0]+k-a[n-1]
for start in range(1,n):
    ans = max(ans,a[start]-a[start-1])
    
print(k-ans)
# Judge status: Accepted
from collections import Counter
n = int(input())
a = list(map(int,input().split()))

cnt = Counter(a)
ans = 0
for k, v in cnt.items():
  tmp = v - k if k <= v else v
  ans += tmp
print(ans)
# Judge status: Wrong Answer
N = int(input())
a = 0
S = []
for i in range(N):
  S.append(input())
  for j in range(i):
    if S[i] != S[j]:
      a += 1

print(int(a/2)+1)
# Judge status: Accepted
A,B,C = map(int, input().split())
K = int(input())

AA = A
BB = B
CC = C

count = 0

for i in range(K):
    if AA < BB < CC:
        print("Yes")
        break
    elif CC <= AA or CC <= BB:
        CC *= 2
        count +=1
    elif BB <= AA:
        BB *= 2
        count +=1

if count == K:
    if AA < BB < CC:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
N = int(input())
S = [int(input()) for _ in range(N)]
if sum(S)%10 != 0:
  print(sum(S))
else:
  A = sorted(S)
  for i in A:
    if (sum(S)-i)%10 != 0:
      print(sum(S)-i)
      exit()
  print(0)
# Judge status: Wrong Answer
N = int(input())
T = 0
t = 0
ans = []
for i in range(N-1):
    C, S, F = map(int, input().split())
    for j in range(len(ans)):
        if ans[j] <= S:
            ans[j] = S+C
        else:
            ans[j] = ans[j]+F-ans[j]%F+C
    ans.append(S+C)
for a in ans:
    print(a)
print(0)
# Judge status: Wrong Answer
def str_replace_to_lower() -> str:
    len_str, target_index = map(int, input().split())
    word = input()

    new = word.replace(word[target_index - 1], word[target_index - 1].lower())
    return new


print(str_replace_to_lower())
# Judge status: Wrong Answer
n = int(input())
w = []
for i in range(n):
   w.append(input())

if (len(set(w)) < len(w)):
   print('No')
   exit()

for i in range(1, n-1):
   if (w[i][0] == w[i-1][-1] and w[i][-1] == w[i+1][0]):
      continue
   else:
      print('No')
      exit()
print('Yes')
# Judge status: Accepted
a=int(input())
b=[]
for i in range(a+1):
    if i%3==0 or i%5==0:
        continue
    else:
        b.append(i)
print(sum(b))
# Judge status: Wrong Answer
a=[]
for i in range(5):
  k = int(input())
  a.append(k)
k = int(input())

if a[4]-a[0] < k:
  print('Yay!')
else:
  print(':(')
# Judge status: Accepted
N=int(input())
S=input()

acc_e=[0]
acc_w=[0]
for i in S:
  acc_e.append(acc_e[-1])
  acc_w.append(acc_w[-1])
  if i=='E':
    acc_e[-1]+=1
  else:
    acc_w[-1]+=1

ans=N
for i in range(N):
  turn=acc_w[i]+acc_e[-1]-acc_e[i+1]
  ans=min(ans,turn)
print(ans)
# Judge status: Accepted
n = int(input())
str_n = str(n)
n_1 = str_n[0]
tmp = int(n_1+"9"*(len(str_n)-1))
ans = int(n_1) + 9*(len(str_n)-1)

if n == tmp:
    print(ans)
else:
    print(ans-1)
# Judge status: Wrong Answer
n, x, y = map(int,input().split())

ans_list = [0]*(n)
for i in range(1, n+1):
    for j in range(1, n+1):
        if i>j:
            min_dis = min(abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i)+1+abs(j-x))
            ans_list[min_dis] += 1

for i, value in enumerate(ans_list):
    print(value)
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
total = 0

curr = -2
for i in a:
    total += b[i - 1]
    if i == curr + 1:
        total += c[i - 2]
    curr = i

print(total)
# Judge status: Accepted
n, m = map(int, input().split())

l = list()
la = [0] * (n+1)
ln = [0] * (n+1)

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        la[b] = 1
    elif b == 1:
        la[a] = 1
    if a == n:
        ln[b] = 1
    elif b == n:
        ln[a] = 1

for i in range(n+1):
    if la[i]*ln[i] == 1:
        print("POSSIBLE") 
        exit()

print("IMPOSSIBLE")
# Judge status: Wrong Answer
D, N = map(int, input().split())

print((100**D) * N)
# Judge status: Accepted
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
Q,H,S,D = LI()
N = I()
min_1 = min(Q*4,H*2,S)
if 2*min_1<=D:
    ans = min_1*N
else:
    ans = N//2*D+(min_1 if N%2==1 else 0)
print(ans)
# Judge status: Wrong Answer
from collections import deque
n = int(input())
s = input()
A = deque([])
for i in range(n):
  if s[i]=='(':
    A.append(s[i])
  elif s[i]==')':
    if len(A)!=0 and A[-1]=='(':
      A.append(s[i])
    elif len(A)==0 or A[-1]==')':
      A.appendleft("(")
      A.append(")")
cou = 0
for i in range(len(A)):
  if A[i]==')':
    cou = i
amari = len(A)-(cou+1)
#print(amari)
for j in range(amari):
  A.append(")")
print("".join(A))
# Judge status: Accepted
from collections import Counter
N, = list(map(int,input().split()))
a  = list(map(int,input().split()))
c  = Counter()
for ai in a:
    for b in range(ai-1,ai+2):
        c[b] += 1
print(max(c.values()))
# Judge status: Accepted
P, Q, R = map(int, input().split())
print(P+Q+R-max(P, max(Q, R)))
# Judge status: Accepted
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    for i in range(n):
        num_list[i] -= 1

    count = 0
    for i in range(n-1):
        if num_list[i] == i:
            num_list[i], num_list[i+1] = num_list[i+1], num_list[i]
            count += 1

    if num_list[n-1] == n-1:
        num_list[i], num_list[i-1] = num_list[i-1], num_list[i]
        count += 1

    print(count)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a = int(input())
b = int(input())
h = int(input())

S= int((a+b)*h//2)
# Judge status: Accepted
a,b,c = map(int,input().split())

if (b // a) > c:
    print(c)
else:
    print(b // a)
# Judge status: Accepted
N = input()

a = N.count("0")
b = N.count("1")

if a == 0 or b == 0:
    ans = 0
else:
    ans = min(a, b) * 2
print(ans)
# Judge status: Wrong Answer
n=int(input())
a=2
b=1
for _ in range(n-1):
    a,b=b,a+b
    print(a,b)
print(b)
# Judge status: Wrong Answer
N=int(input())
txy=[list(map(int,input().split())) for _ in range(N)]
txy.insert(0,[0,0,0])
answer="Yes"

for i,t in enumerate(txy):
    if i>=1:
        base=abs(t[1]-txy[i-1][0])+abs(t[2]-txy[i-1][2])
        time=t[0]-txy[i-1][0]
        if base<=time and (time-base)%2==0:
            pass
        else:
            answer="No"
            break
print(answer)
# Judge status: Wrong Answer
n=int(input());print(800*n-200*n//15)
# Judge status: Accepted
li = list(map(int, input().split()))

n=0

for i in range(0,2):
  if li[i+1] - li[i] ==0:
    n+=1
if li[2] - li[0] ==0:
  n+=1

if n==1:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
def ways_to_climb(total_steps, broken_steps):
	if total_steps < 2:
		return 0 if 1 in broken_steps else 1

	steps = [0] * (total_steps + 1)
	steps[1] = 1 if 1 not in broken_steps else 0
	steps[2] = 2 if 2 not in broken_steps else 0

	for i in range(3, len(steps)):
		if i not in broken_steps:
			steps[i] = steps[i - 1] + steps[i - 2]
		else:
			steps[i] = 0

	return steps[-1] % (10**9 + 7)

if __name__ == '__main__':
	n, m = tuple(input().split())
	n = int(n)
	m = int(m)

	broken = set()
	for i in range(m):
		broken.add(int(input()))

	print(ways_to_climb(n, broken))
# Judge status: Accepted
abc = [int(i) for i in input().split(' ')]
a = abc[0]
b = abc[1]
c = abc[2]
if c-a-b < 0:
    print('No')
else:
    if 4*a*b < (c-a-b)**2:
      print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
N = int(input())

ans = ''
while(N > 0):
  _i = (N-1) % 26
  ans = chr(ord('a') + _i) + ans
  N //= 26
  
print(ans)
# Judge status: Accepted
n = int(input())
l = []

for i in range(n+1):
    if 2**i <= n:
        l.append(2**i)
    
print(max(l))
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
w = [0 for i in range(8)]
count = 0
sup = 0
for i in a:
    if i < 3200 and w[i//400]==0:
        count+=1
        w[i//400] += 1
    elif i >= 3200:
        sup += 1
if count == 0:
    print(1,sup)
elif sup == 0:
    print(count,count)
else:
    b= count+sup
    print(count,b)
# Judge status: Accepted
N, K = map(int, input().split())
D = list(input().split())

for i in range(N, 100000):
    for j in D:
        if j in str(i):
            break
    else:
        print(i)
        break
# Judge status: Accepted
n =int(input())
ls = list(map(int,input().split()))
a = [0 for i in range(n)]
a[0] = ls[0] 
a[n-1] = ls[n-2]
for j in range(n-2):
    b = min(ls[j],ls[j+1])
    a[j+1] = b
print(sum(a))
# Judge status: Accepted
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,M,Q = inputlist()
l = [0]*Q
for i in range(Q):
    l[i] = inputlist()
li = [int(i) for i in range(1,M+1)]
from itertools import combinations_with_replacement
h = combinations_with_replacement(li,N)
ans = 0
for v in h:
    va = list(v)
    tmp = 0
    for i in range(Q):
        a,b,c,d = l[i]
        a-=1
        b-=1
        if va[b] - va[a] == c:
            tmp += d
    ans = max(tmp,ans)
print(ans)
# Judge status: Wrong Answer
from itertools import permutations

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

p = 0
q = 0
i = 0
for n in permutations(range(1,N+1)):
    if n == P:
        p = i
    elif n == Q:
        q = i
    i += 1

print(abs(p-q))
# Judge status: Accepted
s = input()

a = s[:2]
b = s[-2:]

mm = ["01","02","03","04","05","06","07","08","09","10","11","12"]

if a in mm and b in mm:
    print("AMBIGUOUS")
elif a in mm:
    print("MMYY")
elif b in mm:
    print("YYMM")
else:
    print("NA")
# Judge status: Accepted
N = int(input())

for i in range(1, 10):
  if N % i == 0 and len(str(N // i)) == 1:
    print("Yes")
    quit()

print("No")
# Judge status: Wrong Answer
A,B=map(int,input().split())
if B<A:
  temp=A
  A=B
  B=temp
while A>0:
  temp=B%A
  B=A
  A=temp
gcd=B
ans=1
setgcd=gcd
for i in range(2,setgcd):
  if gcd%i==0:
    ans=ans+1
    while gcd%i==0:
      gcd=int(round(gcd/i))
  if gcd==1:
    break
print(ans)
# Judge status: Accepted
R = int(input())
import math
print(R*2*math.pi)
# Judge status: Accepted
N_str = input()

ln = len(N_str)
ans = 0
no_mu, move_up = int(N_str[-1]), 11 - int(N_str[-1])
for i in range(2, ln + 1):
    n = int(N_str[-i])
    no_mu, move_up = n + min(no_mu, move_up), min(11 - n + no_mu, 9 - n + move_up)
print(min(no_mu, move_up))
# Judge status: Accepted
S = input()

if S[0]=="A" and S[2:-1].count("C")==1:
    if S[1:].replace("C","c").islower():
        print("AC")
    else:
        print("WA")
else:
    print("WA")
# Judge status: Accepted
n = int(input())
s = [input() for _ in range(n)]
d = {}
for w in s:
    if w not in d:
        d[w] = 0
    d[w] += 1
d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
    print(ans)
# Judge status: Accepted
##!/usr/bin/env python3
w,h,n = map(int,input().split())
hl = 0
hu = w
wl = 0
wu = h
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1: hl = max(x,hl)
  if a == 2: hu = min(x,hu)
  if a == 3: wl = max(y,wl)
  if a == 4: wu = min(y,wu)
#print(hl,hu,wl,wu)
print(max(0,(hu-hl))*max(0,wu-wl))
# Judge status: Accepted
# 初期入力
import sys
input = sys.stdin.readline
A = list(map(int, input().split()))

a =max(A)
coin =a
a -=1
A.append(a)

A.sort()
a_2 =A[1]
coin +=a_2

print(coin)
# Judge status: Wrong Answer
A=list(map(int,input().split()))
A.sort()
print(A[1]*A[2]//2)
# Judge status: Accepted
n = int(input())
aa = list(map(int, input().split()))
sol = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = aa[i], aa[j], aa[k]
            if a != b and b != c and a != c and a+b > c and a+c > b and b+c > a:
                sol += 1
print(sol)
# Judge status: Accepted
N, A, B = map(int, input().split())
S = str(input())

AB = A + B

count_all = 0
count_abroad = 0
for i in range(N):
    if S[i] == "a" and count_all < AB:
        count_all += 1
        print("Yes")

    elif S[i] == "b" and count_abroad < B and count_all <AB:
        count_all += 1
        count_abroad += 1
        print("Yes")

    else:
        print("No")
# Judge status: Accepted
a, b = input().split()

list_a = [0]*int(b)
list_b = [0]*int(a)

for i in range(0,int(b)):
    list_a[i] = int(a)*10**i

for i in range(0,int(a)):
    list_b[i] = int(b)*10**i
    
a_r = sum(list_a) 
b_r =sum(list_b)

if(a<b):
    print(str(a_r))
elif(a>b):
    print(str(b_r))
else:
    print(str(a_r))
# Judge status: Wrong Answer
N = int(input())
S = input()
x = 0
for i in range(N):
  if 'I' not in S[i:]:
    break
    
  if S[i] == 'I':
    x += 1
  else:
    x -= 1
  
print(x)
# Judge status: Accepted
n,m=(int(i) for i in input().split())
if n*2>=m:
  ans=m//2
else:
  ans=n+(m-n-n)//4
print(ans)
# Judge status: Accepted
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    y, m, d = map(int, S.split('/'))
    if m <= 4:
        print('Heisei')
    elif m > 4:
        print('TBD')

    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
print("NYOE S"[input()in"753"::2])
# Judge status: Accepted
h,n=map(int,input().split())
L=[]
for i in range(n):
    a,b=map(int,input().split())
    L.append((b/a,a,b))

dp=[100000000 for i in range(h+1)]
dp[0]=0
for i in range(h):
    for q in range(n):
        power=L[q][1]
        magic=L[q][2]
        dp[min(h,i+power)]=min(dp[min(h,i+power)],dp[i]+magic)

print(dp[h])
# Judge status: Accepted
n=int(input())
b=list(map(int,input().split()))
a=[b[0]]+[0]*(n-1)

for i in range(n-1):
    a[i]=min(a[i],b[i])
    a[i+1]=b[i]
print(sum(a))
# Judge status: Accepted
sa = input()
sb = input()
sc = input()
s = []
s.append(sa.replace('a', '0').replace('b', '1').replace('c', '2'))
s.append(sb.replace('a', '0').replace('b', '1').replace('c', '2'))
s.append(sc.replace('a', '0').replace('b', '1').replace('c', '2'))
i = 0
while s[i]!='':
    j = int(s[i][0])
    s[i] = s[i][1:]
    i = j
ans = 'ABC'

print(ans[i])
# Judge status: Accepted
a = int(input())
print(a + (a ** 2) + (a ** 3))
# Judge status: Accepted
odd = set(['R','U','D'])
even = set(['L','U','D'])
s = input()
ans = 'Yes'
for i,v in enumerate(s):
  if i % 2 != 0 and v not in even:
    ans = 'No'
    break
  elif i % 2 == 0 and v not in odd:
    ans = 'No'
    break

print(ans)
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[5]:


X = int(input())


# In[6]:


p = 0
for i in range(1,X+1):
    p += i
    if p >= X:
        print(i)
        break


# In[ ]:
# Judge status: Accepted
n,k=map(int,input().split())
ab=[]
for i in range(n):
  aa,bb=map(int,input().split())
  ab.append([aa,bb])
ab.sort(key=lambda x: x[0])
a,b=[],[]
for aa,bb in ab:
  a.append(aa)
  b.append(bb)
from itertools import accumulate
c=list(accumulate(b))
idx=-1
for i in range(n):
  if i==0:
    if 0<=k<=c[i]:
      idx=i
      break
    continue
  if c[i-1]<k<=c[i]:
    idx=i
    break
print(a[idx])
# Judge status: Accepted
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

#累積和
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    A,B = B,A
    if min(A) == N:
        break
print(*A)
# Judge status: Wrong Answer
N, K = map(int, input().split())
X = list(map(int, input().split()))
ans = float("inf")
for i in range(N - K + 1):
    left, right = X[i], X[i + K - 1]
    dist = right - left
    ans = min(abs(left) + dist, abs(right) + dist)
print(ans)
# Judge status: Accepted
N = int(input())
S = input()

cnt = []
for n in range(1, N):
    x = sorted(S[:n])
    y = sorted(S[n:])
    cnt.append(len(set(x)&set(y)))
        
print(max(cnt))
# Judge status: Accepted
import math

N=int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(N)==True:
        print(N)
        break
    N+=1
# Judge status: Accepted
import sys


def solve(inp):
    (X, A, B) = map(int, inp.readline().strip().split(' '))

    if abs(X - A) < abs(X - B):
        return "A"
    else:
        return "B"


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n,m=map(int,input().split())
A=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    A[a-1] += 1
    A[b-1] += 1
for h in range(n):
    print(A[h])
# Judge status: Accepted
r,g,b = map(int,input().split())

if (100*r + g * 10 + b)% 4 == 0: 
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
import collections
n = int(input())
a = list(map(str,input().split()))
c = collections.Counter(a)
set_a = set(a)
lists = []
print(c)
for i in set_a:
    if int(c[i]) >= 2:
       lists.append(int(i))
    if int(c[i]) >= 4:
        lists.append(int(i))
lists.sort()
lists.reverse()
print(lists)
if len(lists) > 1:
    ans = int(lists[0]) * int(lists[1])
else:
    ans = 0
print(ans)
# Judge status: Wrong Answer
S = str(input(""))
if S.endswith(('o', 'ch', 's', 'sh', 'x', 'z')):
    print(S+"es")
else:
    print(S+"s")
# Judge status: Accepted
a,b,c = map(int,input().split())

if 4*a*b < (c-a-b)**2 and c-a-b>=0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = input()

a, b = n.split()

a = int(a)
b = int(b)

for i in range(10 ** 5):
    i = i + 1
    if (i * a) % b == 0:
        print(a*i)
        break
# Judge status: Accepted
n,m=map(int,input().split())
A=set(int(input()) for i in range(m))
 
x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1
 
for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=(x[j-1]+x[j-2])%(10**9+7)
        
 
print(x[n])
# Judge status: Wrong Answer
n, m = map(int, input().split())
a = list(map(int, input().split()))
print(0)
# Judge status: Accepted
a, b = map(int, input().split())

if a % b == 0:
  print(-1)
else:
  for i in range(10**9):
    if (a * i) % b != 0:
      print(a * i)
      exit()
# Judge status: Accepted
n = int(input())
h = [int(x) for x in input().split()]

ans = 0
cur = 1
cnt = 0
while cur < n:
    if h[cur-1] >= h[cur]:
        cnt += 1
        cur += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
        cur += 1
ans = max(ans, cnt)
print(ans)
# Judge status: Wrong Answer
S = input()
ans = 1000
for i in range(len(S)-2):
  ans = min(ans, int(S[i:i+3]))
print(ans)
# Judge status: Wrong Answer
num_input=input().split()   
x=int(num_input[0])
y=int(num_input[1])
ans="No"
if x*2<=y and y<=x*3:
    if y%2==0:
        ans="Yes"
print(ans)
# Judge status: Wrong Answer
from collections import Counter

S = input()
n = len(S)
a = [int(S)]
cnt = 0

for i in range(n):
    a.append(a[i] - int(S[i])*(10**(n-i-1)))

a = Counter(list(map(lambda x: x%2019, a)))

for k, v in a.items():
    if v == 1:
        break
    cnt += v*(v-1)//2

print(cnt)
# Judge status: Wrong Answer
def main():
    N, K = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]
    H.sort()
    print(min(H[-1] - H[-K], H[K-1] - H[0]))


if __name__ == '__main__':
    main()