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

def main():
    import sys
    import heapq
    from copy import deepcopy
    from collections import deque
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    _N, K = [int(x) for x in input().strip().split()]
    V = deque([int(x) for x in input().strip().split()])
    max_ans = sum([v for v in V if v > 0])

    def dfs(ans, q, V, k):
        # print(k, q, V)
        ans = max(ans, sum(q))
        if ans == max_ans:
            print(ans)
            exit()
        if k == K:
            return ans
        if q:
            t = heapq.heappop(q)
            V.appendleft(t)
            ans = max(ans, dfs(ans, q[:], V, k+1))
            V.popleft()
            V.append(t)
            ans = max(ans, dfs(ans, q, V, k+1))
            V.pop()
            heapq.heappush(q, t)
        if V:
            q_l = q[:]
            q_r = q[:]
            t = V.popleft()
            heapq.heappush(q_l, t)
            ans = max(ans, dfs(ans, q_l[:], V, k+1))
            V.appendleft(t)
            t = V.pop()
            heapq.heappush(q_r, t)
            ans = max(ans, dfs(ans, q_r[:], V, k+1))
            V.append(t)
            
        return ans
    print(dfs(-float('inf'), [], V, 0))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    import heapq
    from copy import deepcopy
    from collections import deque
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    V = [int(x) for x in input().strip().split()]
    ans = -float('inf')
    for l in range(min(N, K)+1):
        for r in range(min(N, K)-l+1):
            vt = sorted(V[:l] + V[N-r:])
            c = 0
            i = 0
            for i in range(len(vt)):
                if c == (K-l-r):
                    break
                if vt[i] < 0:
                    vt[i] = 0
                    c += 1
                else:
                    break
            ans = max(ans, sum(vt))

    print(ans)

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

def main():
    from collections import defaultdict
    import sys
    
    s = input()
    t = input()
    ds = defaultdict(int)
    di = {}

    for i in range(len(s)):
        di[i] = defaultdict(int)
    
    for a in s:
        ds[a] = 1
        
    flag = 0
    for b in t:
        if ds[b] == 0:
            flag = 1
    if flag == 1:
        print(-1)
        sys.exit()

    s2 = s[::-1]
    for i in range(2*len(s)):
        for j in di[len(s) - (i-1)%len(s)-1]:
            di[len(s) - i%len(s)-1][j] = di[len(s) - (i-1)%len(s)-1][j] + 1
        di[len(s) - i%len(s) - 1][s2[(i-1)%len(s)]] = 1
    tmp = t[0]

    for k in range(len(s)):
        if tmp == s[k]:
            answer = k+1
            break
    for k in range(len(t)-1):
        l = k+1
        answer += di[(answer-1)%len(s)][t[l]]
        tmp = t[l]
    print(answer)
      

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    from collections import defaultdict
    import sys
    
    s = input()
    t = input()
    ds = defaultdict(int)
    di = {}

    for i in range(len(s)):
        di[i] = defaultdict(int)
    
    for a in s:
        ds[a] = 1
        
    flag = 0
    for b in t:
        if ds[b] == 0:
            flag = 1
    if flag == 1:
        print(-1)
        sys.exit()

    s2 = s[::-1]
    for i in range(2*len(s)):
        for j in di[len(s) - (i-1)%len(s)-1]:
            di[len(s) - i%len(s)-1][j] = di[len(s) - (i-1)%len(s)-1][j] + 1
        di[len(s) - i%len(s) - 1][s2[(i-1)%len(s)]] = 1
    tmp = t[0]

    for k in range(len(s)):
        if tmp == s[k]:
            answer = k+1
            break
    for k in range(len(t)-1):
        l = k+1
        answer += di[(answer-1)%len(s)][t[l]]
        tmp = t[l]
    print(answer)
      

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

def combi(x, y):
    if x < y:
        return 0
    if (x,y) in memo:
        return memo[(x,y)]
    else:
        memo[(x,y)]  = math.factorial(x) // (math.factorial(x - y) * math.factorial(y))
        return memo[(x,y)]
import math
memo = dict()
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mod = 10**9+7
ans = 0
for i in range(n):
    #今回の数字が、最小値として数えられる数の合計
    ans -= a[i] * combi(n - i - 1, k-1)
    #今回の数字が、最大値として数えられる数の合計
    ans += a[i] * combi(i,k-1)
    ans %= mod
print(int(ans))

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
mod = 10**9+7
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod
factorial = [1 for i in range(n+1)]
factorial[0] = 1
for i in range(1,n + 1):
    factorial[i] = factorial[i-1] * i
    factorial[i] %= mod
def mod_combi(a,b):
    if b == 0:
        return 1
    elif a == 0 or a < b:
        return 0
    elif a == b:
        return 1
    else:
        return (factorial[a] * mod_inv(factorial[b], mod) * mod_inv(factorial[a-b],mod)) % mod
ans = 0
#それぞれについて、最小になる場合と最大になる場合をもとめ、ans に加算する。
for i in range(n):
    patt_max = mod_combi(i, k-1)
    patt_min = mod_combi(n-i-1, k-1)
    ans += (patt_max - patt_min) * a[i]
    ans %= mod
print(ans)
### BUGGY CODE ###

L = list(input())
n = len(L)-1
div = 10**9+7

#階乗計算はmodを取りながら行う
def fact(a,n):
  ans = 1
  for i in range(1,n+1):
    ans = ans*a%div
  return ans

number = 1
many = 0
for i in range(1,n+1):
  if int(L[i]) == 1:
    many += fact(3,n-i) * fact(2,number) %div
    number += 1
many += fact(2,number) + fact(3,n)

print(many%div)

### FIXED CODE ###

mod = 10**9+7

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m) (aとmは互いに素)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m


L = list(input())
n = len(L)-1

#これだとTLEする

'''
number = 1
many = 0
for i in range(1,n+1):
  if int(L[i]) == 1:
    many += 3**(n-i) * 2**number %div
    number += 1
many += 2**number + 3**n
'''

beki3 = 3**n % mod
many = beki3
beki2 = 2
for i in range(1,n+1):
  beki3 = (beki3%mod)*mod_inv(3,mod)%mod
  if int(L[i]) == 1:
    many += beki3*beki2 %mod
    beki2 = beki2*2 %mod
many += beki2 % mod
print(many%mod)
### BUGGY CODE ###

N = int(input())
S = [input() for x in range(N)]

S_L = list(set(S))

# for i in S:
    # if i not in S_L:
        # S_L.append(i)
# print(S_L)

S_N = [0] * len(S_L)

for j in S:
    ind = S_L.index(j)
    S_N[ind] += 1
# print(S_N)

S_max = [] # 最大の数を持つ文字列を入れるリスト
S_N_max = max(S_N) # 最大の数を追加

for k in range(len(S_N)):
    if S_N[k] == S_N_max:
        S_max.append(S_L[k])

ans_L = sorted(S_max)

ans = ''
cnt = 0
rng = len(ans_L)
while cnt < rng:
    ans += ans_L[cnt]
    cnt += 1
    if cnt != rng:
        ans += ' '
print(ans)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = [input() for _ in range(N)]

S_cnt = Counter(S)
max_cnt = max(S_cnt.values())
# print(max_cnt)

names = [name for name, v in S_cnt.items() if v == max_cnt]
names.sort()

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

n,a=map(int,input().split())
N=list(map(int,input().split()))
from functools import lru_cache
@lru_cache(maxsize=1000000)
def cal(a,b,c):
    if a==b==c==0:
        return 1
    if a>=1 and c<N[a-1]:
        return cal(a-1,b,c)
    if a>=1 and b>=1and c>=N[a-1]:
        return(cal(a-1,b,c)+cal(a-1,b-1,c-N[a-1]))
    else:
        return 0
    
ans=0
for k in range(n):
    ans+=cal(n,k+1,(k+1)*a)
print(ans)

### FIXED CODE ###

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

for i in range(n):
    lists[i]-=a
answer=0
dp=[[0 for i in range(5001)] for _ in range(51)]
#dp[i][j]で0からi枚目まで好きなように選択してそのそうわがｊ-2500となるような撮り方の総数
#最終的に求めるのはdp[i][0]である

for i in range(n+1):
    for j in range(4951):
        if i>=1 and j>=lists[i-1]:
            dp[i][j]=dp[i-1][j-lists[i-1]]+dp[i-1][j]
        if i>=1 and j<lists[i-1]:
            dp[i][j]=dp[i-1][j]
        else:
            if j==2500 and i==0:
                dp[i][j]=1
            elif j!=2500 and i==0:
                dp[i][j]=0
print(dp[n][2500]-1)
### BUGGY CODE ###

N = int(input())
for n in range(1,N+1):
    if n < 6:
        print(0)
    else:
        M =int((n-2)**0.5)
        count = 0
        for x in range(1,M+1):
            for y in range(1,M+1):
                for z in range(1,M+1):
                    if (x+y)*(x+z)+y**2+z**2 == n:
                        count = count + 1
                    else:
                        pass
        print(count)

### FIXED CODE ###

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

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            p = (x+y)*(x+z)+y**2+z**2
            if p > N:
                break
            else:
                lst[p] += 1
for i in range(1,N+1):
    print(lst[i])
### BUGGY CODE ###

num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
for i in range(num):
	num_a = num_list[i]
	temp_sum = 0
	for j in range(i+1,num):
		temp_sum += num_list[j]
    	
    
	sigma += num_a * temp_sum

sigma %= law
print(sigma)

### FIXED CODE ###

num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
temp_sum = 0
for j in range(num):
	temp_sum += num_list[j]

for i in range(num):
	num_a = num_list[i]
	temp_sum -= num_a
	sigma += num_a * temp_sum


sigma %= law
print(sigma)
### BUGGY CODE ###

def f():
    return int(raw_input())
def f2():
    return map(int, raw_input().split())

def merge(left, mid, right):
    L = S[left:mid]
    R = S[mid:right]
    x = []
    c = right - left
    lp = 0
    rp = 0
    fa = True
    fb = True
    while True:
        if fa:
            try:
                a = L[lp]
            except:
                break
            lp += 1
            fa = False
        if fb:
            try:
                b = R[rp]
            except:
                break
            rp += 1
            fb = False
        if a < b:
            x.append(a)
            fa = True
        else:
            x.append(b)
            fb =True
    if fa:
        x.extend(R[rp-1:])
    else:
        x.extend(L[lp-1:])
    S[left:right] = x
    return c

def mergesort(left, right):
    c = 0
    if left + 1 < right:
        mid = (left + right)/2
        c += mergesort(left, mid)
        c += mergesort(mid, right)
        c += merge(left, mid, right)
    return c

global S
n = f()
S = f2()

c = mergesort(0, n)
print " ".join(map(str,S))
print c

### FIXED CODE ###

def f():
    return int(raw_input())
def f2():
    return map(int, raw_input().split())

def merge(left, mid, right):
    L = S[left:mid]
    R = S[mid:right]
    lp, rp, xp = 0, 0, 0
    a, b = L[0], R[0]
    c = right - left
    x = [0] * c
    flg = True
    while flg:
        while flg and a <= b:
            x[xp] = a
            lp += 1
            xp += 1
            try:
                a = L[lp]
            except:
                for e in R[rp:]:
                    x[xp] = e
                    xp += 1
                flg = False
        while flg and a >= b:
            x[xp] = b
            rp += 1
            xp += 1
            try:
                b = R[rp]
            except:
                for e in L[lp:]:
                    x[xp] = e
                    xp += 1
                flg = False
    S[left:right] = x
    return c

def mergesort(left, right):
    c = 0
    if left + 1 < right:
        mid = (left + right)/2
        c += mergesort(left, mid)
        c += mergesort(mid, right)
        c += merge(left, mid, right)
    return c

global S
n = f()
S = f2()

c = mergesort(0, n)
print " ".join(map(str,S))
print c
### BUGGY CODE ###

def binary(n):
    l = [0] * 40#n<10^12<2^40
    for i in range(39,-1,-1):
        if n >= 2 ** i:
            l[i] = 1
            n = n - 2 ** i
        else:
            l[i] = 0
    return l

def xor_plus(l1,l2):#引数はリストであることに注意
    l = [0] * 40
    for i in range(0,40):
        if l1[i] == l2[i]:
            l[i] = 0
        else:
            l[i] = 1
    return l#返り値はリストであることに注意

def backto10(l):
    s = 0
    for i in range(0,len(l)):
        s = s + l[i] * (2 ** i)
    return s

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

a_bi = [0] * n

for i in range(0,n):
    a_bi[i] = binary(a[i])

#print(a_bi)

k_bi = binary(k+1)

m = [0] * 40

for i in range(0,40):
    x_bi = [0] * 40
    if k_bi[i] == 0:
        continue
    for j in range(39,i,-1):
        x_bi[j] = k_bi[j]
    
    for j in range(0,i):
        count = 0
        for l in range(0,n):
            if a_bi[l][j] == 1:
                count = count + 1
        if count <= n - count:
            x_bi[j] = 1
    
    val = 0
    
    for j in range(0,n):
        val = val + backto10(xor_plus(x_bi,a_bi[j]))
    m[i] = val

print(max(m))

### FIXED CODE ###

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

def f(x):
    ret = 0
    for i in range(N):
        ret += A[i] ^ x
    return ret

###2**(num-1)<=K<2**numなるnumを求める
P = bin(K)
num = len(list(map(int,P[2:])))

best = 0

for i in range(num):
    count = 0###2**iの位が1になるAの個数
    for j in range(N):
        if A[j] > A[j]^(2**i):
            count += 1
    
    if count <= N - count:
        best += 2**i

#print(best)
can = [0]*40

for i in range(40):
    if K & 2**i == 0:
        continue
    for j in range(0,i):
        can[i] += best & 2**j
    for j in range(i+1,40):
        can[i] += K & 2**j

can.append(K)

print(max(list(map(f,can))))
### BUGGY CODE ###

from collections import deque

N, M, K = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int,input().split())
C = [0]*K
D = [0]*K
for i in range(K):
    C[i], D[i] = map(int,input().split())

friend = {i: set([]) for i in range(1, N+1)}
brock = {i: set([]) for i in range(1, N+1)}
for i in range(M):
    friend[A[i]].add(B[i])
    friend[B[i]].add(A[i])
for i in range(K):
    brock[C[i]].add(D[i])
    brock[D[i]].add(C[i])

labels = [0] * (N+1)


def mark(n, label):
    if labels[n] != 0:
        return -1
    else:
        q = deque()
        q.append(n)
        labels[n] = label
        while q != deque():
            node = q.pop()
            labels[node] = label
            for i in friend[node]:
                if labels[i] == 0:
                    q.append(i)
        return label


label = 1
for n in range(1, N + 1):
    if mark(n, label) != -1:
        label += 1

group_size = [0] * label
for l in range(1, len(group_size)):
    group_size[l] = len([i for i in labels if i == l])

res = [0] * N
for n in range(1, N + 1):
    tmp = 0
    for b in brock[n]:
        if labels[n] == labels[b]:
            tmp += 1
    res[n - 1] = group_size[labels[n]] - 1 - len(friend[n]) - tmp

print(*res)


### FIXED CODE ###

from collections import deque
from collections import Counter
N, M, K = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
C = [0]*K
D = [0]*K
for i in range(K):
    C[i], D[i] = map(int,input().split())

friend = {i: set([]) for i in range(1, N+1)}
brock = {i: set([]) for i in range(1, N+1)}
for i in range(M):
    friend[A[i]].add(B[i])
    friend[B[i]].add(A[i])
for i in range(K):
    brock[C[i]].add(D[i])
    brock[D[i]].add(C[i])

labels = [0] * (N+1)


def mark(n, label):
    if labels[n] != 0:
        return -1
    else:
        q = deque()
        q.append(n)
        labels[n] = label
        while q != deque():
            node = q.pop()
            labels[node] = label
            for i in friend[node]:
                if labels[i] == 0:
                    q.append(i)
        return label


label = 1
for n in range(1, N + 1):
    if mark(n, label) != -1:
        label += 1

group_size = Counter(labels)

res = [0] * N
for n in range(1, N + 1):
    tmp = 0
    for b in brock[n]:
        if labels[n] == labels[b]:
            tmp += 1
    res[n - 1] = group_size[labels[n]] - 1 - len(friend[n]) - tmp

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

# -*- coding: utf-8 -*-
# INF=10^7程度じゃインプットの桁数ふえた時に更新処理が正しく走らず結果エラーになってしまう..
INF = 1000000000
n, k = map(int,  input().split())
h = list(map(int, input().split()))
dp = [INF]*n
dp[0] = 0

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

print(dp[n-1])


### FIXED CODE ###

# -*- coding: utf-8 -*-
# INF=10^7程度じゃインプットの桁数ふえた時に更新処理が正しく走らず結果エラーになってしまう..
INF = 1000000000
n, k = map(int,  input().split())
h = list(map(int, input().split()))
dp = [INF]*n
dp[0] = 0

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

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

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

mi = 10000000
for i in range(N):
    f1 = S[0:i]
    f2 = S[i+1:]
    K = f1.count('W')+f2.count('E')
    if K <= mi:mi=K
print(mi)

### FIXED CODE ###

N = int(input())
S = list(input())
E = S[1:].count('E')
W = 0
mi = E+W
for i in range(1,N):
    if S[i] == 'E':E -= 1
    if S[i-1] == 'W':W+=1
    if E+W <= mi:mi = E+W
print(mi)
### BUGGY CODE ###

import fractions
a=0
N=int(input())
for i in range(1,N+1):
  for j in range(1,N+1):
    for k in range(1,N+1):
      c=fractions.gcd(i,j)
      a+=fractions.gcd(c,k)
print(a)

### FIXED CODE ###

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
a=0
N=int(input())
for i in range(1,N+1):
  for j in range(i,N+1):
    for k in range(j,N+1):
      if i==j==k:
        a+=i
      elif i==j or j==k or i==k:
        c=euclid(i, j)
        c=euclid(c, k)
        a+=3*c
      else:
        c=euclid(i, j)
        c=euclid(c, k)
        a+=6*c
print(a)
### BUGGY CODE ###

N, S = map(int,input().split())
A = [int(s) for s in input().split()]
DP = [[0 for j in range(S + 1)] for i in range(N + 1)]
mod = 998244353
DP[0][0] = 1

for i in range(N):
  for j in range(S + 1):
    DP[i + 1][j] += 2 * DP[i][j]
    DP[i + 1][j] %= mod
    if j + A[i] <= S:
      DP[i + 1][j + A[i]] += DP[i][j]
      DP[i + 1][j + A[i]] %= mod

print(DP[N][S])

### FIXED CODE ###

N, S = map(int,input().split())
A = [int(s) for s in input().split()]
DP = [[0 for j in range(S + 1)] for i in range(N + 1)]
mod = 998244353
DP[0][0] = 1

for i in range(N):
  for j in range(S + 1):
    DP[i + 1][j] += 2 * DP[i][j]
    DP[i + 1][j] %= mod
    if j + A[i] <= S:
      DP[i + 1][j + A[i]] += DP[i][j]
      DP[i + 1][j + A[i]] %= mod

print(DP[N][S])
### BUGGY CODE ###

def get_divisors(n):
    divisors = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            divisors.add(i)
            divisors.add(n // i)
        i += 1
    return divisors

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()

div_set = set(x for x in set(a_list) if a_list.count(x) > 1)

count = 0
i = 0
for a in a_list:
    j = 1
    divisible = False
    while j * j <= a:
        if a % j == 0:
            if j in div_set or a // j in div_set:
                divisible = True
                break
        j += 1
    if not divisible:
        count += 1
    div_set.add(a)
print(count)

    

### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[-1]

divisible = [False] * (a_max + 1)

count = 0
i = 0
for i in range(n):
    if divisible[a_list[i]]:
        continue
    if i < n - 1 and a_list[i] == a_list[i + 1]:
        while i < n - 1 and a_list[i] == a_list[i + 1]:
            i += 1
    else:
        count += 1
    x = a_list[i]
    while x <= a_max:
        divisible[x] = True
        x += a_list[i]
print(count)
### BUGGY CODE ###

a,b=map(int,input().split())
g=b
while a<b:
  g^=a
  a+=1
print(g)

### FIXED CODE ###

def calculate(A):
  c=(int((A+1)/2))%2
  if A%2==0:
    c=c^A
  return c

A,B=map(int,input().split())
print(calculate(A-1)^calculate(B))
### BUGGY CODE ###

h,n = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

dp = [float("inf")]*(h+1)
dp[0] = 0

for i in range(h):
  for d,c in ab:
    hp = min(i+d,h)
    dp[hp] = min(dp[hp],dp[i]+c)

print(dp[-1])

### FIXED CODE ###

h,n = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

dp = [float("inf")]*(h+1)
dp[0] = 0

for i in range(h):
  for d,c in ab:
    hp = min(i+d,h)
    dp[hp] = min(dp[hp],dp[i]+c)

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

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

Frends = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Frends[a].append(b)
    Frends[b].append(a)

Blocked = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    Blocked[c].append(d)
    Blocked[d].append(c)

# process
# 友人グループを作成
fg = []
for i in range (N):
    l = [x for x in Frends[i] if x>i]
    if len(l) == 0:
        continue

    l.append(i)
    s = set(l)

    t = -1
    j = 0
    fglen = len(fg)
    while j < fglen:
        sfg = s&fg[j]
        if len(sfg) > 0:
            if t < 0:
                t = j
                fg[j] |= s
            else:
                fg[t] |= fg[j]
                fg.pop(j)
                fglen -= 1
        j += 1

    if t < 0:
        fg.append(s)

# 友人候補を抽出、カウント
cand = [0 for _ in range(N)]
for g in fg:
    for f in g:
        cand[f] = len(g)-len(Frends[f])-len(set(Blocked[f])&g)-1

# output
#print(fg)
print(" ".join(map(str, cand)))


### FIXED CODE ###

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

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

Blocked = [set() for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    Blocked[c].add(d)
    Blocked[d].add(c)

# process
# 友人グループを作成
checked = set()
ans = [0]*N

for i in range (N):
    if i in checked:
        continue
    
    fg = set()

    stack = list(Friends[i])
    while stack:
        f = stack.pop()
        if f in checked:
            continue

        checked.add(f)
        fg.add(f)
        stack.extend(Friends[f])

    for f in fg:
        ans[f] += len(fg)-1-len(fg&(Friends[f]|Blocked[f]))

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

inp = list(map(int, input().split(" ")))
N, K = inp[0], inp[1]
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h_arr[1]-h_arr[0])

for i in range(2, N):
	min_list = []
	for j in range(1, K+1):
		if i >= j:
			min_list.append(abs(h_arr[i]-h_arr[i-j]) + dp[i-j])
	dp[i] = min(min_list)
		
print(dp[-1])

### FIXED CODE ###

n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])