peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 10 ** 10
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
#print(dp)
print(dp[n-1])
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
x = A - 1
y = B - A - 1
z = N -B 

if y % 2 == 1:
  ans = (y + 1) / 2
else:
  if x >= z:
    ans = y + z + 1
  else:
    ans = y + x + 1
print(int(ans))
# Judge status: Wrong Answer
s = input()

upper = int(s[:2])
lower = int(s[2:4])

if upper <= 0 or lower <= 0:
    print('NA')
    exit()

if upper > 12:
    if lower > 31: print('NA')
    else: print('YYMM')
else:
    if lower > 31: print('MMYY')
    else: print('AMBIGUOUS')
# Judge status: Accepted
n = int(input())
def numalpha(num):
    if num <= 26:
        return chr(64+ num)
    elif num % 26 == 0:
        return numalpha(num // 26-1) + chr(90)
    else:
        return numalpha(num//26) + chr(64 + num % 26)
print(numalpha(n).lower())
# Judge status: Accepted
##B
X = int(input())
X500 = X//500
X5 = (X % 500)//5

print(X500*1000+X5*5)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0

for i in range(len(a)):
  if i == 0:
    ans += b[a[i]-1]
  elif a[i] - a[i-1] == 1:
    ans += b[a[i]-1] + c[a[i-1]-1]
  else:
    ans += b[a[i]-1]

print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
s = input()
for i in range(3):
    if s[i] == s[i+1]:
        print("Bad")
        s = 0
        break
if s != 0:
    print("Good")
# Judge status: Accepted
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
x0=0
x1=10**9
while(1):
    sum=0
    mid=(x0+x1)//2
    for i in range(n):
        sum+=math.ceil(a[i]/mid)-1
    if(sum<=k):
        x1=mid
    if(sum>k):
        x0=mid
    if(x0+1==x1):
        print(x1)
        break
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
sw="1"
ans=1

for i in range(N-1):
    if sw=="1":
        if A[i]>A[i+1]:
            sw="2"
        if A[i]<A[i+1]:
            sw="3"
    elif sw=="2":
        if A[i]<A[i+1]:
            ans+=1
            sw="1"
    elif sw=="3":
        if A[i]>A[i+1]:
            ans+=1
            sw="1"

print(ans)
# Judge status: Wrong Answer
L,R,d=map(int,input().split())
def divLR():
  return (R-L+1)//d

print(divLR())
# Judge status: Wrong Answer
import math
A, B = map(int, input().split())
gcd = 1
for i in range(2,min(A,B)):
  if A%i==0 and B%i==0:
    gcd = i
print(int(A*B/gcd))
# Judge status: Accepted
a = int(input())
b = int(input())
c = int(input())
print((a+b)*c//2)
# Judge status: Accepted
r, g, b = map(int, input().split())
num = 100 * r + 10 * g + b
ans = 'NO'
if num % 4 == 0:
    ans = 'YES'
print(ans)
# Judge status: Accepted
X, Y = map(int, input().split())

if (X % Y == 0):
    print(-1)
else:
    print(X)
# Judge status: Wrong Answer
s,w=input().split()
if s>w:print("safe")
else:print("unsafe")
# Judge status: Accepted
n=int(input())
s=[int(input()) for _ in range(n)]
s1=[si for si in s if si%10]
s.sort()
s1.sort()
ans=sum(s)
if ans%10==0:
    if s1:
        ans-=s1[0]
    else:
        ans=0
print(ans)
# Judge status: Accepted
S = input()
if set(S[0::2]) == set('h') and set(S[1::2]) == set('i') and len(S) % 2 == 0:
    ans = True
else:
    ans = False
if ans:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a=map(int,input().split())
b=input().split()
def func(a,b):
    ab=set(b)
    return len(ab)
print(func(a,b))
# Judge status: Accepted
N, T = map(int, input().split())

ans = 1001
for _ in range(N):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(c, ans)

if ans == 1001:
    print('TLE')
else:
    print(ans)
# Judge status: Wrong Answer
n = input()

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

print(max(l) < sum(l) - max(l))
# Judge status: Accepted
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
dp=[[0]*3 for _ in range(n)]
dp[0]=l[0]
for i in range(n-1):
    for j in range(3):
        dp[i+1][j]=max(dp[i][(j+1)%3]+l[i+1][j],dp[i][(j+2)%3]+l[i+1][j])
print(max(dp[n-1]))
# Judge status: Accepted
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def mod_cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * pow(q, mod - 2, mod) % mod


answer = pow(2, n, mod) - 1
answer -= mod_cmb(n, a, mod) + mod_cmb(n, b, mod)
answer %= mod
print(answer)
# Judge status: Accepted
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    if n == 1 or m == 1:
        print(1)
    else:
        ans = ((m + 1) // 2) * ((n + 1) // 2)
        ans += (m // 2) * (n // 2)
        print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
c = [0]*4
for _ in range(n):
    s = str(input())
    if s == 'AC':
        c[0] += 1
    elif s == 'WA':
        c[1] += 1
    elif s == 'TLE':
        c[2] += 1
    else:
        c[3] += 1

print('AC x '+str(c[0]))
print('WA x '+str(c[1]))
print('TLE x '+str(c[2]))
print('RE x '+str(c[3]))
# Judge status: Accepted
n, m = map(int, input().split())
low = 0
high = 100001

for i in range(m):
  l,m = map(int, input().split())
  low = max(low, l)
  high = min(high, m)
if high-low+1<0:
  print(0)
else:
  print(min(high-low+1, n))
# Judge status: Wrong Answer
import numpy as np
n=int(input())
t=np.array(input().split(' '))
num=np.zeros(n)
for a in range(n):
  num[a]=int(t[a])
a=np.sum(num)**2
b=np.sum(num**2)
x=int((a-b)/2)
x=(x-1)%(10**9+7)
print(x)
# Judge status: Accepted
def judge(c):
    if len(c) == 0:
        return 1, c, "-1"
    else:
        return 0, c[0], c[1:]


def main():
    sa = input()
    sb = input()
    sc = input()
    card = {"a": sa, "b": sb, "c": sc}
    next_player = "a"
    while True:
        now = next_player
        is_finish, next_player, card[now] = judge(card[now])
        if is_finish:
            print(now.upper())
            break


if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
L = [int(i) for i in input().split()]
print('Yes' if sum(L) > 2 * max(L) else 'No')
# Judge status: Wrong Answer
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1]*n
for i in range(m):
    print(ans)
    a,b = map(int,input().split())
    if h[a-1]>h[b-1]:
        ans[b-1] = 0
    elif h[b-1]>h[a-1]:
        ans[a-1] = 0
    else:
        print("a")
        ans[a-1] = 0
        ans[b-1] = 0
print(ans.count(1))
# Judge status: Wrong Answer
N = int(input())
s_min = 100
score = 0

for _ in range(N):
    tmp = int(input())
    score += tmp
    s_min = min(s_min, tmp)

print(score - s_min if score % 10 == 0 else score)
# Judge status: Accepted
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
count=0
for i in range(n):
    for j in range(i+1,n):
        ans=0
        for k in range(d):
            ans+=(x[i][k]-x[j][k])**2
        if math.sqrt(ans).is_integer()==True:
            count+=1
print(count)
# Judge status: Wrong Answer
def checkFunction(c):
    count = 0

    while True:
        # print(count, c)
        if not ('WR' in c):
            return count
        while c[-1] == 'W':
            c = c[:-1]
        while c[0] == 'R':
            c = c[1:]
        if (c.index('R') == len(c) - 1):
            return count + 1
        else:
            c = c.replace('WR', 'RR',1)[:-1]
            count += 1

N = int(input())
c= input()

print(checkFunction(c))
# Judge status: Accepted
S = input()
ls = ['Sunny','Cloudy','Rainy']
if S == 'Sunny':
    print(ls[1])
elif S == 'Cloudy':
    print(ls[2])
else:
    print(ls[0])
# Judge status: Accepted
n=input()[-1:]
hon=['2','4','5','7','9']
pon=['0','1','6','8']
bon=['3']

if n in hon:
  print('hon')
elif n in pon:
  print('pon')
else:
  print('bon')
# Judge status: Accepted
N = int(input())
S = input()
ans = str()
for i in S:
	m = (ord(i) - ord('A') + N) % 26
	ans += chr(m + ord('A'))
print(ans)
# Judge status: Wrong Answer
N, K = map(int, input().split())
i = 0
while K**i < N: i += 1
print(i)
# Judge status: Wrong Answer
n,m,co=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
c=2**n
ans=10**10
for i in range(c):
  li=[]
  a=0
  for j in range(n):  
      if ((i >> j) & 1):  
        li.append(l[j])
        a+=l[j][0]
  z=[0]*m
  for k in range(len(li)):
    for kk in range(m):
      z[kk]+=li[k][kk]
  if min(z)>co-1:
    ans=min(ans,a)
if ans==10**10:
  print(-1)
else:
  print(ans)
# Judge status: Wrong Answer
a,b = map(int,input().split())
if a==1 and b!=1 or a>b:
  print('Alice')
elif b==1 and a!=1 or b>a:
  print('Bob')
else:
  print('Draw')
# Judge status: Wrong Answer
import os
import sys
import math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

n, s = [rl().rstrip("\n") for _ in range(2)]
print(n, s)
x = 0
ans = 0
for it in s:
    if it == "I":
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)
# Judge status: Wrong Answer
n,x,y = map(int,input().split())

u = []
for i in range(1,n):
    for j in range(i+1,n+1):
        u.append(min(j-i,abs(x-i)+abs(y-j)+1))

import collections
u2 = collections.Counter(u)
u2 = list(u2.items())
for k in range(n):
    u2.append((0,0))

for i in range(n):
    if u2[i][0] == i+1:
        print(u2[i][1])
    else:
        print(0)
# Judge status: Wrong Answer
n,a,b = map(int,input().split())

if a ==0:
  print(0)
elif b == 0:
  print(a)
else:
  print(n-b)
# Judge status: Wrong Answer
s = list(input())
k = int(input())

for i in range(len(s)):
    a = 26-(ord(s[i])-97)
    # print(ord(s[i]))
    # print(a)
    if k >= a and a != 26:
        k -= a
        s[i] = "a"
# print(k)
s[-1] = chr(97+((ord(s[-1])+k) % 97) % 27)
# print(ord(s[-1]))
print("".join(s))
# Judge status: Accepted
N = int(input())
a = [int(input()) for i in range(N)]
import fractions
ans = a[0]
for i in range(1, N):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
print(ans)
# Judge status: Accepted
import math
from decimal import Decimal 
a, b = map(str, input().split())
a=Decimal(a)
b=Decimal(b)
#print(b)
#print(a*b)
print(math.floor(a*b))
# Judge status: Accepted
x, y = list(map(int, input().split()))

ans = abs(abs(x) - abs(y))

if (x < 0) == (y > 0):
  ans += 1
elif (x > y):
  ans += 2

print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n//2):
    if a[2*i] % 2 == 1:
        ans += 1
print(ans)
# Judge status: Wrong Answer
p,q = input().split()
q_ = int(q) -1 
n = input()
x = n.replace(n[q_], n[q_].lower(), 1)
print(x)
# Judge status: Accepted
wa = 0
for i in input():
    wa += int(i)
    wa %= 9

if wa == 0:
    print('Yes')

else:
    print('No')
# Judge status: Accepted
x,a,b=map(int,input().split())
if a>=b:
  print("delicious")
elif b<=(a+x):
  print("safe")
else:
  print("dangerous")
# Judge status: Accepted
S=input()
print('No' if S=='AAA' or S=='BBB' else 'Yes')
# Judge status: Accepted
# coding: utf-8
S=list(input())
K=int(input())
N=len(S)

L=[]

for i in range(N):
    L.append((26-(ord(S[i])-ord("a")))%26)

for i in range(N):
    if K>=L[i]:
        S[i]="a"
        K-=L[i]

if K>0:
    S[-1]=chr(ord("a")+((ord(S[-1])+K-ord("a"))%26))

print("".join(S))
# Judge status: Accepted
N = int(input())

x = N * 800
y = N // 15 * 200

print(x-y)
# Judge status: Wrong Answer
s= input()
fn1 = None
for i in range(len(s)):
    if s[i] != "1":
        fn1 = s[i]
        break
print("1" if fn1 is None else fn1)
# Judge status: Accepted
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,a,b = readInts()

if (b-a)%2==0:
	print((b-a)//2)
else:
	print(min(b-1,n-a,a+(b-a-1)//2,n-(a+b-1)//2))
# Judge status: Accepted
s=input()
l=[]
for i in s:
  if i=="0":
    l.append("0")
  elif i=="1":
    l.append("1")
  elif i=="B":
    if l!=[]:
    	l.pop()
if l==[]:
  print("")
else:
  print("".join(l))
# Judge status: Accepted
N,M=list(map(int,input().split()))

if N>0 and M>0:
  print(int(M*(M-1)/2+N*(N-1)/2))
elif N==0:
  print(int(M*(M-1)/2))
else:
  print(int(N*(N-1)/2))
# Judge status: Accepted
x,y=map(int,input().split())
ans=1
while 2*x<=y:
    x*=2
    ans+=1
print(ans)
# Judge status: Accepted
S = input()
print(min(S.count('0'), S.count('1')) * 2)
# Judge status: Accepted
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    print(reduce(gcd, A))

main()
# Judge status: Wrong Answer
N = int(input())
print(N/2+N%2)
# Judge status: Accepted
def resolve():
    n = int(input())
    q = 1
    for i in range(1, n+1):
        q *= i
        q %= (10**9+7)
    print(q)
resolve()
# Judge status: Accepted
a, b, c, d = map(int, input().split())

if b <= c or d <= a:
    print(0)
elif (d >= b and c <= a) or (b >= d and a <= c):
    print(min(d - c, b - a))
elif b >= d:
    print(d - a)
else:
    print(b - c)
# Judge status: Accepted
n = int(input())
s = [int(input()) for _ in range(n)]
s.sort()
ans = p_ans = sum(s)
if ans % 10 != 0: print(ans)
else:
    s = [s_i if s_i % 10 != 0 else 0 for s_i in s]
    for s_i in s:
        if s_i != 0:
            ans -= s_i
            break
    if ans == p_ans: print(0)
    else: print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
input()
s = input()
c = 0
for i in s:
    if i == "(":
        c += 1
    else:
        if c > 0:
            c -= 1
d = 0
for i in s[::-1]:
    if i ==")":
        d += 1
    else:
        if d > 0:
            d -= 1
print("("*d+s+")"*c)
# Judge status: Wrong Answer
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

sevn = "7"
i = 1
for i in range(1,10**4+1):
    tmp = int(sevn)
    if tmp%k==0:
        print(i)
        exit()
    sevn += "7"
    #i += 1

print(-1)
# Judge status: Wrong Answer
n,m,k = map(int,input().split())

for i in range(n):

    if (n-2*i) != 0 and (k-m*i) % (n-2*i) == 0:
        print('Yes')
        exit()
print('No')
# Judge status: Accepted
n = int(input())

ans = 0
for i in range(1,n+1):
    if i%2==0:
        continue
    else:
        divcnt = 0
        for j in range(1,i+1):
            if i%j==0:
                divcnt += 1
            if divcnt == 8:
                ans += 1

print(ans)
# Judge status: Wrong Answer
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

mi = A.index(1)
lc = math.ceil(mi//2)
rc = math.ceil((N-mi-1)//2)

print(lc+rc)
# Judge status: Wrong Answer
X, Y = map(int, input().split())

if X == Y or X % Y == 0:
    print(-1)
else:
    for i in range(10**18):
        X1 = int(X*i)
        if X1 % Y != 0:
            print(str(X1))
        break
# Judge status: Wrong Answer
x = list(map(int, input().split()))
for i in range(int(input())):
    x.sort
    x[-1]=x[-1]*2
print(sum(x))
# Judge status: Accepted
n = int(input())
ans = 1
mod = 10**9+7
for i in range(1,n+1):
    ans = ans * i % mod
print(ans)
# Judge status: Wrong Answer
N, M, K = map(int, input().split())
A_N = list(map(int, input().split()))
B_M = list(map(int, input().split()))
 
A_ind = 0
B_ind = 0
count = K
ans = 0
 
for i in range(N+M): 
  if A_N[0] < B_M[0]:
    if count >= A_N[0]:
      count -= A_N.pop(0)
      ans += 1
      if len(A_N) == 0:
        A_N.append(1000000001)
  else:
    if count >= B_M[0]:
      count -= B_M.pop(0)
      ans += 1
      if len(B_M) == 0:
        B_M.append(1000000001)

print(ans)
# Judge status: Wrong Answer
r,g,b=input().split()
l=(r+g+b)
L=int(l)
if L%4==0:
    print('YES')
else:
    print('No')
# Judge status: Wrong Answer
n=int(input())
def dfs(s,st):
  if len(s)==n:
    return print(s)
  else:
    for i in range(ord('a'),ord(st)+1):
      dfs(s+chr(i),chr(i+1))
dfs('','a')
# Judge status: Accepted
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
D = []
for i in range(M):
  B, C = map(int, input().split())
  D.append([C, B])
D.sort(reverse=True)
E = []
j = 0
for i in range(N):
  if j < M:
    if D[j][1] == 0:
      j += 1
    if j == M:
      E.append(0)
    else:
      E.append(D[j][0])
      D[j][1] -= 1
  else:
    E.append(0)
S = 0
for i in range(N):
  S += max(A[i], E[i])
print(S)
# Judge status: Accepted
def is_nine(x):
    res = 0
    while x > 0:
        t = x % 10
        res += t
        x //= 10
    return res

if __name__ == '__main__':
    N = list(input())
    e = 0
    for i in N:
        e += int(i)
        
    if (e % 9 == 0):
        print("Yes")
    else:
        print("No")
# Judge status: Wrong Answer
a,b=map(int,input().split())
s=input()

ans="No"
if len(s)==a+b+1:
  if s[a]=="-":
    if s[0:a].isdigit() and s[b:len(s)].isdigit():
      ans="Yes"
    
print(ans)
# Judge status: Accepted
# C
n = int(input())
d = list(map(int, input().split()))
d.sort()
if n%2 == 1:
    print(0)
else:
    mi = n//2-1
    ml = d[mi]
    mr = d[mi+1]
    print(mr-ml)
# Judge status: Accepted
print('TBD'if input()>'2019/04/30'else'Heisei')
# Judge status: Wrong Answer
N = int(input())
ti_xi_yi = [map(int, input().split(' ')) for n in range(N)]
for ti, xi, yi in ti_xi_yi:
    if not (abs(xi+yi) <= abs(ti) and abs(xi)+abs(yi) <= abs(ti) and ti%2 == (xi+yi)%2):
        print('No')
        exit()
print('Yes')
# Judge status: Accepted
import itertools
import math
import fractions
import functools
import copy

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
original = [a,b,c,d,e]

sum = 0
minimum = 10
index = 0
for i in range(len(original)):
    if original[i] % 10 != 0:
        sum += original[i]//10 * 10 + 10
        if original[i]%10 < minimum:
            index = i
            minimum = original[i]%10
    else:
        sum += original[i]
if minimum != 10:
    print(sum-(original[index]//10 * 10 + 10)+original[index])
else: print(a+b+c+d+e)
# Judge status: Wrong Answer
comp=753
s=input()
ans=1000000000
for i in range(7,0,-1):
  if s.count(str(i)):
    left = s.find(str(i))
    while left!=-1 and left<=len(s)-3:
      tmp = int(s[left:left+3])
      ans = min(ans, abs(comp-tmp))
      left = s.find(str(i),left+1)
print(ans)
# Judge status: Accepted
N, M = map(int, input().split())
if N == 1:
    if M == 1:
        ans = 1
    else:
        ans = M-2
else:
    if M == 1:
        ans = N-2
    else:
        ans = (N-2)*(M-2)
print(ans)
# Judge status: Accepted
n=map(int,input().split())
a=list(map(int,input().split()))

m=1000000
c=[0]*(m+1)

for i in a:c[i]+=1

for i in range(1,m+1):
	if c[i] == 0:continue
	for j in range(i*2,m+1,i):
		c[j]+=1
ans=0
for i in a:
 if c[i]==1:ans+=1
print(ans)
# Judge status: Accepted
A, B, C, K = map(int, input().split())

backup = K
AB = A + B
flag = False
ans = 0
if K <= A:
    print(K)
else:
    if A < K:
        K = K - A
        ans = ans + (A * 1)
    if B <= K:
        K = K - B
        flag = True
    if K > 0 and flag:
        ans = ans + (-1) * (backup - AB)
    print(ans)
# Judge status: Accepted
n = int(input())

count = 0

for i in range(26):
    for j in range(15):
        if 4 * i + 7 * j == n:
            count += 1
            break
        else:
            pass

if count == 0:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer

S = int(input())

S_m = S - 3

import math


num_set = S_m // 3
h = 3
result = 0
for h in range(int(S_m / 3) +1):
    
    
    
    if num_set < h:
        continue
    else:

        rest = S_m - (h * 3)  
        A = math.factorial(h + rest) // (math.factorial(h) * math.factorial(rest)) 
        
        result += A

if S == 6:
    print(3)
else:
    print(result% (10**9+7))
# Judge status: Wrong Answer
import heapq

def main():
    n,k = map(int,input().split())
    tree_heights = []

    for i in range(n):
        tree_heights.append(int(input()))
    tree_heights.sort()
    print(tree_heights)

    mn = 1000000000000000000000000000000
    for i in range(n-k+1):
        print(i,abs(tree_heights[i]-tree_heights[i+k-1]))
        mn = min(abs(tree_heights[i]-tree_heights[i+k-1]),mn)
    print(mn)

    #print(tree_heights)
    #print(tree_diffs)
    #print(sum(tree_diffs[0:k]))





if __name__ == '__main__':
    main()
# Judge status: Accepted
# B - Golden Apple

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

if n%(2*d+1)==0:
    print(n//(2*d+1))
else:
    print(n//(2*d+1)+1)
# Judge status: Wrong Answer
n = int(input())
s = input()
ecounter = [0 for _ in range(n)]
wcounter = [0 for _ in range(n)]
ecounter[0] = (s[0]=='E')
wcounter[n-1] = (s[n-1]=='W')
ans = n
for i in range(1,n):
    ecounter[i] = ecounter[i-1] + (s[i]=='E')
    wcounter[n-1-i] = wcounter[n-i] + (s[n-1-i]=='W')
    cnt = n-(ecounter[i]+wcounter[i])
    ans = min(ans,cnt)
print(ans)
# Judge status: Wrong Answer
N, A, B = [int(item) for item in input().split()]
if (B-A) % 2 == 0:
    print(int((B-A)/2))
else:
    d = min(N-B, A-1)
    print(int(d+1+(B-A-1)/2))
# Judge status: Accepted
a,b = map(int, input().split()) #a,bに[5 3]みたいな入力を格納できる
cost = sorted(map(int, input().split())) # 入力をソート

ans = 0

for i in range(0, b):
  ans = ans + cost[i]

print(ans)
# Judge status: Wrong Answer
# 4桁の数字で3つ以上連続するか判定

N = input()

if N[0] == N[1]:
    if N[1] == N[2] or N[0] == N[3]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
# Judge status: Accepted
A=input()
X=["a","i","u","e","o"]
if A in X:
  print("vowel")
else:
  print("consonant")
# Judge status: Wrong Answer
n,m = map(int, input().split())
print(int(((n+m)*(n+m-1)-n*m)/2))
# Judge status: Wrong Answer
n = int(input())
A = sorted (list(map(int,input().split())))
a = A[0]

while True:
    for v in A:
        x = v%a
        if (x != 0) and x < a:
            a = x
            continue
    print (a)
    exit ()
# Judge status: Accepted
n,k = map(int,input().split())
A = list(map(int,input().split()))
ans = 0

import collections
c = collections.Counter(A)
c = c.most_common()

m = len(set(A))

if m > k:
    for i in range(m-k):
        ans += c[-1-i][1]
        
print(ans)
# Judge status: Accepted
n = int(input())
s = list(input())
i = 0
l = []
while i < n / 2:
  l.append(s[i])
  i += 1
if l * 2 == s:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
    s.append(list(map(int, input().split())))

a = [0]*26
total = 0

for i in range(D):
    saiteki = 0
    p = 0
    for j in range(1, 26):
        a[j-1] = i+1
        cs = sum([x * (i+1 - y) for x, y in zip(c, a)])

        pp = s[i][j-1] - cs
        if p < pp:
            p = pp
            saiteki = j
    else:
        total = total + p
        print(saiteki)
# Judge status: Accepted
# AGC 013 A - Sorted Arrays

n = int(input())
a = list(map(int, input().split()))
up, down = 0, 0
ans = 0

for i in range(1, n):
    if a[i] > a[i-1]:
        up += 1
    if a[i-1] > a[i]:
        down += 1
    if up * down > 0:
        ans += 1
        up = 0
        down = 0
print(ans + 1)
# Judge status: Accepted
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
print(N * X if N <= K else K*X + (N-K)*Y)
# Judge status: Accepted
S = input()
if S[2] == S[3] and S[4]==S[5]:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
    print((b - a) // 2)
else:
    print(min(a - 1, n - b) + (b - a) // 2 + 1)