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

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

import heapq
heapq.heapify(A)
for _ in range(M):
  b, c = map(int, input().split())
  for _ in range(b):
    a = heapq.heappop(A)
    if a < c:
      heapq.heappush(A, c)
    else:
      heapq.heappush(A, a)
      break

print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
from operator import itemgetter
BC.sort(key=itemgetter(1), reverse=True)

for b, c in BC:
  A += [c]*b
  if len(A) > 2*N:
    break

A.sort(reverse=True)
print(sum(A[:N]))
### BUGGY CODE ###

N = int(input())
D = {}
for _ in range(N):
    x = input()
    if D.get(x):
        D[x] += 1
    else:
        D[x] = 1
max_k_list = [kv[0] for kv in D.items() if kv[1] == max(D.values())]
print("\n".join(sorted(max_k_list)))


### FIXED CODE ###

N = int(input())
L = []
D = {}
for _ in range(N):
    x = input()
    L.append(x)

for x in L:
    D[x] = 0
    
for x in L:
    D[x] += 1

SortD = sorted(D.items(), key=lambda x:x[1])
maxD = SortD[-1][1]
ans = []
for x in reversed(SortD):
    if x[1] == maxD:
        ans.append(x[0])
    else:
        break
for x in sorted(ans):
    print(x)
### BUGGY CODE ###

import bisect
N = input()
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())
A.sort()
B.sort()
C.sort()

BC_type_num = []
for b in B:
    upper_bound = bisect.bisect_right(C, b)
    BC_type_num.append(N - upper_bound)

ABC_type_num = []
for a in A:
    upper_bound = bisect.bisect_right(B, a)
    ABC_type_num.append(sum(BC_type_num[upper_bound:]))

print sum(ABC_type_num)

### FIXED CODE ###

import bisect
N = input()
A = map(int, raw_input().split())
B = map(int, raw_input().split())
C = map(int, raw_input().split())
A.sort()
B.sort()
C.sort()

BC_type_num = []
pre = 0
for b in reversed(B):
    upper_bound = bisect.bisect_right(C, b)
    BC_type_num.append(pre + N - upper_bound)
    pre += N - upper_bound
BC_type_num.reverse()

res = 0
for a in A:
    upper_bound = bisect.bisect_right(B, a)
    if upper_bound < N:
        res += BC_type_num[upper_bound]

print res
### BUGGY CODE ###

N = int(input())
L_A = [int(s) for s in input().rstrip().split(' ')]
[M,m] = [0,10**9]
ans = 0
a = 0
for k in range(N,0,-1):
    p = L_A[k-1]
    if p+m <= a:
        for i in range(p+m,min(p+M+1,a+1)):
            if p + L_A[k-1+i] == i:
                ans += 1
    M = max(M,p)
    m = min(m,p)
    a += 1
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
"""
A[i] + A[j] = j - i
<=> A[i] + i = j - A[j]
"""
L_i = [A[i] + i for i in range(N)]
L_j = [j - A[j] for j in range(N)]
# L_j[x] < x <= 2 * (10**5)
ans_lis = [0] * (2*(10**5))
for x in L_i:
    if x < 2*(10**5):
        ans_lis[x-1] += 1
for y in L_j:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)
### BUGGY CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    for i in range(1,N+1):
        ans = A.count(i)
        print(ans)
resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    import collections
    c = collections.Counter(A)
    for i in range(1,N+1):
        print(c[i])
resolve()
### BUGGY CODE ###

n, k = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
def f(x):
    return sum(a^x for a in As)

ans = 0
for i in range(k+1):
    ans = max(ans, f(i))
print(ans)


### FIXED CODE ###

n, k = [int(i) for i in input().split()]
As = [int(i) for i in input().split()]
def func(x):
    return sum(a^x for a in As)

bs = ['{:050b}'.format(a)[::-1] for a in As]
# print(bs)
strk = '{:b}'.format(k)

ans = ['0'] * len(strk)
# print(strk, ans)
for i in range(len(strk)):
    one = len([True for b in bs if b[len(strk) - 1 - i] == '1'])
    zero = len([True for b in bs if b[len(strk) - 1 - i] == '0'])
    # print(zero, one)

    tmp = ans[:]
    # if k < int('1' + ans, 2):

    # if one == zero:
    #     tmp[i] = '1'
    if zero >= one:
        tmp[i] = '1'
    # else:
    #     ans = ['0' + a for a in ans]
    # print(tmp, int(''.join(tmp), 2))
    if k >= int(''.join(tmp), 2):
        ans = tmp
    # print('ans', ans)

print(func(int(''.join(ans), 2)))
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    
    r, c, k = map(int, input().split())
    tizu = [[0 for _ in range(c)] for _ in range(r)]
    for _ in range(k):
        rr, cc, v = map(int, input().split())
        tizu[rr - 1][cc - 1] = v
        
    dp = [[0, 0, 0, 0] for _ in range(c)]
    dp[0][1] = tizu[0][0]
    
    for i in range(r):
        for j in range(c):
            v = tizu[i][j]
            if i != 0:
                tmp = max(dp[j])
                dp[j][0] = tmp
                dp[j][1] = tmp + v
                dp[j][2] = 0
                dp[j][3] = 0
            if j != 0:
                tmp0 = dp[j - 1][0]
                tmp1 = dp[j - 1][1]
                tmp2 = dp[j - 1][2]
                dp[j][0] = max(dp[j][0], tmp0)
                dp[j][1] = max(dp[j][1], tmp1, tmp0 + v)
                dp[j][2] = max(tmp2, tmp1 + v)
                dp[j][3] = max(dp[j - 1][3], tmp2 + v)
    print(max(dp[-1]))
    
main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.buffer.readline
    
    r, c, k = map(int, input().split())
    tizu = [0 for _ in range(r * c)]
    for _ in range(k):
        rr, cc, v = map(int, input().split())
        tizu[(rr - 1) * c + (cc - 1)] = v
        
    dp = [[0, 0, 0, 0] for _ in range(c)]
    dp[0][1] = tizu[0]
    
    for i in range(r):
        for j in range(c):
            v = tizu[i * c + j]
            if v:
                if i != 0:
                    tmp = max(dp[j])
                    dp[j] = [tmp, tmp + v, 0, 0]
                if j != 0:
                    tmp0 = dp[j - 1][0]
                    tmp1 = dp[j - 1][1]
                    tmp2 = dp[j - 1][2]
                    lst = [max(dp[j][0], tmp0), max(dp[j][1], tmp1, tmp0 + v), max(tmp2, tmp1 + v), max(dp[j - 1][3], tmp2 + v)]
                    dp[j] = lst
            else:
                if i != 0:
                    tmp = max(dp[j])
                    dp[j] = [tmp, 0, 0, 0]
                if j != 0:
                    lst = [max(dp[j][0], dp[j-1][0]), dp[j-1][1], dp[j-1][2], dp[j - 1][3]]
                    dp[j] = lst
    print(max(dp[-1]))
    
main()
### BUGGY CODE ###


def green_bin(s, N):
    anagram_num = 0
    sorted_s = []
        
    for i in range(N):

        if i == 0:
            sorted_s.append(sorted(s[i]))

        for j in range(i + 1, len(s)):

                if i == 0:
                    sorted_s.append(sorted(s[j]))

                if sorted_s[i] == sorted_s[j]:
                    anagram_num += 1

    return anagram_num



def green_bin2(s, N):
    anagram_num = 0
    sorted_s_sub = []
    sorted_s = []
        
    for i in range(N):
        sorted_si = sorted(s[i])
        sorted_s_sub.append(''.join(sorted_si))

    sorted_s = sorted(sorted_s_sub)

    i = 0
    item_count = []
    while i < N:
        item = sorted_s[i]
        count = sorted_s.count(item)
        item_count.append(count)
        i += count  # count だけ進める
    
    for count in item_count:
        
        anagram_num += int(count * (count - 1) / 2)

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin2(s, N))


### FIXED CODE ###


def green_bin(s, N):
    anagram_num = 0
    sorted_s_sub = []
    sorted_s = []
        
    for i in range(N):
        sorted_si = sorted(s[i])
        sorted_s_sub.append(''.join(sorted_si))

    sorted_s = sorted(sorted_s_sub)

    i = 0
    item_count = []
    while i < N:
        item = sorted_s[i]
        j = i + 1
        count = 1
        while j < N:
            if item == sorted_s[j]:
                count += 1
                j += 1
            else:
                break
        item_count.append(count)
        i += count  # count だけ進める
    
    for count in item_count:
        
        anagram_num += int(count * (count - 1) / 2)

    return anagram_num


if __name__ == '__main__':
    N = int(input())
    s = []
    for n in range(N):
        sn = input()
        s.append(sn)
    print(green_bin(s, N))
### BUGGY CODE ###

import math
from functools import reduce
import itertools

K = int(input())
data = list(range(1, K + 1))
p_list = list(itertools.product(data, repeat=3))

# print(p_list)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

sum = 0

for p in p_list:
    sum += gcd_list(p)

print(sum)

### FIXED CODE ###

import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            sum += gcd(a, b, c)

print(sum)
### BUGGY CODE ###

import numpy as np

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

S = np.zeros((N+1, M+1), dtype='int')
for n in range(1, N+1):
    S[n, 1:] = list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 
# count edges(row)
ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 
# count edges(col)
EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 

for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    print(N_nodes - N_edges1 - N_edges2)

### FIXED CODE ###

import numpy as np

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

S = np.zeros((N+1, M+1), dtype='float32')

for n in range(1, N+1):
    S[n, 1:] = list(map(int, list(input())))

# count nodes
N_cum = np.cumsum(np.cumsum(S, axis=0), axis=1) 
# count edges(row)
ER_cum = np.cumsum(np.cumsum(S[:N, :]*S[1:, :], axis=0), axis=1) 
# count edges(col)
EC_cum = np.cumsum(np.cumsum(S[:, :M]*S[:, 1:], axis=0), axis=1) 

sol_list = []

for _ in range(Q):
    x1, y1, x2, y2 = map(int, input().split())
    # nodes
    N_nodes = N_cum[x2, y2] - N_cum[x1-1, y2] - N_cum[x2, y1-1] + N_cum[x1-1, y1-1]
    # edges(row)
    N_edges1 = ER_cum[x2-1, y2] - ER_cum[x1-1, y2] - ER_cum[x2-1, y1-1] + ER_cum[x1-1, y1-1]
    # edges(col)
    N_edges2 = EC_cum[x2, y2-1] - EC_cum[x1-1, y2-1] - EC_cum[x2, y1-1] + EC_cum[x1-1, y1-1]
    
    sol_list.append(N_nodes - N_edges1 - N_edges2)

for q in range(Q):
    print(int(sol_list[q]))
### BUGGY CODE ###

l,r=map(int,input().split())
a=2019
for i in range(l,r):
    for j in range(i+1,r+1):
        a=min(i*j%2019,a)
    if a==0:
        break
print(a)


### FIXED CODE ###

l,r=map(int,input().split())
a=2019
if r-l>=2019:
    print(0)
    exit(0)
for i in range(l,r):
    for j in range(i+1,r+1):
        a=min(i*j%2019,a)
print(a)
### BUGGY CODE ###

from collections import defaultdict
def d():
    tree_map = defaultdict(list)
    value_map = defaultdict(int)
    N, Q = map(int,input().split())
    
    for _ in range(1, N):
        a, b = map(int,input().split())
        tree_map[a].append(b)
        tree_map[b].append(a)

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

    res = [0] * N
    stack = []
    stack.append((1, 0))
    visited = set()
    while stack:
        i, s = stack.pop()
        visited.add(i)
        if value_map[i] != 0:
            s += value_map[i]
        res[i-1] += s
        
        for j in tree_map[i]:
            if j in visited:
                continue
            else:
                stack.append((j, s))

    print(*res)


if __name__ == "__main__":
    d()

### FIXED CODE ###

from collections import defaultdict
def d():
    tree_map = defaultdict(list)
    value_map = defaultdict(int)
    N, Q = map(int,input().split())
    
    for _ in range(1, N):
        a, b = map(int,input().split())
        tree_map[a].append(b)
        tree_map[b].append(a)

    res = [0] * N

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

    while stack:
        i, p, s = stack.pop()

        res[i-1] += s
        s = res[i-1]
        
        for j in tree_map[i]:
            if j == p:
                continue
            else:
                stack.append((j, i, s))

    print(*res)


if __name__ == "__main__":
    d()
### BUGGY CODE ###

import sys
import collections
import itertools


def resolve(in_):
    one = ord(b'1')
    two = ord(b'2')
    # print(f'{one=} {two=}')

    S = in_.readline().strip()
    q = collections.deque(S)
    # print(f'{S=} {q=}')

    reverse_flag = 0
    Q = int(in_.readline())
    for query in itertools.islice(in_, Q):
        T = query[0]
        if T == one:
            reverse_flag ^= 1 
            # q.reverse()
        elif T == two:
            if reverse_flag:
                q.reverse()
                reverse_flag = 0
            F = query[2]
            C = query[4]
            if F == one:
                q.appendleft(C)
            elif F == two:
                q.append(C)
    else:
        if reverse_flag:
            q.reverse()
            reverse_flag = 0

    return bytes(q)


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer.decode('ascii'))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import collections
import itertools


def resolve(in_):
    one = ord(b'1')
    two = ord(b'2')
    # print(f'{one=} {two=}')

    S = in_.readline().strip()
    q = collections.deque(S)
    # print(f'{S=} {q=}')

    reverse_flag = False
    Q = int(in_.readline())
    for query in itertools.islice(in_, Q):
        T = query[0]
        if T == one:
            reverse_flag ^= True 
            # q.reverse()
        elif T == two:
            F = query[2]
            C = query[4]
            if (F == one) ^ reverse_flag:
                q.appendleft(C)
            else:
                q.append(C)
    else:
        if reverse_flag:
            q.reverse()
            reverse_flag = 0

    return bytes(q)


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer.decode('ascii'))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys


def len_lcs(s1, s2):
    """Find length of the longest common sequence(LCS) of strings s1 and s2.
    The complexity is ~MN.

    >>> len_lcs("abc", "abc")
    3
    >>> len_lcs("abcbdaba", "bdcaba")
    5
    """
    results = [0] * len(s1)

    for i, c2 in enumerate(s2):
        sec1, pr1 = 0, 0
        for j, c1 in enumerate(s1):
            if c1 == c2:
                match = 1
            else:
                match = 0
            pr2 = results[j]
            mval = max(sec1, pr2, pr1 + match)
            results[j] = mval
            sec1, pr1 = mval, pr2

    return results[-1]


def run():
    n = int(input())
    s = []
    for line in sys.stdin:
        s.append(line.strip())
    for i in range(0, 2*n, 2):
        print(len_lcs(s[i], s[i+1]))


run()


### FIXED CODE ###

import sys


def len_lcs(s1, s2):
    """Find length of the longest common sequence(LCS) of strings s1 and s2.
    The complexity is ~MN.

    >>> len_lcs("abc", "abc")
    3
    >>> len_lcs("abcbdaba", "bdcaba")
    5
    """
    results = [0] * len(s1)

    for i, c2 in enumerate(s2):
        sec1, pr1 = 0, 0
        for j, c1 in enumerate(s1):
            pr2 = results[j]
            if c1 == c2:
                mval = pr1 + 1
            elif sec1 > pr2:
                mval = sec1
            else:
                mval = pr2

            results[j] = mval
            sec1, pr1 = mval, pr2

    return results[-1]


def run():
    n = int(input())
    s = []
    for line in sys.stdin:
        s.append(line.strip())
    for i in range(0, 2*n, 2):
        print(len_lcs(s[i], s[i+1]))

run()
### BUGGY CODE ###

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

history = [0] * (K + 1)
total = 0

divide = pow(10, 9) + 7

for i in range(K, 0, -1):
  history[i] = pow(K//i, N)
  for j in range(2, K//i + 1):
    history[i] -= history[i * j]
  total += ((i * history[i]) % divide)
  
total = total % divide
print(total)


### FIXED CODE ###

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

history = [0] * (K + 1)
total = 0

divide = pow(10, 9) + 7

for i in range(K, 0, -1):
  history[i] = pow(K//i, N, divide)
  for j in range(2, K//i + 1):
    history[i] -= history[i * j]
  total += ((i * history[i]) % divide)
  
total = total % divide
print(total)
### BUGGY CODE ###

A, B, Q = map(int, input().split())
S, T =[None] * (A+1), [None] * (B+1)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S.append(10**20)
T.append(10**20)

def Bsearch(x, L, lenL):
    low, high = 0, lenL
    while high-low > 1:
        mid = (low+high)//2
        if L[mid] > x:
            high = mid
        else: low = mid
    return [x-L[low], L[low+1]-x]

printAns = ""
lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(input())
    sLength0, sLength1 = Bsearch(x, S, lenS)
    tLength0, tLength1 = Bsearch(x, T, lenT)
    Ans = [max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0)]
    printAns += str(min(Ans)) + "\n"
print(printAns)

### FIXED CODE ###

from bisect import bisect
A, B, Q = map(int, input().split())
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S[A+1] = 10**20
T[B+1] = 10**20

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(input())
    si, ti = bisect(S, x, 0, lenS), bisect(T, x, 0, lenT)
    sLength0, sLength1 = x - S[si-1], S[si] - x
    tLength0, tLength1 = x - T[ti-1], T[ti] - x
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print(min(Ans))
### BUGGY CODE ###

#!/usr/bin/env python3
import bisect
import numpy as np

N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
bc_list = []

for _ in range(M):
    b, c = list(map(int, input().split()))
    bc_list.append((b, c))

bc_list = sorted(bc_list, key=lambda x: x[1], reverse=True)
now_list = np.array(sorted(a_list))
min_a = min(a_list)
for bc in bc_list:
    b, c = bc
    if min_a >= c:
        # もう置き換えても合計値は増えない
        break
    # cより小さい数は何個あるか？
    # 線形探索だとTLEになるので、2分探索で考える
    c_index = bisect.bisect_right(now_list, c)
    if c_index < b:
        # c_indexまでをcで置き換えても、順序の入れ替えはない
        now_list[:c_index] = c
    else:
        # cより小さい数全てを置き換えられないので、
        # 小さい方から数えてb個まで置き換える
        now_list[:b] = c
        # c_indexより前の数よりは大きくなるので、
        # 順序の入れ替えが発生する
        now_list = np.hstack([now_list[b:c_index], now_list[:b], now_list[c_index:]])

ans = sum(now_list)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
import bisect
import numpy as np

N, M = list(map(int, input().split()))
a_list = list(map(int, input().split()))
bc_list = []

for i in range(M):
    try:
        b, c = list(map(int, input().split()))
        bc_list.append((b, c))
    except:
        M = i

bc_list = sorted(bc_list, key=lambda x: x[1], reverse=True)
a_list = sorted(a_list)

fix_list = []
s = 0
b, c = bc_list[0]
bc_index = 0
now_b, now_c = 0, c

for i, a in enumerate(a_list):
    # a = a_list[i]
    if now_b >= b:
        bc_index += 1
        if bc_index >= len(bc_list):
            # TODO: 残りを足す
            fix_list.append(a)
            s += a
            continue
        now_b = 0
        b, c = bc_list[bc_index]

    if a < c:
        fix_list.append(c)
        s += c
    else:
        fix_list.append(a)
        s += a
    now_b += 1

ans = s
print(ans)
### BUGGY CODE ###

N=int(input())
AB=[]
for i in range(N):
    AB.append(list(map(int,input().split())))
A=[]
B=[]
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])
for i in range(N):
    if B[i]==min(B):
        bmin=i
print(A[bmin]+B[bmin])

### FIXED CODE ###

N=int(input())
AB=[]
for i in range(N):
    AB.append(list(map(int,input().split())))
a=AB[0][1]
b=0
for i in range(1,N):
    if AB[i][1]<a:
        a=AB[i][1]
        b=i
print(a+AB[b][0])
### BUGGY CODE ###

n=int(input())
L=[[] for _ in range(n)]
ans=0
for i in range(n):
    L[i]=list(input())
    L[i].sort()
    for j in range(i):
        if L[j]==L[i]:
            ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
L=[[] for _ in range(n)]
ans=0
for i in range(n):
    L[i]=sorted(list(input()))
L=sorted(L)
tmp=1
ans=0
for i in range(n-1):
    if L[i]==L[i+1]:
        tmp+=1
    else:
        ans+=tmp*(tmp-1)//2
        tmp=1
ans+=tmp*(tmp-1)//2
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
C=[0]*N
for i in range(N):
  C[i]=A.index(i+1)+1
print(*C)



### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
C=[0]*N
for i in range(N):
  C[A[i]-1]=i+1
print(*C)
### BUGGY CODE ###

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


MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

for i in range(2019):
    idx = myidx(i,i)
    MOD[idx] = 2019

MMM = []
MIN = 2019
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(max(Lmod,i+1), 2019)):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

#MMM=list(set(MMM))
#MMM.sort()
#print(MMM.pop(0))
print(MIN)


### FIXED CODE ###

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

MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(i+1,2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

#for i in range(2019):
#    idx = myidx(i,i)
#    MOD[idx] = 2019

MMM = []
MIN = 2019
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(max(Lmod,i+1), 2019)):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

#MMM=list(set(MMM))
#MMM.sort()
#print(MMM.pop(0))
print(MIN)
### BUGGY CODE ###

n,k = map(int,input().split())
prev = abs(n-k)
now = abs(prev-k)
while(now < prev):
    prev = now
    now = abs(now-k)
print(prev)

### FIXED CODE ###

n,k = map(int,input().split())
a = n%k
print(min(a,k-a))
### BUGGY CODE ###

import sys
L, R = map(int, input().split())
ans = []

def calc_mod(x, y):
    return x * y % 2019

left = L % 2019
right = (R-L) + left

if left==0 or right==0:
    print(0)
    sys.exit(0)

for i in range(left, right):
    for j in range(i+1, right+1):
        ans.append(calc_mod(i, j))

print(min(ans))

### FIXED CODE ###

import sys
L, R = map(int, input().split())
ans = []

def calc_mod(x, y):
    return x * y % 2019

left = L % 2019
right = R % 2019

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

elif left > right:
    print(0)
    sys.exit(0)

elif left==0 or right==0:
    print(0)
    sys.exit(0)

for i in range(left, right):
    for j in range(i+1, right+1):
        ans.append(calc_mod(i, j))

print(min(ans))