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

N, K, Q =map(int, input().split())
A = [int(input()) for _ in range(Q)]
point = [int(K) for _ in range(N)]
result = point[:]

for i in range(Q):
  result = list(map(lambda x: x-1, result))
  result[A[i]-1] += 1

for i in range(N):
  print('Yes' if result[i]>0 else 'No')

### FIXED CODE ###

N, K, Q =map(int, input().split())
A = [int(input()) for _ in range(Q)]
point = [K-Q]*N

for i in range(Q):
  point[A[i]-1] += 1
  
for i in range(N):
  print('Yes' if point[i]>0 else 'No')
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

for List in list(uf.all_group_members().values()):
    tree=set()
    for i in range(len(List)):
        tree.add(p[List[i]])
    for g in range(len(List)):
        if List[g]+1 in tree:
            p[List[g]]=List[g]+1

ans=0
for i in range(n):
    if p[i]==i+1:
        ans+=1
print(ans)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

ans=0
for i in range(n):
    if uf.same(i,p[i]-1):
        ans+=1
print(ans)
### BUGGY CODE ###

N = int(input())
L = sorted([int(i) for i in input().split()], reverse=True)

def count(l, m, ls):
    if ls[0] <= l - m:
        return 0
    if ls[-1] > l - m:
        return len(ls)

    left = 0
    right = len(ls) - 1
    while right - left > 1:
        mid = (left + right) // 2

        if ls[mid] > l-m: left = mid
        if ls[mid] <= l-m: right = mid

    return left + 1

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += count(L[i], L[j], L[j+1:])

print(ans)

### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - (j + 1)

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

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

ans=(ans-s)//2
ans=ans%(10**9+7)



print(ans)


### FIXED CODE ###

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

ans=(t*t-s)//2
ans=ans%(10**9+7)



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

import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m,Q=mp()
grid=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=mp()
    for j in range(1,l+1):
        for k in range(r,n+1):
            grid[j][k]+=1
for i in range(Q):
    p,q=mp()
    print(grid[p][q])



### FIXED CODE ###

import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m,Q=mp()
grid=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=mp()
    for k in range(1,l+1):
        grid[k][r]+=1

for i in range(n):
    for k in range(n):
        grid[i][k+1]+=grid[i][k]



for i in range(Q):
    p,q=mp()
    print(grid[p][q])
### BUGGY CODE ###

# cook your dish here
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    if i % 2 == 0:
        b.insert(0,a[i])
    else:
        b.append(a[i])
c = b[::-1]
ass = ''
for i in range(n):
    if n %2 == 0:
        ass += str(c[i]) + ' '
    else:
        ass += str(b[i]) + ' '
print(ass)

    

### FIXED CODE ###

# cook your dish here
n = int(input())
a = list(map(int,input().split()))
c = []
d = []

for i in range(n):
    if i %2 == 0:
        c.append(a[i])
    else:
        d.append(a[i])
c = c[::-1]

b = c + d
c = b[::-1]
ass = ''
for i in range(n):
    if n %2 == 0:
        ass += str(c[i]) + ' '
    else:
        ass += str(b[i]) + ' '
print(ass)
### BUGGY CODE ###

N,M = map(int,input().split())
XY = []
for i in range(M):
    xy = list(map(int,input().split()))
    XY.append(xy)
p = [i+1 for i in range(N)]
ans = []

while len(p) >= 1:
    for i in p:
        flag = True
        for xy in XY:
            if i == xy[1] and xy[0] not in ans:
                flag = False
        if flag:
            ans.append(i)
            p.remove(i)

dp = [0 for i in range(len(ans))]

for i in range(len(ans)):
    for j in range(i):
        if [ans[j],ans[i]] in XY:
            dp[i] = max(dp[i],dp[j]+1)


print(max(dp))        


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)
### BUGGY CODE ###

import sys
from collections import defaultdict, deque
input = sys.stdin.readline
N, M = map(int, input().split())
guidepost = [None] * N
distance = [0] + [10**9] * (N - 1)
dd = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    dd[a].append(b)
    dd[b].append(a)
stack = deque([1])
checked = [False] * N
while len(stack) >= 1:
    i = stack.popleft()
    checked[i - 1] = True
    for j in dd[i]:
        distance[j - 1] = min(distance[j - 1], distance[i - 1] + 1)
        if guidepost[j - 1] is None:
            guidepost[j - 1] = i
        elif distance[guidepost[j - 1] - 1] > distance[i - 1]:
            guidepost[j - 1] = i
        if not checked[j - 1]:
            stack.append(j)
print('Yes')
# join?
# for i in range(1, N):
#     print(guidepost[i])
print('\n'.join([str(guidepost[i]) for i in range(1, N)]))

### FIXED CODE ###

import sys
from collections import defaultdict, deque
input = sys.stdin.readline
N, M = map(int, input().split())
guidepost = [None] * N
distance = [0] + [10**9] * (N - 1)
dd = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    dd[a].append(b)
    dd[b].append(a)
stack = deque([1])
checked = [False] * N
while len(stack) >= 1:
    i = stack.popleft()
    if checked[i - 1]:
        continue
    checked[i - 1] = True
    for j in dd[i]:
        distance[j - 1] = min(distance[j - 1], distance[i - 1] + 1)
        if guidepost[j - 1] is None:
            guidepost[j - 1] = i
        elif distance[guidepost[j - 1] - 1] > distance[i - 1]:
            guidepost[j - 1] = i
        if not checked[j - 1]:
            stack.append(j)
print('Yes')
# join?
# for i in range(1, N):
#     print(guidepost[i])
print('\n'.join([str(guidepost[i]) for i in range(1, N)]))
### BUGGY CODE ###

import sys

inp = list(map(lambda x: int(x), input().split(" ")))
n = inp[0]
k = inp[1]
inp = list(map(lambda x: int(x), input().split(" ")))

dp = [0]*(n)

for i in range(n-1):
    dp[i+1] = dp[i] + abs(inp[i+1]-inp[i])
    for j in range(2,k+1):
        if (i+1-j>=0):
            dp[i+1] = min(dp[i+1], dp[i+1-j] + abs(inp[i+1]-inp[i+1-j]))

print(dp[-1])

### FIXED CODE ###

import sys

inp = list(map(lambda x: int(x), input().split(" ")))
n = inp[0]
k = inp[1]
inp = list(map(lambda x: int(x), input().split(" ")))

dp = [0]*(n)

for i in range(n-1):
    dp[i+1] = dp[i] + abs(inp[i+1]-inp[i])
    for j in range(2,k+1):
        if (i+1-j>=0):
            dp[i+1] = min(dp[i+1], dp[i+1-j] + abs(inp[i+1]-inp[i+1-j]))

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

x, y = input().split()

l = int(x)
r = int(y)

all_mod = []

for i in range(l, r, 1): # l <= i < r - 1

    for j in range(l + 1, r + 1, 1):

        p = i * j
        mod = p % 2019
        all_mod.append(mod)


print(min(all_mod))

### FIXED CODE ###

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


all_mod = []

cnt1 = 0
for i in range(l, r, 1):
    cnt = 0
    for j in range(l + 1, r + 1, 1):
        mod = (i * j) % 2019

        all_mod.append(mod)

        if mod == 0:
            break

        cnt += 1

        if cnt > 2019:
            break

    if mod == 0:
        break

    cnt1 += 1
    if cnt1 > 2019:
        break

print(min(all_mod))
### BUGGY CODE ###

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

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = len(b)

res = 0
for i in range(51):
    p = res + (1 << (50-i))
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

### FIXED CODE ###

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

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)
### BUGGY CODE ###

from collections import defaultdict
n, q = map(int, input().split())
child_dict = defaultdict(list)
value_dict = defaultdict(lambda: 0)
rank_dict = defaultdict(lambda: 0)
for _ in range(n - 1):
    a, b = map(int, input().split())
    child_dict[a].append(b)
    rank_dict[b] += rank_dict[a] + 1

for _ in range(q):
    c, d = map(int, input().split())
    value_dict[c] += d
from collections import deque
stack = deque()
top = [k for k, v in rank_dict.items() if v == 0][0]
stack.append(top)
while stack:
    top_ = stack.pop()
    for child in child_dict[top_]:
        value_dict[child] += value_dict[top_]
    stack.extend(child_dict[top_])
ans = [value_dict[i] for i in range(1 ,n+1)]
print(*ans)

### FIXED CODE ###

n, q = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
point_list = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    point_list[p] += x

from collections import deque
d = deque()
d.append(0)
visited = set([])

while d:
    x = d.popleft()
    for child in graph[x]:
        if child not in visited:
            point_list[child] += point_list[x]
            d.append(child)
        visited.add(x)
print(*point_list)
### BUGGY CODE ###

import bisect
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    tmp_max = max(a)
    a.remove(tmp_max)
    a.append(tmp_max // 2)
print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
for _ in range(m):
    min = ((heapq.heappop(a) * (-1)) // 2) * (-1)
    heapq.heappush(a, min)
print(sum(a)*(-1))
### BUGGY CODE ###

import numpy as np
import sys

input = sys.stdin.readline

N, M = (int(i) for i in input().split())
input_list = [[int(i) for i in input().split()] for i in range(M)] 

m_list = [[] for j in range(N)]

for inputs in input_list:
    m_list[inputs[0]-1].append(inputs[1])

for arr in m_list:
    arr.sort()

for inputs in input_list:
    num = m_list[inputs[0]-1].index(inputs[1]) + 1
    print(str(inputs[0]).zfill(6) + str(num).zfill(6))

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
N, M = (int(i) for i in input().split())
py_list = [[int(i) for i in input().split()] + [0] for i in range(M)] 
m_list = [[] for j in range(N+1)]
 
sorted_py_list = sorted(py_list, key=lambda x:x[1])

city_list = {}
for py in sorted_py_list:
    city_list[py[0]] = city_list[py[0]]+1 if py[0] in city_list else 1
    py[2] = city_list[py[0]]
 
for py in py_list:
    print(str(py[0]).zfill(6) + str(py[2]).zfill(6))
### BUGGY CODE ###

N=int(input())
s=[]
for i in range(N):
    s.append(input())

su=[]
for i in s:
    shu=sorted(list(i))
    su.append("".join(shu))


count=0
while len(su)>0:
  j=su[0]
  del su[0]
  c=su.count(j)
  count+=c*(c+1)/2
  for i in range(c):
    su.remove(j)
  
print(int(count))

### FIXED CODE ###

import collections
N=int(input())
su=["".join(sorted(list(input()))) for _ in range(N)]

C=list(collections.Counter(su).values())

ans=0
for i in C:
  if i>1:
    ans+=i*(i-1)//2

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

import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S = S[::-1]
    elif q[0] == '2':
        if q[1] == '1':
            S = q[2] + S
        elif q[1] == '2':
            S = S + q[2]

print(S)


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N, H = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    cnt = 0
    max_A = max(A)
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max(A):
            cnt += 1
            H -= b
        else:
            break

        if H <= 0:
            break
    
    cnt += H // max(A) if H % max(A) == 0 else H // max(A) + 1
    print(cnt)



if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N, H = map(int, input().split())

    A = [0] * N
    B = [0] * N

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

    sort_B = sorted(B, reverse=True)
    max_A = max(A)
    ans = 0
    for b in sort_B:
        if b > max_A:
            ans += 1
            H -= b
        else:
            break
        
        if H <= 0:
            break
    
    if H > 0:
        ans += -(-H // max_A)

    print(ans)

main()
### BUGGY CODE ###

import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**6+1

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

sosu_li = [[i,0] for i in range(num)]
kosu = 0

for i in range(n):
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        #print(sosu_li)
        if sosu_li[j][1] == 0:
            sosu_li[j][1] = 1
            kosu += 1
        com_ab[j] = max(com_ab[j],pri_li[i][j])

sosu_li.sort(reverse=True,key=lambda x: x[1])
"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    kari = 1
    for j in range(kosu):
        kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    for j in keys:
        kari *= pow(pow(j,pri_li[i][j],mod),mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)


### FIXED CODE ###

import collections
import math
n = int(input())
ai = [int(i) for i in input().split()]

mod = 10**9+7

if n == 1:
    print(1)
    exit()
    
    
# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor


dic = {}
for a in ai:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

kari = 1
for num,count in dic.items():
    kari *= pow(num,count,mod)
    kari %= mod

kari_old = kari
ans = 0

for i in range(n):
    kari = kari_old
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    #kari = 1
    #for j in range(kosu):
    #kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    kari *= pow(ai[i],mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
    #print(ans)
        
print(ans)
### BUGGY CODE ###

pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])


### FIXED CODE ###

pre_n, city_n = map(int, input().split())
cities = [list(map(int, input().split())) for x in range(city_n)]

history = {}

A = {}

for x in sorted(cities):
    pref = str(x[0])
    if pref not in history:
        history[pref] = '1'

    A.setdefault(str(x), '0'*(6-len(pref)) + pref + '0'*(6-len(history[pref])) + history[pref])

    history[pref] = str(int(history[pref]) + 1)

for x in cities:
    print(A[str(x)])
### BUGGY CODE ###

from collections import Counter

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

A.sort(reverse=True)
c = Counter(A)
res = 0
for a in A:
    for i in range(1, 33):
        n = 2 ** i - a
        if n in c.keys():
            if a == n and c[a] > 1:
                c[a] -= 2
                res += 1
            elif a != n and c[a] > 0 and c[n] > 0:
                c[a] -= 1
                c[n] -= 1
                res += 1
    
print(res)
    



### FIXED CODE ###

from collections import Counter

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

A.sort(reverse=True)
c = Counter(A)
res = 0
for a in A:
    n = 2 ** a.bit_length() - a
    if n in c.keys():
        if a == n and c[a] > 1:
            c[a] -= 2
            res += 1
        elif a != n and c[a] > 0 and c[n] > 0:
            c[a] -= 1
            c[n] -= 1
            res += 1
    
print(res)
### BUGGY CODE ###


#素因数分解（10**6まで）
def soinsu_bunkai(m):
    pf=set()
    mm =m
    for i in pri_num:
        while mm %i==0:
            pf.add(i)
            mm //=i
    if mm !=1:
        pf.add(mm)
    return pf

    # 初期入力
import math
import sys
from collections import Counter
from functools import reduce
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))
intersect =set()
pair_w =set()

# 10**6までの素因数分解するために、「10**6のルート」までの素数を列挙
pri =10**6 +10
sq_pri =int(math.sqrt(pri))
#pri_num =prime_numbers(sq_pri +10 )
pri_num =[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009]

#not coprimeの判定
gcd_a =reduce(math.gcd,A)
if gcd_a !=1:
    ans ="not coprime"

#pairwise coprimeの判定
else:
    for a in A:
        aa =soinsu_bunkai(a)
        if intersect & aa:
            print("setwise coprime")
            sys.exit() #共通要素があったらpair_wではない→set_w
        intersect |=aa

    ans ="pairwise coprime"
print(ans)

### FIXED CODE ###

#高速素因数分解  osa_k法 
def osa_k(a):
    tmp = set()
    while a > 1:
        tmp.add(sieve[a])
        a //= sieve[a]
    return tmp

    # 初期入力
import math
import sys
from bisect import bisect_left
from functools import reduce
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))
used =set()

#not coprimeの判定
gcd_a =reduce(math.gcd,A)
if gcd_a !=1:
    ans ="not coprime"

#pairwise coprimeの判定
else:
    MAXN =10**6 +10
    #osa_k法
    sieve = [i for i in range(MAXN+1)]
    p = 2
    while p*p <= MAXN:
        if sieve[p] == p:
            for q in range(2*p,MAXN+1,p):
                if sieve[q] == q:
                    sieve[q] = p
        p += 1
    
    ans ="pairwise coprime"
    for a in A:
        aa =osa_k(a)
        if used & aa:
            ans ="setwise coprime"
            break #共通要素があったらpair_wではない→set_w
        used |=aa
    
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
H=list(map(int,input().split()))
INF=10**9
add_list=[INF]*K

H.extend(add_list)
K_LOOP=K+1

dp=[INF]*(N+100) #Kの分追加
dp[0]=0
for n in range(N):
    for k in range(1,K_LOOP):
        dp[n+k]=min(dp[n+k], dp[n]+abs(H[n]-H[n+k]))
print(dp[N-1])

### FIXED CODE ###

# 貰うDP
N,K=map(int,input().split())
h=list(map(int,input().split()))
INF=10**9
dp=[INF]*(N)
dp[0]=0

for n in range(1,N):
    dp[n]=min([dp[k] + abs(h[n] - h[k]) for k in range(max(0,n-K), n)])
print(dp[N-1])