Problem:
 Score : 300 points    Problem Statement 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 1 2020 2040      Sample Output 1 2  When (i, j) = (2020, 2021) , (i \times j) \mbox{ mod } 2019  = 2 .       Sample Input 2 4 5      Sample Output 2 20  We have only one choice: (i, j) = (4, 5) .

Solution (Python):
import itertools as itr

l,r = map(int,input().split())

l_r = l % 2019
r_r = r % 2019
l_q = l // 2019
r_q = r // 2019


if r_q > l_q:
	print(0)
else:

	vals = range(l_r,r_r+1)

	print(min([(a*b)%2019 for a,b in itr.combinations(vals, 2)]))

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

if R - L >= MOD - 1:
    print(0)
    exit()

if L % MOD < R % MOD:
    a = [n for n in range(L % MOD, R % MOD + 1)]
elif L % MOD > R % MOD:
    a = [n for n in range(L % MOD, MOD)] + [n for n in range(R % MOD + 1)]
else:
    a = list(range(MOD))

ans = MOD - 1
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        ans = min(ans, (a[i] * a[j]) % MOD)

print(ans)

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    L, R = MAP()
    LL = L % 2019
    RR = R % 2019
    if (R - L) >= 2019:
        print(0)
    else:
        minv = 2019
        for l in range(LL, RR):
            for r in range(l + 1, RR + 1):
                minv = min(minv, (l * r) % 2019)
        print(minv)

if __name__ == '__main__':
    main()

Solution (Python):
def solve():
  l,r = (int(i) for i in input().split())
  mod = 2019
  if r-l >= 2019:
   print(0)
   exit()
  l %= mod
  r %= mod
  ans = 10**15
  if l >= r :
    print(0)
    exit()
  elif l == 0 or r == 0:
    print(0)
    exit()
  else:
    for i in range(l,r):
      for j in range(i+1,r+1):
         ans = min(ans,(i*j)%mod)
  print(ans%mod)

solve()

Solution (Python):
import sys
from fractions import gcd
from itertools import product, combinations
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    l, r = LI()
    mods = [[INF for i in range(2019)] for j in range(2019)]
    ans = INF
    for i, j in product(range(2019), range(2019)):
        mods[i][j] = i * j % 2019
    if r - l >= 2019:
        print(0)
        return
    l = l % 2019
    r = r % 2019
    if r > l:
        for i, j in combinations(range(l, r+1), 2):
            if i == j:
                continue
            ans = min(ans, mods[i][j])
        print(ans)
        return
    print(0)








if __name__ == "__main__":
    main()

Solution (Python):
l, r = list(map(int, input().split()))

if r - l > 2018:
    print(0)
else:
    ans = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            tmp = (i * j) % 2019
            if ans > tmp:
                ans = tmp
    print(ans)

Solution (Python):
L, R = map(int, input().split())
diff = R - L

min_temp = 10000
if diff <= 2019:
    for i in range(L, R + 1):
        for j in range(L, R + 1):
            if i == j:
                continue
            x = (i * j) % 2019
            min_temp = min(x, min_temp)
else:
    for i in range(L, L + 1 + 2019):
        for j in range(L, L + 1 + 2019):
            if i == j:
                continue
            x = (i * j) % 2019
            min_temp = min(x, min_temp)
print(min_temp)

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

print(ans)

Solution (Python):
L, R = map(int, input().split())

if R >= L + 2019:
    print('0')
else:
    xs = [x % 2019 for x in range(L, R + 1)]
    vs = []
    for i in range(len(xs)):
        for j in range(i + 1, len(xs)):
            vs.append((xs[i] * xs[j]) % 2019)
    print(min(vs))

Solution (Python):
L, R = [int(c) for c in input().split()]

if R-L+1 >= 2019:
    print(0)
    exit()

m = 2020
l = [c%2019 for c in range(L,R+1)]
for i in range(len(l)):
    for j in range(i+1, len(l)):
        m = min(m, (l[i]*l[j])% 2019)
print(m)

Solution (Python):
L, R = map(int, input().split())
explore_list = []
def explore(L, R):
    for i in range(L, min(L+2020, R + 1)):
        explore_list.append(i % 2019)

explore(L, R)
answer_list = []
for i in range(len(explore_list)):
    for j in range(i + 1, len(explore_list)):
        answer_list.append(explore_list[i] * explore_list[j] % 2019)

print(min(answer_list))

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    l, r = map(int, input().split())

    l_i = l // 2019
    r_i = r // 2019
    if l_i != r_i:
        print(0)
    else:
        ans = l * r % 2019
        for x in range(l, r):
            for y in range(l + 1, r + 1):
                ans = min(ans, x * y % 2019)
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
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))

Solution (Python):
L, R = (int(_) for _ in input().split())  

result = 2020

if R - L > 2020:
    result = 0
else:
    for i in range(L, R+1):
        for j in range(L, R+1):
            if i < j:
                result = min(result, (j * i) % 2019)

print(result)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline






















def main():

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

	ans = -1
	ed = min(L+2020, R+1)


	for a in range(L, ed):
		for b in range(a+1, ed):
			tmp = (a*b)%2019

			if ans > tmp or ans == -1:
				ans = tmp

	print(ans)




if __name__ == "__main__":
	main()

Solution (Python):
import numpy as np
L,R = (int(x) for x in input().split())

if R - L > 3000:
  print(0)
  exit()
  
x = np.arange(L,R+1,dtype=np.int64)
y = x[:,None] * x[None,:] % 2019
for i in range(len(x)):
  y[i,i] = 3000
answer = y.min()
print(answer)

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
input=lambda : sys.stdin.readline().rstrip()

l,r=map(int,input().split())

x=l%2019
y=r%2019

if x>=y or r-l>=2019 or x==0:
    print(0)
else:
    ans=99999
    for i in range(x,y+1):
        for j in range(x+1,y+1):
            if i==j:
                break
            ans=min(ans,i*j%2019)
    print(ans)

Solution (Python):
import sys, math

readline = sys.stdin.readline

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

P = 2019
L_ = (L // P) * P

if R < L_ + P:
    m = 100000
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            m = min(m, (i * j) % P)
    print(m)
else:
    print(0)

Solution (Python):
def main():
    L, R = map(int, input().split())
    mod = 2019

    if R - L >= 2019:
        ans = 0

    else:
        ans = float('inf')
        for i in range(L, R+1):
            for j in range(i+1, R+1):
                tmp = (i * j) % mod 
                if tmp < ans:
                    ans = tmp
    
    print(ans)

main()

Solution (Python):




l, r = map(int,input().split())


wans = 10 ** 10
for i in range(l, r):
    for j in range(i+1, r+1):
        wans = min(i * j % 2019, wans)
        if wans == 0:
            break
    if wans == 0:
        break
ans = wans


print(ans)

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

Solution (Python):
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)

Solution (Python):
L, R = map(int, input().split())
min = 2200
for i in range(L, R):
    for j in range(i+1, R+1):
        if (i * j) % 2019 < min:
            min = (i * j) % 2019
            if min == 0:
                print(0)
                exit()
print(min)

Solution (Python):
import functools as ft
import heapq
import itertools as it
import logging
import unittest
from collections import (
    OrderedDict,
    defaultdict,
    namedtuple,
    Counter,
)

import numpy as np

_ = [ft, it, np, heapq, namedtuple, Counter, defaultdict, OrderedDict]

debug = logging.getLogger(__name__).debug


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


def _main():
    l, r = input_ints()
    logging.debug([l, r])
    i_close = set()
    j_close = set()
    result = float('inf')
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            result = min(result, (i * j) % 2019)
            j_close.add(j % 2019)
            if len(j_close) == 2019:
                break
        i_close.add(i % 2019)
        if len(i_close) == 2019:
            break
    print(result)


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Solution (Python):
L, R = map(int, input().split())
ans = float('inf')
r = min(L + 2019, R)

for i in range(L, r):
	for j in range(i +1, r + 1):
		tmp = (i * j) % 2019
		if tmp < ans:
			ans = tmp
		
print(ans)

Solution (Python):
l,r=map(int,input().split())
n=2019

if r-l>=2019:
    print(0)
    exit()
else:
    x=[]
    for p in range(l,r):
        if p%n==0:
            print(0)
            exit()
        else:
            for q in range(p+1,r+1):
                x.append(p*q%n)
print(min(x))

Solution (Python):
L,R=map(int,input().split())
MOD=2019
l,r=L%MOD,R%MOD
if R>=L+2018:print(0)
elif l>=r:print(0)
else:
    ans=MOD
    for i in range(l,r):
        for j in range(i+1,r+1):ans=min(ans,((i*j)%MOD))
    print(ans)

Solution (Python):
L, R = map(int, input().split())

if (L // 2019) == (R //2019):
    LL = L % 2019
    RR = R % 2019
    ans = 2019
    for i in range(LL, RR):
        for j in range(i+1, RR+1):
            ans = min(((i * j) % 2019), ans)
else:
    ans = 0

print(ans)

Solution (Python):
L,R = [int(zz) for zz in input().split()]

Lm = L%2019
Rm = R%2019

if Lm*Rm == 0 or R-L > 2017 or Rm <= Lm:
    print(0)
    exit()

ans = 2019
for i in range(Lm,Rm+1):
    for j in range(i+1,Rm+1):
        ans = min(ans,i*j%2019)
print(ans)

Solution (Python):
L,R = map(int, input().split())
'''
if L <= 2019 <= R:
    print(0)
    exit()
'''
ans = 2020
for i in range(L,R):
    x = i % 2019
    for j in range(L+1,R+1):
        y = j % 2019
        tmp = (x * y) % 2019 
        if tmp < ans:
            ans = tmp
        if ans == 0:
            print(ans)
            exit()

print(ans)

Solution (Python):
import itertools
L,R = map(int,input().split())
if R-L >= 2018:
  print(0);exit()
li = [i%2019 for i in range(L,R+1)]
li = list(set(li))
if 0 in li or (3 in li and 673 in li):
  print(0);exit()
pro = []
for i,j in itertools.combinations(li,2):
  pro.append(i*j%2019)
print(min(pro))

Solution (Python):
l, r = map(int, input().split())

mod = 2019

if l//mod != r//mod:
    print(0)
    exit()

l = l%mod
r = r%mod

m = mod
for i in range(l, r+1):
    for j in range(i+1, r+1):
        t = (i*j)%mod
        if t < m:
            m = t

print(m)

Solution (Python):
L, R = map(int, input().split())

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

Solution (Python):
import sys

input = sys.stdin.readline

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

Solution (Python):
import math
[L,R] = list(map(int,input().split()))

if R >= L+2019:
    print(0)
else:
    ans = 2020
    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)

Solution (Python):
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

MOD = 2019

def main():
    L, R = i2nn()
    LN = L // MOD
    RN = R // MOD
    if LN != RN:
        print(0)
        return
    LM = L % MOD
    RM = R % MOD
    LM2 = min(LM, RM)
    RM2 = max(LM, RM)
    n = int(1e+9)
    for i in range(LM2, RM2):
        for j in range(i+1, RM2+1):
            t = (i * j) % MOD
            if n > t:
                n = t
    print(n)

main()

Solution (Python):
L, R = list(map(int,input().split()))

mod_min = 2019

LRrange = min(2019, R-L+1)

for i in range(LRrange):
    for j in range(LRrange):
        if L+i+j+1>R:
            break
        else:
            mod_min = min(mod_min,(L+i)*(L+i+j+1) % 2019)

print(mod_min)

Solution (Python):
import sys
from itertools import combinations

fin = sys.stdin.readline
L, R = [int(elem) for elem in fin().split()]

all_ij = list(range(L, min(R+1, L+2021)))

min_mod = 2020
for each_ij in combinations(all_ij, 2):
    result = (each_ij[0] * each_ij[1]) % 2019
    if result < min_mod:
        min_mod = result
        if min_mod == 0:
            break

print(min_mod)

Solution (Python):
L, R = map(int, input().split())
def main(L, R):
  if R//2019 > L//2019:
    return 0
  L = L%2019
  R = R%2019
  r = 2019
  for i in range(L, R):
    for j in range(i+1, R+1):
      r = min(r, (i*j)%2019)
  return r
print(main(L, R))

Solution (Python):
l,r = map(int,input().split())

if(r-l >= 2018):
	print(0)
	exit()

mi = 2020
mi2 = 2020
for i in range(l,min(l+2019,r)):
	mi = min(mi,i%2019)
	for j in range(i+1,min(l+2019+1,r+1)):
		mi2 = min((i * j) % 2019,mi2)
print(min((mi * (mi + 1)) % 2019,mi2))

Solution (Python):
l, r = list(map(int, input().split(' ')))
mod = 2019
s1 = l % mod
rem = mod - s1
ans = -1

if l + rem > r:
    maxi = r
    lowe = l
    for i in range(l, r + 1):
        for j in range(i + 1, r + 1):
            mini = ((i%mod) * (j%mod)) % mod
            if mini < ans or ans == -1:
                ans = mini
    print(ans)
    
else:
    print(0)

Solution (Python):
(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)

Solution (Python):
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
x,y = ips()

if y-x>=2019:
    print(0)
    exit(0)
x%=2019
y%=2019
if x>y:
    y+=2019
m = rem
for i in range(x,y):
    for k in range(i+1,y+1):
        m = min(m,(i*k)%2019)
print(m)

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

Solution (Python):
l, r = map(int, input().split())
if r//2019 - l//2019 > 0:
    print(0)
else:
    newL = l%2019
    newR = r%2019
    minM = 2019
    index = newL
    while index < newR+1:
        index2 = index+1
        while index2 < newR+1:
            if minM > (index*index2)%2019:
                minM = (index*index2) % 2019
            index2+=1
        index+=1
    print(minM)

Solution (Python):
l, r = map(int, input().split())


rr = min(r, l + 2020)

res = 1000000
for i in range(l, rr+1):
    for j in range(l + 1, rr + 1):
        
        if i >= j:
            
            continue

        if res > i*j % 2019:
            
            res = i*j % 2019
print(res)

Solution (Python):
line = input().split()
l = int(line[0])
r = int(line[1])

dist = r - l
if dist >= 2018:
    print(0)
else:
    l = l % 2019
    
    li = []
    for i in range(dist+1):
        li.append((l+i) % 2019)
    
    smallest = 2018
    for i in range(len(li)):
        for j in range(i+1, len(li)):
            if (li[i] * li[j]) % 2019 < smallest:
                smallest = (li[i] * li[j]) % 2019
                
    print(smallest)

Solution (Python):
L, R = list(map(int, input().split()))

Q = L // 2019
l = L - 2019 * Q
r = R - 2019 * Q

if l == 0:
    print(0)
elif 2019 <= r:
    print(0)
else:
    minimum = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            val = (i * j) % 2019
            minimum = min(minimum, val)
    print(minimum)

Solution (Python):

import sys
input = sys.stdin.readline


sys.setrecursionlimit(10**6)

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

ans = 2018

for i in range(L, min(L+2020, R+1)):
    for j in range(i+1, min(L + 2020, R+1)):
        
        ans = min(ans, (i % 2019) * (j % 2019) % 2019)
print(ans)

Solution (Python):
def solve():
    L, R = map(int, input().split())
    if L + 2019 <= R:
        print(0)
    elif L % 2019 > R % 2019:
        print(0)
    else:
        l = L % 2019
        r = R % 2019
        min_mod = 2019
        for i in range(l, r):
            for j in range(i + 1, r + 1):
                min_mod = min(min_mod, (i * j) % 2019)
        print(min_mod)


if __name__ == '__main__':
    solve()

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

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

Solution (Python):



import fractions

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def calc(n, x):
    return n // x

def lcm(a, b):
    return (a * b) // fractions.gcd(a, b)

def main():
    l, r = rli()
    mod = [[None for _ in range(2019)] for _ in range(2019)]
    for i in range(2019):
        for j in range(i+1, 2019):
            mod[i][j] = i*j % 2019
    if r - l >= 2019:
        print(0)
        return
    l_mod = l % 2019
    r_mod = r % 2019
    if l_mod < r_mod:
        cand = list(range(l_mod, r_mod+1))
    else:
        cand = list(range(l_mod, 2019)) + list(range(0, r_mod+1))
    ans = 2018
    for i in cand:
        for j in cand:
            if i >= j:
                continue
            ans = min(ans, mod[i][j])
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
l,r = map(int,input().split())

if r -l >= 2019:
    print(0)
else:
    res = 2018
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            res = min(res,(i*j)%2019)
    print(res)

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIR(n): return [LI() for _ in range(n)]
mod = 2019

l,r = LI()
mi = float('inf')
if r - l >= 2019:
    print(0)
else:
    for i in range(l+1,r+1):
        for j in range(l,i):
            mi = min(mi,(i*j)% mod)
    print(mi)

Solution (Python):
import itertools

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

if R - L >= 2019:
    L = 0
    R = 2018

print min([(i * j) % 2019 for i, j in itertools.combinations(range(L, R + 1), 2)])

Solution (Python):
L, R = [int(lr) for lr in input().split()]
if R//2019 != L//2019:
  print(0)
else:
  ans = 2019
  for i in range(L, R):
    for j in range(i+1, R+1):
      mod = (i*j) % 2019
      if ans > mod:
        ans = mod
  print(ans)

Solution (Python):
import sys

l, r = [ int(x) for x in sys.stdin.readline().split() ]

lm = l % 2019

if lm + (r-l)>=2019:
    print(0)
    exit(0)

ans= 2019
rm= r % 2019 + 1
for i in range(lm,rm):
    for j in range(i+1,rm):
        ij = ( i * j ) % 2019
        if ij<ans: ans= ij

print( ans )

Solution (Python):
import sys
input = sys.stdin.readline

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

Solution (Python):
L, R = map(int, input().split(" "))
p1, p2 = 3, 673
if (L <= p2 <= R and R - L >= p1) or (R - L >= p2):
    print(0)
else:
    mods = []
    mods_append = mods.append
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            m = (i * j) % 2019
            mods_append(m)
            if m == 1:
                break
        if m == 1:
            break

    print(min(mods))

Solution (Python):
L, R = [int(i) for i in input().split()]
mini = 2019
for i in range(L,R):
    if L + 2019 < i:
        break
    for j in range(i+1, R+1):
        if i + 2020 < j:
            break
        tmp = (i * j) % 2019
        if tmp < mini:
            mini = tmp
print(mini)

Solution (Python):
from collections import defaultdict

def main():
    left, right = map(int, input().split())
    mod = 2019

    aaa = defaultdict(int)
    for i in range(left, min(right + 1, left + 5000)):
        aaa[i % mod] += 1

    score_sorted = list(sorted(aaa.items(), key=lambda x: x[0]))

    

    ans = 2019
    for i in range(len(score_sorted)):
        if score_sorted[i][1] >= 2:
            ans = min(ans, (score_sorted[i][0] * score_sorted[i][0]) % mod)
        for j in range(i + 1, len(score_sorted)):
            ans = min(ans, (score_sorted[i][0] * score_sorted[j][0]) % mod)

    print(ans)







if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

if R - L + 1 >= 2019:
    print(0)
else:
    for i in range(L, R+1):
        if i % 2019 == 0:
            print(0)
            sys.exit()
    else:
        ans = 10**6
        for i in range(L, R):
            for j in range(i+1, R+1):
                ans = min(ans, i * j % 2019)
                if ans == 0:
                    break
        print(ans)

Solution (Python):
def c_remainder_minimization_2019(L, R):
    ans = float('inf')
    for i in range(L, min(R, L + 2019)):
        for j in range(i + 1, min(R + 1, L + 2020)):
            ans = min(ans, (i * j) % 2019)
    return ans

L, R = [int(i) for i in input().split()]
print(c_remainder_minimization_2019(L, R))

Solution (Python):
import numpy as np
import copy


def dist2(y, z):
    return np.sum((y - z)**2)


def main():
    L, R = map(int, input().split())

    m = R // 2019
    if L <= 2019 * m and 2019 * m <= R:
        ans = 0
    else:
        L -= 2019 * m
        R -= 2019 * m
        
        
        
        
        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)


if __name__ == '__main__':
    main()

Solution (Python):
l,r=map(int,input().split())
L=l//2019
R=r//2019
k=[]
if L==R:
    for i in range(l,r):
        for j in range(i+1,r+1):
            k.append((i*j)%2019)
    print(min(k))
else:
    print(0)

Solution (Python):
L,R = map(int,input().split())
a = [i for i in range(L,min(L+2019,R)+1)]
b = len(a)
ans = 10**10
for i in range(b):
    for j in range(b):
        if i==j:
            break
        ans = min(ans,a[i]*a[j]%2019)
print(ans)

Solution (Python):
L, R = map(int, input().split())



if (R%2019 == 0) or (L%2019 == 0):
    print (0)
    exit()
if R//2019 > L//2019:
    print (0)
    exit()

ans = 2018
for i in range(L, R):
    for j in range(i+1, R+1):
        
        ans = min((i * j)%2019, ans)
print (ans%2019)

Solution (Python):
L, R = map(int, input().split()) 

l = L // 2019
r = R // 2019
ll = L % 2019
rr = R % 2019

if l < r:
    ans = 0
else:
    ans = 2019
    for i in range(ll, rr+1):
        for j in range(i+1, rr+1):
            k = i * j % 2019
            ans = min(ans, k)

print(ans)

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

Solution (Python):
l,r=map(int,input().split())
if (r-l)//2019>3:
  r=l+2019*2
ans=10000
for i in range(l,r):
  for j in range(i+1,r+1):
    i%=2019
    j%=2019
    ans=min(ans,i*j%2019)
print(ans)

Solution (Python):
from sys import stdin

L, R = [int(x) for x in stdin.readline().rstrip().split()]

A = [(L + x) % 2019 for x in range(min(2019, R - L + 1))]
A.sort()

ans = 10 ** 8
for l in range(len(A) - 1):
    for m in range(l + 1, len(A)):
        if (A[l] * A[m]) % 2019 < ans:
            ans = (A[l] * A[m]) % 2019

print(ans)

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

Solution (Python):
l,r = map(int,input().split())
if (r - l) >= 2018:
  print(0)
  exit()
rr = r%2019
lr = l%2019
if lr >= rr:
  print(0)
  exit()
mi = 2018
if (rr - lr) >=673:
  print(0)
  exit()
for i in range(lr,rr):
  for j in range(i+1,rr+1):
    a = (i*j)%2019
    if a < mi:
      mi = a
print(mi)

Solution (Python):
import math
l,r = list(map(int,input().split()))
MOD = 2019
res = 100000000000000000000000000000000
ans = []
for i in range(l,r+1):
    if res == 0:
        break
    for j in range(i+1,r+1):
        if res == 0:
            break
        if (i*j)%2019 < res:
            res = (i*j)%2019
print(res)

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

Solution (Python):
l,r = map(int, input().split())

if r-l >= 2019:
  print(0)
  exit(0)
  
ans = 100000000
for i in range(l+1, r+1):
  for j in range(l, i):
    ans = min(ans, (i*j)%2019)
    
print(ans)

Solution (Python):
L, R = map(int, input().split())

Lq = L // 2019
l = L % 2019
Rq = R // 2019
r = R % 2019

if Lq != Rq:
    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)

Solution (Python):
L, R = map(int,input().split())

MOD = 2019

l = L%MOD

if R-L+1 >= 2019:
    print(0)
else:
    ans = 10**10
    for i in range(R-L+1):
        for j in range(i+1,R-L+1):
            s1 = l + i
            s2 = l + j
            ans = min(ans, s1*s2%MOD)
            
    print(ans)

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

Solution (Python):
L, R = map(int, input().split())
if R - L >= 2018: print(0)
else:
    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)

Solution (Python):
import sys

L, R = map(int, input().split())
ans = 2020
for i in range(L, R+1):
    if i % 2019 == 0:
        print(0)
        sys.exit()

for i in range(L, R+1):
    for j in range(L, i):
        tmp = (i * j) % 2019
        if tmp < ans:
            ans = tmp            
print(ans)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

L,R=MAP()

if R-L+1>2019:
    print(0)
else:
    ans=INF
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ans=min(ans, (i%2019)*(j%2019)%2019)
    print(ans)

Solution (Python):
a,b = map(int,input().split())

if b -a >= 2019:
    print(0)
    exit()
a %= 2019
b %= 2019

if b <= a:
    b += 2019
ans = 10 ** 10
for i in range(a,b):
    for j in range(i+1,b+1):
        ans = min(ans,(i * j) % 2019)
print(ans)

Solution (Python):
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
if l > r or R-L >= 2019:
    print(0)
    exit()

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

print(ans)

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

lmod = L%MOD
rmod = R%MOD

ans = 0
if R-L >= 2019:
    ans = 0
else:
    if lmod >= rmod:
        ans = 0
    else:
        ans = float("inf")
        for i in range(lmod,rmod+1):
            for j in range(i+1,rmod+1):
                x = i*j%MOD
                if ans > x:
                    ans = x
print(ans)

Solution (Python):
L,R=map(int,(input().split()))
LL=L
RR=R
L=L%2019
R=R%2019

l=min(L,R)
r=max(L,R)
x=[]
for i in range(l,(r+1)) :
    for j in range(i+1,r+1):
        x.append((i*j)%2019)
if L==0 or R==0:
    print(0)
elif RR-LL>=2019:
    print(0)
else:
    print(min(x))