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

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

if n%k==0:
    print("0")
else:
    while True:
        old=n
        new=abs(n-k)
        if new < old:
            n=new
        else:
            break
    print(n)

### FIXED CODE ###

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

n=n%k

while True:
    old=n
    new=abs(n-k)
    if new < old:
        n=new
    else:
        break
print(n)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def multipleSum(A, n):
    sum = 0
    for i in range(n):
        for j in range(i + 1, n):
            sum += A[i] * A[j]
    return sum%1000000007

N = int(input())
A = list(map(int,input().split()))
n = len(A)
print(multipleSum(A,n))

### FIXED CODE ###

import sys
input = sys.stdin.readline

def multipleSum(A, n):
    sum = 0
    for i in range(n):
        sum += A[i]
    mulsum = sum*sum
    insum = 0
    for i in range(n):
        insum+=A[i]*A[i]
    return (mulsum-insum)//2

N = int(input())
A = list(map(int,input().split()))
n = len(A)
print(multipleSum(A,n)%1000000007)
### BUGGY CODE ###

n,m = map(int,input().split())
ls = list(map(int,input().split()))
for i in range(m):
    b,c = map(int,input().split())
    ls.sort()
    for j in range(b):
        if ls[j] < c:
            ls[j] = c
print(sum(ls))

### FIXED CODE ###

n,m = map(int,input().split())
ls = list(map(int,input().split()))
di = [list(map(int,input().split())) for _ in range(m)]
fi = []
for i,j in di:
    fi.append([j,i])
for k in ls:
    fi.append([k,1])
fi.sort(reverse=True)
ans = 0
cnt = 0
how = 0
while True:
    if how + fi[cnt][1] < n:
        how += fi[cnt][1]
        ans += fi[cnt][1]*fi[cnt][0]
    else:
        ans += (n-how)*fi[cnt][0]
        break
    cnt += 1
print(ans)
### BUGGY CODE ###

import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

mylist=[]
for h in range(len(a)):
  for i in range(len(b)):
    for j in range(len(c)):
      if (h+1)*(i+1)*(j+1) <= k:
        mylist.append(a[h]+b[i]+c[j])

#print(mylist)
mylist.sort(reverse=True)
for i in range(k):
  print(mylist[i])
  

### FIXED CODE ###

#import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
### BUGGY CODE ###

from sys import setrecursionlimit
setrecursionlimit(1<<30)
mod=pow(10,9)+7
def f(x,p,c):
  if z[x][c]==-1:
    z[x][c]=1
    for y in v[x]:
      if y!=p:
      	z[x][c]=(z[x][c]*(f(y,x,1)+c*f(y,x,0)))%mod
  return z[x][c]
n=int(input())
v=[[] for _ in range(n)]
for x,y in [map(int,input().split()) for _ in range(n-1)]:
  v[x-1].append(y-1)
  v[y-1].append(x-1)
z=[[-1,-1] for _ in range(n)]
print((f(0,-1,0)+f(0,-1,1))%mod)

### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(1<<30)
mod=pow(10,9)+7
def f(x,p):
  if z[x][0]==-1:
    z[x][0]=z[x][1]=1
    for y in v[x]:
      if y!=p:
        f(y,x)
      	z[x][0]=(z[x][0]*z[y][1])%mod
        z[x][1]=(z[x][1]*(z[y][0]+z[y][1]))%mod
n=int(input())
v=[[] for _ in range(n)]
for x,y in [map(int,raw_input().split()) for _ in range(n-1)]:
  v[x-1].append(y-1)
  v[y-1].append(x-1)
z=[[-1,-1] for _ in range(n)]
f(0,-1)
print sum(z[0])%mod
### BUGGY CODE ###

n = int(input())
ans = 1
while ans**2 <= n:
    if ans**2 < n: ans += 1
print((ans-1)**2)


### FIXED CODE ###

n = int(input())
ans = 1
while ans**2 <= n:
    if ans**2 <= n: ans += 1
print((ans-1)**2)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from bisect import bisect_left
from heapq import heappush,heappop
from collections import deque
from sys import stdin



def main():
  ## input
  N,Q = map(int, stdin.readline().rstrip().split())
  STX = [[0,0,0] for _ in range(N)]
  for i in range(N):
    s,t,x = map(int, stdin.readline().rstrip().split())
    STX[i] = [x,s-x,t-x]
  Dn = [0]*Q + [10**10]
  ans = {}
  for i in range(Q):
    Dn[i] = int(stdin.readline().rstrip())
    ans[Dn[i]] = -1

  for x,s,t in sorted(STX):
    l = bisect_left(Dn,s)
    while Dn[l] < t:
      ans[Dn[l]] = x
      Dn.pop(l)

  return ans


if __name__ == "__main__":
  ans = main()
  for d in sorted(list(ans.keys())):
    print(ans[d])
    


### FIXED CODE ###

import sys
from bisect import bisect_left



N,Q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:N]:
  s, t, x = map(int, line.split())
  kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[N:]))

ans = [-1] * Q
skip = [-1] * Q
for x, s, t in kkk:
  ss = bisect_left(ddd, s - x)
  tt = bisect_left(ddd, t - x)
  while ss < tt:
    sk = skip[ss]
    if sk == -1:
      ans[ss] = x
      skip[ss] = tt
      ss += 1
    else:
      ss = sk

print('\n'.join(map(str, ans)))
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = 0
    for i,j in enumerate(a):
        if j == 0:
            if x >= 0:
                cnt += n-i-1
        elif j > 0:
            r =  br(a,x//j)
            if r <= i:
                continue
            cnt += r - i - 1
        else:
            l = bl(a,-(x//-j))
            if l <= i:
                l = i+1
            cnt += n - l
    return cnt >= k

n,k = LI()
a = LI()
a.sort()

ok = 10**18
ng = -10**18
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)



    

### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    cnt = 0
    if x < 0:
        j = p-1
        for i in range(m)[::-1]:
            while j >= 0:
                if minus[i]*plus[j] <= x:
                    j -= 1
                else:
                    break
            cnt += p - j - 1
    else:
        j = p-1
        for i in range(p):
            while j >= 0:
                if plus[i]*plus[j] > x:
                    j -= 1
                else:
                    break
            cnt += max(0,j - i)
        j = 0
        for i in range(m)[::-1]:
            while j < m:
                if minus[i]*minus[j] > x:
                    j += 1
                else:
                    break
            cnt += max(0,i - j)
        cnt += (m+p)*zero + zero*(zero-1)//2 + m*p
    return cnt >= k
        
n,k = LI()
a = LI()
a.sort()
minus = [x for x in a if x < 0]
plus = [x for x in a if x > 0]
m = len(minus)
p = len(plus)
zero = bl(a,1) - br(a,-1)
ok = 10**18
ng = -10**18-1
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)
### BUGGY CODE ###

n,k,l=map(int,input().split())
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]
uf1=UnionFind(n)
uf2=UnionFind(n)
for i in range(k):
  p,q=map(int,input().split())
  uf1.union(p-1,q-1)
for i in range(l):
  r,s=map(int,input().split())
  uf2.union(r-1,s-1)
ans=[0]*n
for i in range(n):
  s1=set(uf1.members(i))
  s2=set(uf2.members(i))
  ans[i]=len(s1&s2)
print(*ans)

### FIXED CODE ###

n,k,l=map(int,input().split())
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]
uf1=UnionFind(n)
uf2=UnionFind(n)
d=dict()
a,b=[0]*n,[0]*n
for i in range(k):
  p,q=map(int,input().split())
  uf1.union(p-1,q-1)
ans=[0]*n
for i in range(l):
  r,s=map(int,input().split())
  uf2.union(r-1,s-1)
for i in range(n):
  a[i]=uf1.find(i)
  b[i]=uf2.find(i)
  if (a[i],b[i]) not in d:
    d[(a[i],b[i])]=1
  else:
    d[(a[i],b[i])]+=1
for i in range(n):
  ans[i]=d[(a[i],b[i])]
print(*ans)
### BUGGY CODE ###

N = int(input())
L_list =  sorted(list(map(int,input().split())),reverse=True)
#print(L_list)
result =0

for i in range(N):
    for j in range(i+1,N):
        if L_list[i] > L_list[j] * 2:
            break
        for k in range(j+1,N):
            if L_list[i] >= L_list[j] + L_list[k]:
                break
            elif L_list[i] < L_list[j] + L_list[k] and \
                    L_list[j] < L_list[k] + L_list[i] and \
                    L_list[k] < L_list[i] + L_list[j]:
                #print(i,j,k)
                result += 1
print(result)

### FIXED CODE ###

import bisect
N = int(input())
L_list =  sorted(list(map(int,input().split())))
#print(L_list)
result =0

for i in range(N):
    for j in range(i+1,N):
        a = L_list[i] + L_list[j]
        idx = bisect.bisect_left(L_list,a)
        result += max(0,idx-j-1)
print(result)
### BUGGY CODE ###

import math 
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = ["pairwise coprime", "setwise coprime ", "not coprime"]

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
if gcd_list(A) != 1:
  print(ans[2])
  quit()
  
def seachPrimeNum(N):
    max = int(N ** (1 / 2))
    D = [0] * N
    D[0] = 1
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        nn = seachList[0]
        D[nn - 1] = nn
        primeNum.append(nn)
        tmp = nn
        for i in seachList:
          if i != nn:
            if i % tmp == 0:
              D[i - 1] = nn
        seachList = [i for i in seachList if i % tmp != 0]
    for i in seachList:
      D[i - 1] = i
    primeNum.extend(seachList)
    
    return primeNum, D  
  
primeNum, D = seachPrimeNum(1000000)
used = [0] * len(primeNum)

for i in range(N):
  now = A[i]
  q = []
  #print(now, D[now - 1])
  if now in primeNum:
    q.append(now)
  while now != D[now - 1]:
    now = int(now / D[now - 1])
    if now in primeNum:
      q.append(now)
  for i in q:
    if used[primeNum.index(i)] == 0:
      used[primeNum.index(i)] = 1
    else:
      print(ans[1])
      quit()  

print(ans[0])

### FIXED CODE ###

from math import gcd
n = int(input())
a = [int(i) for i in input().split()]

g = a[0]
for i in range(n):
    g = gcd(g,a[i])
if g != 1:
    print("not coprime")
    exit()

m = max(a)
fac = [1]*(m+1)
for i in range(2,m+1):
    if fac[i] != 1:
      continue
    for j in range(i,m+1,i):
      fac[j] = i
      
s = set()
for i in range(n):
    x = fac[a[i]]
    if x == 1: 
      continue
    if x in s:
      print("setwise coprime")
      exit()
    s.add(x)
print("pairwise coprime")
### BUGGY CODE ###

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

RGB = set(['R', 'G', 'B'])
list_R = []
list_G = []
list_B = []
for k in range(N):
    s_sep = S[k]
    if s_sep == 'R':
        list_R.append(k)
    elif s_sep == 'G':
        list_G.append(k)
    else:
        list_B.append(k)


def count_num(list_RGB, i, j):
    counter = 0
    for k in list_RGB[::-1]:
        if k < j:
            break
        if k - j != j - i:
            counter += 1
    return counter


count = 0
for i in range(0, N):
    for j in range(i+1, N):
        one = RGB - set([S[i], S[j]])
        if len(one) == 1:
            if list(one)[0] == 'R':
                count += count_num(list_R, i, j)
            elif list(one)[0] == 'G':
                count += count_num(list_G, i, j)
            else:
                count += count_num(list_B, i, j)

print(count)

### FIXED CODE ###

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

# RGBとなる組み合わせの数を求める
sum_collection = S.count('R') * S.count('G') * S.count('B')

# RGBとなる組み合わせの数から、 j - i == k - jとなる組の数を減らす
for i in range(N):
    for j in range(i, N):
        # j - i == k - j　となる組を見つける
        k = j + (j - i)
        if k >= N:
            break
        # すべて違ったら　(R G Bの組み合わせであったら)
        if S[i] != S[j] != S[k] != S[i]:
            sum_collection -= 1

print(sum_collection)
### BUGGY CODE ###

# Problem E - Divisible Substring

from collections import Counter

# input
N, P = map(int, input().split())
S = list(input())

# count
if P==2 or P==5:
    ans = 0
    for i in range(N-1, -1, -1):
        s = int(S[i])
        if s%P==0:
            ans += i + 1
    # output
    print(ans)
else:
    p_nums = [0]*(N+1)
    s = ""
    for i in range(N-1, -1, -1):
        s = S[i] + s
        p_nums[N - i] = int(s)%P
    p_counter = [0]*P
    for i in range(N+1):
        p_counter[p_nums[i]] += 1
    ans = 0
    for i in range(P):
        ans += p_counter[i] * (p_counter[i] - 1) // 2
    print(ans)


### FIXED CODE ###

# Problem E - Divisible Substring

from collections import Counter

# input
N, P = map(int, input().split())
S = list(input())

# count
if P==2 or P==5:
    ans = 0
    for i in range(N-1, -1, -1):
        s = int(S[i])
        if s%P==0:
            ans += i + 1
    # output
    print(ans)
else:
    p_nums = [0]*(N+1)
    s = 0
    for i in range(N-1, -1, -1):
        s = int(S[i]) * pow(10, N - i - 1, P) + s
        p_nums[N - i] = s%P
    p_counter = [0]*P
    for i in range(N+1):
        p_counter[p_nums[i]] += 1
    ans = 0
    for i in range(P):
        ans += p_counter[i] * (p_counter[i] - 1) // 2
    print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
d=[[] for _ in range(n)]
e=[1]*m
for i in range(n):
  a,b=map(int,input().split())
  d[i]=(b,a)
d=sorted(d)[::-1]
ans=0
for i,j in d:
  for k in range(j-1,m):
    if e[k]:
      e[k]=0
      break
  else:continue 
  ans+=i
print(ans)

### FIXED CODE ###

from heapq import*
n,m=map(int,input().split())
x=[[]for _ in range(m)]
for _ in range(n):
  a,b=map(int,input().split())
  if a<=m:x[a-1]+=[-b]
q=[]
ans=0
for i in range(m):
  for j in x[i]:heappush(q,j)
  if q:ans-=heappop(q)
print(ans)
### BUGGY CODE ###

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

a = [0]
a.extend(list(map(int, input().split())))
a1 = []
for i in range(0, len(a)):
    a1.append(0)
step = 1
t = 0
if k<=11:
    for i in range(0, k):
        step = a[step]
    print(step)
else:

    for i in range(0, 10):
        step = a[step]

        step1 = step
    while(True):
        t += 1
        step1 = a[step1]
        if step1 == step:
            break
    result = step
    k = (k-10) % t
    for i in range(0, k):
        result = a[result]

    print(result)


### FIXED CODE ###

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

a = [0] + list(map(int, input().split()))
a1 = [0] * (n+1)

step = 1
start = 0
while(True):
    start += 1
    a1[step] += 1
    step = a[step]
    if a1[step] == 1:
        break
c = step
gap = 0
while(True):
    gap += 1
    step = a[step]
    if step == c:
        break
result = 1
if k > start:
    k = (k-start) % gap
    result = c
for _ in range(k):
    result = a[result]

print(result)
### BUGGY CODE ###

def main():
    s = input()
    q = int(input())
    for _ in range(q):
        qu = input()
        if qu == '1':
            s = s[::-1]
        else:
            if qu[2] == '1':
                s = qu[4] + s
            else:
                s = s + qu[4]
    print(s)
main()


### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    jun = True
    mae = ""
    ushiro = ""
    for _ in range(q):
        qu = input()
        if qu == '1':
            jun = not jun
        else:
            if qu[2] == '1':
                if jun:
                    mae = qu[4] + mae
                else:
                    ushiro = ushiro + qu[4]
            else:
                if jun:
                    ushiro = ushiro + qu[4]
                else:
                    mae = qu[4] + mae
    s = mae + s + ushiro
    if not jun:
        s = s[::-1]
    print(s)
main()
### BUGGY CODE ###

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

pin={}
#for i in range(10):
 # for j in range(10):
  #  for k in range(10):
   #   pin['{}{}{}'.format(i,j,k)]=0

l=len(S)
for i in range(l):
  for j in range(i+1,l):
    for k in range(j+1,l):
      s=S[i]+S[j]+S[k]
      pin[s]=1


ans=len(pin)

print(ans)

### FIXED CODE ###

N=int(input())
S=input()
S=list(map(int,S))
ans=0
for s in range(1000):
      A=s//100
      B=(s-A*100)//10
      C=s-A*100-B*10
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if isOne==0:
          if S[i]==A: 
            isOne=1
        elif isTen==0:
          if S[i]==B: 
            isTen=1
        elif isHundred==0:
          if S[i]==C:
            isHundred=1
            ans+=1
        else:
          break

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

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

mod = pow(10,9)+7

from functools import reduce
import math

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


LCM = lcm_list(A)



counter = 0
for a in A:
    counter += LCM//a
    counter %= mod 

print(counter)

### FIXED CODE ###

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

mod = pow(10,9)+7
ok = 1

import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

LCM = lcm_list(A)

import numpy as np
B = np.array(A)
C = LCM//B


print(sum(C)%mod)
### BUGGY CODE ###

from collections import deque


h, w = map(int, input().split())
Ch, Cw = map(lambda x: int(x)-1, input().split())
Dh, Dw = map(lambda x: int(x)-1, input().split())
dy, dx = (-1, 0, 1, 0), (0, -1, 0, 1)
maze = [[float('inf') if x == '.' else -float('inf') for x in input()] for _ in range(h)]
maze[Ch][Cw] = 0
que = deque()
que.append((0, Ch, Cw))
while que:
    c, y, x = que.popleft()
    
    if c > maze[y][x]:
        continue
    
    if y == Dh and x == Dw:
        break
    
    for i in range(4):
        y2, x2 = y + dy[i], x + dx[i]
        if 0 <= y2 < h and 0 <= x2 < w and c < maze[y2][x2]:
            maze[y2][x2] = c
            que.appendleft((c, y2, x2))
            
    for i in range(-2, 3):
        for j in range(-2, 3):
            y3, x3, c2 = y + i, x + j, c+1
            if 0 <= y3 < h and 0 <= x3 < w and c2 < maze[y3][x3]:
                maze[y3][x3] = c2
                que.append((c2, y3, x3))

ans = maze[Dh][Dw]
if ans == float('inf'):
    print(-1)
else:
    print(ans)

### FIXED CODE ###

from collections import deque


h, w = map(int, input().split())
Ch, Cw = map(lambda x: int(x)-1, input().split())
Dh, Dw = map(lambda x: int(x)-1, input().split())
dy, dx = (-1, 0, 1, 0), (0, -1, 0, 1)
maze = [[float('inf') if x == '.' else -float('inf') for x in input()] for _ in range(h)]
maze[Ch][Cw] = 0
que = deque()
que.append((0, Ch, Cw))
while que:
    c, y, x = que.popleft()
    
    if c > maze[y][x]:
        continue
    
    if y == Dh and x == Dw:
        break
    
    for i in range(4):
        y2, x2 = y + dy[i], x + dx[i]
        if 0 <= y2 < h and 0 <= x2 < w and c < maze[y2][x2]:
            maze[y2][x2] = c
            que.appendleft((c, y2, x2))
            
    for i in range(-2, 3):
        for j in range(-2, 3):
            y3, x3, c2 = y + i, x + j, c+1
            if 0 <= y3 < h and 0 <= x3 < w and c2 < maze[y3][x3]:
                maze[y3][x3] = c2
                que.append((c2, y3, x3))

ans = maze[Dh][Dw]
if ans == float('inf'):
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

X = int(input())
A = 1
K = 1
while K < X:
    A += 1
    K = A ** 5
S = A - 2
w = 0
while w != 1:
    P = S ** 5
    Q = P - X
    if Q < 0:
        B = 0
        while (Q != B**5):
            B -= 1
            if Q>(B**5):
                break
        if (Q == B**5):
            w += 1
        else:
            S += 1
        
    elif Q > 0:
        B = 0
        while (Q != B**5):
            B += 1
            if Q<(B**5):
                break
        if (Q == B**5):
            w += 1
        else:
            S += 1
print(S,B)

### FIXED CODE ###

X = int(input())
for i in range (240):
    for j in range (240):
        s = (i -120)**5 - (j -120)**5
        if s == X:
            A = i-120
            B = j -120
print(A,B)
### BUGGY CODE ###

# dpB - Frog 2
# 貰うDP
def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        for j in range(1, k + 1):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
    print(dp[-1])


if __name__ == "__main__":
    main()

### FIXED CODE ###

# EduDPB - Frog 2
import sys
input = sys.stdin.readline

n, k = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans = [0] + [float("inf")] * (n - 1)
for i in range(n):
    for j in range(1, k + 1):
        if i + j >= n:
            break
        ans[i + j] = min(ans[i + j], ans[i] + abs(lst[i] - lst[i + j]))
print(ans[-1])
### BUGGY CODE ###

n = int(input())
m = len(input())

mod = 10**9 + 7
# dp[i][j] = i文字打ってj文字入力されてる0or1 とBの打ち方
dp = [[0]*(n+1) for i in range(n+1)]

dp[0][0] = 1

# 遷移 : dp[i][j] →dp[i+1][j+1]+ dp[i+1][max(j-1,0)]+
for i in range(n):
    for j in range(n):
        dp[i+1][j+1] += dp[i][j]
        dp[i+1][j+1] %= mod
        dp[i+1][max(j-1,0)] += dp[i][j]*(2 - (j==0))
        dp[i+1][max(j-1,0)] %= mod
print(dp[n][m])


### FIXED CODE ###

n = int(input())
m = len(input())

mod = 10**9 + 7

# dp[i][j] = i文字打ってj文字入力されてる0or1 とBの打ち方
dp = [0]*(n+1)
dp[0] = 1

# 遷移 : dp[i][j] →dp[i+1][j+1]+ dp[i+1][max(j-1,0)]+
for i in range(n):
    dpnxt = [0]*(n+1)
    for j in range(n):
        dpnxt[j+1] += dp[j]
        dpnxt[j+1] %= mod
        dpnxt[max(j-1,0)] += dp[j]*(2 - (j==0))%mod
        dpnxt[max(j-1,0)] %= mod
    dp = dpnxt.copy()
print(dp[m])