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

import numpy as np
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
bit_K = bin(K)
max_f = 0
for index in range(41,-2,-1):#range(1,len(bit_K))[::-1]:
   #d-bit目まではKと同じ
   #XがKより大きくならないように、上位ビットをKに合わせる。
    d=index
    if (d != -1 and not (K & 1 << d)):
        continue
    f=0
    for e in range(41,-1,-1):#range(2,len(bit_K))[::-1]:
        e=e
        mask = 1<<e
        num=0
        for a in A:#e-bit目が立っているA[i]を数える
            if a&mask:
                num+=1
        n_num = N - num
        #A[i]のe-bit目が立っていれば、XORの計算上0になるので、e-bit目が立っていないA[i]が加算
        if e>d:#dビット目より上はKに合わせる
            #以下、e-bit目だけ計算したf(x)
            if K&mask:
                f += mask*n_num
            else:
                f += mask*num
        elif e==d:
            f += mask*num
        else:#どうせ後から計算するからなんでもよい？
            f += mask*max(n_num,num)
    max_f = max(f,max_f)
print(max_f)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
"""
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
max_A = max(A)
bit = bin(K)
if max_A > K:
    bit = bin(max_A)"""
max_f = 0
#for d in range(1,len(bit))[::-1]:
for d in range(41,-2,-1):
    #d=d-2
    if (d != -1 and not (K & 1 << d)):
        continue
    f=0
    #for e in range(2,len(bit))[::-1]:
    for e in range(41,-1,-1):
        #e=e-2
        mask = 1<<e
        num=0
        for a in A:
            if a&mask:
                num+=1
        n_num = N - num
        if e>d:
            if K&mask:
                f += mask*n_num
            else:
                f += mask*num
        elif e==d:
            f += mask*num
        else:
            f += mask*max(n_num,num)
    max_f = max(f,max_f)
print(max_f)
### BUGGY CODE ###

n = int(input())
s = [list(map(int, input().split()))for i in range(n)]

l = [[s[0][1]]]

for i in range(1,n):
    if s[i][0]==1:
        l.append(l[-1]+[s[i][1]])
        l[-1].sort()
    else:
        l.append(l[-1])

ans = s[0][2]
p = 0

for i in range(1,n):
    q = s[i]
    if q[0]==1:
        ans += q[2]
        if len(l[i-1])%2==1:
            ans+=abs(l[i-1][p]-q[1])
        else:
            p+=1
            ans+=abs(l[i][p]-q[1])
    if q[0]==2:
        print(l[i][p], ans)


### FIXED CODE ###

import heapq

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

# 中央値より左・右の管理
l=[]
r=[]
heapq.heapify(l)
heapq.heapify(r)
lenl=0
lenr=0
# 中央値
x = s[1]

# b含めた答え
ans = s[2]

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if (lenl+lenr)%2==0:
            lenr+=1
            ans+=abs(x-q[1])
            if x<=q[1]:
                heapq.heappush(r,q[1])
            else:
                heapq.heappush(l,-q[1])
                heapq.heappush(r,x)
                x = -heapq.heappop(l)
        else:
            lenl+=1
            if x<q[1]:
                heapq.heappush(l,-x)
                heapq.heappush(r,q[1])
                x=heapq.heappop(r)
            else:
                heapq.heappush(l,-q[1])
            ans+=abs(x-q[1])
    if q[0]==2:
        print(x, ans)
### BUGGY CODE ###

import sys, heapq
input = sys.stdin.readline
n, q = map(int, input().split())
c = [int(x) - 1 for x in input().split()]


que = []
for i in range(q):
    l, r = map(int, input().split())
    heapq.heappush(que, (r-1, l-1, i))


lastAppeared = [-1 for _ in range(n)]
memo = [0 for _ in range(n)]
ans = [None for _ in range(q)]
for i in range(n):
    if lastAppeared[c[i]] != -1:
        memo[lastAppeared[c[i]]] -= 1
    lastAppeared[c[i]] = i
    memo[i] += 1

    while que and que[0][0] == i:
        r, l, x = heapq.heappop(que)
        ans[x] = sum(memo[l:r+1])

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


### FIXED CODE ###

import sys, heapq
input = sys.stdin.readline
n, q = map(int, input().split())
c = [int(x) - 1 for x in input().split()]

que = []
for i in range(q):
    l, r = map(int, input().split())
    que.append((l, r, i))



class SegTree(object):
    def __init__(self, n):
        self.BIT = [0] * (n + 1)
        self.num = n

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.BIT[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        while i <= self.num:
            self.BIT[i] += x
            i += i & (-i)
    

que.sort(key=lambda x: -x[1])
ans = [None] * q
last = [-1] * n
BIT = SegTree(n)

for i in range(1, n+1):
    if last[c[i-1]] != -1:
        BIT.add(last[c[i-1]], -1)
    last[c[i-1]] = i
    BIT.add(i, 1)

    while que and que[-1][1] == i:
        l, r, x = que.pop()
        ans[x] = BIT.sum(r) - BIT.sum(l-1)

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

from collections import defaultdict

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

d = defaultdict(list)

for i in xrange(m):
    (a, b) = map(int, raw_input().split())
    d[a].append(b)
    d[b].append(a)

pre = [0 for i in xrange(n + 1)]
cnt = 0

q = [1]
while q:
    cur = q.pop(0)
    for nxt in d[cur]:
        if pre[nxt] == 0:
            cnt += 1
            pre[nxt] = cur
            q.append(nxt)


if cnt < n - 1:
    print 'No'
else:
    print 'Yes'
    for i in xrange(2, n + 1):
        print pre[i]


### FIXED CODE ###

from collections import defaultdict, deque

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

d = defaultdict(list)

for i in xrange(m):
    (a, b) = map(int, raw_input().split())
    d[a].append(b)
    d[b].append(a)

pre = [0 for i in xrange(n + 1)]
cnt = 0

q = deque([1])
while q:
    cur = q.popleft()
    for nxt in d[cur]:
        if pre[nxt] == 0:
            cnt += 1
            pre[nxt] = cur
            q.append(nxt)


if cnt < n - 1:
    print 'No'
else:
    print 'Yes'
    for i in xrange(2, n + 1):
        print pre[i]
### BUGGY CODE ###

n, m = map(int, input().split())
s = set(range(1, n+1))

for i in range(m):
    l, r = map(int, input().split())
    s &= set(range(l, r+1))

print(len(s))

### FIXED CODE ###

n, m = map(int, input().split())
l, r = 1, n
for i in range(m):
    li, ri = map(int, input().split())
    if ri<l or r<li:
        print(0)
        exit()
    if l<=li and ri<=r:
        l, r = li, ri
    elif l<=ri<=r:
        r = ri
    elif l<=li<=r:
        l = li
    else:
        continue

print(r-l+1)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
counter = 0

while A:
    x = A[0]
    if A.count(x) % 2 == 1:
        counter += 1
    A = [i for i in A if i != x]

print(counter)


### FIXED CODE ###

N = int(input())
maps = {}

for _ in range(N):
    A = int(input())
    if A in maps:
        maps.pop(A)
    else:
        maps[A] = 1

print(len(maps))
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC0 = [0]*M
for m in range(M):
    BC0[m] = list(map(int, input().split()))
A.sort()
BC0.sort(key=lambda x:x[1])
BC = []
for bc0 in BC0:
    BC = BC + [bc0[1]]*bc0[0]

S = []
while len(S)<N:
    if len(BC)==0:
        S = S + A[-(N-len(S)):]
    elif A[-1] >= BC[-1]:
        S.append(A.pop())
    else:
        S.append(BC.pop())
        
print(sum(S))

### FIXED CODE ###

N, M = map(int, input().split())
A0 = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A = [[1,a] for a in A0] 
ABC = A + BC
ABC.sort(key=lambda x:x[1], reverse=True)

summation = 0
p = 0
n = 0

while n<N:
    summation += ABC[p][1] * (min(ABC[p][0], N-n))
    n += min(ABC[p][0], N-n)
    p += 1

print(summation)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans *= a[i]

if ans <= 10**18:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if a[-1] == 0:
    print(0)
else:
    for i in range(1, n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
    print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * 10 ** (len(S) - 1 - i)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 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()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i, 2019)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 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()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

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

k=int(input())
a=7
if k%2==0 or k%5==0:
	print(-1)
else:
	for i in range(k):
		if a%k==0:
			print(i+1)
			break
		a=a*10+7
	else:
		print(-1)

### FIXED CODE ###

k=int(input())
a=7%k
if k%2==0 or k%5==0:
	print(-1)
elif k==1:
	print(1)
else:
	for i in range(k):
		if a==0:
			print(i+1)
			break
		a=(a*10+7)%k
	else:
		print(-1)
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = []
if n % 2 == 0:
    for i in range(0, n, 2):
        ans.append(a[i])
    for i in range(1, n, 2):
        ans.insert(0, a[i])
else:
    ans.append(a[0])
    for i in range(1, n, 2):
        ans.append(a[i])
    for i in range(2, n, 2):
        ans.insert(0, a[i])
print(*ans)

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]
ans = []
if n == 1: print(a[0])
else:
    for i in a[::-2]:
        ans.append(i)
    if n % 2 == 0:
        for i in a[::2]:
            ans.append(i)
    else:
        for i in a[1::2]:
            ans.append(i)
print(*ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
count_list = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    A_sl.sort()
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A) + 1,max(A)):
        count = A.count(i-1) + A.count(i) + A.count(i+1)
        count_list.append(count)
    print(max(count_list))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
l = [0]*(10**5)
for e in A:
    if e == 0:
        l[0] += 1
        l[1] += 1
    elif e == 99999:
        l[99999] += 1
        l[99998] += 1
    else:
        l[e-1] += 1
        l[e] += 1
        l[e+1] += 1
print(max(l))
### BUGGY CODE ###

import bisect
n = int(input())
s = input()
R,G,B = [],[],[]
for i in range(n):
    if s[i]=='R':
        R.append(i)
    elif s[i]=='G':
        G.append(i)
    else:
        B.append(i)
cnt = 0
for r in R:
    for g in G:
        a,b = min(r,g), max(r,g)
        if 2*a-b in B:
            cnt += 1
        if 2*b-a in B:
            cnt += 1
        if (b-a)%2==0 and a+(b-a)//2 in B:
            cnt += 1
print(len(R)*len(G)*len(B)-cnt)

### FIXED CODE ###

n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
if ans==0:
    print(ans)
else:
    for i in range(n):
        for j in range(i+1, n):
            k=2*j-i
            if k<n:
                if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
                    ans -= 1
    print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from math import factorial 
P = int(1e9)+7
def c(n, m, P):
       ch = 1
       for i in range(m):
           ch *= (n-i)
           ch %= P
       b = factorial(m) 
       b = pow(b, P-2, P)
       return ch*b%P
def main():
    x, y = map(int, readline().split())
    a = 2*y-x
    b = 2*x-y
    if (a%3) or (b%3):
        print(0)
        return
    a = a//3
    b = b//3
    if a < 0:
        print(0)
        return
    if b < 0:
        print(0)
        return
    print(c(a+b, a, P)) 
if __name__ == '__main__':
    main()


### FIXED CODE ###

#python3
from math import factorial
from math import floor
MOD = int(1e9+7)

def comb(n, m, mod):
    comb_a = 1
    for i in range(m): 
        comb_a *= (n-i)
        comb_a %= mod
    comb_tmp = factorial(m) 
    comb_b = pow(comb_tmp, mod-2, mod)
    return (comb_a * comb_b)%mod
def main():
    x, y = map(int, input().split())
    k = (2*x-y)/3
    l = (2*y-x)/3

    if floor(k) - k != 0:
        print(0)
        return
    if floor(l) - l != 0:
        print(0)
        return 
    if k<0:
        print(0)
        return
    if l<0:
        print(0)
        return
    k = int(k)
    l = int(l)
    print(comb(k+l, k, MOD)%MOD) 

main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

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

ans = float("inf")
for i in range(N):
    cnt = 0
    cnt += S[:i].count("W")
    cnt += S[i+1:].count("E")
    ans = min(ans, cnt)
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-

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

# 初期値設定
cnt = S[1:].count("E")
ans = cnt
# 結局自分と1個前しか変化しない
for i in range(1, N):
    if S[i] == "E":
        cnt -= 1
    if S[i-1] == "W":
        cnt += 1
    ans = min(ans, cnt)

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

N = int(input())
A = list(map(int, input().split()))
M = []
for i in range(N):
    X = A[:i] + A[i+1:]
    for v in range(max(X), 0, -1):
        if all([x % v == 0 for x in X]):
            M.append(v)
print(max(M))

### FIXED CODE ###

from fractions import gcd

N = int(input())
As = list(map(int, input().split()))
re_As = As[::-1]
gcds = [0]*(N)
rgcds = [0]*(N)
gcds[0] = 0
rgcds[0] = 0

for i in range(N-1):
    gcds[i+1] = gcd(As[i], gcds[i])
    rgcds[i+1] = gcd(re_As[i], rgcds[i])

rgcds = rgcds[::-1]

ans = [0]*(N+1)

for i, (s, r) in enumerate(zip(gcds, rgcds)):
    ans[i] = gcd(s, r)
    
print(max(ans))
### BUGGY CODE ###

n,y=map(int,input().split())
for a in range(n+1):
    for b in range(n+1):
        c=(y-(a*10000+b*5000))//1000
        if y == (a*10000+b*5000+c*1000):
            if a+b+c==n and c>=0:
              print(a,b,c)
              exit()
print(-1,-1,-1)

### FIXED CODE ###

n,y=map(int,input().split())
for a in range(n+1):
    for b in range(n+1):
        c=(y-(a*10000+b*5000))//1000
        if a+b+c==n and c>=0:
            print(a,b,c)
            exit()
print(-1,-1,-1)
### BUGGY CODE ###

import sys

def max_heapify(A, i):
  l = i * 2
  r = l + 1
  largest = i
  H = len(A) -1
  if l <= H and A[l] > A[i]:
      largest = l
  if r <= H and A[r] > A[largest]:
      largest = r
  if largest != i:
    A[i], A[largest] = A[largest], A[i]
    max_heapify(A, largest)

def build_max_heap(A):
    for i in range(len(A)-1 // 2, 0, -1):
        max_heapify(A, i)

#@profile
def extract(A):
    out = A[1]
    A[1] = A[-1]
    del A[-1]
    max_heapify(A, 1)
    return out

_input = sys.stdin.readlines()
A = [0]

#@profile
def main():
    out = []
    for l in _input:
        if l[0] == "e":
            if l[1] == "n":
                #end
                print(*out, sep = "\n")
                return
            else:
                build_max_heap(A)
                #print(A)
                out.append(extract(A))
        else:
            #insert k
            k = int(l.split()[1])
            A.append(k)
            #build_max_heap(A)
        #print(A)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys

#@profile
def max_heapify(A, i):
    j = i
    largest = i
    H = len(A) -1
    while True:
        l = j * 2
        r = l + 1
        if l <= H and A[l] > A[j]:
            largest = l
        if r <= H and A[r] > A[largest]:
            largest = r
        if largest != j:
            A[j], A[largest] = A[largest], A[j]
            #max_heapify(A, largest)
            j = largest
            
        else:
            break
        

#@profile
def build_max_heap(A):
    i = len(A)-1
    last = A[i]
    parent = i//2
    while  parent > 0 and A[parent] < last:
        A[i] = A[parent]
        i = parent
        parent = i //2
    A[i] = last

#@profile
def extract(A):
    print(A[1])
    A[1] = A[-1]
    del A[-1]
    max_heapify(A, 1)
    
A = [0]

#@profile
def main():
    out = ""
    for l in sys.stdin.readlines():
        if l[0] == "i":
            #insert k
            A.append(int(l[7:]))
            build_max_heap(A)
        #print(A)
        elif l[1] == "n":
            #end
            print(out, end = "")
            return
        else:
            if len(A) <= 1:
                pass
            elif len(A) == 2:
                out += str(A.pop()) + "\n"
                #print(A.pop())
            #extract(A)
            else:
                out += str(A[1]) + "\n"
                A[1] = A.pop()
                max_heapify(A, 1)
                
if __name__ == "__main__":
    main()
### BUGGY CODE ###

n,*l=map(int,open(0).read().split())
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[k]>=l[i]+l[j]:
                break
            if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
                a+=1
print(a)

### FIXED CODE ###

import bisect
n,*l=map(int,open(0).read().split())
l.sort()
a=0
for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]
        a+=max(0,bisect.bisect_left(l,k)-j-1)
print(a)
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

a = [1]
r = -1
loc = 1


for i in range(N):
	loc = A[loc-1]
	#print(loc)
	if not loc in a:
		a.append(loc)
		#print(a)
	else:
		r = i+1
		loop_start = loc
		break

#print(a)
#print(r)
#print(loop_start)

for i in range(N):
	if a[i] == loop_start:
		l = i
		break

first = a[:l]
loop = a[l:]

#print(l, r)
#print(first)
#print(loop)


K += 1

if K <= len(first):
	print(a[K-1])
else:
	K -= len(first)
	K %= len(loop)
	print(loop[K-1])

### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

a = [1]
r = -1
loc = 1
b = [0]*(N+1)
b[1] = 1


for i in range(N):
	loc = A[loc-1]
	#print(loc)
	if b[loc] == 0:
		a.append(loc)
		b[loc] = 1
		#print(a)
	else:
		r = i+1
		loop_start = loc
		break

#print(a)
#print(r)
#print(loop_start)

for i in range(N):
	if a[i] == loop_start:
		l = i
		break

first = a[:l]
loop = a[l:]

#print(l, r)
#print(first)
#print(loop)


K += 1

if K <= len(first):
	print(a[K-1])
else:
	K -= len(first)
	K %= len(loop)
	print(loop[K-1])
### BUGGY CODE ###

n = int(input())
s = input()

result = []

for i in range(n - 2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            result.append(str(s[i])+str(s[j])+str(s[k]))

print(len(set(result)))

### FIXED CODE ###

n = int(input())
s = input()

ans = 0

for i in range(1000):
    # 確認するpinの数字の組み合わせと桁の初期化
    current_digit = 0
    pin = f'{i:0>3}'
    # pin = list(str(i).zfill(3))
    k = pin[current_digit]

    for num in s:
        # 見つけると桁を右に一つずらす
        if num == k:
            current_digit += 1
            # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
            if current_digit <= 2:
                k = pin[current_digit]

            elif current_digit == 3:
                ans += 1
                break

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

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


def calc(x):
    return (A*x)//B - A*(x//B)

index = 1
prev = -1
max_num = -1
flag = True
while flag and index <= N:
    tmp = calc(index)
    if tmp < prev:
        flag = False
    if max_num < tmp:
        max_num = tmp

    index += 1

print(max_num)


### FIXED CODE ###

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


def calc(x):
    return (A*x)//B - A*(x//B)

print(calc(min(B-1, N)))
### BUGGY CODE ###

n = int(input())
ans = 1
c=list(map(int, input().split()))
  
for i in range(n):
  ans *= c[i]

if ans>10**18:
  print(-1)
else:
  print(ans)




### FIXED CODE ###

n = int(input())
ans = 1
c=list(map(int, input().split()))

if 0 in c:
  print(0)
  
else:
  for i in range(n):
    ans *= c[i]
    if ans>10**18:
      print(-1)
      break
    
  if ans<=10**18:
    print(ans)
### BUGGY CODE ###

import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)

ans = 0
todo = []
done = set()
for s in range(N):
    if s in done:
        continue
    pdone = set()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    done |= pdone
    ans = max(ans, len(pdone))
print(ans)

### FIXED CODE ###

import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)
REL = [list(s) for s in REL]

ans = 0
todo = []
done = set()
pdone = set()
for s in range(N):
    if s in done:
        continue
    pdone.clear()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        done.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    ans = max(ans, len(pdone))
print(ans)
### BUGGY CODE ###

n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]
d=[0]*n
for i in range(1,n):
  d[i]=min([d[j] + abs(h[i]-h[j]) for j in range(max(i-k,0),i)])
print(d[n-1])

### FIXED CODE ###

def solve():
  n,k=[int(i) for i in input().split()]
  step=[int(i) for i in input().split()]
  dp=[0]*n
  for i in range(1,n):
    dp[i]=min([dp[j] + abs(step[i]-step[j]) for j in range(max(i-k,0),i)])
  return dp[n-1]
print(solve())