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).



Sample input:
2020 2040


Sample output:
2

Submission status: Runtime Error

Solution code:
l, r = map(int, input().split())
ans = 2020
a = l // 2019
b = r // 2019
ans = []
# print(a)
# print(b) # 2019 num
if a != b:
    print(0)
else:
    for i in range(l, r+1):
        ans.append(i % 2019)
    
ans.sort()
print(ans[0] * ans[1])
    #l.append()
# print(a, b)


# if l // 2019 != r // 2019:
#     #print(0)
# else:
#     a = l % 2019
#     b = l % 2019 + 1
#     print(a * b)
#     # b = r % 2019
    

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




    #print(i)

Submission status: Runtime Error

Solution code:
L,R = map(int,input().split())
def judge_distance(i,j):
    if j-i >= 2019:
        return True

def search_2019(i,j):
    for p in range(j-i+1):
        if i+p % 2019 == 0:
            return True

if judge_distance(L,R) or search_2019(L,R):
    print(0)
else:
    mincount = float("inf")
    for i in range(L,R):
        for j in range(L+1,R+1):
            if i*j%2019 <= mincount:
                mincount = (i*j)%2019

print(mincount)

Submission status: Runtime Error

Solution code:

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

if (l==2019)or(r==2019)or(r-l>=2019):
    print('0')
    
elif r-l==1:
    ans = (r*l)%2019
else:
    ans=2019
    for i in range(l,r-1):
        for j in range(i+1,r):
            if (i*j)%2019 < ans:
                ans = (i*j)%2019
            if ans == 1:
                break
            
print(str(ans))

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c = 1
cmin = 2018

for i in range(a,b+1):
  c = i % 2019
  if c == 0:
    cmin = 0
    break
    #iが決定
  if cmin > c:
    cmin = c
    d = cmin +1
    
print((cmin*d) % 2019)

Submission status: Runtime Error

Solution code:
L,R = map(int, input().split())
if L * R < 2019:
        print(L * R)
        exit()

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

li=range(L, R)
tmp = []
for i in range(min(2019 * 2, R - L)):
        if li[i] % 2019 == 0:
                print(0)
                exit()
        tmp.append(li[i] % 2019)
tmp.sort()

print(tmp[0]* tmp[1])

Submission status: Runtime Error

Solution code:
a = input().split()
a = [int(i) for i in a]

a[0] = a[0] % 2019
a[1] = a[1] % 2019
yojyou_list=[]
if a[0] > a[1]:
    for i in range(a[0]-a[1]):
        yojyou_list.append((a[1] + i) % 2019)
else:
    for i in range(a[1] - a[0]):
        yojyou_list.append((a[0] + i) % 2019)


yojyou_list=sorted(yojyou_list)


print(yojyou_list[0] * yojyou_list[1])

Submission status: Runtime Error

Solution code:
import itertools

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

poss = list(range(L,R))

pairs = list(itertools.combinations(poss, 2))

print(min([pow(p[0]*p[1], 1, 2019) for p in pairs]))

Submission status: Runtime Error

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

res = 1000000007

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

print(res)

Submission status: Runtime Error

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

li = []

for i in range(L, R):
    for j in range(L+1,R):
        li.append((i * j) % 2019)

print(min(li))

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.arange(L, R + 1)
a = a % 2019
a_s = sorted(a)

print(int(a_s[0] * a_s[1]))

Submission status: Runtime Error

Solution code:
a = input().split()
a = [int(i) for i in a]

a[0] = a[0] % 2019
a[1] = a[1] % 2019
yojyou_list=[]
if a[0] > a[1]:
    for i in range(a[0]-a[1]):
        yojyou_list.append((a[1] + i) % 2019)
else:
    for i in range(a[1] - a[0]):
        yojyou_list.append((a[0] + i) % 2019)


yojyou_list = list(set(yojyou_list))
yojyou_list=sorted(yojyou_list)

    
print((yojyou_list[0] * yojyou_list[1]) % 2019)

Submission status: Runtime Error

Solution code:
L,R = map(int, input().split())
result = 2019
for i in range(L,R):
  for j in range(i+1,R+1):
    result = min((i * j)%2019)
    if result <= 2:
      break
print(result)

Submission status: Runtime Error

Solution code:
l,r = map(int,input().split())
result = []
if r-l+1 > 2019:
    print(0)
else:
    for x in range(l,r):
        result.append(x%2019)
        result.sort()
		print(result[0]*result[1])

Submission status: Runtime Error

Solution code:
import numpy as np

if __name__ == "__main__":
    x = list(map(int, input().split()))
    #print(x[0], x[0]%2019)
    #print(x[1], x[1]%2019)
    l = np.arange(x[1]-x[0]+1) + x[0]
    #print(l)
    l = l % 2019
    #print(l)
    l = np.sort(l)
    #print(l)
    print(l[0]*l[1])

Submission status: Runtime Error

Solution code:
import numpy as np

n, p = map(int, input().split())
i = np.array([[i for i in range(n,p+1)]])
l = np.dot(i.T, i)
res = [min(np.mod(np.delete(i, _index, 0),2019)) for _index,i in enumerate(l)]
print(min(res))

Submission status: Runtime Error

Solution code:
l,r = map(int,input().split())
result = []
if r-l+1 > 2019:
    print(0)
else:
    for x in range(l,r):
        result.append(x%2019)
result.sort()
print(result[0]*result[1])

Submission status: Runtime Error

Solution code:
L,R = map(int, input().split())
if L * R < 2019:
        print(L * R)
        exit()

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

li=range(L, R)
tmp = []
for i in range(min(2019, R - L)):
        if li[i] % 2019 == 0:
                print(0)
                exit()
        tmp.append(li[i] % 2019)
tmp.sort()

print(tmp[0]* tmp[1])

Submission status: Runtime Error

Solution code:
def main():
    import sys
    import math
    input = sys.stdin.readline
 
    l, r = [int(i) for i in input().split()]
    
    minmod = math.inf

    for i in range(l, r):
        for j in range(i+1, r+1):
            temp = (i*j)%2019
            if(temp < minmod):
                minmod = temp
 
            #print("i = {}, j = {}, temp = {}, minmod = {}".format(i, j, temp, minmod))
 
    print(minmod)
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
l,r = map(int,raw_input().split())

now = [0]*2020

for a in range(l,r+1):
  now[a % 2019] = 1
  if now[0] == 1 or (now[3]==1 and now[673]==1):
    print 0
    exit(0)

ans = 2019*2019
for x in range(2019):
  if now[x] == 1:
    for y in range(2019):
      if now[y] == 1 and x != y:
        buf = (x*y)%2019
        if ans > buf:
          ans = buf
print ans

Submission status: Runtime Error

Solution code:
import math
import itertools

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

mods = []

for c in itertools.combinations(range(L, R+1), 2):
    # print(c)
    mods.append((c[0]*c[1]) % 2019)
    
print(min(mods))

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
b = []

for i in range((a[1]-a[0])%2019):
  for j in range(i):
    c = ((i+a[0])%2019)*((j+a[0])%2019)
    b.append(c)
else:
  print(min(b))

Submission status: Runtime Error

Solution code:
l, r = map(int, raw_input().split())

tmp = l*r

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

print tmp

Submission status: Runtime Error

Solution code:
if l % 2019 == 0:
    ans = 0
elif r % 2019 == 0:
    ans = 0
elif l // 2019 == r // 2019:
    ans = 10**6
    l, r = l % 2019, r % 2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans = min( ans, (i*j) % 2019 )


elif l // 2019 != r // 2019:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

l, r = (int(i) for i in input().split())

LR = np.arange(l, r + 1)
LR_mod = LR % 2019
LR = LR[np.argsort(LR_mod)]

print(LR[0] * LR[1] % 2019)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
b = []

for i in range(min(a[1]-a[0],2100)):
  for j in range(i):
    c = ((i+a[0])%2019)*((j+a[0])%2019)
    b.append(c)
else:
  print(min(b))

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

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

def main():
    LR = list(range(L, R+1))
    N = len(LR)
    if N >= 2019:
        ans = 0
    else:
        ansLi = LR[0] % 2019
        ansLj = LR[1] % 2019
        ansL = ansLi * ansLj

        ansRi = LR[-1] % 2019
        ansRj = LR[-2] % 2019
        ansR = ansRi * ansRj

        ans = min(ansL, ansR)

    return ans

print(main())

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())
min_mod = 2019
flg=[0]*2018
flg2=[0]*2018
for i in range(L,R):
    idx=i%2019
    if flg[idx]==0:
        for j in range(i+1,R+1):
            mod  = (i*j)%2019
            if flg2[mod]==1:
                break
            flg2[mod]=1
            if min_mod > mod:
                min_mod=mod
        flg[idx]=1
print(min_mod)

Submission status: Runtime Error

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

a = list(range(L,R+1))

N = len(a)
r = 0
total = []

for l in range(N):
  r = l + 1
  while r < N:
    total.append((a[l]*a[r])%2019)
    r += 1
  if l == r:
    l += 1
    
print(min(total))

Submission status: Runtime Error

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

nanka = MOD/L

r = float('inf')
for i in range(L,min(R+1, L+45)):
    for j in range(i+1, R+1):
        t=i*j
        if t < r:
            r = t
print(r)

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;

int main() {
    long long int l, r;
    cin>>l>>r;
    long long int diff = r - l;
    l = l % 2019;
    r = l + diff;
    long long int ans = LLONG_MAX;
    for(long long int i = l;i<=r;i++){
        for(long long int j = i+1;j<=r;j++){
            ans = min(ans, ((i * j) % 2019));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import functools
L, R = map(int, input().split())
mod = 2019

@functools.lru_cache(maxsize = None)
for i in range(L, R) :
	for j in range(i + 1, R + 1) :
		if((i * j) % 2019 < mod) :
			mod = (i * j) % 2019
		else :
			pass
	if(mod == 0) :
		break
	else :
		pass
	
print(mod)

Submission status: Runtime Error

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

l = l % 2019
r = r % 2019
l = min(l,r)
r = max(l,r)
if r == l:
  print((r*l) %2019)
  exit()
for i in range(l,r+1):
  for j in range(i,r+1):
    if i != j:
      ans += [(i * j) %2019]
      
print(min(ans))

Submission status: Runtime Error

Solution code:



L, R = (int(i) for i in input().split())  


l = L % 2019
r = R % 2019

x = list(range(l, r+1))

if 3 in x and 673 in x: ans = 0
else:

    ans = x[0]*x[1]


print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.arange(L, R+1)

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

a = np.linspace(L, R, R - L + 1) % 2019
a_s = sorted(a)

print(int(a_s[0] * a_s[1]))

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
b = []

for i in range(min(a[1]-a[0],2020)):
  for j in range(i):
    c = ((i+a[0])%2019)*((j+a[0])%2019)
    b.append(c)
else:
  print(min(b))

Submission status: Runtime Error

Solution code:
import sys
L, R = map(int, input().split())

# 1，2番目に小さい数字を入れておく
mins = [2019, 2019]

for i in range(L, R + 1):
    mod = i % 2019
    if mod == 0:
        print(0)
        sys.exit(1)
    if mod < mins[0]:
        mins[0] = mod
    elif mins[0] < mod and mod < mins[1]:
        mins[1] = mod

print((mins[0] * mins[1]) % 2019)

Submission status: Runtime Error

Solution code:
import functools

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

@functools.lru_cache(maxsize = None)
for i in range(L, R) :
	for j in range(i + 1, R + 1) :
		if((i * j) % 2019 < mod) :
			mod = (i * j) % 2019
		else :
			pass
	if(mod == 0) :
		break
	else :
		pass
	
print(mod)

Submission status: Runtime Error

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

l = l % 2019
r = r % 2019
l = min(l,r)
r = max(l,r)
ans = []
for i in range(l,r+1):
  for j in range(i,r+1):
    if i != j:
      ans += [(i * j) %2019]
      
print(min(ans))

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())
mod = 2019

lmod = L % mod
rmod = R % mod

if lmod <= rmod:
    list_ij = sorted(list(range(lmod, rmod + 1)))
    print(list_ij[0] * list_ij[1])
else:
    list_ij = sorted(list(range(lmod, rmod + 1)))
    print(list_ij[0] * list_ij[1])

Submission status: Runtime Error

Solution code:
L, R = map(int,input().split())
L_mod = L%2019
R_mod = R%2019
list =[]
for i in range(L_mod,R_mod,1):
  mod_i = i%2019
  for j in range(i+1,R_mod+1,1):
    mod_j = j%2019
    mod = (mod_i *mod_j)%2019
    list.append(mod)
    
print(min(list))

Submission status: Runtime Error

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

lmod=l%2019
rmod=r%2019

if r-l>=2019:
    print(0)
elif l <= 2019*(r//2019):
    print(0)
else:
    mini = 10**9
    for i in range(lmod,rmod+1):
        for j in range(i+1,rmod+1):
            mini = min(mini,(i*j)%2019)
print(mini)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.arange(L, R+1)

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

Submission status: Runtime Error

Solution code:
import itertools

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

poss = list(range(L,R))

pairs = list(itertools.combinations(poss, 2))

print(min([(p[0]*p[1])%2019 for p in pairs]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

m = [-1]*(r-l+1)

if (r-l+1)>=2019:
    print(0)
else:
    for i in range(r-l+1):
        m[i] = (l+i)%2019
    sm = sorted(m)
    print(sm[0]*sm[1])

Submission status: Runtime Error

Solution code:
if R - L > 2019:
      print(0)
else:
    D = R - L
    L = L % 2019
    R = L + D
    a = 2018
    for i in range(D):
        for j in range(i+1,D+1):
            if (L+i)*(L+j)%2019 < a:
                a =(L+i)*(L+j)%2019
    print(a)

Submission status: Runtime Error

Solution code:
L,R=map(int,input().split())
l1=L//2019
l2=L%2019
r1=R//2019
r2=R%2019
if l1!=r1 or l2==0:
  print(0)
else:
  a = [2020]
  for i in range(l2,r2):
    for j in range(i+1,r2+1):
      c = (i*j)%2019
      a.append(c)
print(min(a))

Submission status: Runtime Error

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

li=[]
cnt=0
for i in range(l, r+1):
  li.append(i%2019)
  if i%2019==0:
    li.sort()
    print((li[0]*li[1])%2019)
    break
else:
  ans=2019
  for index, i in enumerate(li):
    for j in li[index+1:]:
      ans = min(ans, (i*j)%2019)
  print(ans)

Submission status: Runtime Error

Solution code:
n, k = tuple([int(s) for s in input().split()])

n = n % 2019
k = k % 2019

a = n
b = n+1

print(a*b)%2019

Submission status: Runtime Error

Solution code:
l,r=map(int,input().split())
i=0
s=[]
if (r-l)>2019:
    print(0)
else:
    while i!=(r-l)+1:
        s.append(((l+i)%2019))
        i+=1
    s.sort()
print(s[0]*s[1])

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c = 1
cmin = 2018

for i in range(a,b+1):
  c = i % 2019
  if c == 0:
    break
    #iが決定
  if cmin > c:
    cmin = c
    d = cmin +1
    
print(cmin*d)

Submission status: Runtime Error

Solution code:
L,R=map(int,input().split())
M=2019
for i in range(L,R):
    for j in range(i+1,R+1) :
        if (i*j)%2019 < MOD :
            M = (i*j)%2019
print (M)

Submission status: Runtime Error

Solution code:
L, R = (int(i) for i in input().split())  


l = L % 2019
r = R % 2019

x = list(range(l, r+1))

ans = x[0]*x[1]
print(ans)

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())
if L//2019 != R//2019:
    print(0
elif:
    L%2019<= 673 and R%2019 >= 673 and L-R >= 2:
    print(0)
else:
    print(min((L*(L+1))%2019,(R*(R-1)%2019)))

Submission status: Runtime Error

Solution code:
L,R = [int(i) for i in input().split()]
if R-L >= 4038:
    print(0)
else:
    ans = []
    for i in range(L,R+1):
        ans.append(i % mod)
    ans = sorted(ans)
    ans2 = (ans[0]*ans[1])%mod
    print(ans2)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
l, r = map(int, input().split())
mod = 2019
X = [x%mod for x in list(range(l, r+1))]
X.sort()
ans = X[0]*X[1]
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
d = list(map(int, input().split()))
L = d[0]
R = d[1]

if L >= 2019:
    L = L%2019
if R >= 2019:
    R = R%2019

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

print(min(list))

Submission status: Runtime Error

Solution code:
import itertools
L,R=map(int,input().split())
if R-L>=2019:
  print(0)
else:
  MIN=2018  
  list1=list(range(L,R+1))
  list2=list(itertools.combinations(list1,2))
  for i in range(len(list2)):
    a=list2[i][0]*list2[i][1]%2019
    MIN=min(MIN,a)
print(MIN)

Submission status: Runtime Error

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

if R-L > 2019:
    print(0)
else:
    i_mod = 2019
    j_mod = 2019
    for k in range(L,R+1):
        mod = k%2019
        if mod < i_mod:
            j_mod = i_mod
            i_mod = mod
        elif mod < j_mod: #要るかこれ？
            j_mod = mod
print(i_mod*j_mod)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
d = list(map(int, input().split()))
L = d[0]
R = d[1]

if L >= 2019:
    L = L%2019
if R >= 2019:
    R = R%2019

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

print(min(list))

Submission status: Runtime Error

Solution code:
L,R = [int(i) for i in input().split()]
if R-L >= 4038:
    print(0)
else:
    ans = []
    for i in range(L,R+1):
        ans.append(i % mod)
    ans = sorted(ans)
    print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
import sys
import bisect

input = sys.stdin.readline

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

LR = list(range(L, R+1))
N = len(LR)
index = bisect.bisect_left(LR, 2019)
if index == 0:
    i, j = LR[0], LR[1]
elif index == N:
    i, j = LR[-2], LR[-1]
else:
    i, j = LR[index-1], LR[index]

modi = i % 2019
modj = j % 2019
print(modi * modj)

Submission status: Runtime Error

Solution code:
from itertools import combinations
l, r = list(map(int, input().split()))
ans = min(map(lambda x: (x[0]*x[1]) % 2019, combinations(range(l, r+1), 2)))
print(ans)

Submission status: Runtime Error

Solution code:
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(1,r+1):
            if i<j:
                res = min(res,(i*j)%2019)
print(res)

Submission status: Runtime Error

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

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

else:
    array = range(l, r + 1, 1)
    kouho = 2018
    for i in array:
        for j in array:
            if i != j:
                mod = (i * j) % 2019
                if kouho > mod:
                    kouho = mod

print(kouho)

Submission status: Runtime Error

Solution code:
L,R=(int(x) for x in input().split())
L_mod=L%2019
R_mod=R%2019
if L_mod>=R_mod:
    print(0)
else:
    print(L_mod*(L_mod+1s))

Submission status: Runtime Error

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

from collections import defaultdict

d = defaultdict(int)

for i in range(L,R+1):
  d[i%2019] += 1
  if d[0]>0:
    break

cnt = 0a
ans = list()
for k,v in sorted(d.items()):
  _v = v
  
  while _v > 0:
    cnt +=1
    ans += [k]
    _v -= 1
    if cnt >=2:
      print((ans[0]*ans[1])%2019)
      break
  if cnt >=2:
    break

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())
mod = 2019

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

    # a, b = left, left + 1
    # c, d = right, right - 1
    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[1]))

    # print(score_sorted)

    if score_sorted[0][1] >= 2:
        a, b = score_sorted[0][0]
    else:
        a, b, = score_sorted[0][0], score_sorted[1][0]

    print((a * b)% mod)






if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
L,R=map(int,input().split())
mod=2019

if R>=L+2020:
    print(0)
else:
    D=list(range(L,R+1))

    L=len(D)

    ANS=1<<40

    for i in range(L-1):
        for j in range(i+1,L):
            ANS=min(ANS,D[i]*D[j]%mod)

print(ANS)