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

from collections import deque
import sys
input = sys.stdin.readline

n=int(input())
s=deque([])
cnt=0
for _ in range(n):
    s.append(sorted(input()))
for i in range(n):
    for j in range(n):
        if i<j:
            if s[i]==s[j]:
                cnt+=1
print(cnt)

### 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 ###

from statistics import mean

N = int(input())
A = list(map(int, input().split()))
A_star = [a - (i + 1) for i, a in enumerate(A)]

def calc_score(b):
    score = 0
    for a in A_star:
        score += abs(a - b)
    return score

def decide_direction(b):
    score0 = calc_score(b)
    score1 = calc_score(b + 1)
    if score0 > score1:
        return 1
    else:
        return -1

b = int(mean(A_star))
direction = decide_direction(b)
pre_score = calc_score(b)

while True:
    b += direction
    score = calc_score(b)
    if score > pre_score:
        print(pre_score)
        break
    else:
        pre_score = score






### FIXED CODE ###

from statistics import median

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

A_star = [a - (i + 1) for i, a in enumerate(A)]

def calc_score(b):
    score = 0
    for a in A_star:
        score += abs(a - b)
    return score

def decide_direction(b):
    score0 = calc_score(b)
    score1 = calc_score(b + 1)
    if score0 > score1:
        return 1
    else:
        return -1

b = int(median(A_star))
direction = decide_direction(b)
pre_score = calc_score(b)

while True:
    b += direction
    score = calc_score(b)
    if score >= pre_score:
        print(pre_score)
        break
    else:
        pre_score = score
### BUGGY CODE ###

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

a = []
b = []

for i in range(N):
  a_dash,b_dash = map(int,input().split())
  a.append(a_dash)
  b.append(b_dash)

#dp[i+1][j] = i番目までの魔法で体力jのモンスターに
#勝つことができる、魔力の最小値
INF = 10**9
dp = [[INF for _ in range(H+1)] for _ in range(N+1)]

#体力0のモンスターは初めからデスしている
for i in range(N+1):
  dp[i][0] = 0

for i in range(N):
  for j in range(H+1):
    if a[i] > j:
      dp[i+1][j] = min(dp[i][j],b[i])
    else:
      dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+ b[i])

print(dp[N][H])


### FIXED CODE ###

import sys

def dp_all(dp):
  length = len(dp)
  for i in range(length):
    print(dp[i])

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

a = []
b = []

for i in range(N):
  a_dash,b_dash = map(int,input().split())
  a.append(a_dash)
  b.append(b_dash)

#dp[i+1][j] = i番目までの魔法で体力jのモンスターに
#勝つことができる、魔力の最小値
INF = 10**9
dp = [[INF for _ in range(H+1)] for _ in range(N+1)]

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

for i in range(N):
  for j in range(H+1):
    if a[i] > j:
      dp[i+1][j] = min(dp[i][j],b[i])
    else:
      dp[i+1][j] = min(dp[i][j],dp[i+1][j-a[i]]+ b[i])

print(dp[N][H])
### BUGGY CODE ###

import sys


def dfs(root, links, in_count):
    topological = []
    q = root.copy()
    while q:
        v = q.pop()
        topological.append(v)
        for u in links[v]:
            in_count[u] -= 1
            if in_count[u] == 0:
                q.add(u)
    return topological


n = int(input())

corr = {}
index = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        corr[i, j] = index
        corr[j, i] = index
        index += 1
match_count = n * (n - 1) // 2

roots = set()
in_count = [0] * match_count
out_links = [set() for _ in range(match_count)]

for i, line in enumerate(sys.stdin, start=1):
    aaa = list(map(int, line.split()))
    j = aaa[0]
    prev = corr[i, j]
    roots.add(prev)

    for j in aaa[1:]:
        key = corr[i, j]
        out_links[prev].add(key)
        in_count[key] += 1
        prev = key

roots = {r for r in roots if in_count[r] == 0}

if not roots:
    print(-1)
    exit()

topological = dfs(roots, out_links, in_count)
if len(topological) != n * (n - 1) // 2:
    print(-1)
    exit()

ans = 0
depth = [1] * match_count
for v in topological:
    d = depth[v] + 1
    for u in out_links[v]:
        depth[u] = max(depth[u], d)

print(max(depth))


### FIXED CODE ###

import sys
from collections import defaultdict


def dfs(root, links):
    status = {}
    topological = []
    q = [(r, 0, 1) for r in root]
    while q:
        node = q.pop()
        if node[1] == 0:
            v, _, d = node
            q.append((v, 1))
            status[v] = 1
            d += 1
            for u in links[v]:
                if u in status:
                    if status[u] == 1:
                        return False
                else:
                    q.append((u, 0, d))
        else:
            v = node[0]
            status[v] = 2
            topological.append(v)
    topological.reverse()
    return topological


n = int(input())
links = defaultdict(set)
may_root = set()
lines = sys.stdin.readlines()
matches = []
for i in range(n):
    line = lines[i]
    aaa = list(map(int, line.split()))
    match_order = []
    for j in aaa:
        j -= 1
        a, b = (i, j) if i < j else (j, i)
        key = a * n + b
        match_order.append(key)
    matches.append(match_order)
    may_root.add(match_order[0])

for i in range(n):
    kkk = matches[i]
    prev = kkk[0]

    for key in kkk[1:]:
        links[prev].add(key)
        may_root.discard(key)
        prev = key

if not may_root:
    print(-1)
    exit()

topological = dfs(may_root, links)
if topological == False:
    print(-1)
    exit()

ans = 0
depth = defaultdict(lambda: 1)
for v in topological:
    d = depth[v] + 1
    for u in links[v]:
        depth[u] = max(depth[u], d)

print(max(depth.values()))
### BUGGY CODE ###

n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
b = max(a)
c = a.index(b)
a.pop(c)
e = a
d = max(e)
a.insert(c, b)
for i in range(0, n):
    if a[i] == max(a):
        print(d)
    else:
        print(b)

### FIXED CODE ###

n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
first = max(a)
second_1 = sorted(a)
second = second_1[-2]
for i in range(0, n):
    if a[i] == first:
        print(second)
    else:
        print(first)
### BUGGY CODE ###

N = int(input())
S = tuple(map(int, input()))

ans = 0
for i in range(1000):
    ii = i
    key = ii%10
    count = 0
    for j in range(N):
        if key == S[j]:
            count += 1
            if count == 3:
                ans += 1
                break
            ii //= 10
            key = ii%10

print(ans)


### FIXED CODE ###

N = int(input())
S = tuple(map(int, input()))

ans = 0
for i in range(1000):
    ii = i
    key = ii%10
    count = 0
    for s in S:
        if key == s:
            count += 1
            if count == 3:
                ans += 1
                break
            ii //= 10
            key = ii%10

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

N = int(input())
A=[]
B=[]
for i in range(N):
    a,b=[int(n) for n in input().split()]
    A.append(a)
    B.append(b)

cnt=0

# print(list(reversed(range(N))))
for i in reversed(range(N)):
    if A[i]%B[i]==0:
        r=0
    else:
        r=B[i]-A[i]%B[i]
    cnt+=r
    A=[A[n]+r if n<=i else A[n] for n in range(N)]

print(cnt)


### FIXED CODE ###

N = int(input())
A=[]
B=[]
for i in range(N):
    a,b=[int(n) for n in input().split()]
    A.append(a)
    B.append(b)

cnt=0

# print(list(reversed(range(N))))
for i in reversed(range(N)):
    if (A[i]+cnt)%B[i]==0:
        d=0
    else:
        d=B[i]-(A[i]+cnt)%B[i]
    cnt+=d
#    A=[A[n]+r if n<=i else A[n] for n in range(N)]

print(cnt)
### BUGGY CODE ###

import heapq

N = int(input())
A = list(map(int,input().split()))
C = A[N:(2*N)]

L = []
R = []
for i in range(N):
  heapq.heappush(L,A[i]) #左側にAの左側からN個を追加
  heapq.heappush(R,-A[-1-i]) #右側数列にAの右側からN個を追加。多いほうから取り出すので-1倍

#左側の総和を求める。
ansL = [sum(L)]
for i in range(N):
  heapq.heappush(L,C[i])
  heapq.heappop(L)
  ansL.append(sum(L))

ansR = [sum(R)]
for i in range(N):
  heapq.heappush(R,-C[-1-i])
  heapq.heappop(R)
  ansR.append(sum(R))

ans = -float('inf')
for i in range(N+1):
  temp = ansL[i]+ansR[-1-i]
  ans = max(ans,temp)
#print(ansL,ansR)
print(ans)

### FIXED CODE ###

import heapq

N = int(input())
A = list(map(int,input().split()))
C = A[N:(2*N)]

L = []
R = []
for i in range(N):
  heapq.heappush(L,A[i]) #左側にAの左側からN個を追加
  heapq.heappush(R,-A[-1-i]) #右側数列にAの右側からN個を追加。多いほうから取り出すので-1倍

#左側の総和を求める。
ansL = [sum(L)]
for i in range(N):
  heapq.heappush(L,C[i])
  rmv = heapq.heappop(L)
  temp = ansL[i] + C[i] - rmv #一つ前の答え＋今新しく加えた数－最小値
  ansL.append(temp)
  #ansL.append(sum(L)) #sum(L)がO(N)かかっている？

ansR = [sum(R)]
for i in range(N):
  heapq.heappush(R,-C[-1-i])
  rmv = heapq.heappop(R)
  temp = ansR[i] - C[-1-i] - rmv
  ansR.append(temp)
  #ansR.append(sum(R)) #sum(R)がO(N)かかっている？

ans = -float('inf')
for i in range(N+1):
  temp = ansL[i]+ansR[-1-i]
  ans = max(ans,temp)
#print(ansL,ansR)
print(ans)
### BUGGY CODE ###

from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

# 再帰的に更新
def update_dp(dp, n):
    for i in nextl[n]:
        if dp[i] < dp[n] + 1:
            dp[i] = dp[n]+1
            update_dp(dp, i)


if __name__ == "__main__":

    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    xv = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]

    # iにいくまでの最長のパス
    dp = [0] * (N+1)

    # iのnextを保持するリスト
    nextl = [[] for _ in range(N+1)]

    for x, v in xv:
        if dp[v] < dp[x] + 1:
            dp[v] = dp[x]+1
            update_dp(dp, v)
        nextl[x].append(v)

    # for DEBUG
    #print(dp)
    print(max(dp))

### FIXED CODE ###

from sys import stdin
import math
import fractions
from collections import deque
import sys

# 再起の上限を変更
sys.setrecursionlimit(100000)

INF = 10 ** 10

# 深さ優先探索
def dfs(i):
    global is_visited
    global tsort_res

    if is_visited[i]:
        return 

    is_visited[i] = True
    for j in nextl[i]:
        dfs(j)
    
    # 帰りがけ順で追加
    # 追加は先頭に行う
    tsort_res.appendleft(i)


# トポロジカルソート
def tsort():
    for i in range(1, N+1):
        dfs(i)

if __name__ == "__main__":

    N, M = [int(x) for x in stdin.readline().rstrip().split()]

    # トポロジカルソートで頂点iより後ろのパスの最大長
    dp = [0] * (N+1)

    # 頂点xから頂点vへの有向辺
    nextl = [[] for _ in range(N+1)]
    for _ in range(M):
        x, v = list(map(int, stdin.readline().rstrip().split()))
        nextl[x].append(v)
    
    # トポロジカルソートされた結果の入るリスト
    tsort_res = deque([])

    is_visited = [False] * (N+1)

    tsort()

    # 今回は逆順に使うのでリバースする
    # 汎用性のため、dfsでは先頭に追加するようにしている
    tsort_res = list(tsort_res)[::-1]

    for x in tsort_res:
        for v in nextl[x]:
            dp[x] = max(dp[x], dp[v] + 1)


    # for DEBUG
    #print(dp)
    print(max(dp))
### BUGGY CODE ###

n, x, y = map(int, input().split())
ans = [0]*n

for i in range(1, n):
    for j in range(i + 1, n + 1):
        diff1 = j - i
        diff2 = x + y - i - j + 1
        if i <= x and j >= y:
            diff2 = x - y - i + j + 1
        elif x <= i <= y and x <= j <= y:
            diff2 = -x + y + i - j + 1
        elif x < i < y and j > y:
            diff2 = -x - y + i + j + 1
        if diff2 < 1:
            diff2 = diff1
        diff = min(diff1, diff2)
        ans[diff] = ans[diff] + 1

for i in range(1, n):
    print(ans[i])

### FIXED CODE ###

n, x, y = map(int, input().split())
ans = [0]*n

for i in range(1, n):
    for j in range(i + 1, n + 1):
        diff1 = j - i
        diff2 = x + y - i - j + 1
        if i <= x and j >= y:
            diff2 = x - y - i + j + 1
        elif x <= i <= y and x <= j <= y:
            diff2 = -x + y + i - j + 1
        elif x < i < y and j > y:
            diff2 = -x - y + i + j + 1
        if diff2 < 1:
            diff2 = diff1
        diff = min(diff1, diff2)
        ans[diff] = ans[diff] + 1

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

import sys

sys.setrecursionlimit(10**9)

input = sys.stdin.readline

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

for i in reversed(range(N)):
    if A[i]:
        put.append(i + 1)

        tmp = 1
        n = i + 1
        while tmp * tmp <= n:
            if n % tmp == 0:
                A[tmp - 1] ^= 1
                if tmp != n // tmp:
                    A[n // tmp - 1] ^= 1
            tmp += 1

if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**9)

input = sys.stdin.readline

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

for i in reversed(range(N)):
    if A[i]:
        put.append(i + 1)

        tmp = 1
        n = i + 1
        while tmp * tmp <= n:
            if n % tmp == 0:
                A[tmp - 1] ^= 1
                if tmp != n // tmp:
                    A[n // tmp - 1] ^= 1
            tmp += 1

if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)
### BUGGY CODE ###

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

s = sum(a)
ans = float('inf')
for i in range(1, n):
    if abs(s-sum(a[:i])*2) < ans:
        ans = abs(s-sum(a[:i])*2)

print(ans)


### FIXED CODE ###

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

tmp = 0
sum_list = [0]
for i in range(n):
    tmp += a[i]
    sum_list.append(tmp)

diff = float('inf')
for i in range(1,n):
    diff = min(diff, abs(sum_list[-1]-2*sum_list[i]))

print(diff)
### BUGGY CODE ###

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

DP = [10 ** 10] * N
DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, N):
  for j in range(1, K + 1):
    if i - j >= 0:
      DP[i] = min(DP[i], DP[i - j] + abs(H[i] - H[i - j]))

#print(DP)
print(DP[-1])


### FIXED CODE ###

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

DP = [10 ** 10] * N
DP[0] = 0
DP[1] = abs(H[1] - H[0])
for i in range(2, N):
  for j in range(1, K + 1):
    if i - j >= 0:
      DP[i] = min(DP[i], DP[i - j] + abs(H[i] - H[i - j]))

#print(DP)
print(DP[-1])
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

def lcs(s, t):
  dp = [['' for _ in range(len(t)+1)] for _ in range(len(s)+1)]
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max([(dp[i-1][j-1]+si) if si==tj else '', dp[i-1][j], dp[i][j-1]], key=lambda x: len(x))
  return dp[-1][-1]

def main():
  s = input().strip()
  t = input().strip()
  print(lcs(s, t))


if __name__=='__main__':
  main()

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

# @profile
def calc_lcs(s, t):
  dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
  # dp = numpy.zeros((len(s)+1, len(t)+1))
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max((dp[i-1][j-1] + 1) if si==tj else 0, dp[i-1][j], dp[i][j-1])

  lcs = ''
  i, j = len(s), len(t)
  while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
      i -= 1
    elif dp[i][j] == dp[i][j-1]:
      j -= 1
    else:
      lcs = s[i-1] + lcs
      i -= 1
      j -= 1
  return lcs

def main():
  s = input().strip()
  t = input().strip()
  print(calc_lcs(s, t))


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

A,B,C,D=map(int,input().split())
cnt=0
k=0
for j in range(A,B+1):
    k+=1
    if j%C==0 or j%D==0:
        cnt+=1  
print(k-cnt)

### FIXED CODE ###

import fractions

A,B,C,D=map(int,input().split())
c=B//C-(A-1)//C 
d=B//D-(A-1)//D 
l=C*D//fractions.gcd(C,D)
cd=B//l-(A-1)//l
print(int(B-(A-1)-c-d+cd))
### BUGGY CODE ###

import heapq
n, m = map(int, input().split())
a_lst = list(map(int, input().split()))
bc_lst = [list(map(int, input().split())) for _ in range(m)]

aa_lst = a_lst[:]

heapq.heapify(aa_lst)
for bc in bc_lst:
    for i in range(bc[0]):
        if aa_lst[0] < bc[1]:
            heapq.heapreplace(aa_lst, bc[1])
        else:
            break
        
print(sum(aa_lst))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a_lst = list(map(int, input().split()))
bc_lst = [list(map(int, input().split())) for _ in range(m)]

bc_lst = sorted(bc_lst, key = lambda x: -x[1])
aa_lst = a_lst[:]

heapq.heapify(aa_lst)
for bc in bc_lst:
    for i in range(bc[0]):
        if aa_lst[0] < bc[1]:
            heapq.heapreplace(aa_lst, bc[1])
        else:
            break
        
print(sum(aa_lst))
### BUGGY CODE ###

time = int(input())
ans = []
for i in range(time):
    now = input()
    if now in ans:
        ans.remove(now)
    else:
        ans.append(now)
print(len(ans))


### FIXED CODE ###

time = int(input())
ans = []
n = 0
for i in range(time):
    ans.append(input())
ans.sort(key=int)
while n+1 < len(ans):
    if ans[n] == ans[int(n + 1)]:
        ans.pop(n)
        ans.pop(n)
    else:
        n += 1
print(len(ans))
### BUGGY CODE ###

S=input()
T=input()
s=len(S)
t=len(T)
dp=[['' for i in range(t+1)] for j in range(s+1)]
for i in range(s):
    for j in range(t):
        if S[i]==T[j]:
            dp[i+1][j+1]=dp[i][j]+S[i]
            continue
        dp[i+1][j+1]=dp[i+1][j]
        if len(dp[i][j+1])>len(dp[i+1][j]):
            dp[i+1][j+1]=dp[i][j+1]
print(dp[s][t])


### FIXED CODE ###

S=input()
T=input()
dp=[[0 for j in range(len(T)+1)] for i in range(len(S)+1)]
for i in range(len(S)):
    for j in range(len(T)):
        if S[i]==T[j]:
            dp[i+1][j+1]=dp[i][j]+1
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j])
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1])
i=len(S)
j=len(T)
ans=""
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans=S[i-1]+ans
        i-=1
        j-=1
print(ans)
### BUGGY CODE ###

# ハッシュテーブル　dictionary
n = int(input())
s = list(input() for i in range(n))
s_dict = {}

# 入力文字をkeyに、その文字の入力回数をvalueにした辞書作成
for word in s:
    num = int(s.count(word))
    s_dict[word] = num

# 入力回数が最大の単語のみのリストを作成
# s_dictに含まれるkeyとvalueを1個ずつ抜き出し、s[1](value) がmaxのときs[0](key) を max_sに入れる
max_s = [s[0] for s in s_dict.items() if s[1] == max(s_dict.values())]
# 作成したリストのソート
max_s.sort()

for word in max_s:
    print(word)

### FIXED CODE ###

import collections

n = int(input())
s = [input() for i in range(n)]

# リストsに含まれる単語と出現回数の辞書を作成
# keyに要素　valueに出現回数 
a = collections.Counter(s)

# 出現回数の最大値を取得
max_a = max(a.values())

# value=max_a　なら　keys　に key（単語） を書き込む
# k / for k, v in a.items() / if v == max_a
keys = [k for k, v in a.items() if v == max_a]
keys.sort()

[print(word) for word in keys]
### BUGGY CODE ###

n=int(input())

a=1
while True:
    t=a*(a-1)//2
    if t>n:
        print("No")
        exit()
    if t==n:
        print("Yes")
        break
    a+=1
print(a)
s=set(range(1,1+n))
l=[0]*(n+1)
ans=[set()]

for i in range(a):
    ll=set()
    for j in ans[:i+1]:
        for p in s&j-ll:
            ll.add(p)
            if l[p]==1:
                s.remove(p)
            else:
                l[p]+=1
            break

    for p in s:
        if len(ll)>=n*2//a:
            break
        else:
            if l[p]==0:
                ll.add(p)
                l[p]+=1

    ans.append(ll)
    print(n*2//a,*ll)

### FIXED CODE ###

def main():
    n=int(input())
    m=int((2*n)**0.5)
    if m*(m+1)==n*2:
        print("Yes")
        m+=1
        print(m)
    else:
        print("No")
        exit()
    
    ans=[[m-1] for i in range(m)]
    c=1
    for i in range(m):
        for j in range(i+1,m):
            ans[i].append(c)
            ans[j].append(c)
            c+=1
    for i in ans:
        print(*i)


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

N = int(input())
S = [input() for i in range(N)]

def check(A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[(A+i)%N][(B+j)%N] != S[(A+j)%N][(B+i)%N]:
                return 0
    return 1

ans = 0
for i in range(N):
    ans += N*check(0, i)
print(ans)

### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]

def check(A, B):
    for i in range(N):
        for j in range(i+1, N):
            if S[(A+i)%N][(B+j)%N] != S[(A+j)%N][(B+i)%N]:
                return 0
    return 1

ans = 0
for i in range(N):
    ans += N*check(0, i)
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
l, r = map(int, input().split())

r = min(r, l+4038)
ans = 2018

for i in range(l, r+1, 1):
  for j in range(i+1, r+1, 1):
    x = i*j%2019
    ans = min(ans, x)

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
l, r = map(int, input().split())

r = min(r, l+673)
ans = 2018

for i in range(l, r+1, 1):
  for j in range(i+1, r+1, 1):
    x = i*j%2019
    ans = min(ans, x)

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

import sys
sys.setrecursionlimit(1000000)
N, u, v = map(int, input().split())
u -= 1
v -= 1

G = [[] for _ in range(N)]
elens = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    elens[a] += 1
    elens[b] += 1
depths = [0] * N
dists = [0] * N


TAKAHASHI = [0] * N
AOKI = [0] * N

def dfs_aoki(cur: int, past: int, d: int):
    AOKI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_aoki(nx, cur, d + 1)

def dfs_takahashi(cur: int, past: int, d: int):
    TAKAHASHI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_takahashi(nx, cur, d + 1)

dfs_takahashi(u, -1, 0)
dfs_aoki(v, -1, 0)

ans = 0

for i in range(N):
    if TAKAHASHI[i] < AOKI[i]:
        ans = max(ans, AOKI[i] - 1)

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N, u, v = map(int, input().split())
u -= 1
v -= 1

G = [[] for _ in range(N)]
elens = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    elens[a] += 1
    elens[b] += 1
depths = [0] * N
dists = [0] * N


TAKAHASHI = [0] * N
AOKI = [0] * N

def dfs_aoki(cur: int, past: int, d: int):
    AOKI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_aoki(nx, cur, d + 1)

def dfs_takahashi(cur: int, past: int, d: int):
    TAKAHASHI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_takahashi(nx, cur, d + 1)

dfs_takahashi(u, -1, 0)
dfs_aoki(v, -1, 0)

ans = 0

for i in range(N):
    if TAKAHASHI[i] < AOKI[i]:
        ans = max(ans, AOKI[i] - 1)

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

import sys
from bisect import bisect_left
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    closure = []
    for _ in range(N):
        start, end, pos = map(int, input().split())
        heappush(closure, (pos, start, end))

    D = [0] * Q
    index = dict()
    for i in range(Q):
        d = int(input())
        D[i] = d

    ans = []
    while len(closure) > 0:
        pos, start, end = heappop(closure)

        left = bisect_left(D, start - pos)
        right = bisect_left(D, end - pos)

        for blocked in D[left:right]:
            heappush(ans, (blocked, pos))

        D = D[0:left] + D[right:]

    for blocked in D:
        heappush(ans, (blocked, -1))

    while len(ans) > 0:
        _, pos = heappop(ans)
        print(pos)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# ref: https://atcoder.jp/contests/abc128/submissions/5654623

import sys
from bisect import bisect_left

def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    closure = []
    for _ in range(N):
        start, end, pos = map(int, input().split())
        closure.append((pos, start, end))

    closure.sort()

    D = [int(input()) for _ in range(Q)]

    ans = [-1] * Q
    skip = [-1] * Q
    for pos, start, end in closure:
        left = bisect_left(D, start - pos)
        right = bisect_left(D, end - pos)

        while left < right:
            if skip[left] == -1:
                ans[left] = pos
                skip[left] = right
                left += 1
            else:
                left = skip[left]

    return ans


if __name__ == '__main__':
    print(*main(), sep='\n')