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

n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])

### FIXED CODE ###

n, k = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
inf = 1e9
dp = [inf] * n
dp[0] = 0
for i in range(1, n):
    cnt = 1
    while cnt <= k and i - cnt > -1:
        dp[i] = min(dp[i], dp[i - cnt] + abs(h[i] - h[i - cnt]))
        cnt += 1
print(dp[-1])
### BUGGY CODE ###

total = input().rstrip().split(" ")
num_high = int(total[0])
ans = num_high
num_load = int(total[1])
height = input().rstrip().split(" ")
kind_load = []
for i in range(num_load):
    line = input().rstrip().split(" ")
    kind_load.append(line)
ans = [t+1 for t in range(num_high) ]

#j番目を選ぶ
for j in range(num_high):
    #print(ans)
    choice = j+1
    #J番目の展望台のある道路を探す
    for list in kind_load:
        if str(choice) in list:
            #比較のため、データを取り出す
            choose = list.index(str(choice))
            check_a = int(list[choose])
            if choose == 1:
                check_b = int(list[0])
            else:
                check_b = int(list[1])
            #比較
            if int(height[check_a - 1]) <= int(height[check_b - 1]):
                del list
                if check_a in ans:
                    link = ans.index(check_a)
                    del ans[link]
print(len(ans))


### FIXED CODE ###

total = input().rstrip().split(" ")
num_high = int(total[0])
ans = num_high
num_load = int(total[1])
height = input().rstrip().split(" ")
ans = [0 for i in range(num_high)]

for j in range(num_load):
    list = input().rstrip().split(" ")
    check_a = int(list[0])
    check_b = int(list[1])
    if int(height[check_a-1]) <= int(height[check_b-1]):
        ans[check_a-1] = 1
    if int(height[check_b-1]) <= int(height[check_a-1]):
        ans[check_b-1] = 1
print(ans.count(0))
### BUGGY CODE ###

import sys
import numpy as np
from collections import Counter
input = sys.stdin.readline
n=int(input())
a = tuple(map(int,input().split()))

c = 0
n = 10**8
for i in range(n):
  c += 1
print(c)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int,input().split()))
c1 = a.count(1)
c2 = a.count(2)
c3 = a.count(3)

dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)] 
dp[0][0][0] = 0
for i in range(c3+1):
    for j in range(c2+c3-i+1):
        for k in range(n-i-j+1):
            if i == j == k == 0:
                continue
            tmp = n
            if k != 0:
                tmp += k*dp[k-1][j][i]
            if j != 0:
                tmp += j*dp[k+1][j-1][i]
            if i != 0:
                tmp += i*dp[k][j+1][i-1]
            dp[k][j][i] = tmp/(i+j+k)

print(dp[c1][c2][c3])
### BUGGY CODE ###

n, d, a = map(int, input().split())
monster = []
for _ in range(n):
  x, h = map(int, input().split())
  monster.append([x, h])
monster.sort()
bomb = 0
j = 0
for i in range(n):
  while j < n and monster[j][0] - monster[i][0] <= 2 * d:
    j += 1
  if monster[i][1] <= 0:
    continue
  b = (monster[i][1] - 1) // a + 1
  atk = a * b
  bomb += b
  for k in range(i+1, j):
    monster[k][1] -= atk
print(bomb)

### FIXED CODE ###

import heapq
from collections import deque

n, d, a = map(int, input().split())
monster = []
for _ in range(n):
  x, h = map(int, input().split())
  heapq.heappush(monster, (x, h))
bomb = 0
damage = 0
queue = deque()
while monster:
  x, h = heapq.heappop(monster)
  while True:
    if queue and x > queue[0][0]:
      damage -= queue.popleft()[1]
    else:
      break
  h -= damage
  if h <= 0:
    continue
  b = (h - 1) // a + 1
  bomb += b
  queue.append((x + 2 * d, a * b))
  damage += a * b
print(bomb)
### BUGGY CODE ###

n=int(input())

if n%2==0:
    print(-1)
    exit()

memo = '7'

ans = 1

while int(memo)%n != 0:
    memo = memo + '7'
    ans += 1
    #print(memo)
print(ans)

### FIXED CODE ###

n=int(input())

x = 0

for i in range(n+1):
    x = x*10+7
    x %= n
    if x == 0:
        print(i+1)
        exit()
    #print(x)
print(-1)
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch-=1; cw-=1; dh-=1; dw-=1
area = [list(input()) for _ in range(h)]
dist = [[-1]*w for i in range(h)]

dk = [(i, j, 0) for i in range(-2, 3) for j in range(-2, 3)]
d = []
for i, j, c in dk:
    if (i, j) in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
        c = 0
    else:
        c = 1
    d.append((c, i, j))

def Dijkstra(ch, cw):
    """
    Dijkstra法を用いて単一始点終点の最短コストを算出する
    0オリジンとする。
    es: 辺を表す配列。
        es[start]: [cost, en]
    n: 頂点数
    source: 始点
    return: dist　最短距離距離配列。
    """
    import heapq
    used = [[False] * w for i in range(h)] # Falseならば計算対象
    edgelist = []
    # 始点の辺を追加
    for e in d:
        c, y, x = e
        if 0<=ch+y<h and 0<=cw+x<w:
            if used[ch+y][cw+x]: continue
            if area[ch+y][cw+x]=='#': continue
            heapq.heappush(edgelist, (c, ch+y, cw+x))
    used[ch][cw] = True
    dist[ch][cw] = 0
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        cost, y, x = minedge
        if used[y][x]:
            continue
        dist[y][x] = cost
        used[y][x] = True
        for e in d:
            next_cost, next_y, next_x = e
            if 0<=y+next_y<h and 0<=x+next_x<w:
                if used[y+next_y][x+next_x]: continue
                if area[y+next_y][x+next_x]=='#': continue
                heapq.heappush(edgelist, (dist[y][x]+next_cost, y+next_y, x+next_x))
    return dist

dist = Dijkstra(ch, cw)
print(dist[dh][dw])

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch-=1; cw-=1; dh-=1; dw-=1
area = [list(input()) for _ in range(h)]
inf = 10**100
dist = [[inf]*w for i in range(h)]

dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)]

def Dijkstra(ch, cw):
    import heapq
    edgelist = [(0, ch, cw)]
    heapq.heapify(edgelist)
    dist[ch][cw] = 0
    while len(edgelist):
        cost, y, x = heapq.heappop(edgelist)
        if y==dh and x==dw:
            return dist
        if dist[y][x] < cost: continue
        for next_y, next_x in dwalk:
            if 0<=y+next_y<h and 0<=x+next_x<w:
                if area[y+next_y][x+next_x]=='#': continue
                if dist[y+next_y][x+next_x]>cost:
                    dist[y+next_y][x+next_x] = cost
                    heapq.heappush(edgelist, (cost, y+next_y, x+next_x))
        for next_y in range(-2, 3):
            for next_x in range(-2, 3):
                    if 0<=y+next_y<h and 0<=x+next_x<w:
                        if area[y+next_y][x+next_x]=='#': continue
                        if dist[y+next_y][x+next_x]>cost+1:
                            dist[y+next_y][x+next_x] = cost+1
                            heapq.heappush(edgelist, (cost+1, y+next_y, x+next_x))
    return dist

dist = Dijkstra(ch, cw)
if dist[dh][dw] == inf:
    print(-1)
else:
    print(dist[dh][dw])
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
P_E = list(((1 + P[i]) / 2) for i in range(N))

E = 0
max = 0
for i in range(N - K + 1):
    work = sum(P_E[i:i+K])
    if work > max:
        max = work

print(max)

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
P_E = list(((1 + P[i]) / 2) for i in range(N))

E = 0
prog = sum(P_E[0:K])
max = prog
for i in range(N - K):
    prog += P_E[i + K] - P_E[i]
    if prog > max:
        max = prog
    else:
        pass
    
print(max)
### BUGGY CODE ###

H, W = map(int, input().split())
s = ['0' * (W+2)]
for _ in range(H):
    s.append('0' + input() + '0')
s.append('0' * (W+2))

ans = []
if s[1][1] == '#': a, b = 1, 1
else: a, b = 0, 0
temp = [[1, 1, a, b]]

while temp:
    p = temp.pop()
    if p[0] == H and p[1] == W:
        ans.append(p[3])
    for y, x in [[p[0]+1, p[1]], [p[0], p[1]+1]]:
        c = p[2]
        d = p[3]
        if s[y][x] == '0':continue
        if s[y][x] == '#':
            if c == 0:
                d += 1
                c = 1
        else:
            c = 0
        temp.append([y, x, c, d])
             
print(min(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
s = [input().rstrip() for _ in range(H)]

dp = [[1000]*W for _ in range(H)]

if s[0][0] == '#': dp[0][0] = 1
else: dp[0][0] = 0

for j in range(W):
    for i in range(H):
        if i <= H - 2:

            if s[i][j] == '.' and s[i+1][j] == '#':
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
            else: dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if j <= W - 2:

            if s[i][j] == '.' and s[i][j+1] == '#':
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
            else: dp[i][j+1] = min(dp[i][j+1], dp[i][j])


print(dp[H-1][W-1])
### BUGGY CODE ###

H,W,M = list(map(int,input().split()))

h = [0] * H
w = [0] * W

hw = []

for _ in range(M):
    a,b = list(map(int,input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    hw.append([a,b])

hp = [i for i, v in enumerate(h) if v == max(h)]
wp = [i for i, v in enumerate(w) if v == max(w)]

for x in hp:
    for y in wp:
        if [x+1,y+1] in hw:
            pass
        else:
            print(max(h) + max(w))
            exit()
else:
    print(max(h) + max(w) - 1)


### FIXED CODE ###


H, W, M = list(map(int, input().split()))

h = [0] * H
w = [0] * W

hw = {}

for _ in range(M):
    a, b = list(map(int, input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    temp = "x" + str(a - 1) + "y" + str(b - 1)
    hw[temp] = 1

hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        temp = "x" + str(x) + "y" + str(y)
        if temp not in hw:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)
### BUGGY CODE ###

#!/usr/bin/env python3

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def main():
    A, B = map(int, input().split())
    cf = []
    if A % 2 == 0 and B % 2 == 0:
        cf.append(2)
    cf.extend(i for i in range(3, int(min(A, B)), 2) if A % i == 0 and B % i == 0)
    a = []
    for i in cf:
        for j in a:
            if gcd(i, j) != 1:
                break
        else:
            a.append(i)
    print(len(a) + 1)




if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3

import math
def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

def fact(n):
    r = [1]
    if n % 2 == 0:
        r.append(2)
        while n % 2 == 0:
            n //= 2
    i = 3
    k = int(math.sqrt(n))
    while i <= k:
        if n % i == 0:
            r.append(i)
            while n % i == 0:
                n //= i
            k = int(math.sqrt(n))
        i += 2
    if n > 1:
        r.append(n)
    return r

def main():
    A, B = map(int, input().split())
    t = gcd(A, B)
    print(len(fact(t)))


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

n=int(input())
a=list(map(int, input().split()))
a.sort()
ans=0
L=[]
for i in range(n-1):
    if a[i]==a[i+1]:
        L.append(a[i])
    else:
        for j in L:
            if a[i]%j==0:
                break
        else:
            L.append(a[i])
            ans+=1
for i in L:
    if a[-1]%i==0:
        break
else:
    ans+=1
print(ans)


### FIXED CODE ###

from collections import Counter

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

m=a[-1]+1
dp=[True]*m
c=Counter(a)
ans=0
for x in a:
    if dp[x] and c[x]==1:
        ans+=1
    
    for j in range(2*x, m, x):
        dp[j]=False

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

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


### FIXED CODE ###

from collections import defaultdict
d = defaultdict(int)

n = int(input())
s = input()
r=[]
g=[]
b=[]
for i in range(n):
  #print(s[i])
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    #b.append(i)
    d[i] = 1

#print(r)
#print(g)
#print(b)
sum = len(r)*len(g)*len(d)
for i in r:
  for j in g:
    ma = max(i,j)
    mi = min(i,j)
    df = ma - mi
    k1 = mi - df
    k2 = ma + df
    k3 = (ma + mi) / 2
    sum -= d[k1]
    sum -= d[k2]
    sum -= d[k3]
print(sum)
### BUGGY CODE ###

from fractions import gcd
from functools import reduce
import itertools

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

cd = []
for i in range(1,gcd(a,b)+1):
    if a%i==0 and b%i==0:
        cd.append(i)

for i in range(len(cd)):
    for comb in itertools.combinations(cd,len(cd)-i):
        for pair in itertools.combinations(comb,2):
            if gcd(pair[0],pair[1])!=1:
                break
        else:
            print(len(comb))
            exit()


### FIXED CODE ###

from fractions import gcd

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

gcd=gcd(a,b)
ab_gcd=gcd

f=[]
for i in range(2,int(ab_gcd**0.5)+1):
    while gcd%i==0:
        gcd=gcd//i
        f.append(i)
if gcd!=1:
    f.append(gcd)

print(len(set(f))+1)
### BUGGY CODE ###

K,S=map(int,input().split())
ans=0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k==S:
        ans+=1
print(ans)

### FIXED CODE ###

K,S=map(int,input().split())
cnt=0

for i in range(K+1):
  for j in range(K+1):
    k=S-(i+j)
    if (k>=0) and (k<=K):
      cnt+=1
print(cnt)
### BUGGY CODE ###

from collections import defaultdict

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

MOD = 10 ** 9 + 7

# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      arr.append([i, cnt])
  if temp != 1:
    arr.append([temp, 1])
  if arr == []:
    arr.append([n, 1])
  return arr

counter = defaultdict(int)
p_list = []
for a in A:
  for p, r in factorization(a):
    if counter[p] == 0:
      p_list.append(p)
    counter[p] = max(counter[p], r)
lcm = 1
  
answer = 0
for a in A:
  counter_a = defaultdict(int)
  for p, r in factorization(a):
    counter_a[p] += r
  tmp = 1
  for p in p_list:
     tmp = (tmp * pow(p, (counter[p] - counter_a[p]), MOD)) % MOD
  answer = (answer + tmp) % MOD

print(answer)

### FIXED CODE ###

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

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)
### BUGGY CODE ###

#区間の管理は　[a, b)で管理していることに注意

# INT_MIN = -10 ** 18
MAX_N = 10 ** 6
# MAX_N = 20


def init(n_):
    #簡単にするために2のべき乗に揃える
    n = 1
    while n < n_:
        n *= 2
    return n

#初期化
N = int(input())
n = init(N) + 1
data = [0] * (2 * MAX_N - 1)

def update(k, a):
    k += n - 1
    data[k] = a
    while k > 0:
        k = (k - 1) // 2
        data[k] = max(data[2 * k + 1], data[2 * k + 2])

def query(a, b, k = 0, l = 0, r = n):
    if r <= a or b <= l:
        return 0
    if a <= l and r <= b:
        return data[k]
    else:
        v1 = query(a, b, 2 * k + 1, l, (l + r)//2)
        v2 = query(a, b, 2 * k + 2, (l + r)//2, r)
        return max(v1, v2)

def initialize(A): #リストAを与えて初期化する
    for i, a in enumerate(A):
        data[i + n - 1] = a
    for i in range(N + n - 1, 0, -2):
        tmp = i
        tmp = (tmp - 1) //2
        data[tmp] = max(data[tmp * 2 + 1], data[tmp * 2 + 2])

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

ans = 0
for i in range(N):
    # h = int(input())
    # a = int(input())
    h = H[i]
    a = A[i]
    tmp = query(1, h + 1) #[1, h)での最大値
    # print (h, tmp)
    update(h, tmp + a)
    ans = max(ans, tmp + a)
    # print (data)

print (ans)

# print (update(1, 1))
# print (update(2, 5))
# print (query(1, 2))



### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    #区間の管理は　[a, b)で管理していることに注意

    # INT_MIN = -10 ** 18
    # MAX_N = 4 * 10 ** 5
    # MAX_N = 20


    # def init(n_):
    #     #簡単にするために2のべき乗に揃える
    #     n = 1
    #     while n <= n_:
    #         n *= 2
    #     return n

    #初期化
    N = int(input())
    # n = 1
    # while n <= N:
    #     n *= 2

    n = 262144
    data = [0] * (2 * n - 1)

    def update(k, a):
        k = k + n - 1
        # data[k] = a
        while k >= 0:
            data[k] = max(a, data[k])
            k = (k - 1) // 2
            # data[k] = max(data[2 * k + 1], data[2 * k + 2])

    def query(a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return data[k]
        else:
            return max(query(a, b, 2 * k + 1, l, (l + r)//2), query(a, b, 2 * k + 2, (l + r)//2, r))

    H = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))

    # ans = 0

    dp = [A[0]] + [0] * (N - 1)
    update(H[0] - 1, A[0])
    for i in range(1, N):
        # h = int(input())
        # a = int(input())
        dp[i] = query(0, H[i] - 1, 0, 0, n) + A[i]
        # h = H[i]
        # a = A[i]
        # tmp = query(1, h + 1) #[1, h)での最大値
        # print (h, tmp)
        update(H[i] - 1, dp[i])
        # ans = max(ans, tmp + a)
        # print (data)

    print (query(0, N, 0, 0, n))

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

# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))
 
N = int(input())
A = inpl()
 
print(min([abs(sum(A[:i])-sum(A[i:])) for i in range(1, N)]))

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)
### BUGGY CODE ###

N = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()), start=1)]
A.sort(reverse=True)

dp = [[0] * (N + 1) for _ in range(N + 1)]

for s, (a, i) in enumerate(A):
    for l in range(s + 1):
        r = s - l
        dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (i - (l + 1)))
        dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * (N - r - i))

ans = max([max(d) for d in dp])
print(ans)


### FIXED CODE ###

N = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()), start=1)]
A.sort(reverse=True)

dp = [[0] * (N + 1) for _ in range(N + 1)]

for s, (a, i) in enumerate(A):
    for l in range(s + 1):
        r = s - l
        dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a * (i - (l + 1)))
        dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + a * (N - r - i))

ans = max([max(d) for d in dp])
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


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

GRAPH = {i:[] for i in range(1, n + 1)}
for _ in range(m):
    a, b = map(int, input().split())
    GRAPH[a].append(b)
    GRAPH[b].append(a)

DISTANCE = {i:-1 for i in range(1, n + 1)}
DISTANCE[1] = 0
QUEUE = [1]
while QUEUE:
    now = QUEUE.pop(0)
    for v in GRAPH[now]:
        if DISTANCE[v] != -1:
            continue
        DISTANCE[v] = DISTANCE[now] + 1
        QUEUE.append(v)

print("POSSIBLE" if DISTANCE[n] == 2 else "IMPOSSIBLE")


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque


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

GRAPH = {i:[] for i in range(1, n + 1)}
for _ in range(m):
    a, b = map(int, input().split())
    GRAPH[a].append(b)
    GRAPH[b].append(a)

DISTANCE = {i:-1 for i in range(1, n + 1)}
DISTANCE[1] = 0
QUEUE = deque([1])
while QUEUE:
    now = QUEUE.popleft()
    for v in GRAPH[now]:
        if DISTANCE[v] != -1:
            continue
        DISTANCE[v] = DISTANCE[now] + 1
        QUEUE.append(v)

print("POSSIBLE" if DISTANCE[n] == 2 else "IMPOSSIBLE")
### BUGGY CODE ###

import sys
import itertools
from math import factorial

input = sys.stdin.readline

def func(l, r):
    num_list = tuple([num for num in range(l, r+1)])
    mod = 0
    mod_min = 2019
    for i, j in itertools.combinations(num_list, 2):
        mod = (i*j % 2019)
        if mod < mod_min:
            mod_min = mod
    print(mod_min)


def main():
    l, r = [int(i) for i in input().split()] 
    func(l, r)
    
# main関数呼び出し
if __name__ == "__main__":
    main() 

### FIXED CODE ###

import sys
import itertools

input = sys.stdin.readline

def func(l, r):
    mod_min = float('inf')

    for i in range(l, r):
        for j in range(i+1, r+1):
            mod = (i*j % 2019)

            if mod == 0:
                print(mod)
                exit()     

            elif mod < mod_min:
                mod_min = mod

    print(mod_min)

def main():
    l, r = [int(i) for i in input().split()] 
    func(l, r)
    
# main関数呼び出し
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import heapq
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def make_divisors(n):
    divisors = set()
    i = 1
    while i*i <= n:
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
        i += 1
    return divisors


def main():
    N = int(input().strip())
    divisors = set()
    ans = set()
    l = [int(i) for i in input().strip().split()]
    heapq.heapify(l)

    for _ in range(N):
        n = heapq.heappop(l)

        if n in divisors:
            if n in ans:
                ans.remove(n)
            continue

        divs = make_divisors(n)

        for d in divs:
            if d in divisors:
                divisors.add(n)
                break
        else:
            divisors.add(n)
            ans.add(n)

    return len(ans)


if __name__ == "__main__":
    print(main())

### FIXED CODE ###

import heapq
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    l = [int(i) for i in input().strip().split()]
    ans = 0
    m = max(l)
    dp = [0] * (m+1)

    for n in l:
        for j in range(n, m + 1, n):
            dp[j] += 1

    for n in l:
        if dp[n] == 1:
            ans += 1

    return ans


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

def knapsack(N, C, weights, values):
    dp = [[0 for _ in range(N + 1)] for _ in range(C + 1)]
    for i in range(1, C + 1):
        for j in range(1, N + 1):
            if weights[j - 1] <= i:
                dp[i][j] = max(dp[i][j - 1], values[j - 1] + dp[i - weights[j - 1]][j - 1])
            else:
                dp[i][j] = dp[i][j - 1]
    return dp[C][N]


if __name__ == '__main__':
    n, c = list(map(int, input().split()))
    weights = [0] * n
    values = [0] * n
    for i in range(n):
        weights[i], values[i] = map(int, input().split())
    print(knapsack(n, c, weights, values))


### FIXED CODE ###

def knapsack(N, C, weights, values):
    dp = [[0 for _ in range(N + 1)] for _ in range(C + 1)]
    for i in range(1, C + 1):
        for j in range(1, N + 1):
            if weights[j - 1] <= i:
                dp[i][j] = max(dp[i][j - 1], values[j - 1] + dp[i - weights[j - 1]][j - 1])
            else:
                dp[i][j] = dp[i][j - 1]
    return dp[C][N]
 
 
if __name__ == '__main__':
    n, c = list(map(int, input().split()))
    weights = [0] * n
    values = [0] * n
    for i in range(n):
        weights[i], values[i] = map(int, input().split())
    print(knapsack(n, c, weights, values))