Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(S[::-1]))
    

Fixed submission:
print('Yes' if len(set(input().strip())) > 1 else 'No')
Buggy python submission (verdict: Runtime Error):
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(S[::-1]))
    

Fixed submission:
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(list(reversed(S))))

Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S = C + S
      else:
        S = S + C
    else:
      if int(F) == 1:
        S = S + C
      else:
        S = C + S

if flag:
  print(S)
else:
  print(S[::-1])
    

Fixed submission:
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(list(reversed(S))))

Buggy python submission (verdict: Time Limit Exceeded):
S = input().strip()
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S = C + S
      else:
        S = S + C
    else:
      if int(F) == 1:
        S = S + C
      else:
        S = C + S

if flag:
  print(S)
else:
  print(''.join([c for c in reversed(list(S))]))  
    

Fixed submission:
from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(list(reversed(S))))
Buggy python submission (verdict: Time Limit Exceeded):
MAX_X = 10 ** 5
buffer = 10 ** 3
prime_flags = [1 for _ in range(MAX_X + buffer)]

for i in range(MAX_X + buffer):
  num = i
  while num < MAX_X + buffer:
    num += i
    prime_flags[num] = 0

X = int(input().strip())
for i, flag in enumerate(prime_flags[X:]):
  if flag == 1:
    print(X + i)
    break
    

Fixed submission:
MAX_X = 10 ** 5
buffer = 10 ** 3
prime_flags = [1 for _ in range(MAX_X + buffer)]

for i in range(2, MAX_X + buffer):
  num = i
  if prime_flags[num] == 0:
    continue
  while num + i < len(prime_flags):
    num += i
    prime_flags[num] = 0

X = int(input().strip())
for i, flag in enumerate(prime_flags[X:]):
  if flag == 1:
    print(X + i)
    break
Buggy python submission (verdict: Runtime Error):
A_prev, B_prev, C_prev, K = map(int, input().split())

for _ in range(K):
  A_cur = B_prev + C_prev
  B_cur = A_prev + C_prev
  C_cur = A_prev + B_prev
  A_prev, B_prev, C_prev = A_cur, B_cur, C_cur
ans = A_cur - B_cur
print(A_cur - B_cur if ans <= 1e18 else 'Unfair')

Fixed submission:
A, B, C, K = map(int, input().split())

if K > 0:
    if K % 2 == 0:
        ans = A - B
    else:
        ans = B - A
else:
    ans = A - B
print(ans if ans <= 1e18 else 'Unfair')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
res = 0
for _ in range(N):
  a.append(int(input()))

hasGreaterBefore = set()
max_v, min_v = 0, 2e5

for e in a:
    if max_v < e:
        max_v = e
    else:
        hasGreaterBefore.add(e)

for num in range(N, 0, -1):
    if num in hasGreaterBefore:
        eidx = a.index(num)
        hasGreaterBefore.remove(num)
        if num > a[0]:
            hasGreaterBefore.add(a[0])
        if eidx != 0:
            a.pop(eidx)
            a = [num] + a
            res += 1

print(res)


Fixed submission:
N = int(input())
a = [0]
for _ in range(N):
  a.append(int(input()))

Q = [0 for i in range(N + 1)]
for i in range(N + 1):
    Q[a[i]] = i
ans = 1
num = 1

for idx in range(2, len(Q)):
    if Q[idx - 1] < Q[idx]:
        num += 1
    else:
        ans, num = max(num, ans), 1

print(N - max(num, ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
res = 0
for _ in range(N):
  a.append(int(input()))

hasGreaterBefore = set()

for num in range(N, 0, -1):
    max_v, min_v = 0, 1e5
    hasGreaterBefore.clear()
    for e in a:
        if max_v < e:
            max_v = e
        else:
            hasGreaterBefore.add(e)

    if num in hasGreaterBefore:
        eidx = a.index(num)
        if eidx != 0:
            a.pop(eidx)
            a = [num] + a
            res += 1

print(res)


Fixed submission:
N = int(input())
a = [0]
for _ in range(N):
  a.append(int(input()))

Q = [0 for i in range(N + 1)]
for i in range(N + 1):
    Q[a[i]] = i
ans = 1
num = 1

for idx in range(2, len(Q)):
    if Q[idx - 1] < Q[idx]:
        num += 1
    else:
        ans, num = max(num, ans), 1

print(N - max(num, ans))
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
l = len(S)
topk = []
vocab = set()

for i in range(l):
    for j in range(i + 1, i + K + 1):
        if j > l - 1:
            break
        ss = S[i: j]
        vocab.add(ss)

print(sorted(list(vocab))[K-1])


Fixed submission:
S = input()
K = int(input())
l = len(S)
topk = []
a = []

for i in range(l):
    for j in range(i + 1, i + K + 1):
        if j > l:
            break
        ss = S[i: j]
        a.append(ss)

print(sorted(list(set(a)))[K-1])

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
l = len(S)
topk = []
vocab = set()

for idx in range(K):
    ss = S[0:idx + 1]
    if ss in vocab:
        continue
    topk.append(ss)
    vocab.add(ss)
for idx in range(1, l):
    sblen = 0
    for sblen in range(1, l - idx):
        ss = S[idx: idx + sblen]
        if ss in vocab:
            continue
        vocab.add(ss)
        if len(topk) < K:
            topk.append(ss)
            continue

        if ss > topk[-1]:
            break
        else:
            topk[-1] = ss
            topk.sort()

print(topk[K-1])


Fixed submission:
S = input()
K = int(input())
l = len(S)
topk = []
a = []

for i in range(l):
    for j in range(i + 1, i + K + 1):
        if j > l:
            break
        ss = S[i: j]
        a.append(ss)

print(sorted(list(set(a)))[K-1])
Buggy python submission (verdict: Runtime Error):
a = list(map(int, input().split())).sorted(reversed=True)
N = int(input())
print((2 ^ N) * a[0] + a[1] + a[2])

Fixed submission:
a = sorted(list(map(int, input().split())), reverse=True)
N = int(input())
print((2 ** N) * a[0] + a[1] + a[2])
Buggy python submission (verdict: Time Limit Exceeded):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

left, right = 0, M
while right - left > 1:
  mid = (left + right) // 2
  if A[mid] > X:
    mid = left
  if A[mid] < X:
    mid = right

res = max(mid, M - mid)
print(res)

Fixed submission:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

idx = 0

while idx < M:
    if A[idx] > X:
        break
    idx += 1

res = min(idx, M - idx)
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
cards = map(int, input().split())
A, B = 0, 0
for idx in range(N):
  if idx % 2 == 0:
    A += cards[idx]
  else:
    B += cards[idx]
print(A - B)

Fixed submission:
N = int(input())
cards = sorted(list(map(int, input().split())), reverse=True)
A, B = 0, 0
for idx in range(N):
  if idx % 2 == 0:
    A += cards[idx]
  else:
    B += cards[idx]
print(A - B)
Buggy python submission (verdict: Runtime Error):
l, r = int(input()) + int(input()), int(input()) + int(input())
if l > r:
  print('Left')
elif r < l:
  print('Right')
else:
  print('Balanced')
  

Fixed submission:
a = list(map(int, input().split()))
l, r = a[0] + a[1], a[2] + a[3]
if l > r:
  print('Left')
elif l < r:
  print('Right')
else:
  print('Balanced')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, K = map(int, input().split())
cnt = Counter(list(map(int, input().split())))
res = 0
l = len(cnt)
for i in range(l, K, -1):
    res += cnt.most_common(i)[-1][1]
print(res)

Fixed submission:
from collections import Counter

N, K = map(int, input().split())
cnt = Counter(list(map(int, input().split())))
res = 0
l = len(cnt)
mc = cnt.most_common()
for i in range(l - 1, K - 1, -1):
    res += mc[i][1]
print(res)
Buggy python submission (verdict: Runtime Error):
print('YES' if input() == ''.join([e for e in reversed(list(input()))] else 'NO')

Fixed submission:
print('YES' if input() == ''.join([e for e in reversed(list(input()))]) else 'NO')
Buggy python submission (verdict: Runtime Error):
print(min(int(input())-int(input()), 0))

Fixed submission:
X, t = map(int, input().split())
print(max(0, X-t))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
cnts = [0 for i in range(N + 1)]
for a in A:
  cnts[a] += 1
res = 0
for idx in range(1, A - 1):
  tmp = sum(A[idx-1:idx+1])
  if tmp > res:
    res = tmp
print(res)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
MAX_N = int(1e5) + 1
cnts = [0 for i in range(MAX_N)]
for a in A:
  cnts[a] += 1
res = 0
for idx in range(1, len(cnts) + 1):
  tmp = sum(cnts[idx-1:idx+2])
  if tmp > res:
    res = tmp
print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
res = 0
for idx in range(len(P)):
    if P[idx] == idx + 1:
        if idx < N:
            P[idx], P[idx+1] = P[idx+1], P[idx]
        res += 1

print(res)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))
res = 0
for idx in range(len(P) - 1):
    if P[idx] == idx + 1:
        P[idx], P[idx+1] = P[idx+1], P[idx]
        res += 1

if P[-1] == N:
    res += 1

print(res)

Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
res = 0
for idx in range(len(P)):
    if P[idx] == idx + 1:
        P[idx], P[idx+1] = P[idx+1], P[idx]
        res += 1

print(res)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))
res = 0
for idx in range(len(P) - 1):
    if P[idx] == idx + 1:
        P[idx], P[idx+1] = P[idx+1], P[idx]
        res += 1

if P[-1] == N:
    res += 1

print(res)
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(A, B):
    A, B = sorted([A, B], reverse=True)
    prev_r = B
    r = A % B
    while r > 0:
        prev_r = B
        r = A % B
        A, B = B, r
    return prev_r

tmp = (T[0] * T[1]) // gcd(T[0], T[1])
for t in T[2:]:
    tmp = (tmp * t) // gcd(tmp, t)

print(tmp)


Fixed submission:
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(A, B):
    A, B = sorted([A, B], reverse=True)
    prev_r = B
    r = A % B
    while r > 0:
        prev_r = B
        r = A % B
        A, B = B, r
    return prev_r

if N > 1:
    tmp = (T[0] * T[1]) // gcd(T[0], T[1])
    for t in T[2:]:
        tmp = (tmp * t) // gcd(tmp, t)
else:
    tmp = T[0]

print(tmp)

Buggy python submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(A, B):
    A, B = sorted([A, B], reverse=True)
    r = A % B
    while r > 0:
        r = A % B
        A, B = B, r
    return max(B, 1)

tmp = (T[0] * T[1]) // gcd(T[0], T[1])
for t in T[2:]:
    tmp = (tmp * t) // gcd(tmp, t)

print(tmp)


Fixed submission:
N = int(input())
T = [int(input()) for _ in range(N)]

def gcd(A, B):
    A, B = sorted([A, B], reverse=True)
    prev_r = B
    r = A % B
    while r > 0:
        prev_r = B
        r = A % B
        A, B = B, r
    return prev_r

if N > 1:
    tmp = (T[0] * T[1]) // gcd(T[0], T[1])
    for t in T[2:]:
        tmp = (tmp * t) // gcd(tmp, t)
else:
    tmp = T[0]

print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import heapq

N = int(input())
INF = float('inf')
edges = [list(map(int, input().split())) for _ in range(N-1)]
nodes = defaultdict(list)

for e in edges:
    nodes[e[0] - 1].append((e[2], e[1] - 1))
    nodes[e[1] - 1].append((e[2], e[0] - 1))


Q, K = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(Q)]

def dijkstra(x, y):
    que = []
    heapq.heapify(que)
    dist = [INF for _ in range(N)]
    dist[x] = 0
    heapq.heappush(que, (0, x))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if dist[v] < p[0]:
            continue
        for e in nodes[v]:
            if dist[e[1]] > dist[v] + e[0]:
                dist[e[1]] = dist[v] + e[0]
                heapq.heappush(que, (dist[e[1]], e[1]))

    return dist[y]


for q in queries:
    x, y = q[0] - 1, q[1] - 1
    print(dijkstra(x, K - 1) + dijkstra(K - 1, y))



Fixed submission:
from collections import defaultdict
import heapq

N = int(input())
INF = float('inf')
edges = [list(map(int, input().split())) for _ in range(N-1)]
nodes = defaultdict(list)

for e in edges:
    nodes[e[0] - 1].append((e[2], e[1] - 1))
    nodes[e[1] - 1].append((e[2], e[0] - 1))


Q, K = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(Q)]

def dijkstra(x):
    que = []
    heapq.heapify(que)
    dist = [INF for _ in range(N)]
    dist[x] = 0
    heapq.heappush(que, (0, x))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if dist[v] < p[0]:
            continue
        for e in nodes[v]:
            if dist[e[1]] > dist[v] + e[0]:
                dist[e[1]] = dist[v] + e[0]
                heapq.heappush(que, (dist[e[1]], e[1]))

    return dist

distk = dijkstra(K - 1)

for q in queries:
    x, y = q[0] - 1, q[1] - 1
    print(distk[x] + distk[y])
Buggy python submission (verdict: Runtime Error):
print('Possible' if (sum(list(map(int, input().split()))) % 3 == 0 else 'Impossible')

Fixed submission:
A, B = map(int, input().split())

if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print('Possible')
else:
    print('Impossible')
Buggy python submission (verdict: Runtime Error):
A, B = map(int(input().split()))
if A == B:
  print('Draw')
elif A == 1:
  print('Alice')
elif B == 1:
  print('Bob')
elif A > B:
  print('Alice')
else:
  print('Bob')

Fixed submission:
A, B = map(int, input().split())
if A == B:
  print('Draw')
elif A == 1:
  print('Alice')
elif B == 1:
  print('Bob')
elif A > B:
  print('Alice')
else:
  print('Bob')
Buggy python submission (verdict: Runtime Error):

t_nums= list(map(int(),input().split()))
print(t_nums[0]*t_nums[1])

Fixed submission:
t_nums= list(map(int,input().split()))
print(t_nums[0]*t_nums[1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
stones = input().rstrip()
pre_word = stones[0]
stones_list =[]
counter = 0

for i in range(N):
    stones_list.append(stones[i])

for i in range(N):
    present_word = stones_list[i]
    if pre_word == '#' and present_word =='.':
        counter += 1
    pre_word = stones_list[i]

print(counter)

Fixed submission:
N = list(map(int, input().split()))

if ((N[0] > N[2]) and (N[1] < N[2])) or ((N[0] < N[2]) and (N[1] > N[2])):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
word = input()
word_list=[]
word_num = int(input())

for i in range(len(word)):
    word_list.append(word[i])
    if str(word[i]) != str(word[word_num -1]):
         word_list[i] = '*'

print(" ".join(list(map(str,word_list))))

Fixed submission:
N = list(map(int, input().split()))

if ((N[0] > N[2]) and (N[1] < N[2])) or ((N[0] < N[2]) and (N[1] > N[2])):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = list(map(int,input().split()))
drinks = [list(map(int,input().split())) for i in range(N[0])]

counter=0
amount=0
flag=0
for i in range(N[0]):
    v = drinks[i]
    x = drinks[i][0]
    j = i-1
    while(j >= 0 and drinks[j][0]>x):
        drinks[j+1] = drinks[j]
        j -= 1
    drinks[j+1] = v
    x = drinks[j+1][0]

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount) 
    


Fixed submission:
N = list(map(int,input().split()))
drinks = [list(map(int,input().split())) for i in range(N[0])]
drinks.sort()

counter=0
amount=0
flag=0

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount)
Buggy python submission (verdict: Runtime Error):
K = input()
S = input()K = int(input())
S = input()
if len(S) <= K:
  print(S)
else:
  print(S[:K] + "...")

Fixed submission:
K = int(input())
S = input()
if len(S) <= K:
  print(S)
else:
  print(S[:K] + "...")
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = '7'
result = -1
if not k % 2 == 0 and not k % 5 == 0:
    for i, _ in enumerate(range(k), 1):
        val = int(s) 
        if val % k == 0:
            result = i
            break
        else:
            s += '7'
print(result) 

Fixed submission:
k = int(input())
target = 7; ans = -1
if not k % 2== 0:
    
    for i in range(1, k + 10):
        if target % k == 0:
            ans = i
            break
        target = (target * 10 + 7) % k
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
sevens = ['7']
result = -1
if not k % 2 == 0 and not k % 5 == 0:
    for i, _ in enumerate(range(k), 1):
        val = int(''.join(sevens))
        if val % k == 0:
            result = i
            break
        else:
            sevens.append('7')
print(result)  

Fixed submission:
k = int(input())
target = 7; ans = -1
if not k % 2== 0:
    
    for i in range(1, k + 10):
        if target % k == 0:
            ans = i
            break
        target = (target * 10 + 7) % k
 
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
sem, per = map(int, input().split())
scores = list(map(int, input().split()))
period_score = []

for i in range(len(scores) - (per - 1)):
    period = scores[i:per + i]
    temp = period[0]
    for j in range(1, per):
        temp *= period[j]
        
    period_score.append(temp)
    
for k in range(1, len(period_score)):
    if period_score[k - 1] < period_score[k]:
        print('Yes')
    else:
        print('No')

Fixed submission:
sem, per = map(int, input().split())
scores = list(map(int, input().split()))

for i in range(sem - per):
    if scores[i] < scores[i + per] :
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
s, t = map(int, input().split(" "))
print(s+t)

Fixed submission:
s, t = map(str, input().split(" "))
print(t+s)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k= map(int, input().split(" "))
for i in range(k):
    if a > 0:
        a-=1
    elif b > 0:
        b-=1
print(a, b)

Fixed submission:
a, b, k= map(int, input().split(" "))
if a > k:
    a -= k
else:
    k-=a
    a = 0
    if b > k:
        b-=k
    else:
        b = 0

print(a, b)

Buggy python submission (verdict: Runtime Error):
a, b, k= map(str, input().split(" "))
for i in range(k):
    if a > 0:
        a-=1
    elif b > 0:
        b-=1
print(a, b)

Fixed submission:
a, b, k= map(int, input().split(" "))
if a > k:
    a -= k
else:
    k-=a
    a = 0
    if b > k:
        b-=k
    else:
        b = 0

print(a, b)
Buggy python submission (verdict: Time Limit Exceeded):
l, r = map(int, input().split())

ans = 2019
for i in range(l, r):
    for j in range(r, l-1, -1):
        if i == j:
            break
        mod = (i * j) % 2019
        if mod < ans:
            ans = mod
    if ans == 0:
        break
print(ans)


Fixed submission:
l, r = map(int, input().split())
ans = 2019

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

Buggy python submission (verdict: Time Limit Exceeded):
l, r = map(int, input().split())

ans = 2019
for i in range(l, r + 1):
    for j in range(r, l-1, -1):
        if i == j:
            break
        mod = (i * j) % 2019
        if mod < ans:
            ans = mod

print(ans)


Fixed submission:
l, r = map(int, input().split())
ans = 2019

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