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

n,m,q = map(int, input().split())
a,b,c,d = [],[],[],[]
for i in range(q):
  ai,bi,ci,di = map(int, input().split())
  a.append(ai)
  b.append(bi)
  c.append(ci)
  d.append(di)

ans = 0
for i in range(1<<q):
  score = 0
  A = [0]*(n+1)
  for j in range(q):
    if (i>>j)&1 == 1:
      A[b[j]] = A[a[j]] + c[j]
  for j in range(q):
    if A[b[j]] - A[a[j]] == c[j]:
      score += d[j]
  if score > ans:
    ans = score
print(ans)

### FIXED CODE ###

n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
a,b,c,d = [],[],[],[]
for i in range(q):
  a.append(abcd[i][0])
  b.append(abcd[i][1])
  c.append(abcd[i][2])
  d.append(abcd[i][3])

def score(A):
  tmp = 0
  for ai, bi, ci, di in zip(a, b, c, d):
      if A[bi] - A[ai] == ci:
          tmp += di
  return tmp

def dfs(A):
  if len(A)==n+1:
    return score(A)
  ans = 0
  for i in range(A[-1],m):
    A.append(i)
    ans = max(ans,dfs(A))
    A.pop()
  return ans

print(dfs([0]))
### BUGGY CODE ###

n = int(input())
a = [sorted(input()) for i in range(n)]
b = []
ans = 0
for i in range(n) :
    x = ''.join(a[i])
    if x in b :
        ans += b.count(x)
        b.append(x)
    else :
        b.append(x)
print(ans)

### FIXED CODE ###

n = int(input())
a = [''.join(sorted(input())) for i in range(n)]
ans = 0
count = 0
a.sort()
for i in range(1,n) :
    if a[i] == a[i-1] :
        count += 1
        ans += count
    else :
        count = 0
print(ans)
### BUGGY CODE ###

L,R = map( int,input().split() )
ans = ( L * (L+1) ) % 2019  
for i in range(L,R):
    if ans == 0:
        break
    j = i + 1
    a = ( i * j ) % 2019
    ans = min(a, ans)
    plus = i % 2019
    while(True):
        over = int( ( 2019 - a ) / plus )
        j = j + over
        if j >= R:
            break
        a = ( i * j) % 2019
        ans = min(a,ans)
print(ans)

### FIXED CODE ###

import math
L,R = map( int,input().split() )
ans = ( L * (L+1) ) % 2019  
for i in range(L,R):
    if ans == 0:
        break
    j = i + 1
    a = ( i * j ) % 2019
    ans = min(a, ans)
    plus = i % 2019
    while(True):
        over = math.ceil( ( 2019 - a ) / plus )
        j = j + over
        if j > R:
            break
        a = ( i * j) % 2019
        ans = min(a,ans)
        if ans == 0:
            break
print(ans)
### BUGGY CODE ###

import copy
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=np.array(A)

MAX=A[0]
MIN=0
MID=(MAX+MIN+1)//2
#print(MID)
for i in range(100):
    B=copy.deepcopy(A)
    B[0]-=MID
    B[N-1]-=MID
    #print(B)
    for j in range(N):
        B[(j+1)%N]-=B[j]
        B[j]=0
    #print(B)
    if B[0]==0:
        C=copy.deepcopy(A)
        ANS=[0 for i in range(N)]
        C[0]-=MID
        C[N-1]-=MID
        ANS[0]+=MID*2
        #ANS[N-1]+=MID
        for j in range(N):
            C[(j+1)%N]-=C[j]
            ANS[(j+1)%N]+=C[j]*2
            #ANS[j]+=C[j]
            C[j]=0
            #print(C)
            #print(ANS)
        ans=str(ANS[0])
        for i in range(1,len(ANS)):
            ans+=" "+str(ANS[i])
        print(ans)
        exit()
    elif B[0]<0:
        MIN=MID
        if i%2==0:
            MID=(MIN+MAX)//2
        else:
            MID=(MIN+MAX+1)//2
    elif B[0]>0:
        MAX=MID
        if i%2==0:
            MID=(MIN+MAX)//2
        else:
            MID=(MIN+MAX+1)//2
        
    

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
n=0
for i in range(1,N):
    B.append(A[i]-B[-1])
B.append(A[0]-B[-1])
#print(B)
X=(B[0]-B[-1])//2
Y=[X]
Z=[X*2]
for i in range(N-1):
    Y.append(A[i]-Y[i])
    Z.append(Y[-1]*2)
print(*Z)
### BUGGY CODE ###


import heapq
import collections
from collections import deque

n = int(input())
ab = []
visit = [-1 for _ in range(n+1)]
tree = [[]  for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int,input().split())
    ab.append([a, b])
    tree[a].append(b)
    tree[b].append(a)

colors = [ [-1] * (n + 1)  for _ in range(n + 1)] # abの色を格納
visit[1]=1

q = deque([(1,0)]) #V,color のtuple
K = 0
while q:
    v,from_color = q.popleft()
    c = 1
    for next_v in tree[v]:
        if visit[next_v] == -1:
            visit[next_v] = 1
            if c == from_color:
               c += 1
            colors[v][next_v] = colors[next_v][v] = c
            q.append((next_v,c))
            c += 1
anss = []
K = 0
for temp in ab:
    a,b = temp
    K = max(K, colors[a][b])
    anss.append(colors[a][b])

print(K)
for c in anss:
    print(c)





# for k,v in di:
#     color = max(colors,len(v))


### FIXED CODE ###


import heapq
import collections
from collections import deque

n = int(input())
ab = []
visit = [-1 for _ in range(n+1)]
tree = [[]  for _ in range(n+1)]
colors = {}
for i in range(n-1):
    a, b = map(int,input().split())
    ab.append((a, b))
    tree[a].append(b)
    tree[b].append(a)
    colors[(a,b)] = -1
    colors[(b,a)] = -1

# abの色を格納
visit[1]=1

q = deque([(1,0)]) #V,color のtuple
K = 0
while q:
    v,from_color = q.popleft()
    c = 1
    for next_v in tree[v]:
        if visit[next_v] == -1:
            visit[next_v] = 1
            if c == from_color:
               c += 1
            colors[(v,next_v)] = colors[(next_v,v)] = c
            q.append((next_v,c))
            c += 1
anss = []
K = 0
for temp in ab:
    a,b = temp
    K = max(K, colors[(a,b)] )
    anss.append(colors[(a,b)])

print(K)
for c in anss:
    print(c)





# for k,v in di:
#     color = max(colors,len(v))
### BUGGY CODE ###

S = [i for i in input()]
ans = 0
c = 0
while S[0] == 'W':
    S = S[1:]
for i,s in enumerate(S):
    if s == 'W':
        ans = ans +i -c
        c += 1

print(ans)


### FIXED CODE ###

S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)
### BUGGY CODE ###

N=int(input())
a=list(map(int,input().split()))
b=[0]*N
c=[]
cnt=0
for i in range(1,N+1)[::-1]:
  if sum([x for x in b if x%i==0])%2 != a[i-1]:
    a[i-1]=1
    c.append(i)
    cnt+=1
print(cnt)
if len(c)>0:
  print(*c,sep='\n')

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
b=[0]*N
c=[]
cnt=0
for i in range(1,N+1)[::-1]:
  if sum(b[i-1::i])%2 != a[i-1]:
    b[i-1]=1
    c.append(i)
    cnt+=1
print(cnt)
if len(c)>0:
  print(*c,sep='\n')
### BUGGY CODE ###

# input
N, M, K = map(int, input().split())

Frends = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a < b:
        Frends[a].append(b)
    else:
        Frends[b].append(a)

Blocked = [[] for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if c < d:
        Blocked[c].append(d)
    else:
        Blocked[d].append(c)

# process
# 友人グループを作成
fg = []
for i in range (N):
    fs = Frends[i]
    for f in fs:
        t = -1

        j = 0
        fglen = len(fg)
        while j < fglen:
            g = fg[j]
            if i in g and f in g:
                if t < 0:
                    t = j              
                else:
                    fg[t] = fg[t] | g
                    fg.pop(j)
                    fglen -= 1
            elif not (i in g or f in g):
                j += 1
                continue
            else:
                if t < 0:
                    if i in g:
                        g.add(f)
                    else:
                        g.add(i)

                    t = j
                else:
                    fg[t] = fg[t] | g
                    fg.pop(j)
                    fglen -= 1
            j += 1

        if t < 0:
            fg.append(set([i, f]))

# 友人候補を抽出、カウント
cand = [0 for _ in range(N)]
for i in range(N):
    for g in fg:
        if i in g:
            for f in g:
                if i < f and not f in Frends[i] and not f in Blocked[i]:
                    cand[i] += 1
                    cand[f] += 1

# output
#print(fg)
print(" ".join(map(str, cand)))


### FIXED CODE ###

# input
N, M, K = map(int, input().split())

Friends = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Friends[a].add(b)
    Friends[b].add(a)

Blocked = [set() for _ in range(N)]
for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    Blocked[c].add(d)
    Blocked[d].add(c)

# process
# 友人グループを作成
checked = set()
ans = [0]*N

for i in range (N):
    if i in checked:
        continue
    
    fg = set()

    stack = list(Friends[i])
    while stack:
        f = stack.pop()
        if f in checked:
            continue

        checked.add(f)
        fg.add(f)
        stack.extend(Friends[f])

    for f in fg:
        ans[f] += len(fg)-1-len(fg&(Friends[f]|Blocked[f]))

# output
print(" ".join(map(str, ans)))
### BUGGY CODE ###

from collections import Counter

def cc(c):
    if c<2: return 0
    return int(c*(c-1)/2)

n=int(input())
a=[int(A) for A in input().split()]

ball_cnt = dict(Counter(a))
for k in range(n):
    cnt=0
    for key, value in ball_cnt.items():
        if a[k]==key:
            cnt+=cc(value-1)
        else:
            cnt+=cc(value)
    print(cnt)

### FIXED CODE ###

from collections import Counter
n=int(input())
a=[int(A) for A in input().split()]

cnt=Counter(a)
s=sum([c*(c-1)//2 for c in cnt.values()])

for k in a:
    print(s-(cnt[k]-1))
### BUGGY CODE ###

n,d ,a = map(int,input().split())
xh = []
for _ in range(n):
    x,y = map(int,input().split())
    kaisuu = y // a if y % a == 0 else y//a +1
    xh.append([x,kaisuu])
xh.sort()
migihasi = xh[0][0] + (2*d)
ans = 0
hidarindex = 0
bombs = [(xh[0][1],migihasi)] #[はぜる回数、右端]
for i in range(1,n):
    needkaisuu = xh[i][1]
    zahyo = xh[i][0]
    for cnt,migi in bombs:
        if zahyo <= migi and zahyo >= migi - (2*d):
            needkaisuu -= cnt
        if needkaisuu <=0:break
    if needkaisuu >0:
        bombs.append((needkaisuu,zahyo+(2*d)))
for x,y in bombs:
    ans+= x
print(ans)
        
    
    
    
    

### FIXED CODE ###

from collections import deque
n,d,a = map(int,input().split())
f = [list(map(int,input().split()))for i in range(n)]
queue = deque()
f.sort()
tot = 0
ans = 0
for i in range(n):
    x = f[i][0]
    h = f[i][1]
    while queue and queue[0][0] < x:
        now = queue.popleft()
        tot -= now[1]
    h -= tot
    if h > 0:
        num = (h+a-1)//a
        ans += num
        damage = num*a
        tot+=damage
        queue.append((x+2*d,damage))
print(ans)
### BUGGY CODE ###

from itertools import product

R, G, B, N = map(int, input().split())
R_max = N // R
G_max = N // G
ans = 0
for r, g in product(range(R_max+1), range(G_max+1)):
    if N >= r*R + g*G and (N - (r*R + g*G)) % B == 0: ans += 1
print(ans)

### FIXED CODE ###

from itertools import product

R, G, B, N = map(int, input().split())
R_max = N // R
G_max = N // G
ans = 0
for r, g in product(range(R_max+1), range(G_max+1)):
    if N >= r*R + g*G and (N - (r*R + g*G)) % B == 0: ans += 1
print(ans)
### BUGGY CODE ###

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0 for _ in range(n+1)] # sum_A[i]:=上からi冊の本を読むときにかかる時間
for i in range(1, n+1):
    sum_A[i] = sum_A[i-1] + A[i-1]
sum_B = [0 for _ in range(m+1)] # sum_B[i]:=上からj冊の本を読むときにかかる時間
for j in range(1, m+1):
    sum_B[j] = sum_B[j-1] + B[j-1]

ans = 0
i = 0
while i <= n and sum_A[i] <= k:
    j = 0
    while j <= m and sum_A[i] + sum_B[j] <= k:
        j += 1
    ans = max(ans, i + j-1)
    i += 1
print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0 for _ in range(n+1)] # sum_A[i]:=上からi冊の本を読むときにかかる時間
for i in range(1, n+1):
    sum_A[i] = sum_A[i-1] + A[i-1]
sum_B = [0 for _ in range(m+1)] # sum_B[i]:=上からj冊の本を読むときにかかる時間
for j in range(1, m+1):
    sum_B[j] = sum_B[j-1] + B[j-1]

ans = 0
i = 0
j = m
while i <= n and sum_A[i] <= k:
    while sum_A[i] + sum_B[j] > k:
        j -= 1
    ans = max(ans, i + j)
    i += 1
print(ans)
### BUGGY CODE ###

N=int(input())
xyh=[list(map(int, input().split())) for _ in range(N)]
maxh = max([h for _,_,h in xyh])

def find(cx, cy, H):
	for x,y,h in xyh:
		if h != max(H-abs(x-cx)-abs(y-cy), 0):
			return False
	return True

def all():
	for cx in range(101):
		for cy in range(101):
			for H in range(min(1, maxh-200), maxh+201):
				if find(cx, cy, H):
					print("%d %d %d" % (cx, cy, H))
					return
	print("NOT FOUND")

all()


### FIXED CODE ###

N=int(input())
xyh=sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2], reverse=True)

def find(cx, cy, H):
	for x,y,h in xyh:
		if h != max(H-abs(x-cx)-abs(y-cy), 0):
			return False
	return True

def solve():
	for cx in range(101):
		for cy in range(101):
			x,y,h = xyh[0]
			H = h + abs(x-cx) + abs(y-cy)
			if find(cx, cy, H):
				return "%d %d %d" % (cx, cy, H)
	raise Exception

print(solve())
### BUGGY CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)

N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

def dfs():
    global counter
    done = [True for _ in range(N)]
    stack = deque([])
    done[0] = False
    for e in edge[0]:
        stack.append([e, 0])
    while stack:
        s = stack.pop()
        if done[s[0]]:
            done[s[0]] = False
            counter[s[0]] += counter[s[1]]
            for n in edge[s[0]]:
                stack.append([n, s[0]])
                
for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x
dfs()

[print(c, end=" ") for c in counter]

### FIXED CODE ###

N, Q = map(int, input().split())

edge = [[] for _ in range(N)]
counter = [0 for _ in range(N + 1)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x

stack = [(0, -1)]
while stack:
    s, parent = stack.pop()
    counter[s] += counter[parent]
    for n in edge[s]:
        if n == parent:
            continue
        stack.append((n, s))

[print(c, end=" ") for c in counter[:N]]
### BUGGY CODE ###

N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
print(power % 1000000007)


### FIXED CODE ###

N = int(input())
power = 1
for i in range(1,N+1):
    power = (power * i) % 1000000007
print(power)
### BUGGY CODE ###

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

ab = [[int(l[0]), int(l[1])] for l in (input().split() for i in range(n))]
ab.sort()
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder
# print(a[index])
# print(remainder)
# print(total)

total += sum([a[i] * b[i] for i in range(index)])


print(total)

### FIXED CODE ###

# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)
### BUGGY CODE ###

N = int(input())
P = [None] + list(map(int, input().split()))

p_to_index = [None] * (N + 1)
for index, x in enumerate(P[1:], 1):
    p_to_index[x] = index

#大きい数から挿入
#左隣にあるインデックスを取得できるようにする
#[1, i]内で書き込んだ数の個数を獲得できるBITを構築する

def BIT_add(i):
    while i <= N:
        tree[i] += 1
        i += i & (-i)

def BIT_sum(i):
    s = 0
    while i:
        s += tree[i]
        i -= i & (-i)
    return s

def BIT_search(x):
    i = 0
    s = 0
    step = 1 << (N.bit_length() - 1)
    while step:
        if i + step <= N and s + tree[i + step] < x:
            i += step
            s += tree[i]
        step >>= 1
    return i + 1

tree = [0] * (N + 1)
ans = 0
for x in range(N, 0, -1):
    c = p_to_index[x]
    L = BIT_sum(c) #左側にある既に書き込んだ数の個数
    BIT_add(c)
    R = N - x - L #右側にある既に書き込んだ数の個数
    a = BIT_search(L - 1) if L >= 2 else 0
    b = BIT_search(L) if L >= 1 else 0
    d = BIT_search(L + 2) if R >= 1 else N + 1
    e = BIT_search(L + 3) if R >= 2 else N + 1
    tmp = 0
    if b != 0:
        tmp += (b - a) * (d - c)
    if d != 0:
        tmp += (e - d) * (c - b)
    ans += tmp * x

print (ans)


### FIXED CODE ###

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

index_lst = [0] * N
for index, i in enumerate(P):
    index_lst[i - 1] = index

left_next_Index = list(range(-1, N - 1)) + [-1, -1]
right_next_Index = list(range(1, N + 1)) + [N, N]
# print (left_next_Index)
# print (right_next_Index)
ans = 0
for i in range(1, N):
    index = index_lst[i - 1]
    # print (i, index)
    l1 = left_next_Index[index]
    l2 = left_next_Index[l1]
    r1 = right_next_Index[index]
    r2 = right_next_Index[r1]
    # print ('l1 =', l1, ' l2 =', l2, ' r1 =', r1, ' r2 =', r2)
    ans += i * ((index - l1) * (r2 - r1) + (r1 - index) * (l1 -l2))

    left_next_Index[r1] = l1
    right_next_Index[l1] = r1

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

S = list(input())
N = int(input())
Q = []
for i in range(N):
    q = input()
    if len(q)>1:
        q = q.split()
    else:
        q = [q]
    Q.append(q)
for i in range(N):
    if len(Q[i])==1:
        S = S[::-1]
    if len(Q[i])>1:
        if Q[i][1]=='1':
            S.insert(0, Q[i][2])
        else:
            S.append(Q[i][2])
print(''.join(S))

### FIXED CODE ###

from collections import deque
S = deque(input())
N = int(input())
Q = []
gyaku = 0
for i in range(N):
    q = input()
    if len(q)>1:
        q = q.split()
    else:
        q = [q]
    Q.append(q)
#print(Q)
for i in range(N):
    if len(Q[i])==1:
        gyaku +=1
        #print(S)
    if len(Q[i])>1:
        if Q[i][1]=='1'and gyaku%2==0:
            S.appendleft(Q[i][2])
        elif Q[i][1]=='1'and gyaku%2==1:
            S.append(Q[i][2])
            #print(S)
        elif Q[i][1]=='2'and gyaku%2==0:
            S.append(Q[i][2])
        else:
            S.appendleft(Q[i][2])
            #print(S)
if gyaku%2==0:
    #print(S)
    print(''.join(S))
else:
    S = list(S)
    print(''.join(S[::-1]))
### BUGGY CODE ###

# -*- coding:utf-8 -*-
import sys

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

a, b, c = 0, 0, 0

am = y // 10000
bm = y // 5000
cm = y // 1000

for i in range(am+1):
    for j in range(bm+1):
        if (9000*i + 4000*j + 1000*n == y) and (n-i-j >= 0):
            print(i, j ,n-i-j)
            sys.exit()
        if (y - 1000*n - 4000*j < 0):
            break

print(-1,-1,-1)


### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys

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

a, b, c = 0, 0, 0

am = y // 10000
bm = y // 5000
cm = y // 1000

for i in range(am+1):
    for j in range(bm+1):
        if (9000*i + 4000*j + 1000*n == y) and (n-i-j >= 0):
            print(i, j ,n-i-j)
            sys.exit()
        if (y - 1000*n - 4000*j < 0):
            break
        if (n-i-j < 0):
            break

print(-1,-1,-1)
### BUGGY CODE ###

N, K = map(int, input().split())
H = [int(x) for x in input().split()]

dp = [10**20] * N  # dp[i]: 足場i+1に到達するための最小コスト
dp[0] = 0
for i in range(N-1):
    for j in range(1, K+1):
        if i+j <= N-1:
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i+j]-H[i]))

answer = dp[-1]
print(answer)


### FIXED CODE ###

N,K=map(int,input().split())
h=[int(i) for i in input().split()] + [0 for i in range(K)]

ans=[10**20 for i in range(N+K)]
ans[0]=0

for i in range(N):
    for j in range(1,K+1):
        ans[i+j]=min(ans[i+j],ans[i]+abs(h[i]-h[i+j]))

print(ans[N-1])
### BUGGY CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))
k = K.bit_length()
dv = [[0]*N for _ in range(k)]
dv[0] = [a-1 for a in A]
for turn in range(1,k):
    for town in range(N):
        dv[turn][town] = dv[turn-1][dv[turn-1][town]]

a = 0
for i in range(k):
    if (K>>i)&1:
        a = dv[i][a]
        
print(a+1)

### FIXED CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))
k = K.bit_length()
dv = [[0]*N for _ in range(k)]
dv[0] = [a-1 for a in A]
for turn in range(1,k):
    for town in range(N):
        dv[turn][town] = dv[turn-1][dv[turn-1][town]]

a = 0
for i in range(k):
    if (K>>i)&1:
        a = dv[i][a]
        
print(a+1)
### BUGGY CODE ###

K,S = map(int,input().split())
count = 0
for p in range(K+1):
    for q in range(K+1):
        for r in range(K+1):
            if p+q+r == S:
                count+=1
print(count)


### FIXED CODE ###

K,S = map(int,input().split())
count = 0
for p in range(K+1):
    for q in range(K+1):
        if S-p-q>=0 and S-p-q <= K:
            count+=1
print(count)
### BUGGY CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
    A=n//i
    ans+=((A**2+A)*i//2)
print(ans)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
    m=n//i
    m*=i
    for j in range(i,m+1,i):
        ans+=j
print(ans)
### BUGGY CODE ###

n = int(input())
nums = list(map(int, input().split()))
sum = 1
flag = 1
upper = pow(10, 18)
for num in nums:
  sum = sum * num
  if sum > upper:
    flag = 2
  elif num == 0:
    sum = 0
    flag = 0
if flag == 0:
  print(0)
elif flag == 1:
  print(sum)
else:
  print(-1)

### FIXED CODE ###

n = int(input())
nums = list(map(int, input().split()))
sum = 1
flag = 1
upper = pow(10, 18)
for num in nums:
  if num == 0:
    sum = 0
    flag = 1
    break
  if flag == 1:
    sum = sum * num
    if sum > upper:
      flag = 2

if flag == 1:
  print(sum)
elif flag == 2:
  print(-1)
### BUGGY CODE ###

t = input()
s = ""
for i in range(len(t)):
    if(t[i] == '?'):
        s += 'D'
    else:
        s += t[i]
print(s)

### FIXED CODE ###

print(input().replace('?','D'))
### BUGGY CODE ###

import math
import calendar
import fractions
import itertools

n, k = map(int, input().split())
p = list(map(int, input().split()))

ans_list = []

for i in p:
    if i % 2 == 0:
        ans_list.append(i / 2 + 0.5)
    else:
        ans_list.append(i // 2 + 1)


ans = 0

for i in range(n - k + 1):
    total = 0
    for j in range(i, i + k):
        total += ans_list[j]
    ans = max(ans, total)
print(ans)

### FIXED CODE ###

import math
import calendar
import fractions
import itertools

n, k = map(int, input().split())
p = list(map(int, input().split()))

ans_list = []

for i in p:
    if i % 2 == 0:
        ans_list.append(i / 2 + 0.5)
    else:
        ans_list.append(i // 2 + 1)


ans = 0
total = 0
for i in range(0, n - k + 1):
    if i == 0:
        for j in range(k):
            total += ans_list[j]
            ans = total
    else:
        total -= ans_list[i - 1]
        total += ans_list[i + k - 1]
    ans = max(ans, total)
print(ans)
### BUGGY CODE ###

"""
#include <stdio.h>
int main(){
  int l, r, ans=99999;
  int lst[99999];
  scanf("%d",&l);
  scanf("%d",&r);
  l %= 2019;
  r %= 2019;
  for(int i=l;i<r;i++){
    for(int j=i+1;j<r+1;j++){
      if(ans>(i*j)%2019){
        ans = (i*j)%2019;
        //printf("%d\n",ans);
      }
    }
  }
  printf("%d\n",ans);

}
/*"""
l, r = map(int, input().split())
#l %= 2019
#r %= 2019

#lst = []
sum = 999999
for i in range(l,r):
  for j in range(i+1,r+1):
    #lst.append(i*j%2019)
    if sum > i*j%2019:
      sum = i*j%2019
print(sum)
#*/

### FIXED CODE ###

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