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

"""
dp[i][j] => 下からi桁目まで見る。あまりがjになるような数。
"""
mod = 10**9 +7
S = input()
S = S[::-1]
N = len(S)
dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    s = S[i]
    for j in range(13):
        if s == "?":
            for k in range(10):
                rest = k*pow(10,i,13)%13
                dp[i+1][(j+rest)%13] += dp[i][j]
                dp[i+1][(j+rest)%13] %= mod
        else:
            rest = int(s)*pow(10,i,13)%13
            dp[i+1][(j+rest)%13] += dp[i][j]
            dp[i+1][(j+rest)%13] %= mod
print(dp[-1][5])

### FIXED CODE ###

"""
dp[i][j] => 下からi桁目まで見る。あまりがjになるような数。
"""
mod = 10**9 +7
S = input()
S = S[::-1]
N = len(S)
dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1
by = 1
for i in range(N):
    s = S[i]
    for j in range(13):
        if s == "?":
            for k in range(10):
                rest = k*by%13
                dp[i+1][(j+rest)%13] += dp[i][j]
                dp[i+1][(j+rest)%13] %= mod
        else:
            rest = int(s)*by%13
            dp[i+1][(j+rest)%13] += dp[i][j]
            dp[i+1][(j+rest)%13] %= mod
    by = by*10%13
print(dp[-1][5])
### BUGGY CODE ###

#!/usr/bin/env python

n=int(input())
a=[int(i) for i in input().split()]
b=[]

for i in a:
    b.append(i)
    b.reverse()

for k,v in enumerate(b):
    print(v, end="")
    if(k!=len(b)-1):
        print(" ", end="")
    else:
        print()


### FIXED CODE ###

#!/usr/bin/env python

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

def cal(p, rev):
    if(rev):
        lst=reversed(list(enumerate(a)))
    else:
        lst=list(enumerate(a))
    for k,v in lst:
        if(k%2==p):
            print(str(v)+" ", end="")

if(n%2==1):
    cal(0, True)
    cal(1, False)
    print()
else:
    cal(1, True)
    cal(0, False)
    print()
### BUGGY CODE ###

#ABC51-B

K,S=map(int,input().split())
sum=0
count=0
for i in range(K+1):
    sum+=i
    a=sum
    L=S-sum
    #print(L)
    LL=min(L,K)
    for j in range(LL+1):
        sum+=j
        if sum==S: #X＝Sの場合
            count+=1
            #print(str(i)+" "+str(j))
            break
        if S-sum>=0 and S-sum<=K :
            count+=1
            #print(str(i)+" "+str(j))
        sum=a #jを足す前に戻す
    sum=0
print(count)            

### FIXED CODE ###

K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(min(K+1,S-x+1)):
        z=S-x-y
        if 0<=z<=K:
            count+=1
print(count)
### BUGGY CODE ###

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

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
  for j in range(i+1,num):
    num_a = num_list[i]
    num_b = num_list[j]
    
    sigma += (num_a * num_b)%law

sigma %= law
print(sigma)

### FIXED CODE ###

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

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

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

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


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

N = int(input())
s = [str(input()) for i in range(N)]
#print(s)

e = []
f = [0] * N
j = 0
ans = 0
for i in range(N):
  s[i] = sorted(s[i])
  if s[i] not in e:
    e.append(s[i])
    f[j] = 1
    j += 1
  else:
    a = e.index(s[i])
    ans += f[a]
    f[a] += 1

print(ans)

### FIXED CODE ###

import time
N = int(input())
s = [str(input()) for i in range(N)]

j = 0
ans = 0
for i in range(N):
  s[i] = "".join(sorted(s[i]))
#print(s)

s = sorted(s)
tango = "yeeeh"
x = 0
#print(s)
for i in range(N):
  if s[i] == tango:
    x += 1
  else:
    ans += x * (x + 1) //2
    x = 0
  tango = s[i]
ans += x * (x + 1) //2

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

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

d=[]
for i in range(a-b+1):
    d.append(sum(c[i:i+b]))

n=max(d)
print((n+b)/2)


### FIXED CODE ###

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

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

if a==b:
    print((sum(c)+a)/2)
    exit()

d=[]

c=[(i+1)/2 for i in c]
n=cumsum(c)

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


print(max(m))
### BUGGY CODE ###

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

import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]

value = [[-1 for j in range(W + 1)] for i in range(N + 1)]

value[0] = [0 for j in range(W + 1)]
for i in range(1, N + 1):
    for j in range(W + 1):
        w, v = wv[i-1]
        if j >= w:
            value[i][j] = max(value[i-1][j], value[i-1][j-w] + v)
        else:
            value[i][j] = value[i-1][j]

ans = max(max(value))
print(ans)


### FIXED CODE ###

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

import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]

value = [[-1 for j in range(W + 1)] for i in range(N + 1)]

value[0] = [0 for j in range(W + 1)]
for i in range(1, N + 1):
    for j in range(W + 1):
        w, v = wv[i-1]
        if j >= w:
            value[i][j] = max(value[i-1][j], value[i-1][j-w] + v)
        else:
            value[i][j] = value[i-1][j]

ans = max(value[N])
print(ans)
### BUGGY CODE ###

from collections import deque

h,w = [int(x) for x in input().split()]
m = []
for _ in range(h):
    m.append(list(input()))

def bfs(sy,sx,gy,gx):
    res = [[-1]*(w) for i in range(h)]
    res[sy][sx] = 0
    q = deque()
    q.append([sy,sx])
    while q:
        z = q.popleft()
        if z[0]==gy and z[1]==gx:
            break
        for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
            ny = z[0] + dy
            nx = z[1] + dx
            if 0<=ny<h and 0<=nx<w and m[ny][nx]=="." and res[ny][nx]==-1:
                q.append([ny,nx])
                res[ny][nx] = res[z[0]][z[1]] + 1
    return res[gy][gx]

ans = -1
for i in range(h):
    for j in range(w):
        for ii in range(h):
            for jj in range(w):
                if i==ii and j==jj:
                    continue
                if (m[i][j]=="." and m[ii][jj]=="."):
                    xxx = bfs(i,j,ii,jj)
                    if xxx != -1:
                        if xxx > ans:
                            ans = xxx
print(ans)

### FIXED CODE ###

from collections import deque

h,w = [int(x) for x in input().split()]
m = []
for _ in range(h):
    m.append(list(input()))

def bfs(sy,sx):
    res = [[-1]*(w) for i in range(h)]
    res[sy][sx] = 0
    q = deque()
    q.append([sy,sx])
    dis = 0
    while q:
        z = q.popleft()
        for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
            ny = z[0] + dy
            nx = z[1] + dx
            if 0<=ny<h and 0<=nx<w and m[ny][nx]=="." and res[ny][nx]==-1:
                q.append([ny,nx])
                res[ny][nx] = res[z[0]][z[1]] + 1
                dis = res[ny][nx]
    return dis

ans = -1
for i in range(h):
    for j in range(w):
        if m[i][j] == ".":
            ret = bfs(i,j)
            if ret > ans:
                ans = ret
print(ans)
### BUGGY CODE ###

n = int(input())
note = dict()
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        note[s] += 1
    else:
        note[s] = 1

ans = 0
for i in note.values():
    ans += i*(i-1)//2

print(ans)

### FIXED CODE ###

import sys
#input = sys.stdin.readline

n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(sys.stdin.readline()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

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

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

mmax = max(a)
mmin = min(a)
mcount = 0
for i in range(mmin, mmax + 1):
    count = 0
    count += a.count(i)
    count += a.count(i + 1)
    count += a.count(i - 1)
    if mcount < count:
        mcount = count

print(mcount)


### FIXED CODE ###

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

c_dic = {}
for i in a:
    if i not in c_dic:
        c_dic[i] = 1
    else:
        c_dic[i] += 1
    
    if i + 1 not in c_dic:
        c_dic[i + 1] = 1
    else:
        c_dic[i + 1] += 1

    if i - 1 not in c_dic:
        c_dic[i - 1] = 1
    else:
        c_dic[i - 1] += 1

print(max(c_dic.values()))
### BUGGY CODE ###

n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
for p in range(n):
    ind = prise.index(min(prise))
    cost += min(prise) * conte[ind]
    ki += conte[ind]
    temp = min(prise)
    conte.pop(ind)
    prise.pop(ind)
    
    if ki >= m:
        if ki-m > 0:
            cost = cost - (ki-m)*temp
        break
    
print(cost)

### FIXED CODE ###

n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)
### BUGGY CODE ###

s=input()[::-1]

count=[0]*2019
count[0]+=1
gh=0
dd=len(s)
for i in range(0,dd):
    gh+=int(s[i])*(10**i)
    count[gh%2019]+=1

ans=0

for cnt in count:
    ans+=cnt*(cnt-1)//2

print(ans)



### FIXED CODE ###

s=input()[::-1]

count=[0]*2019
count[0]+=1
sd=0
d=1
for c in s:
   sd+=int(c)*d
   sd%=2019
   d*=10
   d%=2019
   count[sd]+=1

ans=0
for cnt in count:
    ans+=cnt*(cnt-1)//2

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

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

if N>K:
    for i in range(K):
        H.remove(max(H))
    print(sum(H))
else:
    print(0)


### FIXED CODE ###

import numpy as np

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

if K==0:
    print(sum(H))
elif N>K:
    H=sorted(H)
    del H[-K:]
    print(sum(H))
else:
    print(0)
### BUGGY CODE ###

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

out=[]
for i in range(N):
    dammy = ls_A.index(min(ls_A))
    out.append(dammy+1)
    ls_A[dammy] = N+3   #何よりも大きい数値にする
out=' '.join(map(str,out))
print(out)


### FIXED CODE ###

N = int(input())
A = [0] + list(map(int,input().split()))

ans=[0]*(N+1)
for i in range(1,N+1):
    ans[A[i]] = i

del ans[0]
print(*ans)
### BUGGY CODE ###

from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s)
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())
words = [input() for _ in range(N)]
ans = 0
while True:
    if not words:
        break
    target = words.pop(0)
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_anagrams(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)
    
    # 後ろからも
    if not words:
        break
    target = words.pop()
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_anagrams(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)

print(ans)

### FIXED CODE ###

from collections import Counter

class hashabledict(dict):
    def __hash__(self):
        return hash(tuple(sorted(self.items())))

N = int(input())
words = [hashabledict(dict(Counter(input()))) for _ in range(N)]
ans = 0
counter_hash = {}
for counter in words:
    if counter not in counter_hash.keys():
        counter_hash[counter] = 1
    else:
        counter_hash[counter] += 1
 
for count in counter_hash.values():
    ans += int((count * (count-1)) / 2)
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)
a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = 0

for one in kv[a2]:
    for t in kv[a3]:
        tmp = len(kv[a1])
        if 2*t-one in kv[a1]:
            tmp-=1
        if 2*one-t in kv[a1]:
            tmp-=1
        if (t+one)/2 in kv[a1]:
            tmp-=1
        ans+=tmp
print(ans)

### FIXED CODE ###

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

kv = {'R':[],'G':[],'B':[]}
for i in range(N):
    kv[S[i]].append(i)

a = sorted([[len(kv['R']),'R'],[len(kv['G']),'G'],[len(kv['B']),'B']], key=lambda x:-x[0])
a1, a2, a3 = a[0][1],a[1][1],a[2][1]

ans = a[0][0]*a[1][0]*a[2][0]
set_a3 = set(kv[a3])
for one in kv[a1]:
    for t in kv[a2]:
        ans-=3-len(set([2*t-one,2*one-t,(t+one)/2])-set_a3)
print(ans)
### BUGGY CODE ###

N, M = map( int, input().split())
V = [ 1 for i in range(N)]
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( lambda x:x-1, map( int, input().split()))
    V[y] = 0
    E[x].append(y)
S = []
for i in range(N):
    if V[i] == 1:
        S.append(i)
Pathdistance = [-1 for _ in range(N)]
while S:
    s = S.pop(0)
    Pathdistance[s] = 0
    now = 1
    Z = []
    for t in E[s]:
        if Pathdistance[t] < now:
            Z.append(t)
            Pathdistance[t] = now
    while Z:
        T = []
        now += 1
        for z in Z:
            for t in E[z]:
                if Pathdistance[t] < now:
                    T.append(t)
                    Pathdistance[t] = now
        Z = T
print( max(Pathdistance))

### FIXED CODE ###

import heapq
def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))
### BUGGY CODE ###

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

if 0 in numbers:
  print("0")
else:
 result=1
 for n in numbers:
    result *= n
 if result > 10**18:
  result = -1
 print(result)

### FIXED CODE ###

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

if 0 in numbers:
  print("0")
else:
 result=1
 for n in numbers:
    result *= n
    if result > 10**18:
      result = -1
      break
 print(result)
### BUGGY CODE ###

import sys
import bisect
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
for i in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    ind = bisect.bisect_left(a_ls, c)
    a_ls = (a_ls[:ind] + [c] * b + a_ls[ind:])[-n:]
print(sum(sorted(a_ls)[-n:]))

### FIXED CODE ###

import sys
from collections import Counter
n, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
ls = []
for j in range(m):
    b, c = [int(i) for i in sys.stdin.readline().split()]
    if ct.get(c) is None:
        ct[c] = 0
    ls.append((b, c))
    ct[c] += b
ls.sort(key=lambda x:x[1], reverse=True)
cnt = 0
for b, c in ls:
    if cnt + b < n:
        a_ls += [c] * b
        cnt += b
    else:
        a_ls += [c] * (n - cnt)
        break
a_ls.sort()
print(sum(a_ls[-n:]))
### BUGGY CODE ###

n = int(input())
 
str = input()
sum = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if str[i] == str[j]:
        break
      elif str[i] != str[k] and str[j] != str[k] and j - i != k - j:
        sum += 1
print(sum)

### FIXED CODE ###

n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)
### BUGGY CODE ###

from collections import Counter
n=int(input())
mylist=[]
for i in range(n):
    s=input()
    mylist.append(s)
#print(mylist)
c=Counter(mylist)

max=sum(x==max(mylist) for x in mylist)
answer=[]
#print(max)
for word,i in c.most_common():
    #print(word,i)
    if i==max:
        answer.append(word)
    else:
        break

answer.sort()
for i in range(len(answer)):
    print(answer[i])

### FIXED CODE ###

from collections import Counter
n=int(input())
mylist=[]
for i in range(n):
    s=input()
    mylist.append(s)
#print(mylist)
c=Counter(mylist)

#max=sum(x==max(mylist) for x in mylist)
answer=[]
flag=0
#print(max)
for word,i in c.most_common():
    #print(word,i)
    if flag==0:
        max=i
        flag+=1
        answer.append(word)
    else:
        if i==max:
            answer.append(word)
        else:
            break

answer.sort()
for i in range(len(answer)):
    print(answer[i])
### BUGGY CODE ###

import queue as qu


words = lambda t : list(map(t, input().split()))

h,w = words(int)
mat = []
for _ in range(h):
    a = list(input())
    mat.append(a)

#print(mat)

q = qu.Queue()
for i in range(h):
    for j in range(w):
        if mat[i][j] == "#":
            q.put((i,j))

prev = q
round = -1
while not prev.empty():
    round += 1
    next = qu.Queue()
    while not prev.empty():
        (x,y) = prev.get()
        if x != 0 and mat[x-1][y] != "#":
            next.put((x-1,y))
            mat[x-1][y] = "#"
        if y != 0 and mat[x][y-1] != "#":
            next.put((x,y-1))
            mat[x][y-1] = "#"
        if x != h-1 and mat[x+1][y] != "#":
            next.put((x+1,y))
            mat[x+1][y] = "#"
        if y != w-1 and mat[x][y+1] != "#":
            next.put((x,y+1))
            mat[x][y+1] = "#"
    prev = next

print(round)


### FIXED CODE ###

import functools as ft

h,w = map(int, input().split())
mat = [[True] * (w+2)]
for _ in range(h):
    mat.append([True] + [a == '#' for a in input()] + [True])
mat.append([True]*(w+2))

prev = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if mat[i][j]:
            prev.append((i,j))



round = -1
while prev:
    round += 1
    #print(prev)
    #print(mat)
    def calc(next, tup):
        x = tup[0]
        y = tup[1]
        if not mat[x-1][y]:
            next.append((x-1,y))
            mat[x-1][y] = True
        if not mat[x][y-1]:
            next.append((x,y-1))
            mat[x][y-1] = True
        if not mat[x+1][y]:
            next.append((x+1,y))
            mat[x+1][y] = True
        if not mat[x][y+1]:
            next.append((x,y+1))
            mat[x][y+1] = True
        return next
    next = ft.reduce(calc, prev, [])

    prev = next

print(round)
### BUGGY CODE ###

from math import factorial

s = input()
array = [0]*(len(s)+1)
mod = 2019

for i in range(len(s)):
    array[i] = int(s[i:len(s)]) % mod
    
array[len(s)] = 0

array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w != 1:
            cnt += factorial(w) / (factorial(2)*factorial(w - 2))
            w = 1
            
if w != 1:
    cnt += factorial(w) / (factorial(2)*factorial(w - 2))
    
print(int(cnt))

### FIXED CODE ###

s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
    

    
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += w*(w-1)/2
    
print(int(cnt))
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
AA = sorted([ a - i - 1 for i,a in enumerate(A) ])
C = []
for i,a in enumerate(AA):
    if i == 0:
        C.append(a)
    else:
        C.append(C[-1] + a)
ans = ""
#print(C)
for b in range(AA[0],AA[-1]):
    sample = 0
    num = 0
    for i,a in enumerate(AA):
        if b <= a:
            num = i -1 
            break
        else:
            num = i
    if num == -1:
        sample = C[-1]  - b * (N - 2 * (num + 1))
    else:
        sample = C[-1] - 2 * C[num] - b * (N - 2 * (num + 1))
    if ans == "":
        ans = sample
    if ans > sample:
        ans = sample
if ans == "":
    ans = 0
print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
AA = sorted([ a - i - 1 for i,a in enumerate(A) ])
C = []
for i,a in enumerate(AA):
    if i == 0:
        C.append(a)
    else:
        C.append(C[-1] + a)
ans = ""
#print(C)
for i,b in enumerate(AA):
    sample = 0
    num = i-1
    if num == -1:
        sample = C[-1]  - b * (N - 2 * (num + 1))
    else:
        sample = C[-1] - 2 * C[num] - b * (N - 2 * (num + 1))
    if ans == "":
        ans = sample
    if ans > sample:
        ans = sample
if ans == "":
    ans = 0
print(ans)
### BUGGY CODE ###

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

dp=[int(10e8)]*n

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

print(dp[n-1])


### FIXED CODE ###

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

dp=[int(10e8)]*n
dp[0]=0
for i in range(1,n):
    for j in range(min(i,k)):
        dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]))

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

s = input()
ans = 0
mod = []
for i in range(len(s)):
    mod.append(int(s[i:])%2019)
for i in range(1,2019):
    ans += mod.count(i)*(mod.count(i)-1)/2
ans += mod.count(0)
print(int(ans))

### FIXED CODE ###

s = input()
ans = 0
mod = [0]*2019
t = s[len(s)-1]
n = 1
for i in range(len(s)-1,-1,-1):
#     mod.append(int(s[i:])%2019)
    mod[int(t)%2019] += 1
#     t = int(t) + (10**(len(s)-i-1))*int(s[i])
    t = int(t) + n*10*int(s[i-1])
    n = n*10%2019
for i in range(0,2019):
    ans += mod[i]*(mod[i]-1)/2
ans += mod[0]
print(int(ans))
### BUGGY CODE ###

import numpy as np

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

# if L == R:
#     tmp = L % MOD
#     print(tmp*tmp)
# else:
#     a = np.array(range(L, R+1)) % MOD
#     b = np.sort(a,kind='quicksort')
#     print(b[0]*b[1])

minMOD = 2019
# minMOD2 = 2019
#
# for i in range(L, R+1):
#     tmp = i % MOD
#     if tmp == 0:
#         minMOD = 0
#         break
#
#     if tmp < minMOD:
#         minMOD = tmp
#     elif tmp < minMOD2:
#         minMOD2 = tmp

#print((minMOD * minMOD2) % MOD)

for i in range(L, R+1):
    for j in range(i+1, R+1):
        tmp = (i*j)%MOD
        if tmp < minMOD:
            minMOD = tmp
            if(tmp == 0):
                break

print(minMOD)


### FIXED CODE ###

import numpy as np

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

# if L == R:
#     tmp = L % MOD
#     print(tmp*tmp)
# else:
#     a = np.array(range(L, R+1)) % MOD
#     b = np.sort(a,kind='quicksort')
#     print(b[0]*b[1])

minMOD = 2019
# minMOD2 = 2019
#
# for i in range(L, R+1):
#     tmp = i % MOD
#     if tmp == 0:
#         minMOD = 0
#         break
#
#     if tmp < minMOD:
#         minMOD = tmp
#     elif tmp < minMOD2:
#         minMOD2 = tmp

#print((minMOD * minMOD2) % MOD)

for i in range(L, R+1):
    if(i % MOD) == 0:
        minMOD = 0
        break
    for j in range(i+1, R+1):
        if(j % MOD) == 0:
            minMOD = 0
            break
        tmp = (i*j)%MOD
        if tmp < minMOD:
            minMOD = tmp
            if(tmp == 0):
                break

print(minMOD)