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

def calcAreas(sections):
    areas = []

    for s in sections:
        if len(s) <= 1:
            continue;

        areas.append(toArea(s))

    return areas

def toArea(section):
    a = 0
    b, _ = section[0]

    for s, e in section:
        a += (max(s, e) - b) - (0.5 if s != e else 0)

    return int(a)

def toDelta(p):
    if '/' == p:
        return -1
    if '\\' == p:
        return 1
    return 0

def toPaths(path):
    h = 0
    ph = 0
    paths = []

    for p in path:
        h += toDelta(p)
        paths.append((ph,h))
        ph = h

    return paths

def update(sections):
    [(lf, ll)] = sections.pop()

    n = None

    for i in range(len(sections)-1, -1, -1):
        if sections[i][0][0] == ll:
            n = i
            break

    if n == None:
        sections.append([(lf, ll)])
        return

    lst = [(lf, ll)]
    for i in range(len(sections)-1, n-1, -1):
        s = sections.pop()
        lst = s + lst

    sections.append(lst)

def main():
    paths = toPaths(input())

    prev = -1
    sections = []

    for f, l in paths:
        sections.append([(f, l)])
        if l < prev:
            update(sections)
        prev = l

    areas = calcAreas(sections)
    l = len(areas)

    print(sum(areas))
    print(l, end='')
    if l > 0:
        print(' {}'.format(' '.join([str(x) for x in areas])), end='')
    print()

if __name__ == '__main__':
    main()



### FIXED CODE ###

def calcAreas(sections):
    areas = []

    for s in sections:
        if len(s) <= 1:
            continue;

        areas.append(toArea(s))

    return areas

def toArea(section):
    a = 0
    b, _ = section[0]

    for s, e in section:
        a += (max(s, e) - b) - (0.5 if s != e else 0)

    return int(a)

def toDelta(p):
    if '/' == p:
        return -1
    if '\\' == p:
        return 1
    return 0

def toPaths(path):
    h = 0
    ph = 0
    paths = []

    for p in path:
        h += toDelta(p)
        paths.append((ph,h))
        ph = h

    return paths

def update(sections):
    [(lf, ll)] = sections.pop()

    n = None

    for i in range(len(sections)-1, -1, -1):
        if sections[i][0][0] == ll:
            n = i
            break

    if n == None:
        sections.append([(lf, ll)])
        return False

    lst = [(lf, ll)]
    for i in range(len(sections)-1, n-1, -1):
        s = sections.pop()
        lst = s + lst

    sections.append(lst)
    return True

def main():
    paths = toPaths(input())

    prev = -1
    sections = []

    prev_update = True

    for f, l in paths:
        sections.append([(f, l)])
        if l < prev:
            if prev_update:
                prev_update = update(sections)
        else:
            prev_update = True

        prev = l

    areas = calcAreas(sections)
    l = len(areas)

    print(sum(areas))
    print(l, end='')
    if l > 0:
        print(' {}'.format(' '.join([str(x) for x in areas])), end='')
    print()

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

#129_C
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
mod=10**9+7
dp=[1 for i in range(n+1)]
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    elif i==1:
        dp[i]=dp[i-1]
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mod
        
print(dp[n]%mod)

### FIXED CODE ###

#129_C
n,m=map(int,input().split())
a={int(input()) for _ in range(m)}
mod=10**9+7
dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mod
        
print(dp[n])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    for i in range(K):
        if A >= 1:
            A -= 1
        elif B>=1:
            B-=1
        else:
            break
    print(A,B)
    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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    if A <= K:
        K -= A
        A = 0
        if B <= K:
            B = 0
        else:
            B-=K
    else:
        A -= K
    print(A,B)
    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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)

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

n,q=map(int,input().split())
s=input()
dp=[0]*n
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    dp[i]=1

for i in range(q):
  l,r=map(int,input().split())
  print(sum(dp[l-1:r-1]))
  


### FIXED CODE ###

n,q=map(int,input().split())
s=input()
dp=[0]*n
count=0
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    dp[i]=1+count
    count+=1
  else:
    dp[i]=count

#print(dp)
for i in range(q):
  l,r=map(int,input().split())
  print(dp[r-2]-dp[l-2])
### BUGGY CODE ###

def main():
    from bisect import bisect_right as br
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())), reverse=True)
    m = n % 2
    xor = 0
    for i in b:
        xor ^= i
    for i in range(n):
        b[i] = 2**28 - b[i]
    ans = 0
    for loop in range(28, -1, -1):
        j = pow(2, loop)
        k = (xor & j) // j
        temp = br(b, j-1)
        for i in range(temp, n):
            b[i] -= j
        b.sort()
        x = k*m % 2
        b0 = br(b, 0) % 2
        for i in a:
            k2 = m * (i & j) // j
            x += (k2 + br(b, i % j) - b0) % 2
        ans += (x % 2)*j
    print(ans)


main()


### FIXED CODE ###

def main():
    from bisect import bisect_right as br
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())), reverse=True)
    m = n % 2
    xor = 0
    for i in b:
        xor ^= i
    for i in range(n):
        b[i] = 2**28 - b[i]
    ans = 0
    for loop in range(28, -1, -1):
        j = pow(2, loop)
        k = (xor & j) // j
        temp = br(b, j-1)
        for i in range(temp, n):
            b[i] -= j
        b.sort()
        temp = br(a, j-1)
        for i in a[:temp]:
            k += (i & j) // j
        for i in range(temp, n):
            k += (a[i] & j) // j
            a[i] -= j
        x = (k+br(b, 0))*m % 2
        a.sort()
        l = 0
        for i in a:
            while l < n:
                if i >= b[l]:
                    l += 1
                else:
                    break
            x += l % 2
        ans += (x % 2)*j
    print(ans)


main()
### BUGGY CODE ###

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

a = []
for i in range(n):
    a.append(aa[i]-(i+1))
        
c = list(set(a))

#print(c[-1][0])

count = []

for i in c:
    counts = 0
    for j in a:
        counts += abs(j-i)
    count.append(counts)
print(min(count))

### FIXED CODE ###

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

a = []
for i in range(n):
    a.append(aa[i]-(i+1))
b = list(sorted(a))

ans = 0

for i in range(n//2):
    ans += b[-i-1] - b[i]
print(ans)
### BUGGY CODE ###

#ABC129D-Lamp.py

#import list
from sys import stdin, setrecursionlimit
from functools import lru_cache

input = stdin.readline
setrecursionlimit(10000)

#constant
H, W = list(map(int,input().split()))
S = [input() for _ in range(H)]

#variable

#function
#@lru_cache(maxsize=None)
def Left(i,j,listL):
    if S[i][j] == "#":
        return 0
    elif S[i][j] == ".":
        if j == 0:
            return 1
        else:
            return listL[i][j-1] + 1

def Right(i,j,listR):
    if S[i][j] == "#":
        return 0
    elif S[i][j] == ".":
        if j == W-1:
            return 1
        else:
            return listR[i][j+1] + 1

def Up(i,j,listU):
    if S[i][j] == "#":
        return 0
    elif S[i][j] == ".":
        if i == 0:
            return 1
        else:
            return listU[i-1][j] + 1

def Down(i,j,listD):
    if S[i][j] == "#":
        return 0
    elif S[i][j] == ".":
        if i == H-1:
            return 1
        else:
            return listD[i+1][j] + 1

#class

#main function
def main():
    L = [[None for _ in range(W)] for _ in range(H)]
    R = [[None for _ in range(W)] for _ in range(H)]
    U = [[None for _ in range(W)] for _ in range(H)]
    D = [[None for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            L[i][j] = Left(i,j,L)
            R[i][W-1-j] = Right(i,W-j-1,R)
            U[i][j] = Up(i,j,U)
            D[H-1-i][j] = Down(H-i-1,j,D)
    maxScore = 0
    for i in range(H):
        for j in range(W):
            score = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
            if score > maxScore:
                maxScore = score
    print(maxScore)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#ABC129D-Lamp.py

#import list
import sys
import numpy as np

#main function
def main():
    buffer = sys.stdin.buffer
    H, W = list(map(int,buffer.readline().split()))
    S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
    S = S.reshape((H,W+1))[:,:-1]
    L = np.empty((H,W), dtype="i4")
    R = np.empty((H,W), dtype="i4")
    U = np.empty((H,W), dtype="i4")
    D = np.empty((H,W), dtype="i4")

    L[:,0] = S[:,0]
    for i in range(1,W):
        L[:,i] = (L[:,i-1] + 1) * S[:,i]

    R[:,-1] = S[:,-1]
    for i in range(1,W):
        R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]

    U[0] = S[0]
    for i in range(1,H):
        U[i] = (U[i-1] + 1) * S[i]

    D[-1] = S[-1]
    for i in range(1,H):
        D[-1-i] = (D[-i] + 1) * S[-1-i]

    score = L + R + U + D - 3
    print(int(score.max()))


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

def main():
    s = input()
    cnt = 0
    tmp = ""

    while tmp != s:
        tmp = s
        s = s.replace("BW", "WB", 1)
        if tmp == s:
            break
        cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    length = len(s)-1
    count = s.count('B')
    init = sum([i for i in range(len(s)) if s[i] == "B"])
    processed = sum(range(length-count+1, length+1))

    print(processed-init)


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

import math


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


def main(A, B, N):
    last = 0
    x = 0
    while x <= N:
        tmp = f(A, B, x)
        if tmp < last:
            print(last)
            return
        else:
            last = tmp
            x += 1
    else:
        print(last)
        return


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


### FIXED CODE ###

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


def f(x):
    global A, B
    return (A * x) // B - A * (x // B)


if N < B:
    print(f(N))
else:
    print(f(B - 1))
### BUGGY CODE ###

import sys

H, N = map(int, input().split())
A = [0] * N
B = [0] * N

for i in range(N):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    A[i] = a
    B[i] = b

max_A = max(A)
INF = 10**18
dp = [INF] * (H + max_A)
dp[0] = 0

for i in range(1, H + max_A):
    for j in range(N):
        if i >= A[j]:
            dp[i] = min(dp[i], dp[i - A[j]] + B[j])

print(min(dp[H:H + max_A]))


### FIXED CODE ###

import sys

H, N = map(int, input().split())
A = [0] * N
B = [0] * N

for i in range(N):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    A[i] = a
    B[i] = b

max_A = max(A)
INF = 10**18
dp = [INF] * (H + max_A)
dp[0] = 0

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

print(min(dp[H:H + max_A]))
### BUGGY CODE ###

N = int(input())
S = list(input())
count_list = []
camu_west = []
for i in range(1,N+1):
  look_west = len([S[j] for j in range(i) if S[j] == "W"])
  camu_west.append(look_west)
for i in range(N):
  count_l = camu_west[i-1]
  if i == 0:
    count_l = 0
  count_r = N-1-i-(camu_west[N-1]-camu_west[i])
  if i == N:
    count_r = 0
  count = count_l + count_r 
  count_list.append(count)
print(min(count_list))

### FIXED CODE ###

N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
ans = count_E
for i in range(N):
    if S[i] == "E":
        count_E -= 1
    if S[i-1] == "W" and i != 0:
        count_W += 1
    if count_E + count_W < ans :
        ans = count_E + count_W
print(ans)
### BUGGY CODE ###

import math  # noqa: F401
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, A: List[int]):
    ans = 1
    for a in A:
        ans *= a
        if ans > 10 ** 18:
            ans = -1
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)


### FIXED CODE ###

import math  # noqa: F401
from typing import Dict, List, Optional, Tuple, Union  # noqa: F401


def main(N: int, A: List[int]):
    A = sorted(A, reverse=True)
    if A[-1] == 0:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10 ** 18:
            ans = -1
            break
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)
### BUGGY CODE ###

N = int(input())
lst = []
dic = {}
for i in range(0,N):
  inp = input()
  if inp not in dic:
    dic[inp] = 1
  else:
    dic[inp] +=1

keys = [k for k,v in dic.items() if v == max(dic.values())]

keys.sort()

for i in range(0,len(keys)):
  print(keys[i])


### FIXED CODE ###

N = int(input())
dic = {}
for i in range(0,N):
  inp = input()
  if inp not in dic:
    dic[inp] = 1
  else:
    dic[inp] +=1

m = max(dic.values())

keys = [k for k,v in dic.items() if v == m]

keys.sort()

for i in range(0,len(keys)):
  print(keys[i])
### BUGGY CODE ###

# define
def isAnagram(str1, str2) : 
    true_flag = 1
    
    for i in str1 : 
        if (str1.count(i) != str2.count(i)) : 
            true_flag = 0
            
    if (true_flag == 1) : 
        return True
    else : 
        return False

# initial setting
cnt = 0
        
# number input
n = int(input())
s = [0] * n

# letter input
for i in range(n) : 
    s[i] = input()
    
# charcter count
for i in range(n) : 
    for j in range(i) : 
        if isAnagram(s[i], s[j]) == True : 
            cnt += 1

# output
print(cnt)
        
# all selection patterns(test)
# for i in range(4) : 
#     for j in range(i) : 
#         if i != j : 
#             print(i, j)

### FIXED CODE ###

from collections import Counter

n = int(input())
S = [input() for _ in range(n)]
ans = 0

ctr = Counter()

for s in S : 
    a = ''.join(sorted(list(s)))
    if ctr[a] != 0 : 
        ans += ctr[a]
    ctr[a] += 1
print(ans)
### BUGGY CODE ###

from fractions import gcd
n,m = map(int,input().split())
if m%n==0:
    print(int(m//n))
    exit()
else:
  a = m//n
  for i in range(a,0,-1):
    s = m-n*i
    if (s+i)%i==0:
      print(i)
      exit()

### FIXED CODE ###

n,m = map(int,input().split())
if m%n==0:
    print(int(m//n))
    exit()
else:
  a = m/n
  l = []
  for i in range(int(m**0.5),0,-1):
    if m%i==0:
      l.append(i)
      l.append(m//i)
  l = sorted(l)[::-1]
  for j  in l:
    if j<=a:
      print(j)
      exit()
  else:
    print(1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
  n = int(input())
  T = [[] for _ in range(n)]
  for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    T[a].append(b)
    T[b].append(a)
  m = int(input())

  def dfs(u, v):
    parent = [-1]*n
    seen = [False]*n
    stack = [u]
    seen[u] = True
    while stack:
      nv = stack[-1]
      if nv == v:
        return stack
      f = True
      for i in T[nv]:
        if seen[i]:
          continue
        stack.append(i)
        seen[i] = True
        f = False
        break
      if f:
        stack.pop()

  E = [set() for _ in range(m)]
  for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edge = dfs(u, v)
    for j in range(len(edge)-1):
      E[i].add((min(edge[j], edge[j+1]), max(edge[j], edge[j+1])))

  ans = 0
  for i in range(2**m):
    s = set()
    for j in range(m):
      if i>>j & 1:
        s |= E[j]
    cnt = bin(i).count("1") % 2
    ans += (-1)**cnt * 2**(n-1-len(s))
  print(ans)
  
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
  n = int(input())
  T = [[] for _ in range(n)]
  D = {}
  for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    T[a].append(b)
    T[b].append(a)
    D[(a, b)] = 1<<i
    D[(b, a)] = 1<<i
  m = int(input())

  def dfs(u, v):
    parent = [-1]*n
    seen = [False]*n
    stack = [u]
    seen[u] = True
    while stack:
      nv = stack[-1]
      if nv == v:
        return stack
      for i in T[nv]:
        if seen[i]:
          continue
        stack.append(i)
        seen[i] = True
        break
      else:
        stack.pop()

  E = [0]*m
  for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edge = dfs(u, v)
    for j in range(len(edge)-1):
      E[i] |= D[(edge[j], edge[j+1])]

  ans = 0
  for i in range(2**m):
    s = 0
    for j in range(m):
      if i>>j & 1:
        s |= E[j]
    cnt = bin(i).count("1") % 2
    ans += (-1)**cnt * 2**(n-1-bin(s).count("1"))
  print(ans)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split())) #上司の社員番号

for i in range(1,n+1):
    print(a.count(i))


### FIXED CODE ###

import collections
n = int(input())
a = list(map(str,input().split())) #上司の社員番号

result = collections.Counter(a)

for i in range(1,n+1):
    print(result[str(i)])
### BUGGY CODE ###

from collections import deque
from copy import copy, deepcopy
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)


ans = [0]*N
visited = [False]*N
visited[0]=True
ans[0] = 1
d = deque([[0,[A[0]]]])
while len(d)>0:
    v,LIS = d.popleft()
    for u in edge[v]:
        if visited[u]==False:
            visited[u] = True
            lis = copy(LIS)
            ind = bisect_left(lis,A[u])
            if ind < len(lis):
                lis[ind] = A[u]
            else:
                lis.append(A[u])
            ans[u] = len(lis)
            d.append([u,lis])
print(*ans, sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left, bisect_right
N = int(input())
A = list(map(int, input().split()))
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,LIS):
    if len(edge[v])==0:
        return
    for u in edge[v]:
        if visited[u]==False:
            visited[u]=True
            if A[u] > LIS[-1]:
                LIS.append(A[u])
                ans[u] = len(LIS)
                dfs(u,LIS)
                LIS.pop()
            else:
                ind = bisect_left(LIS,A[u])
                stack = LIS[ind]
                LIS[ind] = A[u]
                ans[u] = len(LIS)
                dfs(u,LIS)
                LIS[ind] = stack
    return

ans = [0]*N
visited = [False]*N
visited[0]=True
LIS = [A[0]]
ans[0] = 1
dfs(0,LIS)
print(*ans, sep='\n')
### BUGGY CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

H, W = map(int,input().split())
sth, stw = map(int,input().split())
glh, glw = map(int,input().split())
sth, stw = sth-1, stw-1
glh, glw = glh-1, glw-1

INF = -1
Gmap = [list(input()) for _ in range(H)]
seen = [[INF]*W for _ in range(H)]
direc = {(1,0), (-1,0), (0,1), (0,-1)}
direc5 = set([])
for i in range(-2,3):
    for j in range(-2,3):
        direc5.add((i, j))
direc5 = direc5 - direc
direc5 = direc5 - {(0,0)}

def bfs(pnxt):
    next_q = deque([])
    for h, w in pnxt:
        next_q.append((h,w))
        seen[h][w] = 0
    nxt = set([])
    while len(next_q)!=0:
        h, w = next_q.popleft()
        if h == glh and w == glw:
            print(ret)
            exit()
        for dh, dw in direc:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF:
                next_q.append((hs, ws))
                seen[hs][ws] = 0
        for dh, dw in direc5:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF and not (hs, ws) in nxt:
                nxt.add((hs, ws))
    return nxt

ret = 0
nxt_st = set([])
nxt_st.add((sth, stw))
while len(nxt_st)>0:
    nxt_st = bfs(nxt_st)
    ret += 1
print(-1)


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import deque

H, W = map(int,input().split())
sth, stw = map(int,input().split())
glh, glw = map(int,input().split())
sth, stw = sth-1, stw-1
glh, glw = glh-1, glw-1

INF = -1
Gmap = [list(input()) for _ in range(H)]
seen = [[INF]*W for _ in range(H)]
direc = {(1,0), (-1,0), (0,1), (0,-1)}
direc5 = set([])
for i in range(-2,3):
    for j in range(-2,3):
        direc5.add((i, j))
direc5 = direc5 - direc
direc5 = direc5 - {(0,0)}

def bfs(pnxt):
    next_q = deque([])
    for h, w in pnxt:
        next_q.append((h,w))
        seen[h][w] = 0
    nxt = set([])
    while len(next_q)!=0:
        h, w = next_q.popleft()
        if h == glh and w == glw:
            print(ret)
            exit()
        for dh, dw in direc:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF:
                next_q.append((hs, ws))
                seen[hs][ws] = 0
        for dh, dw in direc5:
            hs, ws = h + dh, w + dw
            if not (0<=hs<H and 0<=ws<W):
                continue
            if Gmap[hs][ws]=='.' and seen[hs][ws]==INF and not (hs, ws) in nxt:
                nxt.add((hs, ws))
    return nxt

ret = 0
nxt_st = set([])
nxt_st.add((sth, stw))
while len(nxt_st)>0:
    nxt_st = bfs(nxt_st)
    ret += 1
print(-1)
### BUGGY CODE ###

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

print(a[-1])


### FIXED CODE ###

#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()