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

from collections import deque


def main():
    N, M = map(int, input().split())
    dp = [[set() for _ in range(N)] for _ in range(3)]
    for _ in range(M):
        u, v = map(int, input().split())
        dp[0][v-1].add(u-1)
    S, T = map(int, input().split())
    for i in range(1, 3):
        for j in range(N):
            tmp = set()
            for nxt in dp[i-1][j]:
                tmp = tmp.union(dp[0][nxt])
            dp[i][j] = tmp
    adj = [set() for _ in range(N)]
    for i in range(N):
        for j in dp[2][i]:
            adj[j].add(i)
    searchq = deque()
    visited = set()
    searchq.append((S-1, 0))
    visited.add(S-1)
    while len(searchq):
        p, cost = searchq.popleft()
        if p == T-1:
            print(cost)
            return
        for nxt in adj[p]:
            if nxt not in visited:
                searchq.append((nxt, cost+1))
                visited.add(nxt)
    print(-1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N*3)]
    dp = [[[] for _ in range(N)] for _ in range(3)]
    for _ in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        adj[u].add(N*1+v)
        adj[N*1+u].add(N*2+v)
        adj[N*2+u].add(v)
    S, T = map(int, input().split())
    searchq = deque()
    visited = set()
    searchq.append((S-1, 0))
    visited.add(S-1)
    while len(searchq):
        p, cost = searchq.popleft()
        if p == T-1:
            print(cost//3)
            return
        for nxt in adj[p]:
            if nxt not in visited:
                searchq.append((nxt, cost+1))
                visited.add(nxt)
    print(-1)


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

# encoding: utf-8
import sys

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

# num of Ai each Bi can lift
capacity_B = [0] * N
idx_A = 0
idx_B = 0
for i in range(2 * N):
    if idx_B == N: break
    elif idx_A == N:
        for i in range(idx_B, N): capacity_B[i] = N
    elif A[idx_A] >= B[idx_B]:
        capacity_B[idx_B] = idx_A
        idx_B += 1
    else:
        idx_A += 1
        
# print("#", capacity_B)

# num of Bi each Ci can lift
capacity_C = [0] * N
idx_B = 0
idx_C = 0
for i in range(2 * N):
    if idx_C == N: break
    elif idx_B == N:
        for i in range(idx_C, N): capacity_C[i] = N
    elif B[idx_B] >= C[idx_C]:
        capacity_C[idx_C] = idx_B
        idx_C += 1
    else:
        idx_B += 1

# print("#", capacity_C)

# num of (Ai, Bi) each Ci can lift
stacked = [0] * N
idx_AB = 0
idx_BC = 0
sum_tmp = 0
for i in range(2 * N):
    if idx_BC == N: break
    elif idx_AB == N:
        for i in range(idx_BC, N): stacked[i] = sum_tmp
    elif idx_AB >= capacity_C[idx_BC]:
        stacked[idx_BC] = sum_tmp
        idx_BC += 1
    else:
        sum_tmp += capacity_B[idx_AB]
        idx_AB += 1

# print("#", stacked)

# the answer is sum of All
print(sum(stacked))

### FIXED CODE ###

# encoding: utf-8
import sys

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

### TLE test in NlogN ###

# num of Ai each Bi can lift
capacity_B = [0] * N
idx_A = 0
idx_B = 0
for i in range(2 * N):
    if idx_B == N: break
    elif idx_A == N:
        for i in range(idx_B, N): capacity_B[i] = N
        break # oh...
    elif A[idx_A] >= B[idx_B]:
        capacity_B[idx_B] = idx_A
        idx_B += 1
    else:
        idx_A += 1
        
# print("#", capacity_B)

# num of Bi each Ci can lift
capacity_C = [0] * N
idx_B = 0
idx_C = 0
for i in range(2 * N):
    if idx_C == N: break
    elif idx_B == N:
        for i in range(idx_C, N): capacity_C[i] = N
        break # oh...
    elif B[idx_B] >= C[idx_C]:
        capacity_C[idx_C] = idx_B
        idx_C += 1
    else:
        idx_B += 1

# print("#", capacity_C)

# sum of [num of (Ai, Bi) each Ci can lift]
ans = 0
idx_AB = 0
idx_BC = 0
sum_tmp = 0
for i in range(2 * N):
    if idx_BC == N: break
    elif idx_AB == N:
        for i in range(idx_BC, N): ans += sum_tmp
        break # oh...
    elif idx_AB >= capacity_C[idx_BC]:
        ans += sum_tmp
        idx_BC += 1
    else:
        sum_tmp += capacity_B[idx_AB]
        idx_AB += 1

# print("#", stacked)

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

n = int(input())

for i in range(1,n+1):
    ans = 0
    for x in range(1,int(i**0.5+1)):
        for y in range(1,int((i-x**2)**0.5+1)):
            a = (x+y)**2 - 4*(x**2 + y**2 + x*y - i)
            if a >= 0:
                z1 = (a**0.5) -(x+y)
                z2 = -(a**0.5) -(x+y)
                if z1//1 == z1 and z1 > 0:
                    ans += 1
                if z2//1 == z2 and z2 > 0:
                    ans += 1
    print(ans)

### FIXED CODE ###

n = int(input())

a = [0]*(10**4)

for x in range(1,10**2):
    for y in range(1,10**2):
        for z in range(1,10**2):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if s <= 10**4:
                a[s-1] += 1

for i in range(n):
    print(a[i])
### BUGGY CODE ###


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

import math
from fractions import gcd

A, B = map(int, input().split())

# 最大公約数
g = gcd(A, B)

if g == 1:
    print(1)
    exit()

ggg = set()
for i in range(1, g):
    for j in range(i+1, g+1):
        if A%i == 0 and B%i == 0 and A%j == 0 and B%j == 0:
            ggg.add(i)
            ggg.add(j)

#print(ggg)

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

prime = get_sieve_of_eratosthenes(g)
phash = {}
for p in prime:
    phash[p] = True

#print(prime)
#print(phash)

count = 0
for x in ggg:
    if x in phash:
        count += 1

# 1 の分を +1
print(count+1)

### FIXED CODE ###


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

from fractions import gcd

A, B = map(int, input().split())

# 最大公約数
g = gcd(A, B)

if g == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

print(len(prime_factorize(g)) +1)
### BUGGY CODE ###

import sys
X, K, D = map(int, input().split())
if X == D and K%2 == 0:
    print(abs(X))
    sys.exit(0)
for _ in range(K):
    if abs(X+D) > abs(X-D):
        X -= D
    else:
        X += D
print(abs(X))

### FIXED CODE ###

X, K, D = map(int, input().split())

X = abs(X)

if K <= int(X/D):
    X -= D*K
    print(abs(X))
else:
    K -= int(X/D)
    X -= D*int(X/D)
    if K % 2 == 0:
        print(abs(X))
    else:
        print(abs(X-D))
### BUGGY CODE ###

n, x, y = map(int, input().split())
a = []
for s in range(1, n): #start
    for g in range(s+1, n+1): #goal
        a.append(min(g-s, abs(x-s)+1+abs(g-y), abs(y-s)+1+abs(g-x)))

#print(a)
for i in range(1, n):
    print(a.count(i))

### FIXED CODE ###

n, x, y = map(int, input().split())
a = [0 for i in range(n)]
for s in range(1, n): #start
    for g in range(s+1, n+1): #goal
        a[min(g-s, abs(x-s)+1+abs(g-y), abs(y-s)+1+abs(g-x))] += 1

#print(a)
for i in range(1, n):
    print(a[i])
### BUGGY CODE ###

##################################################################

if __name__ == "__main__":
    Input = [input() for i in range(2)]
    N = int(Input[0])
    L = list(map(int,Input[1].split()))
    L.sort()
    ans = 0
    for i1 in range(N-1,1,-1):
        a = L[i1]
        for i2 in range(i1-1,0,-1):
            b = L[i2]
            for i3 in range(i2-1,-1,-1):
                if L[i3]>a-b:
                    ans += 1
                else:
                    break
    print(ans)


### FIXED CODE ###

import bisect
##################################################################
def main():
    Input = [input() for i in range(2)]
    N = int(Input[0])
    L = list(map(int,Input[1].split()))
    L.sort()
    ans = 0
    for i1 in range(0,N-2):
        a = L[i1]
        for i2 in range(i1+1,N-1):
            b = L[i2]
            ans += bisect.bisect_left(L, a+b) - i2 - 1
    print(ans)



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

import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0 for _ in range(M)]
for i in range(M):
	a[i] = int(input())

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

for i in range(N+1):
	if a.count(i):
		continue
	for j in [1, 2]:
		if i - j >= 0 and not a.count(i-j):
			dp[i] += dp[i-j]
print(dp[-1]%1000000007)

### FIXED CODE ###

import sys
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N, M = map(int, input().split())
n = [True for _ in range(N+1)]
for _ in range(M):
	n[int(input())] = False

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

for i in range(N+1):
	if not n[i]:
		continue
	for j in [1, 2]:
		if i - j >= 0:
			dp[i] += dp[i-j]
print(dp[-1]%1000000007)
### BUGGY CODE ###

N,K = map(int,input().split())
S = list(map(int,input()))
blobs = []
if S[0] == 0:
    blobs.append(0)
cnt = 0
past_i = 0
for i in range(len(S)):
    if i == 0:
        past_i = S[i]
    if past_i == S[i]:
        cnt += 1
        past_i = S[i]
        
    else:
        blobs.append(cnt)
        cnt = 1
        past_i = S[i]
    if i == len(S)-1:
        blobs.append(cnt)

if S[-1] == 0:
    blobs.append(0)
sums = []
for i in range(len(blobs)//2-min(K,len(blobs)//2)+1):
    temp_sum = sum(blobs[2*i:min(2*(i+K)+1,len(blobs))])
    sums.append(temp_sum)
    if temp_sum == N:
        break
print(max(sums))

### FIXED CODE ###

N,K = map(int,input().split())
S = input()
one = [0]
zero = [0]
if S[0] == '0':
    one.append(0)
cnt = 1
for i in range(1,len(S)):
    if S[i] != S[i-1]:
        if S[i-1] == '1':
            one.append(cnt+one[-1])                
        else:
            zero.append(cnt+zero[-1])                
        cnt = 1
    else:
        cnt += 1
else:
    if S[-1] == '1':
        one.append(cnt+one[-1])                
    else:
        zero.append(cnt+zero[-1])                
        one.append(one[-1])                
window_size = min(len(zero)-1,K)
MAX = 0
for i in range(len(zero)-window_size):
    if MAX < (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i]):
        MAX = (zero[i+window_size] - zero[i]) + (one[i+window_size+1] - one[i])

print(MAX)
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))
B=[]
mod=10**9+7
for i in range(N-1):
    for j in range(i, N):
        B.append((A[i]^A[j])%mod)
print(sum(B)%mod)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)
### BUGGY CODE ###

N, K = map(int, input().lower().split())
H = []
total = 0
input_string = input()
H = input_string.split()
H = list(map(int, H))
for j in range(K):
    if not H:
        break
    else:
        H.remove(max(H))
print(sum(H))


### FIXED CODE ###

N, K = map(int, input().lower().split())
H = []
total = 0
input_string = input()
H = input_string.split()
H = list(map(int, H))

H.sort(reverse = True)
del H[0:K]

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

n,k,l=map(int,input().split())
load=[[] for _ in range(n)]
train=[[] for _ in range(n)]
for _ in range(k):
  a,b=map(int,input().split())
  a-=1
  b-=1
  load[a].append(b)
  load[b].append(a)
for _ in range(l):
  a,b=map(int,input().split())
  a-=1
  b-=1
  train[a].append(b)
  train[b].append(a)
# 道路の連結グループ
not_seen=set(range(n))
load_grp={}
load_grp_id=[-1]*n
while not_seen:
  t0=list(not_seen)[0]
  todo=[t0]
  seen=[0]*n
  load_grp[t0]=set([t0])
  load_grp_id[t0]=t0
  while todo:
    t=todo.pop()
    not_seen.discard(t)
    l=load[t]
    for li in l:
      if load_grp_id[li]==-1:
        load_grp[t0].add(li)
        load_grp_id[li]=t0
        todo.append(li)
# 鉄道の連結グループ
not_seen=set(range(n))
train_grp={}
train_grp_id=[-1]*n
while not_seen:
  t0=list(not_seen)[0]
  todo=[t0]
  seen=[0]*n
  train_grp[t0]=set([t0])
  train_grp_id[t0]=t0
  while todo:
    t=todo.pop()
    not_seen.discard(t)
    l=train[t]
    for li in l:
      if train_grp_id[li]==-1:
        train_grp[t0].add(li)
        train_grp_id[li]=t0
        todo.append(li)
from collections import defaultdict
d=defaultdict(int)
for i in range(n):
  lid=load_grp_id[i]
  tid=train_grp_id[i]
  d[(lid,tid)]+=1
ans=[]
for i in range(n):
  lid=load_grp_id[i]
  tid=train_grp_id[i]
  ans.append(str(d[(lid,tid)]))
print(' '.join(ans))

### FIXED CODE ###

n,k,l=map(int,input().split())
load=[[] for _ in range(n)]
train=[[] for _ in range(n)]
for _ in range(k):
  a,b=map(int,input().split())
  a-=1
  b-=1
  load[a].append(b)
  load[b].append(a)
for _ in range(l):
  a,b=map(int,input().split())
  a-=1
  b-=1
  train[a].append(b)
  train[b].append(a)

# 道路の連結グループ
load_grp_id=[-1]*n
not_grp=set(range(n))
while not_grp:
  t0=not_grp.pop()
  todo=[t0]
  load_grp_id[t0]=t0
  while todo:
    t=todo.pop()
    l=load[t]
    for li in l:
      if load_grp_id[li]==-1:
        load_grp_id[li]=t0
        not_grp.discard(li)
        todo.append(li)
# 鉄道の連結グループ
train_grp_id=[-1]*n
not_grp=set(range(n))
while not_grp:
  t0=not_grp.pop()
  todo=[t0]
  train_grp_id[t0]=t0
  while todo:
    t=todo.pop()
    l=train[t]
    for li in l:
      if train_grp_id[li]==-1:
        train_grp_id[li]=t0
        not_grp.discard(li)
        todo.append(li)

d={}
for i in range(n):
  lid=load_grp_id[i]
  tid=train_grp_id[i]
  if (lid,tid) in d:
    d[(lid,tid)]+=1
  else:
    d[(lid,tid)]=1
ans=[]
for i in range(n):
  lid=load_grp_id[i]
  tid=train_grp_id[i]
  ans.append(str(d[(lid,tid)]))
print(' '.join(ans))
### BUGGY CODE ###

S = input()
Q = int(input())
query = [0]*Q

for i in range(Q):
    inp = input()
    if inp == "1":
        query[i] = "1"
    else:
        query[i] = list(inp.split())

for i in range(Q):
    if query[i] == "1":
        S = S[::-1]
    else:
        if query[i][1] == "1":
            S = query[i][2] + S
        else:
            S = S + query[i][2]

print(S)

### FIXED CODE ###

S = input()
Q = int(input())
query = [0]*Q

for i in range(Q):
    inp = input()
    if inp == "1":
        query[i] = "1"
    else:
        query[i] = list(inp.split())

left_head_if_even = 0
right = ""
left = ""

for i in range(Q):
    if query[i] == "1":
        left_head_if_even += 1
    else:
        if query[i][1] == "1":
            if left_head_if_even%2 == 0:
                left = query[i][2] + left
            else:
                right = right + query[i][2]

        else:
            if left_head_if_even%2 == 1:
                left = query[i][2] + left
            else:
                right = right + query[i][2]

if left_head_if_even%2==0:
    S = left + S + right
else:
    S = left + S + right
    S = S[::-1]

print(S)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
j=0
for i in range(M):
    A[A.index(max(A[:j+1]))]=A[A.index(max(A[:j+1]))]//2
    j=j+1
    if j==1000:
        A.sort(reverse=True)    
        j=0
print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x: x*(-1),list(map(int,input().split()))))
A.sort()
B=[]
for i in range(N):
    heapq.heappush(B,A[i])
for i in range(M):
    heapq.heappush(B,(((heapq.heappop(B))*(-1))//2)*(-1))
print((sum(B))*(-1))
### BUGGY CODE ###

n = int(input())
l = []
ans = 0
for i in range(n):
  s = input()
  if s in l:
    continue
  else:
    ans+=1
    l.append(s)
print(ans)

### FIXED CODE ###

n = int(input())
d = {}
ans = 0
for i in range(n):
  s = input()
  if d.get(s, 0)==0:
    d[s]=1
    ans+=1
print(ans)
### BUGGY CODE ###

import sys
 
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
 
sys.setrecursionlimit(10 ** 9)
 
 
def main():
    N = INT()
    S = [INPUT() for _ in range(N)]
    check = []
    alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    count = 0

    for i in range(N):
        check.append([0] * 26)
        for j in range(10):
            for k in range(26):
                if S[i][j] == alphabet[k]:
                    check[i][k] += 1

    for i in range(N - 1):
        for j in range(i + 1, N):
            if check[i] == check[j]: count += 1

    print(count)
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]

    l = []
    for s in S:
        tmp_l = []
        for c in s:
            tmp_l.append(ord(c))
        tmp_l = sorted(tmp_l)

        tmp_s = ""
        for n in tmp_l:
            tmp_s += chr(n)
        l.append(tmp_s)

    C = Counter(l)
    ans = 0
    for c in C.values():
        if c > 1:
            ans += factorial(c) // (factorial(c - 2) * factorial(2))

    print(ans)


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

n,x = map(int,input().split())
if x in (1, 2 * n - 1):
    print('No')
    exit()
res = list(range(1, 2 * n))
while res[n - 1] != x:
    res = res[1:] + [res[0]]
print('Yes')
print(*res, sep = '\n')


### FIXED CODE ###

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

# 仮説
if x in (1,2*n-1):
    print('No')
    exit()

res = [i for i in range(1,2*n)]

flag = False
if x > n:
    x = 2 * n - x
    flag = True

res = res[x-n:] + res[:x-n]

if flag:
    for i in range(2*n-1):
        res[i] = 2 * n - res[i]

print('Yes')
print(*res, sep='\n')
### BUGGY CODE ###

n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a].append(b)
  else:
    wars[a] = [b]

cuts = 0
antis = []

for i in range(1, n):
  if i in wars.keys():
    for anti in wars[i]:
      antis.append(anti)
  if i + 1 in antis:
    cuts += 1
    antis.clear()
    
print(cuts)

### FIXED CODE ###

n, m = map(int, input().split())
wars = {}
for i in range(m):
  a, b = map(int, input().split())
  if a in wars.keys():
    wars[a] = min(wars[a], b)
  else:
    wars[a] = b

cuts = 0
antis = 10**6

for i in range(1, n):
  if i in wars.keys():
    antis = min(antis, wars[i])
  if i + 1 == antis:
    cuts += 1
    antis = 10**6
    
print(cuts)
### BUGGY CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [0] + A
B = [0] + B
BM = M
X = 0
SA = 0
for i in range(N + 1):
    SA += A[i]
    SB = 0
    for j in range(M + 1):
        SB += B[j]
        if SA + SB <= K:
            X = max(X, i + j)
            M = j
        else:
            break
print(X)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
x = 0
bj = M
for i in range(N + 1):
    if a[i] > K:
        break
    for j in range(bj, -1, -1):
        if a[i] + b[j] <= K:
            bj = j
            x = max(x, i + j)
            break
print(x)
### BUGGY CODE ###

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

ans = 1
for i in range(1, n):
    if p[i] <= min(p[:i]):
        ans += 1

print(ans)


### FIXED CODE ###

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

ans = 1
min = p[0]
for i in range(1, n):
    if min > p[i]:
        min = p[i]
    if p[i] <= min:
        ans += 1

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

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

### FIXED CODE ###

L, R = list(map(int, input().split()))
a = (L * (L + 1)) % 2019
for i in range(L, min(R + 1, L + 2019)):
    for j in range(i + 1, min(i + 2020, R + 1)):
        if (i * j) % 2019 < a:
            a = (i * j) % 2019
print(a)
### BUGGY CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

ans = 0
while M > 0:
    if AB[0][1] == 0:
        AB = AB[1:]

    ans += AB[0][0]
    M -= 1

    AB[0][1] -= 1

print(ans)



### FIXED CODE ###

# coding: utf-8

# import sys
# input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

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

N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

A = sorted(A,reverse=True)
bc = sorted(bc,key=lambda x : x[1],reverse=True)

AA = []
for i in range(M):
    l = [bc[i][1]]*bc[i][0]
    AA += l

AA = sorted(AA)
AAA = []
for i in range(1,min(len(A),len(AA))+1):
    if A[-i] < AA[-i]:
        AAA.append(AA[-i])
    else:
        AAA.append(A[-i])
if len(A) >= len(AA):
    AAA += A[:N-len(AAA)]
print(sum(AAA))


### FIXED CODE ###

N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
bc = []
for i in range(M):
    bc.append(list(map(int,input().split())))

bc = sorted(bc,key=lambda x : -x[1])
i = 0
for b,c in bc:
    for j in range(i,min(N,i+b)):
        if A[j] < c:
            A[j] = c
    i += b
print(sum(A))
### BUGGY CODE ###

a, b, c, k = map(int, input().split())
for i in range(k):
    a, b, c = b + c, a + c, a + b 
ans = a - b
if ans >= 10 ** 18:
    print("Unfair")
else:
    print(ans)

### FIXED CODE ###

a, b, c, k = map(int, input().split())
if k == 0:
    print(a - b)
else:
    a, b, c = b + c, a + c, a + b 
    if a - b <= 0:
        print(abs(a - b) * (-1) ** k)
    
    elif a - b > 0:
        print(abs(a - b) * (-1) ** (k - 1))