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

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    ## 1の位からi+1文字のうち13で割ったもののあまりがjであるものの数
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0]=1
    list10 = range(0,10)
    list13 = range(0,13)
    keta =1
    for i in range(1,N+1):
        if S[N-i]=="?":
            for j in list10:
                addmod = j*keta%13
                for k in list13:
                    modmod = (k+addmod)%13
                    dp[i][modmod] += dp[i-1][k]%MOD
        else:
            addmod = (int(S[N-i])*keta)%13
            for k in list13:
                modmod = (k+addmod)%13
                dp[i][modmod] = dp[i-1][k]%MOD
        keta*=10
    print(dp[N][5]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    ## 1の位からi+1文字のうち13で割ったもののあまりがjであるものの数
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0]=1
    list10 = range(0,10)
    list13 = range(0,13)
    keta =1
    for i in range(1,N+1):
        if S[N-i]=="?":
            for j in list10:
                addmod = j*keta%13
                for k in list13:
                    modmod = (k+addmod)%13
                    dp[i][modmod] += dp[i-1][k]%MOD
        else:
            addmod = (int(S[N-i])*keta)%13
            for k in list13:
                modmod = (k+addmod)%13
                dp[i][modmod] = dp[i-1][k]%MOD
        keta*=10
        keta%=13
    print(dp[N][5]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

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

N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

X, Y = [], []
for i in range(N):
  x, y = XY[i]
  X.append((x, i + 1))
  Y.append((y, i + 1))
X.sort()
Y.sort()

edge = [0] * (N - 1) * 2
xa, ax = X[0]
ya, ay = Y[0]
for i in range(N - 1):
  xb, bx = X[i + 1]
  edge[i * 2] = (abs(xa - xb), (ax, bx))
  yb, by = Y[i + 1]
  edge[i * 2 + 1] = (abs(ya - yb), (ay, by))
  xa, ax = xb, bx
  ya, ay = yb, by
edge.sort()

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 size(self, x):
    if self.parents[x] < 0:
      return -self.parents[x]
    else:
      self.parents[x] = self.size(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
  
answer = 0
edge_cnt = 0
U = UnionFind(N + 1)

for e in edge:
  c, ab = e
  a, b = ab
  if U.find(a) != U.find(b):
    U.union(a, b)
    answer += c
    edge_cnt += 1
  if edge_cnt == N - 1:
    break
    
print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

N = int(input())
XY = [list(map(int, input().split())) + [i + 1] for i in range(N)]

dist = []

XY.sort()
for i in range(N - 1):
  dist.append((abs(XY[i][0] - XY[i + 1][0]), (XY[i][2], XY[i + 1][2])))
XY.sort(key = lambda x: x[1])
for i in range(N - 1):
  dist.append((abs(XY[i][1] - XY[i + 1][1]), (XY[i][2], XY[i + 1][2])))
dist.sort()

root = [i for i in range(N + 1)]
comp_size = [1] * (N+1)
 
def root_find(x):
  y = root[x]
  if x == y:
    return x
  else:
    z = root_find(y)
    root[x] = z
    return z

def merge(x, y):
  rx = root_find(x)
  ry = root_find(y)
  sx = comp_size[rx]
  sy = comp_size[ry]
  if rx != ry:
    if sx >= sy:
      root[ry] = rx
      comp_size[rx] = sx + sy
    else:
      root[rx] = ry
      comp_size[ry] = sx + sy
      
answer = 0
for d, (a, b) in dist:
  if root_find(a) != root_find(b):
    merge(a, b)
    answer += d

print(answer)
### BUGGY CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
idx = 0
s=0
e=0

for i in range(n-k+1):
    if sum(p[i:i+k]) > s:
        idx = i
        s = sum(p[i:i+k])

for i in range(idx,idx+k):
    e1 = (1 + p[i])*(p[i]//2 + 0.5*(p[i]%2))/p[i]
    e += e1

print(e)
    

### FIXED CODE ###

n,k=map(int,input().split())
p=list(map(int,input().split()))
l=[sum(p[:k])]

for i in range(n-k):
    l1=l[i] - p[i] + p[i+k]
    l.append(l1)

print((max(l)+k)/2)
### BUGGY CODE ###

s = input()
t = input()
before = -1
len_s = len(s)
ans = 0
cnt = 0
moji = [[] for _ in range(26)]
for i,S in enumerate(s):
        moji[ord(S) - 97].append(i)

for T in t:
        found = False
        if not moji[ord(T) - 97]:
                print(-1)
                exit()
        for num in moji[ord(T) - 97]:
                if num > before:
                        before = num
                        found = True
                        break
        if not found:
                cnt += 1
                before = moji[ord(T) - 97][0]
ans = cnt * len_s + before + 1
print(ans)

### FIXED CODE ###

import bisect
s = input()
t = input()
before = -1
len_s = len(s)
ans = 0
cnt = 0
moji = [[] for _ in range(26)]
for i,S in enumerate(s):
        moji[ord(S) - 97].append(i)

for T in t:
        if not moji[ord(T) - 97]:
                print(-1)
                exit()
        if moji[ord(T) - 97][-1] <= before:
                cnt += 1
                before = moji[ord(T) - 97][0]
                continue
        before = moji[ord(T) - 97][bisect.bisect_right(moji[ord(T) - 97],before)]
        # for num in moji[ord(T) - 97]:
        #         if num > before:
        #                 before = num
        #                 break
ans = cnt * len_s + before + 1
print(ans)
### BUGGY CODE ###

import itertools
n=int(input())
a=list(map(str,input().split()))
s=list(itertools.combinations(a,2))
cnt=0
for i in s:
  if i[0]==i[1]:
    cnt+=1

for i in a:
  c=a.count(i)
  print(cnt-c+1)

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
s=Counter(a)
sums=0
for k in s.keys():
  sums+=(s[k]-1)*s[k]//2

for i in a:
  print(sums-s[i]+1)
### BUGGY CODE ###

N = int(input())
li = [input() for x in range(N)]
ans = 0
wli = list()
for k in li:
    wli.append(''.join(sorted(list(k))))
for i in range(N):
    word = wli[i]
    for j in range(i+1, N):
        comp = wli[j]
        if word == comp:
            ans += 1
print(ans)            

### FIXED CODE ###

import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
di = dict()
for k in li:
    word = ''.join(sorted(list(k)))
    if word in di.keys():
        ans += di[word]
        di[word] += 1
    else:
        di[word] = 1
print(ans)
### BUGGY CODE ###

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

h_ = sorted(h)
minn = 999999999
for i in range(len(h) - K + 1):
    min_temp = max(h_[i:i+K]) - min(h_[i:i+K])
    if min_temp <= minn:
        minn = min_temp

print(minn)


### FIXED CODE ###

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

hs = sorted(h)
ans = hs[-1] - hs[0]
for i in range(N - K + 1):
    ans = min(ans, hs[i+K-1]-hs[i])

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

s = input()
t = input()
ls = len(s)
lt = len(t)

dp = [[-1 for _ in range(ls+1)] for _ in range(lt+1)]
dp[0] = [0] * (ls+1)

for i in range(lt+1):
  dp[i][0] = 0

for i in range(1,lt+1):
  for j in range(1,ls+1):
    if t[i-1] == s[j-1]:
      dp[i][j] = max((dp[i-1][j-1] + 1),(dp[i-1][j]))
    else:
      dp[i][j] = max((dp[i][j-1]),(dp[i-1][j]))

res = ""
while ls > 0 and lt > 0:
  if dp[lt][ls] == dp[lt][ls-1]:
    ls -= 1
  elif dp[lt][ls] == dp[lt-1][ls]:
    lt -= 1
  else:
    res = s[ls-1] + res
    ls -= 1
    lt -= 1

print(res)

### FIXED CODE ###

s = input()
t = input()
ls = len(s)
lt = len(t)

dp = [[-1 for _ in range(ls+1)] for _ in range(lt+1)]
dp[0] = [0] * (ls+1)

for i in range(lt+1):
  dp[i][0] = 0

for i in range(1,lt+1):
  for j in range(1,ls+1):
    if t[i-1] == s[j-1]:
      dp[i][j] = max((dp[i-1][j-1] + 1),(dp[i-1][j]))
    else:
      dp[i][j] = max((dp[i][j-1]),(dp[i-1][j]))

res = ""
while ls > 0 and lt > 0:
  if dp[lt][ls] == dp[lt][ls-1]:
    ls -= 1
  elif dp[lt][ls] == dp[lt-1][ls]:
    lt -= 1
  else:
    res = s[ls-1] + res
    ls -= 1
    lt -= 1

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

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

import numpy as np
Cumsum = np.cumsum(A)
counter = 0
for l in range(0, N):
    for r in range(l, N):
        if l == r:
            if A[l] % M == 0:
                counter += 1
        elif l != r and l == 0:
            if Cumsum[r] % M == 0:
                counter += 1
        elif l != r and l >= 1:
            if (Cumsum[r] - Cumsum[l-1]) % M == 0:
                counter += 1


print(counter)

### FIXED CODE ###

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

ans = 0
hash = defaultdict(int)
hash[0] = 1
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

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

import sys
input = sys.stdin.readline


def main():
    N = int(input())
    S = input().strip()

    ans = 0
    for k in range(N):
        now_S = S[k:]
        ans_length = [-1] * (len(now_S)+1)
        j = -1
        for i, c in enumerate(now_S):
            left_end = now_S[j]
            right_end = c
            while j >= 0 and left_end != right_end:
                j = ans_length[j]
                left_end = now_S[j]
            j += 1
            ans_length[i+1] = j

        for i, length in enumerate(ans_length):
            tmp_max_length = i // 2
            if length <= tmp_max_length:
                ans = max(ans, length)
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline


def main():
    N = int(input())
    S = input().strip()

    dp = [0] * N
    for i, s in enumerate(S):
        if i == 0:
            continue
        before_ans = dp[i-1]
        now_S = S[:i+1]
        tmp_ans = now_S[-(before_ans+1):i+1]
        # print(i, before_ans, tmp_ans)
        if tmp_ans in now_S[:-(before_ans+1)]:
            dp[i] = before_ans + 1
        else:
            dp[i] = before_ans
    print(dp[-1])


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

from heapq import *
N = int(input())
A = [int(a) for a in input().split()]
x, t, s, i, h = 0, 0, 0, 59, []
for a in A:
    t ^= a
for a in A:
    heappush(h, -(a&~t))
while h:
    a = -heappop(h)
    while i >= 0 and (a >> i) & 1 == 0:
        i -= 1
        x = 0
    if i < 0: break
    if x:
        heappush(h, -(a^x))
    else:
        x = a
        s = max(s, s^x)
print(s+(t^s))

### FIXED CODE ###

from heapq import *
N = int(input())
A = [int(a) for a in input().split()]
x, t, s, i, h = 0, 0, 0, 59, []
for a in A:
    t ^= a
for a in A:
    heappush(h, -(a&~t))
while h:
    a = -heappop(h)
    while i >= 0 and (a >> i) & 1 == 0:
        i -= 1
        x = 0
    if i < 0: break
    if x:
        heappush(h, -(a^x))
    else:
        x = a
        s = max(s, s^x)
print(s+(t^s))
### BUGGY CODE ###

n,m,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0] + list(map(int,input().split()))
for i in range(1,n+1):
  a[i] += a[i-1]
for i in range(1,m+1):
  b[i] += b[i-1] 
ans,ai,bi = 0,0,0
for i in range(n+1):
  if a[i]<=k:
    ai = i
for j in range(m+1):
  if a[ai]+b[j]<=k:
    bi = j
ans = ai+bi
for i in range(ai):
  for j in range(bi,m+1):
    if a[ai-i-1]+b[j]<=k:
      ans = max(ans,ai-i-1+j)
      bi = j
print(ans)

### FIXED CODE ###

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a,b = [0],[0]
for i in range(n):
  a.append(a[i]+A[i])
for i in range(m):
  b.append(b[i]+B[i])

ans,j = 0,m
for i in range(n+1):
  if a[i]>k:
    break
  while b[j]+a[i]>k:
    j -= 1
  ans = max(ans,i+j)

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

N = int(input())
c = input()
C = []
for c_i in c:
    C.append(c_i)
count = 0
left = N - 1
for i in range(N):
    if i >= left:
        print(count)
        break
    if C[i] == 'W':
        for j in reversed(range(N)):
            if i == 1:
                if j == i:
                    C[i] = 'R'
                    left = i
                    break
            else:
                if j == i-1:
                    left = i
                    break
            if C[j] == 'R':
                C[i] = 'R'
                C[j] = 'W'
                left = j
                count += 1
                break

### FIXED CODE ###

N = int(input())
c = input()
C = []
for c_i in c:
    C.append(c_i)
count = 0
left = N-1
for i in range(N):
    if i >= left:
        print(count)
        break
    if C[i] == 'W':
        for j in reversed(range(left+1)):
            if i == 1:
                if j == i:
                    C[i] = 'R'
                    left = i
                    break
            else:
                if j == i-1:
                    left = i
                    break
            if C[j] == 'R':
                C[i] = 'R'
                C[j] = 'W'
                left = j
                count += 1
                break
### BUGGY CODE ###

def bit_add(bit, i, x):
    i += 1
    while i <= len(bit):
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [list(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


### FIXED CODE ###

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)
### BUGGY CODE ###

n = int(input())
l = []
lb = []
la = []
c = 0
for _ in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l = sorted(l)
for i in range(0,n):
    lb.append(l[i][0])
    la.append(l[i][1])

for i in range(0,n):
    if lb[i] < sum(la[:i+1]):
        c = 1
        break
    else:
        continue
if c == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = int(input())
l = []
c = 0
d = 0
for _ in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l = sorted(l)


for i in range(0,n):
    if l[i][0] < d + l[i][1]:
        c = 1
        break
    else:
        d = d+ l[i][1]
        continue
if c == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,x,y = [int(i) for i in readline().split()]

INF = 1001001001

from collections import deque

def push(v,d):
    if dist[v] != INF:
        return
    dist[v] = d
    q.append(v)

x -= 1
y -= 1
ans = [0]*n
for sv in range(n):
    dist = [INF]*n
    q = deque()
    push(sv, 0) # 初期状態
    while len(q):
        v = q.popleft()
        d = dist[v]
        if v-1 >= 0: push(v-1, d+1)
        if v+1 < n: push(v+1, d+1)
        if v == x: push(y, d+1)
        if v == y: push(x, d+1)
    for i in range(n):
        ans[dist[i]] += 1
for i in range(n):
    ans[i] //= 2 # (1,2)と(2,1)を2度数えてしまっているので2で割る
for i in range(1,n):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,x,y = [int(i) for i in readline().split()]

ans = [0] * n

for a in range(1, n+1):
    for b in range(a+1, n+1):
        d = b - a
        d2 = abs(x-a) + abs(y-b) + 1
        d = d if d < d2 else d2
        ans[d] += 1

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

a=[]
for _ in range(int(input())):
    b=input().split()
    if len(b)>1:c=int(b[1])
    b=b[0]
    if b[0]=='i':a=[c]+a
    elif len(b)>10:a=a[1:]
    elif len(b)>6:a.pop()
    else:
        try:a.remove(c)
        except:pass
print(*a)

### FIXED CODE ###

import collections
a=collections.deque()
for _ in range(int(input())):
    b=input()
    if b[0]=='i':a.appendleft(b[7:])
    elif b[6]==' ':
        try:a.remove(b[7:])
        except:pass
    elif len(b)>10:a.popleft()
    elif len(b)>6:a.pop()
print(*a)
### BUGGY CODE ###

from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    n, k = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    a.sort()
    ans = 0

    def cmb(n, r, mod=10 ** 9 + 7):
        r = min(r, n - r)
        x = y = 1
        for i in range(r):
            x *= n - i
            x %= mod
            y *= i + 1
            y %= mod
        return x * pow(y, mod - 2, mod) % mod

    for i in range(n - k + 1):
        ans -= a[i] * cmb(n - 1 - i, k - 1)
        ans %= mod
    for i in range(k - 1, n):
        ans += a[i] * cmb(i, k - 1)
        ans %= mod
    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

### FIXED CODE ###

from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    n, k = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    a.sort()
    ans = 0

    m = n + 1

    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def initialize_cmb(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % mod
                inv[i] = mod - inv[mod % i] * (mod // i) % mod
                finv[i] = finv[i - 1] * inv[i] % mod

    def cmb(n, k, mod=10 ** 9 + 7):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

    initialize_cmb(m)

    for i in range(n - k + 1):
        ans -= a[i] * cmb(n - 1 - i, k - 1)
        ans %= mod
    for i in range(k - 1, n):
        ans += a[i] * cmb(i, k - 1)
        ans %= mod
    print(ans % mod)


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

INF=10**9
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
ch-=1
cw-=1
dh,dw=f()
dh-=1
dw-=1
g=[input() for _ in range(h)]
from heapq import *
def dijkstra_grid(x,y):
  d=[[INF]*w for _ in range(h)]
  d[x][y]=0
  q=[(0,x,y)]
  while q:
    td,tx,ty=heappop(q)
    if d[tx][ty]<td: continue
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=tx+dx,ty+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td:
        d[nx][ny]=td
        heappush(q,(td,nx,ny))
    for dx in range(-2,3):
      for dy in range(-2,3):
        nx,ny=tx+dx,ty+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td+1:
          d[nx][ny]=td+1
          heappush(q,(td+1,nx,ny))
  return d
a=dijkstra_grid(ch,cw)[dh][dw]
print([-1,a][a<INF])

### FIXED CODE ###

INF=10**6
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
ch-=1
cw-=1
dh,dw=f()
dh-=1
dw-=1
g=[input() for _ in range(h)]
from collections import *
def grid_01_bfs(x,y):
  d=[[INF]*w for _ in range(h)]
  d[x][y]=0
  q=deque([(0,x,y)])
  while q:
    td,tx,ty=q.popleft()
    if d[tx][ty]<td: continue
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=tx+dx,ty+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td:
        d[nx][ny]=td
        q.appendleft((d[nx][ny],nx,ny))
    for dx in range(-2,3):
      for dy in range(-2,3):
        nx,ny=tx+dx,ty+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td+1:
          d[nx][ny]=td+1
          q.append((d[nx][ny],nx,ny))
  return d
a=grid_01_bfs(ch,cw)[dh][dw]
print([-1,a][a<INF])
### BUGGY CODE ###

n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[0]=0
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])


### FIXED CODE ###

n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[0]=0
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    a = sorted(a, reverse=True)
    a[0] = a[0] // 2
print(sum(a))

### FIXED CODE ###

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

N = int(input())

input_1 = input()
input_2 = input_1.split()

A = map(int, input_2)

def equal(num):
    return num
A = [equal(x) for x in A]

for k in range(N):
    ans = 0

    re = A[k]
    A.remove(A[k])

    for l in range(N - 1):
        ans += A.count(A[l]) - 1

    ans = ans / 2

    A.insert(k,re)

    print(int(ans))

### FIXED CODE ###

#TLE
n = int(input())
a = input().split()
ans = 0
import collections
dic = collections.Counter(a)
for i in dic.values():
    ans += i * (i-1)
ans /= 2
for i in range(n):
    print(int(ans - dic[a[i]] + 1))
### BUGGY CODE ###

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

s=[-1]+[ord(chr[i])-ord("A")+1 for i in range(N)]+[-1]
state=[0]+[1 for i in range(N)]+[0]

for i in range(Q):
    a,b=input().split()
    k=ord(a)-ord("A")+1
    for j in range(1,N+1):
        if s[j]==k:
            if b=="R": state[j+1]+=state[j]
            if b=="L": state[j-1]+=state[j]
            state[j]=0

zanki=N-state[0]-state[N+1]

print(zanki)

### FIXED CODE ###

N,Q=map(int,input().split())
s="0"+input()+"0"
queri=[list(input().split()) for i in range(Q)]

L,R=0,N+1
for i in range(Q-1,-1,-1):
    t,d=queri[i]
    if t==s[L] and d=="R":
        L-=1
    elif t==s[L+1] and d=="L":
        L+=1
    if t==s[R] and d=="L":
        R+=1
    elif t==s[R-1] and d=="R":
        R-=1

print(R-L-1)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1,-1,-1):
    temp=0
    for j in range(i,n): temp+=ans[j]
    if a[i]!=temp%2: ans[i]=1
print(sum(ans))                                 
for i in range(n):
    if ans[i]==1: print(i+1,end=" ")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*(n+1)
for i in range(n,0,-1):
    temp=0
    for j in range(i,n+1,i): temp+=ans[j]
    if a[i-1]!=temp%2: ans[i]=1
print(sum(ans))           
for i in range(n+1):
    if ans[i]==1: print(i,end=" ")
### BUGGY CODE ###

import numpy as np

L,R = map(int, input().split())

if  R-L > 2019:
    print(0)
    
else:
    ans = 2019
    for i in np.arange(L, R+1):
        for j in np.arange(i+1, R+1):
            ans = np.amin(np.array([i * j % 2019, ans]))
    print(ans)  

### FIXED CODE ###

import numpy as np

L,R = map(int, input().split())

if  R-L > 2018:
    print(0)
    
else:
    ans = 2018
    
    R = R % 2019
    L = L % 2019

    if L > R:
        R += 2019
        
    if R - L > 500:
        print(0)
        
    else:
        for i in np.arange(L, R+1):
            for j in np.arange(i+1, R+1):
                i = i % 2019
                j = j % 2019
                k = i * j % 2019
                ans = np.amin(np.array([k, ans]))
            
        print(ans)