AtCoder Beginner Contest 133 - Remainder Minimization 2019

You are given two non-negative integers L and R.
We will choose two integers i and j such that L \leq i < j \leq R.
Find the minimum possible value of (i \times j) \mbox{ mod } 2019.

-----Constraints-----
 - All values in input are integers.
 - 0 \leq L < R \leq 2 \times 10^9

-----Input-----
Input is given from Standard Input in the following format:
L R

-----Output-----
Print the minimum possible value of (i \times j) \mbox{ mod } 2019 when i and j are chosen under the given condition.

-----Sample Input-----
2020 2040

-----Sample Output-----
2

When (i, j) = (2020, 2021), (i \times j) \mbox{ mod } 2019  = 2.

Difficulty: EASY

Starter code:

Solutions:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

def main():
	(l, r) = list(map(int, input().split()))
	diff = r - l
	if diff >= 2018:
		return 0
	else:
		min_ = 2 ** 20
		p = l // 2019
		q = l % 2019
		for xi in range(l, r):
			qi = (q + (xi - l)) % 2019
			if qi == 0:
				return 0
			for xj in range(xi + 1, r + 1):
				qj = (q + (xj - l)) % 2019
				if qj == 0:
					return 0
				else:
					qij = qi * qj % 2019
					if qij < min_:
						min_ = qij
	return min_
print(main())


(l, r) = map(int, input().split())
mod = 2019
ans = 2222
if (r - l) // mod > 0:
	ans = 0
else:
	ans = 2020
	for i in range(l, r + 1):
		for j in range(i + 1, r + 1):
			ans = min(ans, i % mod * (j % mod) % mod)
print(ans)


(l, r) = map(int, input().split())
s = range(l, min(r + 1, l + 2019))
print(min((i * j % 2019 for i in s for j in s if i < j)))


(l, r) = map(int, input().split())
ans = 2019
cnt = min(l + 2019, r)
for i in range(l, cnt):
	for j in range(i + 1, cnt + 1):
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
d = range(l, r + 1)
print(0 if r - l > 671 else min((i * j % 2019 for i in d for j in d if i < j)))


(L, R) = map(int, input().split())
ans = 2019
for i in range(L, L + 2020 - 1):
	for j in range(i + 1, i + 2020):
		if j > R:
			break
		ans = min(i * j % 2019, ans)
print(ans)


import math
(L, R) = map(int, input().split())
m = 2018
for i in range(L, min(L + 2018, R) + 1):
	for j in range(i + 1, min(i + 2019, R) + 1):
		m = min(m, i * j % 2019)
print(m)


(L, R) = map(int, input().split())
R = min(R, L + 2019)
print(min([i * j % 2019 for i in range(L, R + 1) for j in range(i + 1, R + 1)]))


(L, R) = map(int, input().split())
A = []
for i in range(min(R - L, 2020)):
	for j in range(i + 1, min(R - L + 1, 2021)):
		A.append((i + L) * (j + L) % 2019)
print(min(A))


(L, R) = map(int, input().split())
if R - L >= 673:
	print(0)
else:
	ans = 2019
	for i in range(L, R):
		for j in range(i + 1, R + 1):
			ans = min(ans, i * j % 2019)
	print(ans)


(L, R) = list(map(int, input().split()))
ans = 2020
if R - L >= 4037:
	print(0)
else:
	for i in range(L, R):
		for j in range(i + 1, R + 1):
			temp = i % 2019 * (j % 2019) % 2019
			if ans > temp:
				ans = temp
	print(ans)


(L, R) = map(int, input().split())
ans = float('inf')
for i in range(L, min(L + 2019, R + 1)):
	for j in range(i + 1, min(L + 2019, R + 1)):
		ans = min(ans, i * j % 2019)
print(ans)


(L, R) = map(int, input().split(' '))
rst = float('inf')
if R > L + 2019 * 2:
	R = R % 2019 + 2019
else:
	R %= 2019
L %= 2019
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		rst = min(rst, i * j % 2019)
print(rst)


(l, r) = map(int, input().split())
r = min(r, l + 673)
ans = 2018
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		x = i * j % 2019
		ans = min(ans, x)
print(ans)


(l, r) = map(int, input().split())
l_mod = l % 2019
r_mod = r % 2019
if l + 2019 <= r:
	print(0)
	return
m = 3000
for i in range(l_mod, r_mod + 1):
	for j in range(i + 1, r_mod + 1):
		m = min(m, i * j % 2019)
print(m)


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
input = sys.stdin.readline

def RD():
	return input().rstrip()

def F():
	return float(input().rstrip())

def I():
	return int(input().rstrip())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def LI():
	return list(map(int, input().split()))

def TI():
	return tuple(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def Init(H, W, num):
	return [[num for i in range(W)] for j in range(H)]

def main():
	S = set()
	(L, R) = MI()
	mod = 2019
	if R // mod > (L - 1) // mod:
		print(0)
		return
	l = [i % mod for i in range(L, R + 1)]
	ans = float('inf')
	N = len(l)
	for index in range(N):
		for index2 in range(index + 1, N):
			ans = min(ans, l[index] * l[index2] % mod)
	print(ans)

def __starting_point():
	main()
__starting_point()


(L, R) = map(int, input().split())
P = min(R, L + 2018)
c = []
for i in range(L, P + 1):
	for j in range(L, P + 1):
		if i != j:
			c.append(i * j % 2019)
print(min(c))


mod = 2019
(l, r) = map(int, input().split())
m = min(r, l + mod)
MN = []
for i in range(l, m):
	for j in range(i + 1, m + 1):
		MN.append(i * j % mod)
print(min(MN))


(l, r) = list(map(int, input().split()))
t = []
if r - l >= 2019:
	print(0)
	return
elif r - l < 2019:
	if 2019 <= l:
		for i in range(l, r):
			for j in range(i + 1, r + 1):
				ii = i % 2019
				jj = j % 2019
				s = ii * jj % 2019
				t.append(s)
		ans = min(t)
		print(ans)
	elif l < 2019 < r:
		for i in range(l, r):
			for j in range(i + 1, r + 1):
				ii = i % 2019
				jj = j % 2019
				s = ii * jj % 2019
				t.append(s)
		ans = min(t)
		print(ans)
	elif r <= 2019:
		for i in range(l, r):
			for j in range(i + 1, r + 1):
				s = i * j % 2019
				t.append(s)
		ans = min(t)
		print(ans)


(L, R) = map(int, input().split())
mod = 2019
if R - L >= mod:
	x = list(range(mod))
else:
	x = list(range(L, R + 1))
print(min((i * j % mod for j in x for i in x if j != i)))


(L, R) = map(int, input().split())
if R - L >= 2018:
	print(0)
else:
	m = 2019
	for i in range(L, R):
		for j in range(i + 1, R + 1):
			m = min(m, i * j % 2019)
	print(m)


def main():
	(L, R) = [int(i) for i in input().split()]
	if L // 2019 < R // 2019:
		ans = 0
	else:
		ans = 10 ** 10
		for l in range(L, R + 1):
			for r in range(l + 1, R + 1):
				ans = min(ans, l * r % 2019)
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
(l, r) = map(int, input().split())
if r - l > 2100:
	print(0)
	return
ans = 9999
for i in range(l, r):
	for j in range(i + 1, r + 1):
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = [int(x) for x in input().split()]
L = l % 2019
a = 2020
for i in range(1, 2020):
	if l + i <= r:
		for j in range(i):
			a = min((L + j) * (L + i) % 2019, a)
print(a)


(l, r) = map(int, input().split())
a = 0
if r - l < 2019:
	a = min([i * j % 2019 for i in range(l, r + 1) for j in range(i + 1, r + 1)])
print(a)


M = 2019
(L, R) = map(int, input().split())
(l, r) = (L % M, R % M)
s = range(l, r + 1)
print(0 if R // M - L // M > 0 else min((i * j % M for i in s for j in s if i < j)))


(l, r) = map(int, input().split())
if r - l >= 2019:
	print(0)
	exit()
ans = 10 ** 9
for i in range(l, r):
	for j in range(i + 1, r + 1):
		ans = min(ans, i * j % 2019)
print(ans)


temp = input().split()
L = int(temp[0])
R = int(temp[1])
if R - L >= 2019:
	print(0)
else:
	print(min([i * j % 2019 for i in range(L, R) for j in range(i + 1, R + 1)]))


(L, R) = map(int, input().split())
MOD = 2019
ans = 2020 ** 2
if R - L >= 2020:
	print(0)
else:
	for i in range(L, R):
		for j in range(i + 1, R + 1):
			ans = min(ans, i % MOD * j % MOD)
	print(ans)


(l, r) = map(int, input().split())
m = 2019
for i in range(l, min(r + 1, l + 2020)):
	for j in range(i + 1, min(r + 1, l + 2020)):
		i %= 2019
		j %= 2019
		m = min(m, i * j % 2019)
print(m % 2019)


(l, r) = map(int, input().split())
ans = 2020
for i in range(l, r):
	for j in range(i + 1, r + 1):
		if i * j % 2019 == 0:
			print(0)
			return
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
r = min(r, l + 2019)
c = [4 * 10 ** 18]
for i in range(l, r):
	for j in range(i + 1, r + 1):
		c.append(i * j % 2019)
print(min(c))


(L, R) = map(int, input().split())
(left, right) = (L % 2019, R % 2019)
print(0 if R - L >= 2019 else min((i * j % 2019 for i in range(left, right + 1) for j in range(i + 1, right + 1))))


(l, r) = (int(i) for i in input().split())
a = []
for i in range(l, min(r, l + 2019)):
	for j in range(i + 1, min(r, l + 2019) + 1):
		a.append(i * j % 2019)
print(min(a))


import itertools
(L, R) = list(map(int, input().split()))
if R - L + 1 >= 2019:
	ans = 0
else:
	LL = L % 2019
	RR = R % 2019
	if LL < RR:
		Amari_List = list(range(LL, RR + 1))
		ans = 2019
		for (v1, v2) in itertools.combinations(Amari_List, 2):
			ca = v1 * v2 % 2019
			if ca < ans:
				ans = ca
	else:
		ans = 0
print(ans)


(l, r) = map(int, input().split())
a = min(r + 1, l + 2019)
b = 2019
for i in range(l, a):
	for j in range(l, a):
		if i == j:
			continue
		else:
			b = min(b, i * j % 2019)
print(b)


(l, r) = list(map(int, input().split()))
if (r - l) // 2019 >= 1:
	print(0)
else:
	ans = float('inf')
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			if i != j:
				ans = min(ans, i * j % 2019)
	print(ans)


(L, R) = [int(i) for i in input().split()]
c = set()
for i in range(L, R + 1):
	t = i % 2019
	if t in c:
		break
	c.add(t)
m = float('inf')
l = list(c)
for i in range(len(l)):
	for j in range(i + 1, len(l)):
		m = min(m, l[i] * l[j] % 2019)
print(m)


import os
import sys

def main():
	(L, R) = list(map(int, input().split()))
	cool = R // 2019 - L // 2019
	if cool == 0:
		ans = 2020
		for l in range(L, R + 1):
			for r in range(l + 1, R + 1):
				if ans > l * r % 2019:
					ans = l * r % 2019
		print(ans)
	else:
		print(0)

def __starting_point():
	main()
__starting_point()


INT = lambda : int(input())
INTM = lambda : map(int, input().split())
STRM = lambda : map(str, input().split())
STR = lambda : str(input())
LIST = lambda : list(map(int, input().split()))
LISTS = lambda : list(map(str, input().split()))

def do():
	(l, r) = INTM()
	mods = []
	for i in range(l, min(l + 3000, r + 1)):
		mods.append(i % 2019)
	ans = 2018
	ml = len(mods)
	for i in range(ml - 1):
		for j in range(i + 1, ml):
			ans = min(ans, mods[i] * mods[j] % 2019)
	print(ans)

def __starting_point():
	do()
__starting_point()


(L, R) = map(int, input().split())
ans = 4 * 10 ** 18
if R - L >= 2019:
	print(0)
else:
	for i in range(L, R):
		for j in range(L + 1, R + 1):
			ans = min(ans, i * j % 2019)
	print(ans)


(l, r) = list(map(int, input().split()))
if r - l >= 2019:
	ans = 0
else:
	ans = 2019 ** 2
	for i in range(l, r + 1):
		for j in range(i + 1, r + 1):
			tmp = i * j % 2019
			ans = min(ans, tmp)
print(ans)


(l, r) = map(int, input().split())
ans = 2018
if r - l >= 2019:
	print('0')
else:
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			temp = i * j % 2019
			ans = min(ans, temp)
	print(ans)


(L, R) = map(int, input().split())
A = []
if R - L > 2019:
	print(0)
elif 2 <= R - L and R - L <= 2019:
	for i in range(L, R):
		for j in range(i + 1, R + 1):
			A.append(i * j % 2019)
	print(min(A))
elif R - L == 1:
	print(R * L % 2019)


(L, R) = list(map(int, input().split()))
ans = 2019
for l in range(L, L + 2019):
	for r in range(l + 1, min(R + 1, L + 2020)):
		ans = min(ans, l * r % 2019)
print(ans)


(L, R) = map(int, input().split())
R = min(R, L + 2019)
ans = 2018
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		x = i * j % 2019
		ans = min(ans, x)
print(ans)


(L, R) = map(int, input().split())
mod = 2019
ans = 10 ** 18 + 7
for i in range(L, min(R, L + mod)):
	for j in range(L + 1, min(R + 1, L + mod + 1)):
		tempans = i % mod * (j % mod)
		tempans %= mod
		if tempans < ans:
			ans = tempans
print(ans)


import itertools
(l, r) = map(int, input().split())
if r - l >= 2019:
	print(0)
	return
w = []
q = list(itertools.combinations(range(l, r + 1), 2))
for i in range(len(q)):
	w.append(q[i][0] * q[i][1] % 2019)
print(min(w))


(l, r) = map(int, input().split())
ans = 10 ** 15
for i in range(l, min(r, l + 2100)):
	for j in range(i + 1, min(r + 1, l + 2100)):
		ans = min(ans, i * j % 2019)
print(ans)


(L, R) = map(int, input().split())
res = 0
if R - L < 2019:
	res = min([i % 2019 * j % 2019 for i in range(L, R + 1) for j in range(i + 1, R + 1)])
print(res % 2019)


(l, r) = map(int, input().split())
r += 1
if r >= l + 2019:
	r = l + 2019
ans = 10000000
for i in range(l, r):
	for j in range(l, i):
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
mini = 2019
for i in range(l, min(r - 1, l + 2018) + 1):
	for j in range(max(l + 1, r - 2018), r + 1):
		mini = min(mini, i * j % 2019)
print(mini)


(l, r) = (int(_) for _ in input().split())
r = min(r, l + 2019)
x = [i * ii % 2019 for i in range(l, r + 1) for ii in range(i + 1, r + 1)]
print(min(x))


(l, r) = map(int, input().split())
x = 2018
if r - l >= 2019:
	x = 0
else:
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			if i * j % 2019 < x:
				x = i * j % 2019
print(x)


(L, R) = list(map(int, input().split()))
if R - L >= 2019:
	print(0)
else:
	l = [i * j % 2019 for i in range(L, R + 1) for j in range(i + 1, R + 1)]
	print(min(l))


from itertools import *
(a, b) = map(int, input().split())
if b - a >= 2019:
	print(0)
else:
	print(min((s * t % 2019 for (s, t) in combinations(range(a, b + 1), 2))))


(L, R) = map(int, input().split())
val = 2019
for l in range(L, min(R, L + 2019)):
	for r in range(l + 1, min(R + 1, l + 1 + 2019)):
		val = min(l * r % 2019, val)
print(val)


(L, R) = list(map(int, input().split()))
ans = 2018
for i in range(L, R):
	for j in range(i + 1, R + 1):
		a = i * j % 2019
		if a < ans:
			ans = a
		if ans == 0:
			break
	else:
		continue
	break
print(ans)


(l, r) = list(map(int, input().split()))
m = 2018
for i in range(l, min(r + 1, l + 2019)):
	for j in range(i + 1, min(r + 1, l + 2019)):
		m = min(m, i * j % 2019)
print(m)


(l, r) = map(int, input().split())
m = 2018 * 2019
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		m = min(m, i * j % 2019)
		if m == 0:
			print(m)
			exit()
print(m)


(L, R) = map(int, input().split())
if R - L >= 2018:
	print(0)
else:
	print(min((min((l * r % 2019 for r in range(l + 1, R + 1))) for l in range(L, R))))


import itertools
(L, R) = map(int, input().split())
for i in range(2 * 10 ** 9 // 2019 + 1):
	if L <= i * 2019 and i * 2019 <= R:
		print(0)
		return
ans = 2020
for h in range(L, R + 1):
	for g in range(h + 1, R + 1):
		ans = min(ans, h * g % 2019)
print(ans)


(l, r) = map(int, input().split())
ans = 2018 ** 2
for i in range(l, min(r, l + 2019)):
	v = i % 2019
	for j in range(l + 1, min(r + 1, l + 2020)):
		w = j % 2019
		ans = min(ans, v * w % 2019)
print(ans)


(x, y) = list(map(int, input().split()))
if y > x + 2020:
	y = x + 2020
ans = 2019
for i in range(x, y + 1):
	for j in range(i + 1, y + 1):
		if i * j % 2019 < ans:
			ans = i * j % 2019
print(ans)


from itertools import combinations as f
(l, r) = map(int, input().split())
s = set(map(lambda x: x % 2019, range(l, r + 1)[:2019]))
print(min([i * j % 2019 for (i, j) in f(s, 2)]))


(L, R) = map(int, open(0).read().split())
ans = 2020
m = min(L + 2020, R) + 1
for i in range(L, m):
	for j in range(i + 1, m):
		ans = min(ans, i * j % 2019)
print(ans)


(L, R) = map(int, input().split())
m = 10 ** 4
a = min(R, L + 2019)
for i in range(L, a):
	for j in range(i + 1, a + 1):
		m = min(i * j % 2019, m)
print(m)


(L, R) = list(map(int, input().split()))
l = L % 2019
r = R % 2019
if R - L >= 2019:
	ans = 0
elif l < r:
	min = 100000000
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			tmp = i * j % 2019
			if tmp < min:
				min = tmp
	ans = min
else:
	min = 100000000
	for i in range(l, r + 2019):
		for j in range(i + 1, r + 2019 + 1):
			tmp = i * j % 2019
			if tmp < min:
				min = tmp
	ans = min
print(ans)


(L, R) = map(int, input().split())
if R - L > 2017:
	print(0)
	quit()
ans = 2018
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
li = []
r = min(r, l + 4040)
for i in range(l, r):
	for j in range(i + 1, r + 1):
		li.append(i * j % 2019)
print(min(li))


[L, R] = [int(i) for i in input().split()]
ans = 2018
if R - L >= 2018:
	ans = 0
else:
	l = L % 2019
	r = R % 2019
	if r < l:
		ans = 0
	else:
		for i in range(l, r):
			for j in range(i + 1, r + 1):
				if i * j % 2019 < ans:
					ans = i * j % 2019
print(ans)


(l, r) = list(map(int, input().split()))
MOD = 2019
ans = MOD
if r - l + 1 >= MOD:
	kouho = list(range(MOD))
else:
	kouho = [i % MOD for i in list(range(l, r + 1))]
for i in range(len(kouho)):
	for j in range(i + 1, len(kouho)):
		ans = min(ans, kouho[i] * kouho[j] % MOD)
print(ans)


(L, R) = map(int, input().split())
mod = 2019
Min = 2018
for i in range(L, min(L + mod, R)):
	for j in range(i + 1, min(L + mod, R + 1)):
		Min = min(i * j % 2019, Min)
print(Min)


(L, R) = map(int, input().split())
k = 0
l = 2020
m = 2020
apList = [0] * 2019
for i in range(L, R + 1):
	k = i % 2019
	if apList[k] != 0:
		break
	else:
		apList[k] += 1
res = 2018
for i in range(2019):
	for j in range(i + 1, 2019):
		if apList[i] != 0 and apList[j] != 0:
			res = min(i * j % 2019, res)
print(res)


(L, R) = map(int, input().split())
Dif = abs(L - R) + 1
if Dif >= 2020:
	Ans = 0
else:
	Box = []
	for i in range(L, R + 1):
		Box.append(i % 2019)
	Box.sort()
	Ans = 2020 * 2020
	for i in range(len(Box) - 1):
		B1 = Box[i]
		for j in range(i + 1, len(Box)):
			B2 = Box[j]
			Ans = min(B1 * B2 % 2019, Ans)
print(Ans % 2019)


(l, r) = map(int, input().split())
ans = 10000
for i in range(l, l + min(r - l, 2020)):
	for j in range(i + 1, l + min(r - l, 2020) + 1):
		ans = min(ans, i * j % 2019)
print(ans)


def main():
	(l, r) = list(map(int, input().split()))
	mi = 2019
	c = 0
	for i in range(l, r):
		a = i * i % 2019
		for _ in range(min(r - l - c, 2019)):
			a = (a + i) % 2019
			if a < mi:
				mi = a
				if a == 0:
					print(0)
					return
		c += 1
	print(mi)

def __starting_point():
	main()
__starting_point()


(l, r) = map(int, input().split())
if r - l >= 2019:
	minimum = 0
else:
	(left, right) = (l % 2019, r % 2019)
	minimum = 2018 ** 2
	for i in range(left, right + 1):
		for j in range(i + 1, right + 1):
			minimum = min(minimum, i * j % 2019)
print(minimum)


(L, R) = [int(_) for _ in input().split()]
ans = 10000
R = min(R, L + 2019)
for j in range(L, R + 1):
	for i in range(L, j):
		ans = min(i * j % 2019, ans)
print(ans)


(L, R) = list(map(int, input().split()))
if L + 2019 > R:
	tmp = 10 ** 9
	for l in range(L, R):
		for r in range(l + 1, R + 1):
			if l * r % 2019 < tmp:
				tmp = l * r % 2019
	print(tmp)
else:
	print('0')


(l, r) = map(int, input().split())
if l // 2019 != r // 2019:
	print(0)
	exit()
ans = 2019
for i in range(l, r):
	for k in range(i + 1, r + 1):
		ans = min(ans, i * k % 2019)
print(ans)


(s, e) = map(int, input().split())
ans = 10 ** 9
b = min(s + 2019, e)
for i in range(s, b + 1):
	for j in range(i + 1, b + 1):
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
mini = 2019
L = l
R = r + 1 if r - l < 2019 * 2 else l + 2019 + 1
for i in range(L, R):
	for j in range(i + 1, R):
		mini = min(mini, i * j % 2019)
print(mini)


(l, r) = map(int, input().split())
ans = 3000
if r - l < 673:
	for i in range(l + 1, r + 1):
		for j in range(l, i):
			ans = min(ans, i * j % 2019)
else:
	ans = 0
print(ans)


def main():
	(l, r) = list(map(int, input().split()))
	ans = 2019
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			ans = min(ans, i * j % 2019)
			if ans == 0:
				break
		if ans == 0:
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


(l, r) = map(int, input().split())
ans = float('INF')
mod = 2019
for i in range(l, r + 1):
	if i == l + 2019 or ans == 0:
		break
	for j in range(l, r + 1):
		if j == l + 2019:
			break
		if i == j:
			continue
		ans = min(ans, i * j % mod)
print(ans)


(L, R) = map(int, input().split())
ans = 2020
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		n = i * j
		if n % 2019 == 0:
			ans = 0
			break
		n = n % 2019
		ans = min(ans, n)
	else:
		continue
	break
print(ans)


MOD = 2019
(L, R) = list(map(int, input().split()))
mod_l = L % MOD
mod_r = R % MOD
if R - L >= 2019:
	print('0')
else:
	ans = 2018
	for i in range(mod_l, mod_r):
		for j in range(i + 1, mod_r + 1):
			_ans = i * j % MOD
			if ans > _ans:
				ans = _ans
	print(ans)


(L, R) = (int(x) for x in input().split())
if R - L > 2019 * 2:
	R -= ((R - L) // 2019 - 1) * 2019
ans = 2019
for i in range(L, R):
	for j in range(i + 1, R + 1):
		ans = min(ans, i * j % 2019)
print(ans)


(L, R) = list(map(int, input().split()))
N = min(R - L + 1, 2019)
MOD = 2019
m = MOD
for i in range(L, L + N):
	for j in range(i + 1, L + N):
		m = min(m, i * j % MOD)
print(m)


(l, r) = map(int, input().split())
a = []
if r - l > 2019:
	for i in range(l, l + 2019):
		for j in range(i + 1, min(r + 1, l + 2020)):
			a.append(i * j % 2019)
else:
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			a.append(i * j % 2019)
ans = min(a)
print(ans)


(L, R) = map(int, input().split())
m = 2019
flag = False
for i in range(L, R):
	for j in range(i + 1, R + 1):
		m = min(m, i * j % 2019)
		if m == 0:
			flag = True
			break
	if flag:
		break
print(m)


(l, r) = map(int, input().split())
a = 0
if r - l < 2019:
	a = min([x * y % 2019 for x in range(l, r + 1) for y in range(x + 1, r + 1)])
print(a)


(L, R) = list(map(int, input().split()))
if R - L >= 2019:
	minimum = 0
else:
	(left, right) = (L % 2019, R % 2019)
	minimum = 2018 ** 2
	for i in range(left, right + 1):
		for j in range(i + 1, right + 1):
			minimum = min(minimum, i * j % 2019)
print(minimum)


(L, R) = map(int, input().split())
ls = list(range(L, min(L + 2019, R + 1)))
ans = 2019
for i in range(len(ls)):
	for j in range(i + 1, len(ls)):
		ans = min(ans, ls[i] * ls[j] % 2019)
print(ans)


(L, R) = map(int, input().split())
R = min(L + 2019, R)
m = 3000
for x1 in range(L, R):
	for x2 in range(x1 + 1, R + 1):
		if m > x1 * x2 % 2019:
			m = x1 * x2 % 2019
print(m)


MOD = 2019
(l, r) = map(int, input().split())
if r - l >= 2019:
	print(0)
	return
lst = []
for num in range(l, r + 1):
	lst.append(num % MOD)
ans = 2020
ll = len(lst)
for i in range(ll):
	for j in range(i + 1, ll):
		tmp = lst[i] * lst[j] % MOD
		ans = min(ans, tmp)
print(ans)


(l, r) = map(int, input().split())
(x, y) = (l // 2019, r // 2019)
p = 0
if x == y:
	p = 2019
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			p = min(p, i % 2019 * (j % 2019) % 2019)
print(p)


(L, R) = map(int, input().split())
mod = 2019
ans = 20000
for i in range(L, min(R, L + mod)):
	for j in range(L + 1, min(R + 1, L + mod + 1)):
		tempans = i % mod * (j % mod)
		tempans %= mod
		if tempans < ans:
			ans = tempans
print(ans)


(l, r) = map(int, input().split())
if r - l >= 2019:
	print(0)
else:
	MIN = 10000
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			p = i * j % 2019
			if p < MIN:
				MIN = p
	print(MIN)


(l, r) = map(int, input().split())
X = []
if r - l >= 2019:
	print(0)
else:
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			X.append(i * j % 2019)
	print(min(X))


(L, R) = map(int, input().split())
result = R * R
if R - L + 1 > 2019:
	R = L + 2018
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		if i * j % 2019 < result:
			result = i * j % 2019
print(result)


(l, r) = map(int, input().split())
ans = 2019
if r - l <= 2021:
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			a = i % 2019 * (j % 2019) % 2019
			ans = min(a, ans)
	print(ans)
else:
	for p in range(l, l + 2021):
		for q in range(p + 1, l + 2022):
			b = p % 2019 * (q % 2019) % 2019
			ans = min(b, ans)
	print(ans)


import sys

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_str_split():
	return list(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def Main():
	(l, r) = read_ints()
	ans = 2020
	if r - l >= 2019:
		print(0)
		return
	for i in range(l, r + 1):
		for j in range(l, i):
			ans = min(ans, i * j % 2019)
	print(ans)

def __starting_point():
	Main()
__starting_point()


(L, R) = map(int, input().split())
r = 2018
for i in range(L, min(R, L + 2019)):
	for j in range(L + 1, min(R + 1, L + 2020)):
		r = min(r, i * j % 2019)
print(r)


import sys
(l, r) = map(int, input().split())
k = 2020
if r - l >= 2020:
	print(0)
	return
else:
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			k = min(k, i * j % 2019)
print(k)


(L, R) = map(int, input().split())
if R - L >= 2019:
	print(0)
else:
	list = []
	for i in range(L, R + 1):
		for j in range(i + 1, R + 1):
			list.append(i * j % 2019)
	list = sorted(list)
	print(list[0])


import sys
(L, R) = map(int, input().split())
mod = 2019
if R - L >= 2019:
	print(0)
else:
	ans = 10 ** 8
	for i in range(L, R):
		for j in range(i + 1, R + 1):
			if i * j % mod == 0:
				print(0)
				return
			ans = min(ans, i * j % mod)
	print(ans)


(L, R) = list(map(int, input().split()))
m = 2019
if R - L >= 2018:
	print('0')
else:
	ans = 2020
	for i in range(L, R + 1):
		for j in range(i + 1, R + 1):
			t = i % m * (j % m) % m
			ans = min(ans, t)
	print(ans)


(L, R) = map(int, input().split())
a = 2019
for i in range(L, min(R, L + 2019)):
	for j in range(i + 1, min(R + 1, L + 2019)):
		d = i * j % 2019
		if d < a:
			a = d
print(a)


import itertools
(L, R) = map(int, input().split())
ans = 2019
for (i, j) in itertools.combinations(range(L, min(R + 1, L + 2020)), 2):
	ans = min(ans, i * j % 2019)
print(ans)


(l, r) = list(map(int, input().split()))
if r - l >= 2019:
	print(0)
else:
	m = 2019
	for i in range(l, r + 1, 1):
		for j in range(i + 1, r + 1, 1):
			m = min(i * j % 2019, m)
	print(m)


(L, R) = map(int, input().split())
l1 = L // 2019
r1 = R // 2019
if l1 < r1:
	print(0)
elif l1 == r1:
	res = []
	for i in range(L, R + 1):
		for j in range(i + 1, R + 1):
			res.append(i * j % 2019)
	print(min(res))


(L, R) = map(int, input().split())
ans = []
if R - L >= 2019:
	print(0)
	exit()
for i in range(L, R):
	for j in range(i + 1, R + 1):
		ans.append(i * j % 2019)
print(min(ans))


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return map(int, input().split())

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	(L, R) = i_map()
	ans = 2018
	for i in range(L, min(R + 1, L + 2030)):
		for j in range(L + 1, min(R + 1, L + 2030)):
			if i != j:
				ans = min(ans, i * j % 2019)
	print(ans)

def __starting_point():
	main()
__starting_point()


(L, R) = map(int, input().split())
ans = 2018
for x in range(L, min(R, L + 2019)):
	for y in range(L + 1, min(R + 1, L + 2019)):
		ans = min(ans, x * y % 2019)
print(ans)


(l, r) = map(int, input().split())
d = range(l, r + 1)[:673]
print(min((i * j % 2019 for i in d for j in d if i < j)))


(L, R) = map(int, input().split())
mi = 10 ** 20
for i in range(L, min(R, L + 2030)):
	for j in range(i + 1, min(R + 1, i + 2030)):
		mi = min(mi, i * j % 2019)
print(mi)


(l, r) = map(int, input().split())
mod = 2019
a = l % mod
b = r % mod
if r - l >= 2018:
	print(0)
elif a > b:
	print(0)
else:
	t = a * (a + 1) % mod
	for x in range(a, b):
		for y in range(x + 1, b + 1):
			if x * y % mod < t:
				t = x * y % mod
	print(t)


(L, R) = map(int, input().split())
a = []
if R - L >= 2019:
	print(0)
else:
	for i in range(L, R + 1):
		for j in range(i + 1, R + 1):
			a.append(i % 2019 * (j % 2019) % 2019)
	print(min(a))


import sys
(L, R) = map(int, input().split())
M = 2019
R = min(R, L + 2 * M - 1)
X = M + 1
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		X = min(X, i * j % M)
print(X)


(L, R) = map(int, input().split())
MOD = 2019
if MOD <= R - L + 1:
	ans = 0
else:
	ans = MOD - 1
	nums = set()
	start = L % MOD
	for i in range(start, start + (R - L) + 1):
		if i % MOD in nums:
			break
		nums.add(i % MOD)
	nums = tuple(nums)
	for i in range(len(nums)):
		for j in range(i + 1, len(nums)):
			ans = min(ans, nums[i] * nums[j] % MOD)
print(ans)


from itertools import combinations as f
(l, r) = map(int, input().split())
print(min([i * j % 2019 for (i, j) in f(range(l, r + 1)[:2019], 2)]))


(l, r) = list(map(int, input().split()))
if r - l >= 2019:
	print(0)
	return
ans = 2018
for i in range(l, r):
	for j in range(i + 1, r + 1):
		if ans > i * j % 2019:
			ans = i * j % 2019
print(ans)


(L, R) = map(int, input().split())
ans = 10 ** 100
for i in range(L, min(R, L + 2019)):
	for j in range(i + 1, min(R + 1, L + 2019)):
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
m = 2019
c = m - 1
r = min(r, l + m - 1)
for i in range(l, r):
	for j in range(i + 1, r + 1):
		s = i * j
		c = min(c, s % m)
print(c)


def main():
	(l, r) = map(int, input().split())
	(q, ll) = (l // 2019, l % 2019)
	rr = r % 2019
	rng = [*range(ll, rr + 1)] if r - l < (2019 * q - ll) % 2019 else [*range(ll, 2019)] + [*range(rr + 1)]
	lenrng = len(rng)
	ans = 2020
	for i in range(lenrng - 1):
		for j in range(i + 1, lenrng):
			tmp = rng[i] * rng[j] % 2019
			if tmp < ans:
				ans = tmp
	print(ans)

def __starting_point():
	main()
__starting_point()


(a, b) = map(int, input().split())
c = []
for i in range(a, min(b, a + 2019) + 1):
	for j in range(i + 1, min(b, a + 2019) + 1):
		c.append(i * j % 2019)
print(min(c))


(L, R) = map(int, input().split())
ans = 0
if R - L < 2018:
	nums = list(range(L, R + 1))
	A = []
	for i in range(len(nums)):
		for j in range(i + 1, len(nums)):
			A.append(nums[i] * nums[j] % 2019)
	ans = min(A)
print(ans)


s = range(*eval(input().replace(' ', ',1+')))[:673]
print(min((i * j % 2019 for i in s for j in s if i < j)))


import sys
(l, r) = map(int, input().split())
if l + 2019 <= r:
	print(0)
	sys.exit()
mn = 2018 * 2018
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		mn = min(mn, i * j % 2019)
print(mn)


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

def mod(num):
	return num % 2019
ans = 10 ** 9
lr = min(R, L + 2019) + 1
for i in range(L, lr):
	for j in range(i + 1, lr):
		ans = min(ans, mod(i * j))
print(ans)


(L, R) = map(int, input().split())
if R // 2019 - L // 2019 > 0:
	print(0)
else:
	buf = 2020
	for i in range(L, R + 1):
		for j in range(i + 1, R + 1):
			buf = min(buf, i % 2019 * (j % 2019) % 2019)
	print(buf)


(l, r) = map(int, input().split())
p = 2019
if r - l >= p:
	print(0)
else:
	tmp = p
	for i in range(l, r + 1):
		for j in range(i + 1, r + 1):
			tmp = min(tmp, i * j % p)
	print(tmp)


(L, R) = map(int, input().split())
MOD = 2019
ans = 2020
if R - L > 2010:
	print(0)
	return
for i in range(L, R):
	for j in range(i + 1, R + 1):
		ans = min(ans, i * j % MOD)
print(ans)


(l, r) = map(int, input().split())
if r - l > 672:
	p = 0
else:
	x = []
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			x.append(i * j % 2019)
	p = min(x)
print(p)


(L, R) = map(int, input().split())
kouho = set([])
while len(kouho) < 2019 and L <= R:
	temp = L % 2019
	kouho.add(temp)
	L += 1
A = list(kouho)
A.sort()
ans = 2018
for i in range(len(A)):
	for j in range(i + 1, len(A)):
		temp = A[i] * A[j] % 2019
		ans = min(ans, temp)
print(ans)


import sys
(l, r) = map(int, sys.stdin.readline().split())
r = min(r, l + 673)
ans = 2019
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		ans = min(ans, i * j % 2019)
print(ans)


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	(l, r) = inl()
	if r - l > 2200:
		return 0
	a = 2018
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			x = i * j % 2019
			a = min(a, x)
	return a
print(solve())


def LI():
	return list(map(int, input().split()))
(L, R) = LI()
ans = 2020
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		y = i * j % 2019
		ans = min(ans, y)
		if ans == 0:
			break
	if ans == 0:
		break
print(ans)


(L, R) = list(map(int, input().split()))
ans = 2 * 10 ** 9 + 1
for i in range(L, min(R, L + 2019) + 1):
	for j in range(i + 1, min(R, L + 2019) + 1):
		i %= 2019
		j %= 2019
		ans = min(ans, i * j % 2019)
print(ans)


(l, r) = map(int, input().split())
a = 10 ** 5
if r - l >= 2017:
	print(0)
	exit()
else:
	for i in range(l, r + 1):
		for j in range(i + 1, r + 1):
			a = min(a, i * j % 2019)
print(a)