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

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

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

print(ans)


### FIXED CODE ###

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

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

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

N, K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [[]for i in range(N)]

dp[0] = 0
dp[1] = abs(lst[0] - lst[1])
for i in range(2, N):
    ans = []
    for j in range(min(i, K)):
        ans.append(dp[i-j-1] + abs(lst[i-j-1] - lst[i]))
    dp[i] = min(ans)

print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
lst = list(map(int, input().split()))
dp = [[]for i in range(N)]

dp[0] = 0
dp[1] = abs(lst[0] - lst[1])
for i in range(2, N):
    ans = []
    for j in range(min(i, K)):
        ans.append(dp[i-j-1] + abs(lst[i-j-1] - lst[i]))
    dp[i] = min(ans)

print(dp[-1])
### BUGGY CODE ###

N, M = map(int, input().split())
L, R = map(int, input().split())
CARDS = {i for i in range(L,R+1)}

for i in range(M-1):
    L, R = map(int, input().split())
    CARDS &= {card for card in range(L,R+1)}
    if CARDS == set():
        break

print(len(CARDS))

### FIXED CODE ###

N, M = map(int, input().split())
Ls, Rs = set(), set()

for _ in range(M):
    L, R = map(int, input().split())
    Ls.add(L)
    Rs.add(R)

print(len([i for i in range(max(Ls), min(Rs)+1)]))
### BUGGY CODE ###

import itertools

N = int(input())
S = input()
S_No = []

for n in range(N):
    S_No.append( (n, S[n]) )
    
ans = 0

C = list(itertools.combinations(S_No ,3))

for c in C:
    if c[0][1] != c[1][1] and c[0][1] != c[2][1] and c[1][1] != c[2][1] and c[1][0] - c[0][0] != c[2][0] - c[1][0] :
        ans += 1

print(ans)
        

### FIXED CODE ###

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

A = [0]*3

for s in S:
    if s == "R":
        A[0] += 1
    elif s =="G":
        A[1] += 1
    elif s == "B":
        A[2] += 1
        
ans = 1

for a in A:
    ans *= a

for i in range(N-1):
    for j in range(i+1, N):
        k = 2*j - i
        if(k >= N):
            continue
        if(S[j] != S[i] and S[j] != S[k] and S[i] != S[k]):
            ans -= 1
            
print(ans)
### BUGGY CODE ###

# import math
# import numpy as np

# S = input()
# N = int(input())
H, N = map(int, input().split())
# A = list(map(int, input().split()))
# B = [int(input()) for _ in range(n)]
A = []
B = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

# 二次元配列
# [[inf, inf, inf], [inf, inf, inf]]
# dp = [[float('inf')] * (H + 1) for i in range(N + 1)]

INF = 10 ** 18
dp = [INF] * (H + 1)
dp[0] = 0

def solve():
    for i in range(N):
        for j in range(H):
            nj = min(j + A[i], H)
            dp[nj] = min(dp[nj], dp[j] + B[i])
    return dp[H]

print(solve())


### FIXED CODE ###

import numpy as np

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

A = []
B = []
for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

A = np.array(A)
B = np.array(B)

dp = np.full((H+1), np.inf)
dp[0] = 0

def solve():
    for i in range(1, H + 1):
        dp[i] = np.amin(dp[np.maximum(i - A , 0)] + B)
    return int(dp[H])

print(solve())
### BUGGY CODE ###

n = int(input())
nodes = []
id_list = []
output = []
cnt = 0
root = set(range(n))
for i in range(n):
    id, _, *li = list(map(int, input().split(' ')))
    root -= set(li)
    nodes.append(li)
    id_list.append(id)

def rooted_tree(id, depth, parent):
    out = {}
    ind = id_list.index(id)
    out['node'] = id
    out['parent'] = parent
    out['depth'] = depth
    out['c'] = nodes[ind]
    if len(nodes[ind]) == 0:
        if depth == 0:
            out['type'] = 'root'
        else:
            out['type'] = 'leaf'
        output.append(out)
        return
    if depth == 0:
        out['type'] = 'root'
    else:
        out['type'] = 'internal node'
    output.append(out)
    for i in (nodes[ind]):
        rooted_tree(i, depth+1, id)

rooted_tree(root.pop(), 0, -1)
for line in sorted(output, key=lambda x:x['node']):
    print("node {}: parent = {}, depth = {}, {}, {}".format(line['node'], line['parent'], line['depth'], line['type'], line['c']))



### FIXED CODE ###

n = int(input())
nodes = [0 for i in range(n)]
output = [None for i in range(n)]
cnt = 0
root = set(range(n))
for i in range(n):
    id, _, *li = list(map(int, input().split(' ')))
    root -= set(li)
    nodes[id] = li

def rooted_tree(id, depth, parent):
    out = {}
    out['node'] = id
    out['parent'] = parent
    out['depth'] = depth
    out['c'] = nodes[id]
    if depth == 0:
        out['type'] = 'root'
    elif len(nodes[id]) == 0:
        out['type'] = 'leaf'
    else:
        out['type'] = 'internal node'
    output[id] = out
    for i in (nodes[id]):
        rooted_tree(i, depth+1, id)

rooted_tree(root.pop(), 0, -1)
for line in output:
    print("node {}: parent = {}, depth = {}, {}, {}".format(line['node'], line['parent'], line['depth'], line['type'], line['c']))
### BUGGY CODE ###

def func_R(li, s, hi):
    for wi, si in enumerate(s):
        if si == '#':
            li[hi][wi] = 0
        else:
            if wi == 0:
                li[hi][wi] = 1
            else:
                li[hi][wi] = li[hi][wi-1] + 1

def func_L(li, s, hi):
    for wi, si in enumerate(s[::-1]):
        wi = w - wi - 1
        if si == '#':
            li[hi][wi] = 0
        else:
            if wi == w-1:
                li[hi][wi] = 1
            else:
                li[hi][wi] = li[hi][wi+1] + 1

def func_U(li, s, wi):
    for hi, si in enumerate(s):
        if si == '#':
            li[hi][wi] = 0
        else:
            if hi == 0:
                li[hi][wi] = 1
            else:
                li[hi][wi] = li[hi-1][wi] + 1

def func_D(li, s, wi):
    for hi, si in enumerate(s[::-1]):
        hi = h - hi - 1
        if si == '#':
            li[hi][wi] = 0
        else:
            if hi == h-1:
                li[hi][wi] = 1
            else:
                li[hi][wi] = li[hi+1][wi] + 1

def main():
    global h, w
    h, w = map(int, input().split())
    L = [[0]*w for _ in range(h)]
    R = [[0]*w for _ in range(h)]
    U = [[0]*w for _ in range(h)]
    D = [[0]*w for _ in range(h)]
    s_list = ['']*w
    for hi in range(h):
        s = input()
        func_L(L, s, hi)
        func_R(R, s, hi)
        for wi, si in enumerate(s):
            s_list[wi] += si

    for wi in range(w):
        s = s_list[wi]
        func_U(U, s, wi)
        func_D(D, s, wi)

    ans = 0
    for hi in range(h):
        for wi in range(w):
            ans = max(ans, L[hi][wi] + R[hi][wi] + U[hi][wi] + D[hi][wi])

    print(ans-3)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np

def main():
    H, W = map(int, input().split())
    S = np.array([list(input()) for _ in range(H)]) == '.'

    L = np.zeros((H, W), dtype=int)
    R = np.zeros((H, W), dtype=int)
    U = np.zeros((H, W), dtype=int)
    D = np.zeros((H, W), dtype=int)

    for w in range(1, W):
        L[:, w] = (L[:, w-1] + 1) * S[:, w-1]
    for w in range(W-2, -1, -1):
        R[:, w] = (R[:, w+1] + 1) * S[:, w+1]
    for h in range(1, H):
        U[h, :] = (U[h-1, :] + 1) * S[h-1, :]
    for h in range(H-2, -1, -1):
        D[h, :] = (D[h+1, :] + 1) * S[h+1, :]

    print(((L+R+U+D)*S).max() + 1)

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

s=input()
c=0
n=1
while n>0 or m>0:
  n=s.count('01')
  s=s.replace('01','')
  c=c+n
  m=s.count('10')
  s=s.replace('10','')
  c=c+m
print(c*2)

### FIXED CODE ###

s=input()
print(2*min(s.count('0'),s.count('1')))
### BUGGY CODE ###

m,n = map(int,input().split())
k = m
for i in range(1,n):
    m *= k
    if m > 1000000007:
        m  %= 1000000007
        
print(m)

### FIXED CODE ###

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

def amari(m,n):
    if n == 0:
        return 1
    
    if n % 2 == 0:
        return amari(m,n/2)**2%1000000007 
    else:
        return  m*amari(m,n-1)%1000000007 
print(amari(m,n))
### BUGGY CODE ###

n, k, c = list(map(int, input().split()))
s = input()

a = []
b = []

d = 0
for i in range(k):
    while s[d] == 'x':
        d += 1
    a.append(d)
    d += c+1

d = -1
for i in range(k):
    while s[d] == 'x':
        d -= 1
    b.insert(0, n+d)
    d -= c+1

for i in range(k):
    if a[i] == b[i]:
        print(a[i]+1)

### FIXED CODE ###

n, k, c = list(map(int, input().split()))
s = input()

b = []

d = -1
for i in range(k):
    while s[d] == 'x':
        d -= 1
    b.append(n+d)
    d -= c+1

d = 0
for i in range(k):
    while s[d] == 'x':
        d += 1
    if d == b[-i-1]:
        print(d+1)
    d += c+1
### BUGGY CODE ###

n = int(input())
s = [0] * n
inc = []
zeros = []
dec = []

for i in range(n):
    s[i] = input()
    start = 0
    minimum = 0
    now = 0
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        minimum = min(minimum, now)
    end = now
    
    if end == 0:
        zeros.append((minimum, i))
    elif start < end:
        inc.append((minimum, i))
    else:
        minimum = minimum - end
        dec.append((minimum, i))

inc.sort(reverse=True)
dec.sort()

ans = ""
for (m, i) in inc:
    ans += s[i]

for (m, i) in zeros:
    ans += s[i]

for (m, i) in dec:
    ans += s[i]

now = 0

for c in ans:
    if c == '(':now += 1
    else: now -= 1
    if now < 0:
        print("No")
        exit()

if now != 0:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

n = int(input())
s = [0] * n
inc = [[] for _ in range(1100000)]
zeros = []
dec = [[] for _ in range(1100000)]

for i in range(n):
    s[i] = input()
    start = 0
    minimum = 0
    now = 0
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        minimum = min(minimum, now)
    end = now
    
    if end == 0:
        zeros.append(i)
    elif start < end:
        inc[minimum].append(i)
    else:
        minimum = minimum - end
        dec[minimum].append(i)

now = 0
for m in range(0, -1000000, -1):
    for i in inc[m]:
        for c in s[i]:
            if c == '(':now += 1
            else: now -= 1
            if now < 0:
                print("No")
                exit()
        
for i in zeros:
    for c in s[i]:
        if c == '(':now += 1
        else: now -= 1
        if now < 0:
            print("No")
            exit()
            
for m in range(-1000000, 1):
    for  i in dec[m]:
        for c in s[i]:
            if c == '(':now += 1
            else: now -= 1
            if now < 0:
                print("No")
                exit()
                
if now != 0:
    print("No")
else:
    print("Yes")
### BUGGY CODE ###

from bisect import bisect_right
N = int(input())
D = list(map(int, input().split()))
D.sort(reverse=False)

count = 0

for i in range(N):
    for j in range(i + 1, N - 1):
        target = int(D[N - i - 1]) - int(D[N - j - 1])
        l = D[:N - j - 1]
        count += len(l) - bisect_right(l, target)

print(count)


### FIXED CODE ###

from bisect import bisect_right
N = int(input())
D = list(map(int, input().split()))
D.sort(reverse=False)

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        # target = int(D[N - i - 1]) - int(D[N - j - 1])
        # l = D[:N - j - 1]
        # count += len(l) - bisect_right(l, target)
        ind = bisect_right(D, D[i] + D[j] - 1)
        count += max(ind - j - 1, 0)

print(count)
### BUGGY CODE ###

n = int(input())
pwr = 1
for i in range(1,n+1):
  pwr *= i
print(pwr%(10**9+7))

### FIXED CODE ###

n = int(input())
pwr = 1
for i in range(1,n+1):
  pwr *= i
  if pwr>10**9+7:
    pwr = pwr%(10**9+7)
print(pwr%(10**9+7))
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
memo = P[:K]
ans = sum(memo)

for i in range(K, N):
    memo.pop(0)
    memo.append(P[i])
    ans = max(ans, sum(memo))

print(K-1+((ans-K+1) - 0.5*((ans-K+1)-1)))


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
memo = sum(P[:K])
ans = memo

for i in range(K, N):
    memo = memo - P[i-K] + P[i]
    ans = max(ans, memo)

print(K-1+((ans-K+1) - 0.5*((ans-K+1)-1)))
### BUGGY CODE ###

N = int(input())
ans = [1] * N
for i in range(1, N):
    ans[i] = ans[i - 1] * (i + 1)

big = 10 ** 9 + 7
print(ans[N - 1] % big)

### FIXED CODE ###

N = int(input())
big = 10 ** 9 + 7
import math
print(math.factorial(N) % big)
### BUGGY CODE ###

import math
from functools import reduce
def gcd(*nums):
    return reduce(math.gcd, nums)

K = int(input())
s = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            s += gcd(a, b, c)
print(s)

### FIXED CODE ###

import math
from functools import reduce
def gcd(*nums):
    return reduce(math.gcd, nums)

K = int(input())
s = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(b, K+1):
            if b == c:
                s += gcd(a, b, c)
            else:
                s += 2*gcd(a, b, c)
print(s)
### BUGGY CODE ###

q = int(input())

for k in range(q):
    x = input()
    y = input()
    ex = len(x)+1
    lcs = [0] *ex 
    for i in range(1,len(y) + 1):
        lcs_2 = lcs[:]
        for j in range(1,ex):
            if x[j-1] == y[i-1]:
                lcs[j] = lcs_2[j-1] + 1  
            elif lcs[j] < lcs[j-1]:
                lcs[j] = lcs[j-1]
    print(lcs[-1])

### FIXED CODE ###

q = int(input())
 
def lcss(x,y):
     
    lcs = [0]*(len(x)+1)
    for i in range(len(y)):
        w1 = y[i]
        lcs_2 = lcs[:]
        for j in range(len(x)):
            if x[j] == w1:
                lcs[j+1] = lcs_2[j] + 1  
            elif lcs[j+1] < lcs[j]:
                lcs[j+1] = lcs[j]
    return lcs[-1]
 
for i in range(q):
    x = input()
    y = input()
    print(lcss(x,y))
### BUGGY CODE ###

from collections import defaultdict as dd
from collections import deque

n,m=map(int,input().split())
dic=dd(list)
for i in range(1,m+1):
    dic[i]=[0]*m

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


for k,v in dic.items():
    dic[k]=deque(sorted(dic[k],reverse=True))

#print(dic)

ans=0
max2nd=[0]*m
for i in reversed(range(m)):
    d=m-i
    a=dic[d][0]
    max2nd=deque(sorted(max2nd,reverse=True))
    b=max2nd[0]
    if a>=b:
        ans+=dic[d].popleft()
    else:
        ans+=max2nd.popleft()
    max2nd+=dic[d]
        

print(ans)


### FIXED CODE ###

import heapq

n,m=map(int,input().split())
mm=10**5+5
c=[[0] for i in range(mm)]

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

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  for j in c[d]:
    heapq.heappush(h,-j)
  #heapq.heapify(h)
  ans+=-heapq.heappop(h)

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

n = int(input())
p = list(map(int,input().split()))
miss = 0
for i in range(n):
    for j in range(i):
        if p[i] > p[j]:
            #print(i,p[i],j)
            miss += 1
            break

print(n-miss)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
cnt = 0
t = p[0]

for i in range(n):
    if t >= p[i]:
        cnt += 1
        t = p[i]


print(cnt)
### BUGGY CODE ###

N,Q = map(int,input().split())
STX = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

starts = []
ends = []
for i,(s,t,x) in enumerate(STX):
    starts.append((s-x,i))
    ends.append((t-x,i))
starts.sort(key=lambda x:x[0], reverse=True)
ends.sort(key=lambda x:x[0], reverse=True)

import heapq
hq = []
heapq.heapify(hq)
delset = set()

ans = []
for d in D:
    while starts and starts[-1][0] <= d:
        _,i = starts.pop()
        x = STX[i][2]
        heapq.heappush(hq, (x,i))
    while ends and ends[-1][0] <= d:
        _,i = ends.pop()
        delset.add(i)
    while hq:
        _,i = hq[0]
        if i in delset:
            heapq.heappop(hq)
        else:
            break
    if len(hq)==0:
        ans.append(-1)
    else:
        x,i = hq[0]
        ans.append(x)

print(*ans, sep='\n')

### FIXED CODE ###

N,Q = map(int,input().split())
STX = [tuple(map(int,input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]

starts = []
ends = []
for i,(s,t,x) in enumerate(STX):
    starts.append((s-x,i))
    ends.append((t-x,i))
starts.sort(key=lambda x:x[0], reverse=True)
ends.sort(key=lambda x:x[0], reverse=True)

import heapq
hq = []
heapq.heapify(hq)
delset = set()

ans = []
for d in D:
    while starts and starts[-1][0] <= d:
        _,i = starts.pop()
        x = STX[i][2]
        heapq.heappush(hq, x*N+i)
    while ends and ends[-1][0] <= d:
        _,i = ends.pop()
        delset.add(i)
    while hq:
        i = hq[0]%N
        if i in delset:
            heapq.heappop(hq)
        else:
            break
    if len(hq)==0:
        ans.append(-1)
    else:
        ans.append(hq[0]//N)

print(*ans, sep='\n')
### BUGGY CODE ###

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

M = 1
for a in A:
    M *= a

print(-1 if M > 1e18 else M)

### FIXED CODE ###

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

if 0 in A:
    print(0)
else:
    M = 1
    for a in A:
        M *= a
        if M > 1000000000000000000: break

    print(-1 if M > 1000000000000000000 else M)
### BUGGY CODE ###

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

a_list_index = [a_list.index(i+1) + 1 for i in range(N)]

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

### FIXED CODE ###

N = int(input())
a = input().split()
 
#a_list = [int(i) for i in a]
#a_list_index = [a_list.index(i+1) + 1 for i in range(N)]
#print(' '.join(map(str, a_list_index)))

new_list =[0] * N
for i , b in enumerate(a):
  new_list[int(b)-1] = i + 1
print(' '.join(map(str, new_list)))
### BUGGY CODE ###

N, M = map(int,input().split())
A = []
for _ in range(M):
    A.append(int(input()))

dp = [ 0 for _ in range(N+5)]


dp[0] = 1
for i in range(N):
    if i+1 not in A:
        dp[i+1] += dp[i]
    if i+2 not in A:
        dp[i+2] += dp[i]
    dp[i] %= 1000000007

print(dp[N] % 1000000007)


### FIXED CODE ###

import bisect
N, M = map(int,input().split())
A = []
for _ in range(M):
    A.append(int(input()))

dp = [ 0 for _ in range(N+5)]

def check(n):
    i = bisect.bisect_left(A, n)
    if i != M and A[i] == n:
        return False
    else:
        return True

dp[0] = 1
for i in range(N):
    if check(i+1):
        dp[i+1] += dp[i]
        dp[i] %= 1000000007
    if check(i+2):
        dp[i+2] += dp[i]
        dp[i] %= 1000000007

print(dp[N] % 1000000007)
### BUGGY CODE ###

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

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

mysum = 0

for i in range(N-K+1):
    if mysum < sum(mylist[i:i+K]):
        mysum = sum(mylist[i:i+K])
        myans = 0
        for j in range(i,i+K):
            myans += (mylist[j] + 1)/2 
            #print(myans)
#print(mysum,myans)
print(myans)

### FIXED CODE ###

import sys

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

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

if N == K:
    myans = 0
    for n in range(N):
        myans += (mylist[n]+1)/2
    print(myans)
    sys.exit()

if K == 1:
    print((1+max(mylist))/2)
    sys.exit()
    
dp = [0 for n in range(N)]

for i in range(K):
    dp[i] = (mylist[i]+1)/2
dp[K-1] = sum(dp[0:K])

myans = -999999999
for n in range(K,N):
    dp[n] = (mylist[n]+1)/2 + dp[n-1] - (mylist[n-K]+1)/2 
    if myans < dp[n]:
        myans = dp[n]

        
print(myans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    l = [0]*X*Y
    for i in range(X):
        for j in range(Y):
            l[i+j*X] = A[i]+B[j]

    l.sort()
    t = min(3000, K)
    l = l[-t:]

    ans = [0] * len(l)*Z
    ls = len(l)
    for i in range(ls):
        for j in range(Z):
            ans[i+j*ls] = l[i] + C[j]

    ans.sort(reverse=True)
    for i in range(K):
        print(ans[i])


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    l = [0]*X*Y
    for i in range(X):
        for j in range(Y):
            l[i+j*X] = A[i]+B[j]

    l.sort(reverse=True)
    t = min(3000,X*Y)
    l = l[:t]

    ans = [0] * (t) * Z
    for i in range(t):
        for j in range(Z):
            ans[i+j*t] = l[i] + C[j]

    ans.sort(reverse=True)
    for i in range(K):
        print(ans[i])


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

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

def point(m, list):
    for i in range(len(list)):
        if i+1 == m:
            pass
        else:
            list[i] -= 1
N, K, Q = map(int, input().split())
list = [int(input()) for i in range(Q)]
p_list = []
for i in range(N):
    p_list.append(K)
for i in list:
    point(i, p_list)
for i in p_list:
    if i > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N, K, Q = map(int, input().split())
list = [int(input()) for i in range(Q)]
p_list = []
for i in range(N):
    p_list.append(0)
for i in list:
    p_list[i-1] += 1
for i in p_list:
    if K - (Q - i) > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
  a = [0] * min(i,k)
  for j in range(1, min(i,k)+1): 
    a[j-1] = dp[i-j]+abs(h[i]-h[i-j])
  dp[i] = min(a)

print(dp[-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
  a = [0] * min(i,k)
  for j in range(1, min(i,k)+1): 
    a[j-1] = dp[i-j]+abs(h[i]-h[i-j])
  dp[i] = min(a)

print(dp[-1])