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

import itertools


X, Y, Z, K  = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)[:K]
B = sorted(list(map(int, input().split())), reverse=True)[:K]
C = sorted(list(map(int, input().split())), reverse=True)[:K]

R = [sum([A[0], B[0], C[0]])]
Q = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}

while len(R) < K:
    iS = sorted([((a, b, c), sum([A[a], B[b], C[c]])) for a, b, c in Q], key=lambda x: [x[1], x[0]], reverse=True)
    R.append(iS[0][1])
    abc = iS[0][0]
    Q.remove(abc)
    if abc[0] + 1 < X:
        if not (   abc[0] + 1, abc[1]    , abc[2]) in D:
            Q.add((abc[0] + 1, abc[1]    , abc[2]))
            D.add((abc[0] + 1, abc[1]    , abc[2]))
    if abc[1] + 1 < Y:
        if not (   abc[0]    , abc[1] + 1, abc[2]) in D:
            Q.add((abc[0]    , abc[1] + 1, abc[2]))
            D.add((abc[0]    , abc[1] + 1, abc[2]))
    if abc[2] + 1 < Z:
        if not (   abc[0]    , abc[1]    , abc[2] + 1) in D:
            Q.add((abc[0]    , abc[1]    , abc[2] + 1))
            D.add((abc[0]    , abc[1]    , abc[2] + 1))

for r in R:
    print(r)


### FIXED CODE ###

X, Y, Z, K  = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)[:K]
B = sorted(list(map(int, input().split())), reverse=True)[:K]
C = sorted(list(map(int, input().split())), reverse=True)[:K]

R  = [sum([A[0], B[0], C[0]])]
Q  = {(0, 0, 1), (0, 1, 0), (1, 0, 0)}
D  = {(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0)}
iS = [((a, b, c), sum([A[a], B[b], C[c]])) for a, b, c in Q if (a < X) and (b < Y) and (c < Z)]
iS = sorted(iS, key=lambda x: [x[1], x[0]], reverse=True)

while len(R) < K:
    R.append(iS[0][1])
    abc     = iS[0][0]
    a, b, c = abc[0], abc[1], abc[2]
    iS      = iS[1:]
    if a + 1 < X:
        if not (a + 1, b, c) in D:
            s = sum([A[a + 1], B[b], C[c]])
            is_done = False
            for i in range(len(iS)):
                if iS[i][1] < s:
                    iS = iS[:i] + [((a + 1, b, c), s)] + iS[i:]
                    is_done = True
                    break
            if is_done == False:
                iS = iS + [((a + 1, b, c), s)]
            D.add((a + 1, b, c))
    if b + 1 < Y:
        if not (a, b + 1, c) in D:
            s = sum([A[a], B[b + 1], C[c]])
            is_done = False
            for i in range(len(iS)):
                if iS[i][1] < s:
                    iS = iS[:i] + [((a, b + 1, c), s)] + iS[i:]
                    is_done = True
                    break
            if is_done == False:
                iS = iS + [((a, b + 1, c), s)]
            D.add((a, b + 1, c))
    if c + 1 < Z:
        if not (a, b, c + 1) in D:
            s = sum([A[a], B[b], C[c + 1]])
            is_done = False
            for i in range(len(iS)):
                if iS[i][1] < s:
                    iS = iS[:i] + [((a, b, c + 1), s)] + iS[i:]
                    is_done = True
                    break
            if is_done == False:
                iS = iS + [((a, b, c + 1), s)]
            D.add((a, b, c + 1))

for r in R:
    print(r)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

"""
H Wの後に
#.#.
###.
みたいな文字列を受け取る
"""
H,W = map(int,input().split(' '))
MAP = [['#']*(W+1)] + [None]*H

for i in range(1,H+1):
    MAP[i] = ['#'] + list(map(str,input()))
import queue
q = queue.Queue()


MAP[H][W] = 'G'
visited = [None]*(H+1)
for i in range(H+1):
    visited[i] = [False]*(W+1)

d_num = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if MAP[i][j]=='#':
            d_num += 1

def is_okay(x,y):
    if not (0<x<W+1) or not (0<y<H+1):
        return False
    if visited[y][x] or MAP[y][x]=='#':
        return False
    return True

n = 0
q.put([1,1,n])
ans = 10**7 + 7

while not q.empty():
    x,y,n = q.get()
    k = MAP[y][x]

    n += 1
    if k=='G':
        ans = min(ans,n)
        break

    if is_okay(x+1,y): q.put([x+1,y,n])
    if is_okay(x-1,y): q.put([x-1,y,n])
    if is_okay(x,y+1): q.put([x,y+1,n])
    if is_okay(x,y-1): q.put([x,y-1,n])
    visited[y][x] = True

if not ans==10**7 + 7:
    ANS = H*W - ans - d_num
else:
    ANS = -1

print(ANS)

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]

"""
H Wの後に
#.#.
###.
みたいな文字列を受け取る
"""
H,W = map(int,input().split(' '))
MAP = [['#']*(W+1)] + [None]*H

for i in range(1,H+1):
    MAP[i] = ['#'] + list(map(str,input()))
import queue
q = queue.Queue()


MAP[H][W] = 'G'
visited = [None]*(H+1)
for i in range(H+1):
    visited[i] = [False]*(W+1)

d_num = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if MAP[i][j]=='#':
            d_num += 1

def is_okay(x,y):
    if not (0<x<W+1) or not (0<y<H+1):
        return False
    if visited[y][x] or MAP[y][x]=='#':
        return False
    return True

n = 0
q.put([1,1,n])
ans = 10**7 + 7

while not q.empty():
    x,y,n = q.get()
    k = MAP[y][x]

    n += 1
    if k=='G':
        ans = min(ans,n)
        break

    if is_okay(x+1,y):
        q.put([x+1,y,n])
        visited[y][x+1] = True
    if is_okay(x-1,y):
        q.put([x-1,y,n])
        visited[y][x-1] = True
    if is_okay(x,y+1):
        q.put([x,y+1,n])
        visited[y+1][x] = True
    if is_okay(x,y-1):
        q.put([x,y-1,n])
        visited[y-1][x] = True


if not ans==10**7 + 7:
    ANS = H*W - ans - d_num
else:
    ANS = -1

print(ANS)
### BUGGY CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    i=2
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        arr.append([i, cnt])
            
    for i in range(3, int(-(-n**0.5//1))+1,2):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])    

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=int(input())
A=list(map(int,input().split()))
d = collections.defaultdict(int)
for a in A:
    arr = factorization(a)
    for ar in arr:
        if d[ar[0]]<ar[1]:
            d[ar[0]]=ar[1]

gcd = 1
for key,val in d.items():
    gcd = gcd*pow(key,val)

ans = 0
for a in A:
    ans = (ans+gcd//a)%m
print(ans)


### FIXED CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    i=2
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        arr.append([i, cnt])
            
    for i in range(3, int(-(-n**0.5//1))+1,2):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])    

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=int(input())
A=list(map(int,input().split()))
d = collections.defaultdict(int)
for a in A:
    arr = factorization(a)
    for ar in arr:
        if d[ar[0]]<ar[1]:
            d[ar[0]]=ar[1]

gcd = 1
for key,val in d.items():
    gcd = gcd*pow(key,val)

ans = 0
for a in A:
    ans = ans+gcd//a
print(ans%m)
### BUGGY CODE ###

N = int(input())
print(sum(range(1,N)))

### FIXED CODE ###

N = int(input())
print(sum(range(1,N)))
### BUGGY CODE ###

import numpy as np

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
table = np.zeros(w+1, dtype=np.int16)

for i in range(n):
    l = table[:-wv[i][0]]
    r = table[wv[i][0]:]
    np.maximum(l + wv[i][1], r, out = r)

print(table[w])

### FIXED CODE ###

import numpy as np

def main():
	N, W = map(int, input().split())
	dp = np.full(N * 1000 + 1, 10 ** 10, dtype=np.int64)
	dp[0] = 0
	for _ in range(N):
		w, v = map(int, input().split())
		np.minimum(dp[:-v] + w, dp[v:], out=dp[v:])
	print(((dp <= W) * np.arange(N * 1000 + 1)).max())

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

s = input()
q = int(input())
Q = [ list(input().split()) for _ in range(q) ]
count = 0
for i in range(q):
    t = int(Q[i][0])
    if t==1:
        count += 1
    else:
        f = int(Q[i][1])
        if count%2==0 and f==1:
            s = Q[i][2] + s
        elif count%2==0 and f==2:
            s = s + Q[i][2]
        elif count%2==1 and f==1:
            s = s + Q[i][2]
        elif count%2==1 and f==2:
            s = Q[i][2] + s
        else:
            pass

# print(count)

if count%2==0:
    print(s)
    exit()
else:
    s = s[::-1]
    print(s)
    exit()

### FIXED CODE ###

s = input()
q = int(input())
Q = [ list(input().split()) for _ in range(q) ]

from collections import deque
s = deque(list(s))

count = 0
for i in range(q):
    t = int(Q[i][0])
    if t==1:
        count += 1
    else:
        f = int(Q[i][1])
        new = Q[i][2]
        if count%2==0 and f==1:
            s.appendleft(new)
        elif count%2==0 and f==2:
            s.append(new)
        elif count%2==1 and f==1:
            s.append(new)
        elif count%2==1 and f==2:
            s.appendleft(new)
        else:
            pass

# print(count)

if count%2==0:
    print("".join(s))
    exit()
else:
    s = list(s)[::-1]
    print("".join(s))
    exit()
### BUGGY CODE ###

N,M,Q=map(int,input().split())
List = []

for i in range(Q):
  a = list(map(int,input().split()))
  List.append(a)

arr = []
for i in range(2 ** Q):
    ans = [1 for i in range(N)]
    cnt = 0
    ck = 0
    
    for j in range(Q):  # このループが一番のポイント
      if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
        a = List[j][0]
        b = List[j][1]
        c = List[j][2]
        d = List[j][3]
        cnt += d
        ans[b-1] = ans[a-1] + c

    for j in range(Q):  # このループが一番のポイント
      if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
        a = List[j][0]
        b = List[j][1]
        c = List[j][2]
        d = List[j][3]
        if ans[b-1] - ans[a-1] != c:
          ck = 1
        if ans[b-1] > M:
          ck = 1
      
    if ck == 0:
      arr.append(cnt)

print(max(arr))

### FIXED CODE ###

import itertools

N,M,Q=map(int,input().split())
List = []

for i in range(Q):
  a = list(map(int,input().split()))
  List.append(a)
  
ans = 0

for team in itertools.combinations_with_replacement(range(1,M+1), N):
  cnt = 0
  for i in range(Q):
    a = List[i][0]
    b = List[i][1]
    c = List[i][2]
    d = List[i][3]
    
    if team[b-1] - team[a-1] == c:
      cnt += d
  ans = max(ans ,cnt)  
  
print(ans)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

R, C, k = (int(x) for x in input().split())
RCV = [tuple(int(x) for x in input().split()) for _ in range(k)]
V = [[0] * (C + 5) for _ in range(R + 5)]
for r, c, v in RCV:
    V[r][c] = v
# dp[i][j][3]
dp = [[[0] * 4 for _ in range(C + 5)] for _ in range(R + 5)]
for i in range(1, R + 3):
    for j in range(1, C + 3):
        for k in range(4):
            # 行移動
            dp[i][j][0] = max(dp[i][j][0], max(dp[i-1][j]))
            dp[i][j][1] = max(dp[i][j][1], max(dp[i-1][j])+V[i][j])
            # 列移動
            if k > 0:
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k - 1] + V[i][j])
            dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
print(max(dp[R][C]))


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

R, C, k = (int(x) for x in input().split())
V = [[0] * (C + 5) for _ in range(R + 5)]
for _ in range(k):
    r, c, v = (int(x) for x in input().split())
    V[r][c] = v

# dp[3][i][j]
dp = [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)]
for i in range(R + 3):
    for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1])
print(max(dp[k][R][C] for k in range(4)))
### BUGGY CODE ###

K, S = map(int, input().split())
cnt = 0
for i in range(K + 1):
  for j in range(K + 1):
    for k in  range(K + 1):
      if i + j + k == S:
        cnt += 1
print(cnt)

### FIXED CODE ###

K, S = map(int, input().split())
cnt = 0
for i in range(K + 1):
  for j in range(K + 1):
    if S >= i + j >= S - K:
      cnt += 1
print(cnt)
### BUGGY CODE ###

import bisect
N, M = map(int,input().split())
al = list(map(int,input().split()))
al.sort()

for _ in range(M):
    x = al.pop()
    bisect.insort(al, x//2)

print(sum(al))

### FIXED CODE ###

import heapq
N, M = map(int,input().split())
al = list(map(int,input().split()))
al = list(map(lambda x: x*(-1), al))
heapq.heapify(al)

for _ in range(M):
    tmp_min = heapq.heappop(al)
    heapq.heappush(al, -1*(-tmp_min//2))
print(-sum(al))
### BUGGY CODE ###

n, p = map(int, input().split())
s = input()

def twofive(n, p, s):
    res = 0
    for i in range(n):
        mostlow = int(s[i])
        if mostlow%p==0:
            res += i+1
    return res

def others(n, p, s):
    from collections import Counter
    res = 0
    
    s = s + '0'
    amari = []
    for i in range(len(s)):
        ak = int(s[i:])
        amari.append(ak%p)
    
    amaricnt = Counter(amari)
    for val in amaricnt.values():
        if val == 1:
            continue
        else:
            res += val*(val-1)//2
    
    return res

if p == 2 or p==5:
    print(twofive(n, p, s))
else:
    print(others(n, p, s))

### FIXED CODE ###

n, p = map(int, input().split())
s = input()

def twofive(n, p, s):
    res = 0
    for i in range(n):
        mostlow = int(s[i])
        if mostlow%p==0:
            res += i+1
    return res

def others(n, p, s):
    from collections import Counter
    res = 0
    
    num = 0
    amari = [0 for _ in range(n+1)]
    for i in range(n)[::-1]:
        j = n-1-i
        num += int(s[i]) * pow(10, j, p) %p
        num %= p
        amari[j+1] = num
    
    amaricnt = Counter(amari)
    for val in amaricnt.values():
        if val == 1:
            continue
        else:
            res += val*(val-1)//2
    
    return res

if p == 2 or p==5:
    print(twofive(n, p, s))
else:
    print(others(n, p, s))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
keys=[]
values=[]
ans=0
for i in A:
  if i in keys:
    pass
  else:
    counts=A.count(i)
    keys.append(i)
    values.append(counts)
    ans+=(counts)*(counts-1)/2
for k in A:
  a=keys.index(k)
  print(int(ans-values[a]+1))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
dic={}
for i in A:
  if i not in dic.keys():
    dic.update({i:1})
  else:
    dic[i]+=1
ans=sum([int(j*(j-1)/2) for j in dic.values()])
for k in A:
  num=dic[k]
  if num>=1:
    print(int(ans-num+1))
  else:
    print(ans)
### BUGGY CODE ###

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


def kouyaku(n,p):
    if n==1:
        return p 
    else:
        for i in range(round((p**(1/n)+1)),0,-1):        
            if p%i==0:
                if p%(i**2)==0:
                    if p%(i**n)==0:
                        return i

            
print(kouyaku(n,p))

### FIXED CODE ###

N, P = map(int, input().split())
ans = 1
 
if N >= 45:
  print(ans)
elif N == 1:
  print(P)
  
 
  
else:
  i = 1
  while(i**N <= P):
    if P % (i**N) == 0:
      ans = i
    i += 1
  print(ans)
### BUGGY CODE ###

#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_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 = int(input())
A = list(map(int, input().split()))
# A.sort(reverse=True)
A.sort()

def prime_decomposition(n):
    i = 2
    table = defaultdict(int)
    while i*i <= n:
        while n%i == 0:
            n //= i
            table[i] += 1
        i += 1
    if n > 1:
        table[n] += 1
    return table

ansA = [1]*N

num = defaultdict(int)
pdA = [prime_decomposition(val) for val in A]
for i, pdai in enu(pdA):
    num[A[i]] += 1
    for j, pdaj in enu(pdA[i+1:]):
        if ansA[i+j+1] == 0:
            continue
        if len(pdai) <= len(pdaj):
            for pdaii in pdai.items():
                ki, vi = pdaii
                if pdaj[ki] < vi:
                    break
            else:
                ansA[i+j+1] = 0

# print(A)
# print(ansA)
cnt = 0
for i, a in enu(A):
    if ansA[i] == 0:
        continue
    if num[a] > 1:
        continue
    cnt += 1

print(cnt)

### FIXED CODE ###

#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 = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
S = set(A)

maxA = A[-1]
chk = [0] * (maxA+1)
for s in S:
    for i in range(s, maxA+1, s):
        chk[i] += 1

res = [s for s in S if chk[s] == 1 and C[s] == 1]
# print(res)
print(len(res))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = [0] * N
for i in range(N):
    x = 1
    for j in range(N):
        if x == 1:
            ans[i] += A[(i+j)%N]
        else:
            ans[i] -= A[(i+j)%N]
        x ^= 1


print(" ".join(map(str, ans)))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = [0] * N
x = 1
for j in range(N):
    if x == 1:
        ans[0] += A[j%N]
    else:
        ans[0] -= A[j%N]
    x ^= 1

for i in range(N-1):
    ans[i+1] = (A[i] - ans[i] // 2) * 2

print(" ".join(map(str, ans)))
### BUGGY CODE ###

class UnionFind:
    def __init__(self, n, p):
        '木の初期化をする'
        # zero-index
        self.p  = [-1] * n
        self.rank = [1]*n
        # one -index
        self.g  = [set([i]) for i in range(n+1)]
        self.gp = [set([i]) for i in p]

    def find(self, x):
        'x の親を返す'
        if self.p[x] == -1:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def unite(self, x, y):
        'rankの低い親を高い方のの親にする'
        if not self.same(x,y):
            x = self.find(x)
            y = self.find(y)
            if self.rank[x] > self.rank[y]:
                x,y = y,x
            elif self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.g[y+1] = self.g[y+1] | self.g[x+1]
            self.gp[y+1]= self.gp[y+1]| self.gp[x+1]
            self.p[x] = y # x の親を y にする
            return True
        else:
            return False

    def same(self, x, y):
        return self.find(x) == self.find(y)


n,m = map(int,input().split())
p = [0] + list(map(int,input().split()))

uf = UnionFind(n,p)
for i in range(m):
    x,y = map(int,input().split())
    uf.unite(x-1,y-1)

parent = set()
for i in range(n):
    parent.add(uf.find(i))
ans = 0
for i in parent:
    ans += len(uf.g[i+1]) + len(uf.gp[i+1]) - len(uf.g[i+1] | uf.gp[i+1])
print(ans)


### FIXED CODE ###

class UnionFind:
    def __init__(self, n, p):
        '木の初期化をする'
        # zero-index
        self.p  = [-1] * n
        self.rank = [1]*n

    def find(self, x):
        'x の親を返す'
        if self.p[x] == -1:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def unite(self, x, y):
        'rankの低い親を高い方のの親にする'
        if not self.same(x,y):
            x = self.find(x)
            y = self.find(y)
            if self.rank[x] > self.rank[y]:
                x,y = y,x
            elif self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.p[x] = y # x の親を y にする
            return True
        else:
            return False

    def same(self, x, y):
        return self.find(x) == self.find(y)

def main():
    n,m = map(int,input().split())
    p = list(map(int,input().split()))

    uf = UnionFind(n,p)
    for i in range(m):
        x,y = map(int,input().split())
        uf.unite(x-1,y-1)

    ans = 0
    for i,j in enumerate(p):
        ans += uf.same(i, j-1)
    print(ans)
main()
### BUGGY CODE ###

# C - Remainder Minimization 2019
import numpy as np

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

ans = 2019
for i in range(l,r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)
        if ans==0:
            break

print(ans)

### FIXED CODE ###

# C - Remainder Minimization 2019
import numpy as np

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

ans = 2019
for i in range(l,r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)
        if ans==0:
            break
    else:
        continue
    break

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

#ABC172-D

def calc(x):
    a=0
    p=floor(x**0.5)
    cnt=0
    for i in range(1,p+1):
        if x%i==0:
            if i!=x//i:
                cnt +=2
            else:
                cnt +=1
    return cnt

from math import floor
N=int(input())
ans=0
for i in range(1,N+1):
    #print(i,calc(i))
    ans += i*calc(i)
print(ans)

### FIXED CODE ###

#ABC172-D

N=int(input())
yaku=[0]+[1]*N

for i in range(2,N+1):
    t=N//i
    for j in range(1,t+1):
        #print(i,j)
        yaku[i*j] +=1
ans=0
for i in range(1,N+1):
    ans += i*yaku[i]
print(ans)
### BUGGY CODE ###

def lcs_len(x, y):
    ly = len(y)
    tcsl = [0 for i in range(ly + 1)]
    for x_i in x:
        pre_tcsl = list(tcsl)
        for j in range(ly):
            if x_i == y[j]:
                tcsl[j] = pre_tcsl[j - 1] + 1
            else:
                tcsl[j] = max(pre_tcsl[j], tcsl[j - 1])
    return tcsl[j]


q = int(input())

ans = []

for i in range(q):
    ax = input()
    ay = input()
    ans.append(lcs_len(ax, ay))

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

### FIXED CODE ###

def lcs_len(x, y):
    indices = [0]
    for y_i in y:
        t_index = 0
        for i, index in enumerate(indices, 1):
            c_index = x.find(y_i, t_index) + 1
            if c_index:
                if i < len(indices):
                    t_index = indices[i]
                    indices[i] = min(c_index, t_index)
                else:
                    indices.append(c_index)
                    break
    print(len(indices) - 1)


q = int(input())

for i in range(q):
    ax = input()
    ay = input()
    lcs_len(ax, ay)
### BUGGY CODE ###

n,k = map(int,input().split())
l = list(map(int,input().split()))
l_ans = [0,abs(l[1]-l[0])]
for i in range(2,n):
    l_tmp=[]
    for j in range(1,min(i+1,k+1)):l_tmp.append(l_ans[i-j]+abs(l[i]-l[i-j]))
    l_ans.append(min(l_tmp))
print(l_ans[::-1][0])

### FIXED CODE ###

n,k = map(int,input().split())
l = list(map(int,input().split()))
l_ans = [0,abs(l[1]-l[0])]+[0]*(n-2)
for i in range(2,n):
    tmp1=float("inf")
    for j in range(1,min(i+1,k+1)):
        tmp2=l_ans[i-j]+abs(l[i]-l[i-j])
        if tmp1>tmp2:tmp1=tmp2
    l_ans[i]=tmp1
print(l_ans[::-1][0])