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

import sys
sys.setrecursionlimit(10 ** 6)

N, K = [int(v) for v in sys.stdin.readline().split()]
R, S, P = [int(v) for v in sys.stdin.readline().split()]
T = input()

l = [''] * K

for i in range(N):
    l[i % K] += T[i]


def okjudge(ss, p):
    lss = len(ss)
    if p == lss:
        return 0

    c = ss[p]

    if lss - p == 1:
        if c == 'r':
            return P
        elif c == 's':
            return R
        else:
            return S
    if ss[p + 1] == ss[p]:
        if c == 'r':
            return max(okjudge(ss, p + 1), P + okjudge(ss, p + 2))
        elif c == 's':
            return max(okjudge(ss, p + 1), R + okjudge(ss, p + 2))
        else:
            return max(okjudge(ss, p + 1), S + okjudge(ss, p + 2))
    elif c == 'r':
        return P + okjudge(ss, p + 1)
    elif c == 's':
        return R + okjudge(ss, p + 1)
    else:
        return S + okjudge(ss, p + 1)

print(sum([okjudge(v, 0) for v in l]))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

N, K = [int(v) for v in sys.stdin.readline().split()]
R, S, P = [int(v) for v in sys.stdin.readline().split()]
T = input()

l = [''] * K
memo = [{} for _ in range(K)]

for i in range(N):
    l[i % K] += T[i]

def okjudge(m, ss, p):
    if p in memo[m]:
        return memo[m][p]

    lss = len(ss)
    if p == lss:
        ret =  0
        memo[m][p] = ret
        return ret

    c = ss[p]

    if lss - p == 1:
        if c == 'r':
            ret = P
        elif c == 's':
            ret =  R
        else:
            ret =  S
        memo[m][p] = ret
        return ret

    if ss[p + 1] == ss[p]:
        if c == 'r':
            ret =  max(okjudge(m, ss, p + 1), P + okjudge(m, ss, p + 2))
        elif c == 's':
            ret =  max(okjudge(m, ss, p + 1), R + okjudge(m, ss, p + 2))
        else:
            ret =  max(okjudge(m, ss, p + 1), S + okjudge(m, ss, p + 2))
    elif c == 'r':
        ret =  P + okjudge(m, ss, p + 1)
    elif c == 's':
        ret =  R + okjudge(m, ss, p + 1)
    else:
        ret =  S + okjudge(m, ss, p + 1)

    memo[m][p] = ret
    return ret

print(sum([okjudge(mi, v, 0) for mi,v in enumerate(l)]))
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
k = ni()
li = []
for i in range(len(s)):
    for j in range(i, len(s)):
        if s[i:j+1] not in li:
            li.append(s[i:j+1])
li.sort()
print(li[k-1])

### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
k = ni()
li = []
for i in range(len(s)):
    for j in range(i, i+k+1):
        li.append(s[i:j+1])
li = list(set(li))
li.sort()
print(li[k-1])
### BUGGY CODE ###

import copy
n,k = map(int, input().split())
p = list(map(int, input().split()))

max_set = p[:k]
pair = p[:k]
for i in range(n-k):
    pair.remove(p[i])
    pair.append(p[i+k])
    if sum(max_set) < sum(pair):
        max_set = copy.copy(pair)

ans = 0
for i in max_set:
    ans += (i+1)/2
print(ans)

### FIXED CODE ###

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

max_set = sum(p[:k])
pair = sum(p[:k])
for i in range(n-k):
    pair -= p[i]
    pair += p[i+k]
    if max_set < pair:
        max_set = pair

print((max_set+k)/2)
### BUGGY CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**7)

N, Q = map(int, input().split())

g = [[int(i) for i in input().split()] for j in range(N-1)]
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = g[i]
    G[a-1].append(b-1)
    G[b-1].append(a-1)

q = [[int(i) for i in input().split()] for j in range(Q)]
count = [0 for i in range(N)]
for i in range(Q):
    p, x = q[i]
    count[p-1] += x

def dfs(v, p):
    if p != -1:
        count[v] += count[p]
    for next_v in G[v]:
        if next_v == p: continue
        dfs(next_v, v)

dfs(0, -1)
print(" ".join(map(str, count)))

### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())

ab = [[int(i) for i in input().split()] for j in range(N-1)]
G = [[] for i in range(N)]
for i in range(N-1):
    a, b = ab[i]
    G[a-1].append(b-1)
    G[b-1].append(a-1)

q = [[int(i) for i in input().split()] for j in range(Q)]
count = [0 for i in range(N)]
for i in range(Q):
    p, x = q[i]
    count[p-1] += x

ls = deque([0])
seen = [0 for i in range(N)]
while len(ls) > 0:
    root = ls.popleft()
    seen[root] = 1

    for next_v in G[root]:
        if not seen[next_v]:
            count[next_v] += count[root]
            ls.append(next_v)

for i in range(N):
    print(count[i], end=" ")
### BUGGY CODE ###

N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    if all([x % min(x_ls) == 0 for x in x_ls]):
        break
    else:
        x_ls = [x % min(x_ls) for x in x_ls]
    x_ls = [x for x in x_ls if x != 0]
print(min(x_ls))

### FIXED CODE ###

N, X = [int(i) for i in input().split()]
x_ls = [int(i) for i in input().split()]
x_ls = [abs(x - X) for x in x_ls]
while True:
    min_x = min(x_ls)
    x_ls = [x % min_x for x in x_ls]
    if not any(x_ls):
        break
    x_ls = [x for x in x_ls if x != 0]
print(min_x)
### BUGGY CODE ###

M=998244353
n,s,*l=map(int,open(0).read().split())
dp=[[0]*(s+1) for _ in '01']
dp[0][0]=1
b=0
for i in range(n):
  b^=1
  for j in range(s+1):
    dp[b][j]=dp[b^1][j]*2
    if j>=l[i]: dp[b][j]+=dp[b^1][j-l[i]]
    dp[b][j]%=M
print(dp[n%2][s])

### FIXED CODE ###

M=998244353
n,s,*l=map(int,open(0).read().split())
dp=[[0]*(s+1) for _ in '01']
dp[0][0]=1
b=0
for i in range(n):
  b^=1
  for j in range(s+1):
    dp[b][j]=dp[b^1][j]*2
    if j>=l[i]: dp[b][j]+=dp[b^1][j-l[i]]
    dp[b][j]%=M
print(dp[n%2][s])
### BUGGY CODE ###

n=int(input())
a=list(input().split())
x=1000000000000000000
res=1
for i in range(n):
  res=res*int(a[i])
if(res>x):
  print("-1")
else:
  print(res)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
res=1
if 0 in a:
  print("0")
else:
  for x in a:
    res=res*x
    if(res>1000000000000000000):
      res=-1
      break
  print(res)
### BUGGY CODE ###

n=int(input())
a=[int(x) for x in input().rstrip().split()]

ans=[]
for i in range(n):
  if (i+1)%2==1:
    ans=[str(a[i])]+ans
  else:
    ans=ans+[str(a[i])]

if n%2==0:
  print(*ans[::-1])
else:
  print(*ans)

### FIXED CODE ###

from collections import deque
n=int(input())
a=[int(x) for x in input().rstrip().split()]

ans=deque()
for i in range(n):
  if (i+1)%2==1:
    ans.appendleft(str(a[i]))
  else:
    ans.append(str(a[i]))

ans=list(ans)
if n%2==0:
  print(*ans[::-1])
else:
  print(*ans)
### BUGGY CODE ###

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

days=[]
i=0
while i<N:
    if S[i]=='o':
        days.append(i)
        i+=C
    if len(days)>=K:
        break
    i+=1

days=days[::-1]
while len(days)!=0:
    p=days.pop()
    S[p]='x'
    days2=[]
    j=0
    while j<N:
        if S[j]=='o':
            days2.append(j)
            j+=C
        if len(days2)>=K:
            break
        j+=1
    if len(days2)>=K:
        days=set(days)&set(days2)
    else:
        print(p+1)

### FIXED CODE ###

N,K,C=map(int,input().split())
S=input()

maekara=[]
i=1
cnt=0
while i<=N and cnt<K:
    if S[i-1]=='o':
        maekara.append(i)
        i+=C+1
        cnt+=1
    else: i+=1

usirokara=[]
j=N
cnt=0
while j>=1 and cnt<K:
    if S[j-1]=='o':
        usirokara.append(j)
        j-=C+1
        cnt+=1
    else: j-=1
usirokara=usirokara[::-1]

for i in range(K):
    if maekara[i]==usirokara[i]:
        print(maekara[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

import bisect

def main():
  n, k = map(int, input().split())
  minus = []
  zero = 0
  plus = []
  lm = 0
  lp = 0
  for i in map(int, input().split()):
    if i < 0:
      minus.append(-i)
      lm += 1
    elif i == 0:
      zero += 1
    else:
      plus.append(i)
      lp += 1

  minus.sort()
  plus.sort()

  def test(x):
    count = 0
    if x < 0:
      x = -x
      for i in minus:
        count += lp - bisect.bisect_left(plus, -(-x//i))
      return count >= k

    if x == 0:
      count = lm*lp
      return count + zero*(n-zero) + zero*(zero-1)//2 >= k

    count = lm*lp + zero*(n-zero) + zero*(zero-1)//2
    for i in range(lm-1):
      t = minus[i]
      count += bisect.bisect_right(minus[i+1:], x//t)
    for i in range(lp-1):
      t = plus[i]
      count += bisect.bisect_right(plus[i+1:], x//t)
    return count >= k

  ng = -(10**18)
  ok = 10**18
  while ok-ng > 1:
    mid = (ok+ng)//2
    if test(mid):
      ok = mid
    else:
      ng = mid
  print(ok)
  
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a, b, c = 0, 0, 0
L, R = [], []
for p in map(int, input().split()):
  if p < 0:
    a += 1
    L.append(p)
  elif p == 0:
    b += 1
  else:
    c += 1
    R.append(p)
L.sort()
R.sort()
s = a*c
t = b*(b-1)//2 + (a+c)*b
if s < k <= s+t:
  ans = 0
else:
  if k <= s:
    ok = -1
    ng = -(10**18+1)
    while ok - ng > 1:
      mid = (ok+ng)//2
      now = 0
      temp = 0
      for l in L:
        while now < c and l*R[now] > mid:
          now += 1
        temp += c - now
      if temp >= k:
        ok = mid
      else:
        ng = mid
  else:
    ok = 10**18
    ng = 0
    while ok - ng > 1:
      mid = (ok+ng)//2
      now = c - 1
      temp = s+t
      for i, r in enumerate(R):
        if now <= i:
          break
        while now > i and r*R[now] > mid:
          now -= 1
        temp += now - i
      now = 0
      for i in range(a-1, -1, -1):
        l = L[i]
        if now >= i:
          break
        while now < i and l*L[now] > mid:
          now += 1
        temp += i - now
      if temp >= k:
        ok = mid
      else:
        ng = mid
  ans = ok
print(ans)
### BUGGY CODE ###

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

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

ans = INF
for i in range(K):
    if i+K > N:
        break
    A2 = A[i:i+K]
    l = A2[0]
    r = A2[-1]
    # 左だけ行く
    if r <= 0:
        ans = min(ans, -l)
    # 右だけ行く
    elif l >= 0:
        ans = min(ans, r)
    # 両方行く
    else:
        # 短い方を先に行って往復
        ans = min(ans, min(-l, r) * 2 + max(-l, r))
print(ans)


### FIXED CODE ###

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

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

ans = float('inf')
for i in range(N-K+1):
    tmp = float('inf')
    # 範囲が0を含む
    if xN[i] <= 0 <= xN[i+K-1]:
        # 距離の短い方を往復する
        if abs(xN[i]) <= abs(xN[i+K-1]):
            tmp = abs(xN[i])*2 + abs(xN[i+K-1])
        else:
            tmp = abs(xN[i]) + abs(xN[i+K-1])*2
    # 範囲が全て0より大きい
    elif xN[i] > 0:
        tmp = abs(xN[i+K-1])
    # 範囲が全て0より小さい
    elif xN[i+K-1] < 0:
        tmp = abs(xN[i])
    ans = min(tmp, ans)

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

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

dp = [[-1]*100000 for i in range(n+1)]
dp[0][0] = 1000


for i in range(n):
    for j in range(99999):
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
        if dp[i+1][j] >= a[i]:
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]-a[i])
        
    for j in range(99999,0,-1):
        if dp[i+1][j] >= 0:
             dp[i+1][j-1] = max(dp[i+1][j-1],dp[i+1][j]+a[i])
print(max(dp[-1]))


### FIXED CODE ###

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

count = [1000,0]
x = a[0]
for i in range(1,n):
    if a[i] > x:
        d = count[0]//x
        count = [count[0]-d*x, d+count[1]]
    else:
        count = [count[0]+count[1]*x,0]
    x = a[i]
if count[1]:
    count[0] += count[1]*x
print(count[0])
### BUGGY CODE ###

from collections import deque
H, W = map(int,input().split())
sh, sw = map(int,input().split())
gh, gw = map(int,input().split())
sh, sw, gh, gw = sh-1, sw-1, gh-1, gw-1
S = [input() for _ in range(H)]

INF = 10**9
ans = [[INF] * W for _ in range(H)]
ans[sh][sw] = 0

Q = deque([[sh,sw]])

while len(Q) > 0:
    h, w = Q.popleft()
    
    for nh, nw in [[h,w+1],[h,w-1],[h+1,w],[h-1,w]]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w]:
            ans[nh][nw] = ans[h][w]
            Q.append([nh, nw])

    for nh in range(h-2,h+3):
        for nw in range(w-2,w+3):
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w] + 1:
                ans[nh][nw] = ans[h][w] + 1
                Q.append([nh,nw])

if ans[gh][gw] == INF:
    print(-1)
else:
    print(ans[gh][gw])

### FIXED CODE ###

from collections import deque

H, W = map(int,input().split())
sh, sw = map(int,input().split())
gh, gw = map(int,input().split())
sh, sw, gh, gw = sh-1, sw-1, gh-1, gw-1
S = [input() for _ in range(H)]

INF = 10**9
ans = [[INF] * W for _ in range(H)]
ans[sh][sw] = 0

Q = deque([[sh,sw]])
while Q:
    h, w = Q.popleft()

    for nh, nw in [[h,w+1],[h,w-1],[h+1,w],[h-1,w]]:
        if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w]:
            ans[nh][nw] = ans[h][w]
            Q.appendleft([nh, nw])

    for nh in range(h-2,h+3):
        for nw in range(w-2,w+3):
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and ans[nh][nw] > ans[h][w] + 1:
                ans[nh][nw] = ans[h][w] + 1
                Q.append([nh,nw])

if ans[gh][gw] == INF:
    print(-1)
else:
    print(ans[gh][gw])
### BUGGY CODE ###

N, Q = map(int, input().split())
s = " " + input() + " "
td = []
for i in range(Q):
    td.insert(0, input().split())
#print("td = {}".format(td))

llim = 0
rlim = N + 1
for t, d in td:
    if((s[llim + 1] == t) and ("L" == d)):
        llim += 1
    elif((s[llim] == t) and ("R" == d)):
        llim -= 1
    if((s[rlim - 1] == t) and ("R" == d)):
        rlim -= 1
    elif((s[rlim] == t) and ("L" == d)):
        rlim += 1
#    print("td = {}, llim = {}, rlim = {}".format([t, d], llim, rlim))

print(str(max(0, rlim - llim - 1)))


### FIXED CODE ###

N, Q = map(int, input().split())
s = " " + input() + " "
td = []
for i in range(Q):
    td.append(input().split())
#print("td = {}".format(td))

llim = 0
rlim = N + 1
for t, d in reversed(td):
    if((s[llim + 1] == t) and ("L" == d)):
        llim += 1
    elif((s[llim] == t) and ("R" == d)):
        llim -= 1
    if((s[rlim - 1] == t) and ("R" == d)):
        rlim -= 1
    elif((s[rlim] == t) and ("L" == d)):
        rlim += 1
#    print("td = {}, llim = {}, rlim = {}".format([t, d], llim, rlim))

print(str(max(0, rlim - llim - 1)))
### BUGGY CODE ###

def main():
  n=int(input())
  s=input()
  dp=[[0]*(n+1) for i in range(n+1)]
  for i in range(n-1,-1,-1):
    for j in range(n-1,i,-1):
      if s[i]==s[j]:
        dp[i][j]=dp[i+1][j+1]+1
  #for i in dp:
  #  print(i)
  
  ans=0
  for i in range(n-1):
    for j in range(i+1,n):
      ans=max(ans,min(j-i,dp[i][j]))
  print(ans)      
        

if __name__=='__main__':
  main()


### FIXED CODE ###

def main():
  n=int(input())
  s=input()
  dp=[[0]*(n+1) for i in range(n+1)]
  for i in range(n-1,-1,-1):
    for j in range(n-1,i,-1):
      if s[i]==s[j]:
        dp[i][j]=dp[i+1][j+1]+1
  #for i in dp:
  #  print(i)
  
  ans=0
  for i in range(n-1):
    for j in range(i+1,n):
      ans=max(ans,min(j-i,dp[i][j]))
  print(ans)      
        

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

import bisect

n = (int)(input())
a = sorted(list(map(int, input().split(" "))))
b = sorted(list(map(int, input().split(" "))))
c = sorted(list(map(int, input().split(" "))))

count = 0
for i in a:
  for j in b[bisect.bisect_left(b, i + 1):]:
    #for k in c[bisect.bisect_left(c, j):]:
    #print(i, j, c[bisect.bisect_left(c, j + 1):])
    count += len(c[bisect.bisect_left(c, j + 1):])
print(count)

### FIXED CODE ###

import bisect

n = (int)(input())
a = sorted(list(map(int, input().split(" "))))
b = list(map(int, input().split(" ")))
c = sorted(list(map(int, input().split(" "))))

count = 0
for i in b:
  #print((a[:bisect.bisect_right(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) 
  #print(bisect.bisect_right(a, i - 1), i, (n - bisect.bisect_left(c, i + 1)) ) 
  count += bisect.bisect_right(a, i - 1) * (n - bisect.bisect_left(c, i + 1)) 
print(count)
### BUGGY CODE ###

from collections import deque

h, w = map(int, input().split())
a = [input() for _ in range(h)]

d = [[-1] * w for _ in range(h)]


def bfs():
    q = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                q.append((j, i))
                d[i][j] = 0

    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append((vx, vy))


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


### FIXED CODE ###

from scipy.ndimage import distance_transform_cdt


def main():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


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

h,n=map(int,input().split())
MAX_NUM=9999999999
ab=[]
for _ in range(n):
    ab.append(list(map(int,input().split())))
dp=[MAX_NUM for _ in range(h+1)]
dp[0]=0

for i in range(h):
    if(dp[i]==MAX_NUM):
        continue

    for j in range(n):
        if(i+ab[j][0]<h):
            dp[i+ab[j][0]]=min(dp[i+ab[j][0]],dp[i]+ab[j][1])
        else:
            dp[-1]=min(dp[-1],dp[i]+ab[j][1])
print(dp[-1])



### FIXED CODE ###

h,n=map(int,input().split())
ab=[]
for _ in range(n):
    ab.append(list(map(int,input().split())))
max_a=max([a for a,b in ab])
dp=[0 for _ in range(h+max_a)]

for i in range(1,len(dp)):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(min(dp[h:]))


#
# MAX_NUM=9999999999
# ab=[]
# for _ in range(n):
#     ab.append(list(map(int,input().split())))
# dp=[MAX_NUM for _ in range(h+1)]
# dp[0]=0
#
# for i in range(h):
#     if(dp[i]!=MAX_NUM):
#         for j in range(n):
#             a,b=ab[j]
#             ind = i+a if i+a<h else -1
#             dp[ind]=min(dp[ind],dp[i]+b)
# print(dp[-1])
### BUGGY CODE ###

import itertools
n = int(input())
a = list(map(int, input().split()))
idList = [i for i in range(1, n+1)]
temp = 0
for i in range(n):
    tar = a[temp]
    if (tar >= n):
        del a[temp]
        del idList[temp]

    else:
        temp += 1

com = list(itertools.combinations(idList, 2))

num = len(com)
ans = 0
for i in range(num):
    aa = com[i]
    # print(aa)
    idA = aa[0]
    idB = aa[1]
    dif = abs(idA - idB)
    indexA = idList.index(idA)
    indexB = idList.index(idB)

    height = a[indexA] + a[indexB]

    if (height == dif):
        ans += 1

print(ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))

minus = [0] * N
plus = [0] * N

for i in range(N):
    minus[i] = (i + 1) - A[i]
    plus[i] = (i + 1) + A[i]

count = Counter(minus)
most = count.most_common()
num = len(most)

countPP = Counter(plus)
#mostPP = countPP.most_common()
#check = mostPP[:][0]
ans = 0

for i in range(num):
    elm = most[i]
    fir = elm[0]
    sec = elm[1]
    # if (fir in check):

    aa = countPP[fir]
    #    print(aa)
    ans += aa * sec

    # try countPP[tar]:

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

import bisect

n = int(input())
a = [int(input()) for _ in range(n)]


b = []

for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[0]:
            b = [ai] + b
        else:
            index = bisect.bisect_left(b, ai)
            b[index-1] = ai

print(len(b))


### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]


b = []

for ai in a:
    if len(b) == 0:
        b.append(ai)
    else:
        if ai <= b[-1]:
            b.append(ai)
        else:
            l = -1
            r = len(b)
            mid = (l + r) // 2
            while (r - l > 1):
                mid = (l + r) // 2
                if b[mid] >= ai:
                    l = mid
                else:
                    r = mid
            b[r] = ai

print(len(b))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans * A[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)       

### FIXED CODE ###

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

#129
H,W=map(int,input().split())
s=[]
c_a=0
for i in range(H):
    s.append(list(input()))

for i in range(H):
    for j in range(W):
        c=0
        if s[i][j]!="#":
            c=W+H-1
            if j!=W-1:
                for n in range(1,W-j):
                    if s[i][j+n]=="#":
                        c-=W-j-n
                        break
            if j!=0:
                for n in range(1,j+1):
                    if s[i][j-n]=="#":
                        c-=j-n+1
                        break
            if i!=H-1:
                for m in range(1,H-i):
                    if s[i+m][j]=="#":
                        c-=H-i-m
                        break
            if i!=0:
                for m in range(1,i+1):
                    if s[i-m][j]=="#":
                        c-=i-m+1
                        break
        if c>c_a:
            c_a=c
print(c_a)           

### FIXED CODE ###

import numpy as np
h, w = map(int, input().split())
S = np.array([list(input()) for _ in range(h)]) == "."
U=np.zeros( (h,w),dtype=int )
D=np.zeros( (h,w),dtype=int )
L=np.zeros( (h,w),dtype=int )
R=np.zeros( (h,w),dtype=int )
for i in range(h):
    U[i]=(U[i-1]+1)*S[i]
    D[-i-1]=(D[-i]+1)*S[-i-1]
for j in range(w):
    L[:,j]=(L[:,j-1]+1)*S[:,j]
    R[:,-j-1]=(R[:,-j]+1)*S[:,-j-1]
print(np.max(U+D+R+L)-3)
### BUGGY CODE ###

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
# for i in range(1, N):
#     for j in range(1, K+1):
#         if i-j >= 0:
#             DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))

for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])

print(int(DP[-1]))

### FIXED CODE ###

import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))