Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

k,s = map(int,input().split())

ans = 0

for x in range(s+1):
    for y in range(s+1):
        z = s - x - y
        if  k >= x and k >= y and k >= z >=0:
            ans +=1

print(ans)


### FIXED CODE ###

k,s = map(int,input().split())
cnt=0

for i in range(min(k,s)+1):
    for j in range(min(k,s-i)+1):
        if s-i-j<=k:
            cnt+=1
print(cnt)
### BUGGY CODE ###

fact_list=[None]*300001
fact_list[0]=1
def inv(n):
    s=1
    for i in range(30):
        if i!=23 and i!=26:
            s=(s*n)%998244353
        n=(n**2)%998244353
    return s

def comb(n,r):
    if r==0 or r==n:
        return 1
    return (((fact_list[n]*inv(fact_list[n-r]))%998244353)*inv(fact_list[r]))%998244353

for i in range(1,300001):
    fact_list[i]=(fact_list[i-1]*i)%998244353

s=input().split()
n,a,b,k=int(s[0]),int(s[1]),int(s[2]),int(s[3])
res=0
for i in range(n+1):
    if k-a*i<0:
        break
    if (k-a*i)%b==0 and 0<=(k-a*i)//b<=n:
        res=(res+comb(n,i)*comb(n,(k-a*i)//b))%998244353
print(res)

### FIXED CODE ###

fact_list=[None]*300001
inv_fact_list=[None]*300001
fact_list[0]=1
inv_fact_list[0]=1
"""
def inv(n):
    if inv_fact_list[n]!=None:
        return inv_fact_list[n]
    m=fact_list[n]
    s=1
    for i in range(30):
        if i!=23 and i!=26:
            s=(s*m)%998244353
        m=(m**2)%998244353
    inv_fact_list[n]=s
    return s
def enc(n):
    if n==0:
        return "("
    s=""
    while n>0:
        s+=chr(n%86+40)
        n//=86
    return s
 
def dec(s):
    n=0
    for i in range(len(s)):
        n+=(86**i)*(ord(s[i])-40)
    return n
"""
def comb(n,r):
    if r==0 or r==n:
        return 1
    if r==1 or r==n-1:
        return n
    if inv_fact_list[n-r]!=None:
        invnr=inv_fact_list[n-r]
    else:
        m=fact_list[n-r]
        invnr=1
        for i in range(30):
            if i!=23 and i!=26:
                invnr=(invnr*m)%998244353
            m=(m**2)%998244353
        inv_fact_list[n-r]=invnr
    if inv_fact_list[r]!=None:
        invr=inv_fact_list[r]
    else:
        m=fact_list[r]
        invr=1
        for i in range(30):
            if i!=23 and i!=26:
                invr=(invr*m)%998244353
            m=(m**2)%998244353
        inv_fact_list[r]=invr
    return (((fact_list[n]*invnr)%998244353)*invr)%998244353
 
for i in range(1,300001):
    fact_list[i]=(fact_list[i-1]*i)%998244353
 
s=input().split()
n,a,b,k=int(s[0]),int(s[1]),int(s[2]),int(s[3])
res=0
for i in range(n+1):
    if k-a*i<0:
        break
    if (k-a*i)%b==0 and 0<=(k-a*i)//b<=n:
        res=(res+comb(n,i)*comb(n,(k-a*i)//b))%998244353
print(res)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

n = int(input())
ls = [list(map(int, input().split())) for _ in range(n - 1)]

cs = [[0] * (n + 1) for _ in range(n + 1)]
es = [[] for _ in range(n + 1)]
for a, b, c in ls:
    cs[a][b] = cs[b][a] = c
    es[a].append(b)
    es[b].append(a)
ds = [0] * (n + 1)


def dfs(cur, prev):
    ds[cur] = ds[prev] + cs[prev][cur]
    for e in es[cur]:
        if e != prev:
            dfs(e, cur)


q, k = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(q)]

dfs(k, k)
for x, y in qs:
    print(ds[x] + ds[y])

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**6)

input = sys.stdin.readline

n = int(input())
ls = [list(map(int, input().split())) for _ in range(n - 1)]

es = [[] for _ in range(n + 1)]
for a, b, c in ls:
    es[a].append((b, c))
    es[b].append((a, c))
ds = [0] * (n + 1)


def dfs(cur, prev, c):
    ds[cur] = ds[prev] + c
    for e, c in es[cur]:
        if e != prev:
            dfs(e, cur, c)


q, k = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(q)]

dfs(k, k, 0)
for x, y in qs:
    print(ds[x] + ds[y])
### BUGGY CODE ###

#!python3

import numpy as np

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    dp = np.zeros((n + 1, 13), dtype=int)
    dp[0][0] = 1
    for i in range(1, n + 1):
        for j in range(10):
            x = w[i - 1] * j % 13
            dp[i] += np.roll(dp[i - 1], x)
            dp[i] %= MOD
    
    ans = dp[-1][m]
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = [0] * 13
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = [0] * 13
        for j in range(10):
            x = w[i - 1] * j % 13
            for k in range(13):
                t = (x + k) % 13
                l2[t] += l1[k]
        l1 = [y % MOD for y in l2]
    
    ans = l1[m]
    print(ans)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

# import bisect
# from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())

    i = 0
    print(i, flush=True)
    s = str(input())
    if s == 'Vacant':
        sys.exit()
    elif s == 'Male':
        plsex = 0
    else:
        plsex = 1

    pl = 0
    pr = N
    while pl + 1 < pr:
        pc = (pl + pr) // 2
        print(pc, flush=True)

        s = str(input())
        if s == 'Vacant':
            sys.exit()
        else:
            if s == 'Male':
                pcsex = 0
            else:
                pcsex = 1
        if (pc - pl) % 2 == 1 and plsex == pcsex:
            pr = pc
        else:
            plsex = pcsex
            pl = pc


resolve()


### FIXED CODE ###

N = int(input())


def query(i):
    print(i)
    s = input()
    if s == 'Vacant':
        exit()
    return s


root = query(0)


def is_ok(ind):
    # 左ならTrue
    response = query(ind)
    if ind % 2 == 1:
        return root == response
    else:
        return root != response


def bin_search_meguru():
    """
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng, okは,とり得る最小の値-1,とり得る最大の値+1
    """

    # 適当にいじる
    ng = -1  # ind=0が条件を満たすこともあるため
    ok = N  # ind=len(a)-1が条件を満たさないこともあるため

    # いじらない
    # okとngのどちらが大きいかわからないことを考慮
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return False


bin_search_meguru()
### BUGGY CODE ###

N = int(input())

paper = []
numbers = [int(input()) for _ in range(N)]

for n in numbers:
    if n in paper:
        paper.remove(n)
    else:
        paper.append(n)

print(len(paper))

### FIXED CODE ###

N = int(input())

paper = []
numbers = sorted([int(input()) for _ in range(N)])

# for n in numbers:
for i in range(N - 1):
    if numbers[i] == numbers[i + 1]:
        numbers[i] = -1
        numbers[i + 1] = -1
    if numbers[i] != -1:
        paper.append(numbers[i])

if numbers[N - 1] != -1:
    paper.append(numbers[N - 1])
print(len(paper))
### BUGGY CODE ###

N = int(input())
S = input()
answer = N

for x in range(0,N):
    a = S[:x]
    if not x == N-1:
        b = S[x+1:]
    anum = a.count('W')
    bnum = b.count('E')
    num = anum + bnum
    answer = min(answer,num)

print(answer)

### FIXED CODE ###

N = int(input())
S = input()
answer = S.count('E')
if S[0] =='E':
    test = S.count('E') - 1
else:
    test = S.count('E')

for x in range(0,N-1):
    if S[x] == 'W':
        test += 1
    if S[x+1] =='E':
        test -= 1
    answer = min (answer,test)

print(answer)
### BUGGY CODE ###

N = int(input())
S = list(input())

ans = N

for n in range(N):
  if n == 0:
    ans = min(ans,S[1:].count("E"))
  elif n == N-1:
    ans = min(ans,S[:n].count("W"))
  else:
    left_W = S[:n].count("W")
    right_E = S[n:].count("E")
    ans = min(ans,left_W + right_E)
print(ans)

### FIXED CODE ###

N = int(input())
S = list(input())

ans = N

left_W = 0
right_E = S[1:].count("E")

for n in range(N):
  if n == 0:
    ans = min(ans,S[1:].count("E"))
        
  elif n == N-1 :
    ans = min(ans,S[:n].count("W"))
      
  else:
    if S[n] == "E":
      right_E -= 1
    if S[n-1] == "W":
      left_W += 1
    ans = min(ans,left_W + right_E)

print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 9)

# Nがノードの数, Qが操作回数
N, Q = map(int, input().split())

parents = [None] * N
childrens = [set() for _ in range(N)]
relations = [set() for _ in range(N)]
shown = set()

for _ in range(N - 1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  # parents[b] = a
  # childrens[a].add(b)
  relations[a].add(b)
  relations[b].add(a)

def f(parent):
  global relations, parents, childrens
  shown.add(parent)
  for c in relations[parent]:
    if c not in shown:
      parents[c] = parent
      childrens[parent].add(c)
      f(c)

f(0)
points = {}
result = [0] * N

for _ in range(Q):
  p, x = map(int, input().split())
  p -= 1
  if p not in points:
    points[p] = 0
  points[p] += x

def solve(idx):
  global parents, childrens, points, result
  # print(idx)
  if idx in points:
    result[idx] += points[idx]
  if parents[idx] is not None:
    result[idx] += result[parents[idx]]
  for child in childrens[idx]:
    solve(child)
    

solve(0)
print(*result)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 9)

def main():
  input = sys.stdin.buffer.readline
  read = sys.stdin.buffer.read
  # Nがノードの数, Qが操作回数
  N, Q = map(int, input().split())
  ABPX = list(map(int, read().split()))
  AB = iter(ABPX[:N+N-2])
  PX = iter(ABPX[N+N-2:])

  parents = [None] * N
  childrens = [set() for _ in range(N)]
  relations = [[] for _ in range(N)]
  shown = set()

  for a, b in zip(AB, AB):
    a -= 1
    b -= 1
    relations[a].append(b)
    relations[b].append(a)

  points = [0] * N
  result = [0] * N

  for p, x in zip(PX, PX):
    p -= 1
    points[p] += x

  def solve(parent, relations, points, result):
    result[parent] += points[parent]
    shown.add(parent)
    for child in relations[parent]:
      if child not in shown:
        result[child] += result[parent]
        solve(child, relations, points, result)
      
  solve(0, relations, points, result)
  print(*result)

if __name__ == "__main__":
  main()
### BUGGY CODE ###

import itertools
n= int(input())
s = [str(sorted(list(input()))) for i in range(n)]
l=[]
for si in set(s):
  x=0
  for sj in s:
    if si==sj:
      x+=1
  l.append(x)
ans=0
for i in l:
  x=len(list(itertools.combinations(range(i),2)))
  ans+=x
print(ans)

### FIXED CODE ###

import math
from collections import Counter
n=int(input())
s = [str(sorted(list(input()))) for i in range(n)]
c = Counter(s)
#l=[]
#for si in set(s):
#    l.append(s.count(si))
ans=0
for i in c.values():
    if i>=2:
        x = (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
        ans+=x
print(ans)
### BUGGY CODE ###

import fractions
mod = 10**9 + 7
n = int(input())
lst = list(map(int, input().split()))
koubai = lst[0]
def gcd(a, b):
    if a > b:
        a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a
for i in range(1, n):
    koubai = koubai*lst[i]//gcd(koubai, lst[i])
 
total = 0
for l in lst:
    b = koubai//l
    total += b
    total %= mod
print(total)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
lcm = a[0]

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

for i in range(1, n):
    lcm = lcm * a[i] // gcd(lcm, a[i])
mod = 10**9 + 7
ans = 0
for i in range(n):
    ans += lcm // a[i]
print(ans % mod)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
kosuu = 1
tadoru = [1]
pin = 1
tmp = 1
while pin == 1:
    tmp = A[tmp-1]
    if tmp == 1:
        break
    else:
        tadoru.append(tmp)
        kosuu += 1
mod = K % kosuu
print(tadoru[mod])

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
toujou = [0] * N
toujou[0] = 1
kosuu = 1
tadoru = [1]
pin = 1
tmp = 1
while pin == 1:
    tmp = A[tmp-1]
    toujou[tmp-1] += 1
    if toujou[tmp - 1] == 2:
            break
    else:
        tadoru.append(tmp)
        kosuu += 1

loop_start = tadoru.index(tmp)
loop = kosuu - loop_start
if K < kosuu:
    print(tadoru[K])
else:
    K = K - loop_start
    a = K % loop
    print(tadoru[loop_start + a])
### BUGGY CODE ###

#python3
n = int(input())
a = [''.join(sorted(input())) for _ in range(n)]
d = {string: a.count(string) for string in a}
sum=0
for i in d.values():
  sum+=i*(i-1)//2 
print(sum)

### FIXED CODE ###

#python3
n = int(input())
s = [str(input()) for _ in range(n)]
sep = ''
dic = dict()
for string in s:
  tmp = sep.join(sorted(string))
  if tmp in dic:
    dic[tmp] += 1 
  else :
    dic[tmp] = 1
ans = 0
for i in dic.values(): 
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M, K = (int(i) for i in input().split())
    fre = [set() for _ in range(N)]
    blo = [set() for _ in range(N)]
    mem = {i for i in range(N)}
    for i in range(M):
        a, b = (int(i) for i in input().split())
        fre[a-1].add(b-1)
        fre[b-1].add(a-1)
    for i in range(K):
        a, b = (int(i) for i in input().split())
        blo[a-1].add(b-1)
        blo[b-1].add(a-1)
    par = [i for i in range(N)]
    rank = [0 for i in range(N)]

    def find_root(x):
        if par[x] == x:
            return x
        else:
            par[x] = find_root(par[x])
            return par[x]

    def is_same_group(x, y):
        return find_root(x) == find_root(y)

    def unite(x, y):
        x = find_root(x)
        y = find_root(y)
        if x == y:
            return
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
    for i in range(N):
        for j in fre[i]:
            unite(i, j)
    for i in range(N):
        cur = 0
        for j in mem - fre[i] - {i} - blo[i]:
            if is_same_group(i, j):
                cur += 1
        print(cur, end=" ")
    print()


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M, K = (int(i) for i in input().split())
    par = [i for i in range(N)]
    rank = [0 for i in range(N)]

    def find_root(x):
        if par[x] == x:
            return x
        else:
            par[x] = find_root(par[x])
            return par[x]

    def is_same_group(x, y):
        return find_root(x) == find_root(y)

    def unite(x, y):
        x = find_root(x)
        y = find_root(y)
        if x == y:
            return
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
    fre = [set() for _ in range(N)]
    blo = [set() for _ in range(N)]
    mem = {i for i in range(N)}
    for i in [0]*M:
        a, b = (int(i) for i in input().split())
        fre[a-1].add(b-1)
        fre[b-1].add(a-1)
        unite(a-1, b-1)
    cur = [-1]*N
    from collections import Counter
    for i, x in enumerate(par):
        unite(i, x)
    c = Counter(par)
    # print(par, is_same_group(5, 7))
    for i in [0]*K:
        a, b = (int(i) for i in input().split())
        if is_same_group(a-1, b-1):
            blo[a-1].add(b-1)
            blo[b-1].add(a-1)
    for i in range(N):
        cur = c[par[i]] - len(fre[i]) - len(blo[i]) - 1
        print(cur, end=" ")
    print()


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    L = [[0] * W for _ in range(H)]
    R = [[0] * W for _ in range(H)]
    T = [[0] * W for _ in range(H)]
    B = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] == "#":
                R[h][w] = 0
            elif w == 0:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h][w] == "#":
                L[h][w] = 0
            elif w == W - 1:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h][w] == "#":
                B[h][w] = 0
            elif h == 0:
                B[h][w] = 1
            else:
                B[h][w] = B[h-1][w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h][w] == "#":
                T[h][w] = 0
            elif h == H - 1:
                T[h][w] = 1
            else:
                T[h][w] = T[h + 1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h][w] + L[h][w] + B[h][w] + T[h][w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    L = [[0] * W for _ in range(H)]
    R = [[0] * W for _ in range(H)]
    T = [[0] * W for _ in range(H)]
    B = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] == "#":
                R[h][w] = 0
            elif w == 0:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h][w] == "#":
                L[h][w] = 0
            elif w == W - 1:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h][w] == "#":
                B[h][w] = 0
            elif h == 0:
                B[h][w] = 1
            else:
                B[h][w] = B[h-1][w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h][w] == "#":
                T[h][w] = 0
            elif h == H - 1:
                T[h][w] = 1
            else:
                T[h][w] = T[h + 1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h][w] + L[h][w] + B[h][w] + T[h][w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

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

B = []
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        B.append(c)

A.sort()
B.sort(reverse=True)
for i in range(N):
    if i < len(B) and A[i] < B[i]:
        A[i] = B[i]

ans = sum(A)
print(ans)

### FIXED CODE ###

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

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

count = 0
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))

A.sort()
BC.sort(reverse=True, key=lambda x: x[1])

count = 0
CArr = []
for b, c in BC:
    if count >= N:
        break
    for i in range(b):
        CArr.append(c)
        count += 1
        if count >= N:
            break

for i in range(len(CArr)):
    if A[i] < CArr[i]:
        A[i] = CArr[i]

ans = sum(A)
print(ans)
### BUGGY CODE ###

import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a,b,k = f()
    for i in range(a, b+1):
        if i - a<=k-1 or b-i<=k-1:
            print(i)

solve()


### FIXED CODE ###

import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a,b,k = f()
    s = set()
    for i in range(a, min(a+k, b)):
        s.add(i)
    

    for i in range(max(a,b+1-k), b+1):
        s.add(i)
    
    s = sorted(list(s))
    for i in s:
        print(i)

solve()
### BUGGY CODE ###

s = input()
q = int(input())

for i in range(q):
    t = input()
    if t == "1":
        s = s[::-1]
    elif t[0] == "2":
        f = t[2]
        if f == "1":
            c = t[4]            
            s = c + s
        elif f == "2":
            c = t[4]
            s += c

print(s)


### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())

flg = 1
for _ in range(q):
    t = input()
    if t == "1":
        flg = not flg
    elif t[0] == "2":
        f = t[2]
        if f == "1":
            c = t[4]
            if flg:
                s.appendleft(c)
            else:
                s.append(c)
        elif f == "2":
            c = t[4]
            if flg:
                s.append(c)
            else:
                s.appendleft(c)

if flg:
    print(''.join(s))
else:
    print(''.join(reversed(s)))
### BUGGY CODE ###

N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        k = i
    else:
        k = K
    for j in range(i-k, i):
        dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]))

print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
for j in range(K):
    h.append(0)
INF = float('inf')
dp = [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[i]-h[i+j]))
print(dp[N-1])