peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
a, b, c, d = list(map(int, input().split()))
if d <= a:
    print(0)
    exit()
if a <= c <= b:
    if b >= d:
        print(d - c)
        exit()
    else:
        print(b - c)
        exit()
elif c < a:
    if b >= d:
        print(d - a)
        exit()
    else:
        print(b - a)
        exit()
else:
    print(0)
# Judge status: Accepted
n = input()
digit = [int(n[-(i + 1)]) for i in range(len(n))]
digit.append(0)

ans = 0
for i in range(len(digit)):
  if digit[i] > 5 or (digit[i] == 5 and digit[i + 1] >= 5):
    ans += 10 - digit[i]
    digit[i] = 0
    digit[i + 1] += 1
  else:
    ans += digit[i]
    digit[i] = 0

print(ans)
# Judge status: Wrong Answer
a, b = map(int, input().split())
print(a + b - 1// b)
# Judge status: Accepted
S = input()
T = input()
 
ls = len(S)
lt = len(T)
left = -1
 
for i in range(ls-lt+1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
       left = i
if left == -1:
    ans = "UNRESTORABLE"
else:
    ans = S[:left]+T+S[left+lt:]
    ans = ans.replace("?", "a")
print(ans)
# Judge status: Wrong Answer
d, n = map(int, input().split())
a = map(int, input().split())
remaining = d - sum(a)
print(d if d >= 0 else -1)
# Judge status: Accepted
import math
NN = int(input())

def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res


a = power_func(10, NN , 10 ** 9 + 7)
b = power_func(9 , NN , 10 ** 9 + 7)
c = power_func(8 , NN , 10 ** 9 + 7)

x = ((a - b - b + c) + 10 ** 9 + 7 + 10 ** 9 + 7 ) % (10 ** 9 + 7)
print(x)
# Judge status: Accepted
x = int(input())
#6,5,6,5を繰り返す
if x % 11 == 0:
    ans = x // 11 * 2
elif 0 < x % 11 <= 6:
    ans = x // 11 * 2 + 1
else:
    ans = x // 11 * 2 + 2
print(ans)
# Judge status: Accepted
def resolve():
    H,N=(int(i) for i in input().split())
    magics=[[int(i) for i in input().split()] for j in range(N)]
    mx=2**31
    dpt=[mx for i in range(H+1)]
    dpt[-1]=0
    for i in range(H,0,-1):
        
        current=dpt[i]
        if current> dpt[0]:
            continue
        for m in magics:
            dpt[max(0,i-m[0])]=min(dpt[max(0,i-m[0])],current+m[1])
    print(dpt[0])

if __name__ == "__main__":
    resolve()
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
x=0
y=sum(a)
ans=10**15
for i in range(n-1):
    x+=a[i]
    y-=a[i]
    ans=min(ans,abs(x-y))
print(ans)
# Judge status: Wrong Answer
hours_p_distance, hours_q_distance, hours_r_distance = map(int, input().split())

root_p_q = hours_p_distance + hours_q_distance
root_p_r = hours_p_distance + hours_r_distance
root_q_r = hours_q_distance + hours_r_distance

print(min(root_p_q, root_q_r, root_q_r))
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
total = 0
for i in a:
    total ^= i

ans = [0] * N
for i in range(N):
    ans[i] = total ^ a[i]

print(*ans)
# Judge status: Accepted
from functools import reduce
from fractions import gcd
def lcm(x,y):return x*y//gcd(x,y)
def lcmm(l):return reduce(lcm,l)
a = int(input())
List=list(map(int,input().split()))
b = lcmm(List)
c = 0
for i in range(a):
  c = c + b // List[i]
print(c%1000000007)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())

if A == B:
    if B == C:
        print('No')
    else:
        print('Yes')
elif A == C:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import numpy as np

n = int(input())
A = np.array(list(map(int,input().split())))

balls = np.array([0]*(n+1))

for i in range(1,n+1):
    s = sum(balls[n+1-i::n+1-i])
    if (s%2 and not A[-i]) or (A[-i] and not s%2):
        balls[-i] += 1

#print(balls)

ans = np.where(balls==1)[0].tolist()
if sum(balls):
    print(sum(balls))
    print(*ans)
else:
    print(0)
# Judge status: Accepted
N=int(input())
a=list(map(int,input().split()))

def calc_cost(x,avg):
  return (x-avg)**2

avg = sum(a)//N

delta = [-2,-1,0,1,2]

ans=10**20
for i in range(len(delta)):
  val = sum(map(lambda x:calc_cost(x,avg+delta[i]),a))
  ans = min(ans,val)
  
print(ans)
# Judge status: Accepted
MOD = pow(10,9)+7
N = int(input())
now = 1
for i in range(1,N+1):
  now = now*i%MOD
print(now)
# Judge status: Wrong Answer
N = int(input())

candy=N*(1+N)/2
print(candy)
# Judge status: Accepted
A, B = map(int, input().split())
time=A+B
ans=time%24
print(ans)
# Judge status: Wrong Answer
A,B,C=map(int,input().split())
X=(10*A+B)+C
Y=A+(10*B+C)
print(max(X,Y))
# Judge status: Accepted
N = int(input())

lst = []
i = 1
sm = 0
while sm < N:
  lst.append(i)
  sm += i
  i += 1
  
if sm == N:
  for l in lst:
    print(l)
else:
  a = sm - N
  lst.remove(a)
  for l in lst:
    print(l)
# Judge status: Accepted
import sys
input =sys.stdin.readline

N,X,T=(int(x) for x in input().rstrip('\n').split())
if N%X==0:
  print(T*(N//X))
else:
  print(T*(N//X)+T)
# Judge status: Wrong Answer
import math
K = int(input())
ans = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      ans += math.gcd(a+1, math.gcd(b+1, c+1))
print(ans)
# Judge status: Accepted
s = sorted(input())
t = sorted(input(),reverse=True)
flag = -1
i = 0



while(i < min(len(s),len(t))):
  if s[i] > t[i]:
    flag = -1
    break
  elif s[i] < t[i]:
    flag = 1
    break
  else:
    if (i+1 == len(s)) & (len(s) != len(t)):
      flag = 1
      break
    i += 1

if flag == 1: print("Yes")
else: print("No")
# Judge status: Accepted
A, B = map(int,input().split())
if (0<=A<=9) and (0<=B<=9):
  print(A*B)
else:
  print(-1)
# Judge status: Wrong Answer
N,K = map(int, input().split())
i = 0
while K**i < N:
    i+=1
else:
    print(i)
# Judge status: Accepted
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
#print(a,b,c)
cnt = 0
for i in range(n):
    d = bisect.bisect_left(a,b[i])
    e = bisect.bisect_right(c,b[i])
    cnt += d*(n-e)
print(cnt)
# Judge status: Accepted
N,M,K=map(int,input().split(' '))
for i in range(N+1):
    for j in range(M+1):
        if i*j+(N-i)*(M-j)==K:
            print('Yes')
            exit()
print('No')
# Judge status: Accepted
H, N = map(int, input().split())

attack_list = []
mp_list = []
for i in range(N):
    a, m = map(int, input().split())
    attack_list.append(a)
    mp_list.append(m)

inf = float('inf')
max_hp = H+max(attack_list)
dp = [inf for i in range(max_hp)]
dp[0] = 0

for i in range(H):
    for j in range(N):
        next_i = i + attack_list[j]
        dp[next_i] = min(dp[next_i], dp[i] + mp_list[j])

print(min(dp[H:max_hp+1]))
# Judge status: Accepted
s = list(input())
j= 2
count = 0
if not s[0] == 'A':
    print('WA')
    exit()

for i in s[2:-1]:
    if i == 'C':
        count += 1
        tmp = j
    j += 1
if not count == 1:
    print('WA')
    exit()

del s[0]
del s[tmp-1]
s = ''.join(s)

if s.islower():
    print('AC')
    exit()

print('WA')
# Judge status: Wrong Answer
N, M = map(int, input().split())
from fractions import gcd
print(gcd(M//N, M-((M//N)*(N-1))))
# Judge status: Wrong Answer
s = int(input())

if s % 10 == 9 or s / 10 == 9:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
S = list(input())

S = list(map(int, S))

if S[0] == S[1] == 0 or S[2] == S[3] == 0 or (S[0] > 1 and S[2] > 1):
    print("NA")
elif S[2] > 1 or (S[2] == 1 and S[3] > 2):
    print("MMYY")
elif S[0] > 1 or (S[0] == 1 and S[1] > 2):
    print("YYMM")
else:
    print("AMBIGUOUS")
# Judge status: Accepted
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()


arr = []
for i in range(1,len(x)):
    arr.append(x[i] - x[i-1])

    
arr.sort()
arr.reverse()
print(x[-1] - x[0] - sum(arr[:n-1]))
# Judge status: Accepted
x=int(input())
List=[]
counter=0
for i in range(x):
  List.append(list(map(int,input().split())))
for i in range(len(List)):
  if List[i][0]==List[i][1]:
    counter+=1
  else:
    counter=0
  if counter ==3:
    print("Yes")
    break
if counter<3:
  print("No")
# Judge status: Accepted
a,b,c,x,y=map(int,input().split())
res1=a*x+b*y
if x>y:
    res2=c*2*y+a*(x-y)
else:
    res2=c*2*x+b*(y-x)
res3=c*2*max(x,y)
print(min(res1,res2,res3))
# Judge status: Accepted
N=int(input())
P=list(map(int,input().split()))
cnt,minimum=0,max(P)
for i in range(N):
    if P[i]<=minimum:
        cnt+=1
        minimum=P[i]
print(cnt)
# Judge status: Accepted
import sys
a = []
for l in sys.stdin:
    a.append(int(l))
if (max(a[:-1]) - min(a[:-1])) <= a[-1]:
  print('Yay!')
else:
  print(':(')
# Judge status: Accepted
s =input()
n = len(s)
k = int(input())

for i in range(k):
    if s[i] == '1':
        continue
    else:
        print(int(s[i]))
        break
else:
    print(1)
# Judge status: Accepted
# coding:utf-8
x = int(input())

for i in range(-120, 120):
    for j in range(-120, 120):
        if i**5 - j**5 == x:
            print(i, j)
            exit()
# Judge status: Accepted
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(len(l)-2):
    for j in range(i+1,len(l)-1):
        for k in range(j+1,len(l)):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and 2 * max(l[i],l[j],l[k]) < l[i]+l[j]+l[k]:
                ans += 1
print(ans)
# Judge status: Wrong Answer
x, y = map(int, input().split())
a = list(map(int, input().split()))
print("yes" if sum(a) >= x else "no")
# Judge status: Accepted
n, x = map(int, input().split())
l = list(map(int, input().split()))
count = 1
point = 0

for i in range(n):
  point += l[i]
  if point <= x:
    count += 1
  else:
    break

print(count)
# Judge status: Accepted
W, H, N = list(map(lambda n: int(n), input().split(" ")))
xmin = [0] # a = 1
xmax = [W] # a = 2
ymin = [0] # a = 3
ymax = [H] # a = 4
for i in range(N):
  tmp = input().split(" ")
  if tmp[2] == "1":
    xmin.append(int(tmp[0]))
  elif tmp[2] == "2":
    xmax.append(int(tmp[0]))
  elif tmp[2] == "3":
    ymin.append(int(tmp[1]))
  elif tmp[2] == "4":
    ymax.append(int(tmp[1]))

S = max([min(xmax) - max(xmin), 0]) * max([min(ymax) - max(ymin), 0])
print(S)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

direc = ""
ans = 0
for i in range(N-1):
  d = A[i+1] - A[i]
  if direc == "":
    if d > 0:
      direc = "up"
    elif d < 0:
      direc = "down"
  else:
    if direc == "up" and d < 0:
      ans += 1
      direc = ""
    elif direc == "down" and d > 0:
      ans += 1
      direc = ""
print(ans+1)
# Judge status: Accepted
N,K=map(int,input().split())
h=[int(input()) for _ in range(N)]
h.sort()
ans=10**9
for i in range(N-K+1):
    ans=min(ans,h[i+K-1]-h[i])
print(ans)
# Judge status: Wrong Answer
N = input()

N = list(N)

if N[2] == N[3] and N[4] == N[5] and N[3] != N[4] :
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import itertools as it

S = input()
R = [(k,len(list(g))) for k,g in it.groupby(S)]
#print(R)

tot = 0
n = 0
for k,val in R:
  if k == "<":
    n = val
    tot += n*(n+1)/2
  elif k == ">":
    tot += max(0,val-n)
    tot += val*(val-1)/2
    n = 0
  
print(int(tot))
# Judge status: Accepted
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b,a%b)

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


n = int(input())
ans = 1
for i in range(n):
    tmp = int(input())
    ans = lcm(ans, tmp)
print(ans)
# Judge status: Accepted
A,B,T = map(int,input().split())
print(T//A*B)
# Judge status: Accepted
from math import gcd, ceil
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i // 2 for i in a]
l = 1
for i in a:
    l *= i // gcd(l, i)
for i in a:
    if l // i % 2 == 0:
        print(0)
        exit()
#print(ceil((m // l) / 2))
print((m//l+1)//2)
# Judge status: Wrong Answer
N = int(input())

def Main(N):
    B = 43
    ans = [0]*(6*B*B+10)
    for i in range(1, B+1):
        for j in range(1, B+1):
            for k in range(1, B+1):
                a = i*i+j*j+k*k+i*j+j*k+k*i
                ans[a] += 1
    return ans

            
        
                    
out = Main(N)
for i in range(1, N+1):
    print(out[i])
# Judge status: Accepted
N = int(input())
L = list(map(int, input().split()))

if max(L) * 2 < sum(L):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
s=input()
t=input()
sl=len(s)
tl=len(t)
kotae=tl
for i in range(0,sl-tl+1):
  x=s[i:i+tl]
  b=0
  for j in range(tl):
    if x[j]!=t[j]:
      b+=1
  if b<kotae:
    kotae=b
print(kotae)
# Judge status: Wrong Answer
X = int(input())

if X < 1000:
  print('ABC' + f'{X:03}')
else:
  X = X % 999
  print('ABD' + f'{X:03}')
# Judge status: Wrong Answer
a = list(input())
a.sort()
print(a)
b = "".join(a)
if b == "abc":
    print("Yes")
else:
    print("No")
# Judge status: Accepted
def recta():
    r = int(input())
    area1 = r**2
    print(area1)


if __name__ == "__main__":
    recta()
# Judge status: Accepted
s = list(input())
flg = True

if s[0] != "A":
    flg = False

count = 0
for i in s[2:-1]:
    if i == "C":
        count += 1
if count != 1:
    flg = False

n = 0
for i in s:
    if i.isupper():
        n += 1
if n != 2:
    flg = False

if flg:
    print("AC")
else:
    print("WA")
# Judge status: Accepted
a=input()

if a =="ABC":
    print('ARC')
else:
    print('ABC')
# Judge status: Accepted
import sys

n, *aaa = map(int, sys.stdin.buffer.read().split())

ans = 0
for i in range(n - 1):
    d, m = divmod(aaa[i], 2)
    ans += d
    if m and aaa[i + 1]:
        aaa[i + 1] -= 1
        ans += 1
ans += aaa[-1] // 2
print(ans)
# Judge status: Accepted
T = list(input())
for i in range(len(T)):
    if T[i] == "?":
        T[i] = "D"
print("".join(T))
# Judge status: Accepted
import math
n,d = map(int,input().split())
a = [list(map(int, input().split())) for i in range(n)]
count = 0

for i in range(n-1):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (a[i][k] - a[j][k])**2
        if math.sqrt(dis) == int(math.sqrt(dis)):
            count += 1
print(count)
# Judge status: Wrong Answer
ans=1
a,b=map(int,input().split())
if a<0 and b>0:
    print ("Zero")
else:
    if a>0 and b>0:
        print ("Positive")
    else:
        print ("Negative")
# Judge status: Wrong Answer
list=[1, 1, 1, 1, 1]
for i in range(1, 7):
  list.append(6**i)
for j in range(1, 7):
  list.append(9**i)
sorted(list, reverse=True)
N=int(input())
count=0
for i in list:
  if i <= N:
    N=N-i
    count+=1
# Judge status: Wrong Answer
N = input()

if N[0] == 9 or N[1] == 9:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
a,b,c=map(int,input().split())
if c-a-b>0 and 4*a*b<(c-a-b)**2:
    print('Yes')
else:
    print("No")
# Judge status: Wrong Answer
user_input=input()
i=len(user_input)-1
j=int(user_input)
number=0
while i>=0:
        number+=int(user_input[i])
        i=i-1
if number%9==0:
    print("Yes")
else :
    print("no")
# Judge status: Accepted
import collections

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

ans=0
dic=collections.Counter(A)
keys=list(dic.keys())
values=list(dic.values())


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

for j in A:
    ANS=ans
    num=dic[j]
    ANS=ANS-(num-1)
    print(ANS)
# Judge status: Accepted
N = int(input())
S = input()
T = input()

best = float('inf')
for i in range(len(T)+1):
    s = S + T[i:]
    if s[::-1][:N][::-1] == T:
        best = min(best, len(s))

print(best)
# Judge status: Accepted
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
N = len(T)
ans = 0
for i in range (0,N-K):
  if str(T[i]) == str(T[i+K]):
    T = T[:i+K] + 'a' + T[i+K+1:]
for i in range (0,N):
  if str(T[i]) == "r":
    ans = ans + P
  elif str(T[i]) == "s":
    ans = ans + R
  elif str(T[i]) == "p":
    ans = ans + S
print(ans)
# Judge status: Wrong Answer
#!/usr/bin/env python3
N = int(input()) 

count = 0
result = 'No'
for i in range(1, N):
    d1, d2 = map(int, input().split())
    if(d1 == d2):
        count += 1
    else:
        count = 0
    if(count == 3):
        result = 'Yes'

print(result)
# Judge status: Accepted
n = int(input())
print("ABC" if n <= 999 else "ABD")
# Judge status: Wrong Answer
k = int(input())
a, b = map(int, input().split())
for i in range(a, b+1):
  if k % i == 0:
    print("OK")
  else:
    print("NG")
# Judge status: Wrong Answer
N,A,B=map(int,input().split())

if A%2==B%2:
    print(int(abs(A-B)/2))
else:
    print(min(int((N-A-B)/2),int((A+B-1)/2)))
# Judge status: Wrong Answer
N = int(input())
A = int(input())

if N % 500 <= A:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
import fractions
a,b = map(int,input().split())

g = a*b/fractions.gcd(a,b)
print(g)
# Judge status: Wrong Answer
a,b=map(int,input().split())
a+=b;
if a>24:
    print(a-24)
else :
    print(a)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
n = int(input())
b = list(map(int,input().split()))

b.sort(reverse=True)
ret = 0
from collections import deque
stack_deque = deque([])
if n == 1:
    print(0)
    import sys
    sys.exit()
if n == 2:
    print(b[1])
    import sys
    sys.exit()

stack_deque.append(b[1])
stack_deque.append(b[1])
ret = b[0]
for bi in b[2::]:
    ret += stack_deque.popleft()
    stack_deque.append(bi)
    stack_deque.append(bi)
print(ret)
# Judge status: Wrong Answer
#!/usr/bin/env python3

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [None] * n
    for i in range(n - 1):
        allxor = a[i] ^ a[i + 1]
    for i in range(n):
        ans[i] = allxor ^ a[i]
    print(*ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
def solver():
	N,W = map(int, input().split())
	item = []
	for i in range(N):
		item.append(list(map(int, input().split())))
	dp = [0 for _ in range(W+1)]

	for i in range(0,N):
		for j in range(W, item[i][0]+1, -1):
			if(j-item[i][0] >= 0):
				dp[j] = max(dp[j], dp[j-item[i][0]]+item[i][1])
	print(dp[W])

solver()
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

cumsum = [0]
for i in range(N):
    cumsum.append(cumsum[-1] + A[i])

tmp_x = -1
tmp_x_diff = -1
for i in range(N - 1):
    sum1 = cumsum[i + 1]
    sum2 = cumsum[-1] - cumsum[i + 1]
    diff = abs(sum2 - sum1)
    if tmp_x_diff == -1 or diff < tmp_x_diff:
        tmp_x = i
        tmp_x_diff = diff
print(tmp_x_diff)
# Judge status: Accepted
def main():
    N = int(input())
    A = [int(input()) for i in range(5)]
    m = min(A)
    print(4 + (N + m - 1)//m)


if __name__ == '__main__':
    main()
# Judge status: Accepted
A, B, C = map(int, input().split())

lst = [A, B, C]
lst.sort(reverse = True)
ctr = 0

while lst[0] > lst[1]:
    lst[1] += 1
    lst[2] += 1
    ctr += 1

while lst[1] > lst[2]:
    lst[2] += 2
    ctr += 1

if lst[2] > lst[1]:
    ctr += 1

print(ctr)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

movements = ['bull' if A[i+1]>A[i] else 'bear' for i in range(N-1)]
movements.append('bear')
movements.insert(0, 'bear')

money = 1000
stock = 0
for i in range(1, N+1):
    if movements[i-1] == 'bear' and movements[i] == 'bull':
        stock = money // A[i-1]
        money = money % A[i-1]
    elif stock > 0:
        money += A[i-1] * stock
        stock = 0
    else:
        pass

print(money)
# Judge status: Accepted
r, g, b = map(int, input().split())
print('YES' if (10 * g + b) % 4 == 0 else 'NO')
# Judge status: Accepted
A = set(map(int, input().split()))
print(len(A))
# Judge status: Wrong Answer
R,G,B =map(str,input().split())
RGB=R+G+B
if int(RGB) %4 ==0:
	print('Yes')
else:
	print('No')
# Judge status: Accepted
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
for i in range(n):
    sa[i+1] = sa[i] + a[i]
sb = [0] * (m+1)
for i in range(m):
    sb[i+1] = sb[i] + b[i]

ans = 0
for i in range(n+1):
    if sa[i] > k:
        break
    bi = bisect.bisect_right(sb, k-sa[i])-1
    ans = max(ans, i + bi)
print(ans)
# Judge status: Accepted
X=int(input())

Acoin=X//500
Bcoin=(X-500*Acoin)//5

print(Acoin*1000+Bcoin*5)
# Judge status: Wrong Answer
N = list(map(int,input().split()))
N.sort()
if N[0] == 5:
    if N[1] == 5:
        if N[2] == 7:
            print("Yes")
            exit()
print("No")
# Judge status: Accepted
L,R=map(int,input().split())
if R-L+1>=671:
    print(0)
else:
    m=2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            x=(i*j)%2019
            if x<m:
                m=x
    print(m)
# Judge status: Accepted
n, m = map(int, input().split())
all = {int(i) for i in range(1, m + 1)}
for _ in range(n):
    k, *i_th = map(int, input().split())
    all &= set(i_th)
print(len(all))
# Judge status: Wrong Answer
c1 = list(input())
c2 = list(input())

if c1[0] == c2[-1] and c1[-1] == c2[0] and c1[2] == c2[2]:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
now = A[0]
kind = 0
ans = 0
for i in range(1,N):
    if kind == 0:
        if now < A[i]:
            kind = 1
        elif now > A[i]:
            kind = 2
    elif kind == 1: # 増加
        if now > A[i]:
            ans += 1
            kind = 0
    else: # 減少
        if now < A[i]:
            ans += 1
            kind = 0
    now = A[i]
print(ans+1)
# Judge status: Accepted
a,b,c=map(int,input().split())
if(a+b+c<=21):
    print('win')
else:
    print('bust')
# Judge status: Accepted
n = input()
 
d = [ [0] * 10 for _ in range(10) ]
for i in range( 1, int( n ) + 1 ):
  k = str(i)
  d[ int( k[ 0 ])][ int( k[ -1 ])] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += d[i][j] * d[j][i]
print(ans)
# Judge status: Wrong Answer
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(k)

s = 0
for i in range(n):
    s += a[i + 1] - a[i]
ans = s
for i in range(n):
    ans = min(ans, s - a[i + 1] - a[i])

print(ans)
# Judge status: Wrong Answer
N=int(input())
A=list(map(int,input().split()))


if len(list(set(A)))==1:
    print(0)
    exit()

f=[True]*(max(A)+1)
chk=[0]*(max(A)+1)

for a in A:
    chk[a]+=1

for a in A:
    cnt=2
    while a*cnt<=max(A):
        f[a*cnt]=False
        cnt+=1
ans=0
for a in A:
    if f[a]==True and chk[a]==1:
        ans+=1
print(ans)
# Judge status: Accepted
N = int(input())
x = 111
while x < N:
    x += 111
print(x)
# Judge status: Accepted
a,b,c,d = map(int,input().split())
ans = "Yes"
if abs(a-c)>d:
    if not (abs(a-b)<=d and abs(b-c)<=d):
        ans = "No"
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
import itertools


def main():
    L, R = map(int, input().split())
    if R - L > 2017:
        print(0)
        return
    xs = [n % 2019 for n in range(L, R + 1)]
    ans = 2018
    for i, j in itertools.combinations(xs, 2):
        tmp = (i * j) % 2019
        if tmp == 0:
            ans = 0
            break
        else:
            if tmp < ans:
                ans = tmp

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n,m = map(int, input().split())

s = int((n + m) * (n + m -1) / 2)
s -= n * m

print(s)
# Judge status: Wrong Answer
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
def check(i, j):
  d2 = 0
  for k in range(d):
    d2 += (x[i][k] * x[j][k]) ** 2
  for j in range(d2):
    if j ** 2 > d2:
      return False
    if j ** 2 == d2:
      return True
  return False

for i in range(n):
  for j in range(i + 1, n):
    if check(i, j):
      ans += 1

print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split(" ")))
a.sort()
ai = a.pop()
aj = a[0]
diff = abs(ai - 2 * aj)


for i in range(1, len(a)):
    if diff > abs(ai - 2 * a[i]):
        aj = a[i]
        diff = abs(ai - 2 * a[i])
print(ai, aj)
# Judge status: Wrong Answer
N = int(input())
pl = list(map(int, input().split()))

cnt = 0
for i in range(1,N):
    if pl[i-1] == i:
        a = pl[i - 1]
        pl[i - 1] = pl[i]
        pl[i] = a
        cnt += 1
    if pl[N-1] == N:
        cnt += 1
print(cnt)
# Judge status: Accepted
N, K = list(map(int, input().split()))
A = list(map(lambda x: int(x) - 1, input().split()))

v = [A[:]]
now = 0
for i in range(60):
    v.append([v[i][v[i][j]] for j in range(N)])
    if K>>i & 1:
        now = v[i][now]
print(now + 1)