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

from bisect import bisect_left, bisect_right

N = int(input())
S = list(input())
Q = int(input())

D = {chr(ord('a') + i): [] for i in range(26)}

for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

    if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

        print(ans)

### FIXED CODE ###

from bisect import bisect_left, bisect_right

N = int(input())
S = list(input())
Q = int(input())

D = {chr(ord('a') + i): [] for i in range(26)}

for i, s in enumerate(S):
    D[s].append(i)

for q in range(Q):
    query = list(input().split())
    if query[0] == '1':
        i, x = int(query[1]), query[2]
        i -= 1
        s = S[i]
        if s == x:
            continue

        D[s].remove(i)
        next_i = bisect_left(D[x], i)
        D[x].insert(next_i, i)
        S[i] = x

    if query[0] == '2':
        l, r = int(query[1]), int(query[2])
        l, r = l - 1, r - 1
        ans = 0
        for i in range(26):
            s = chr(ord('a') + i)

            li = bisect_left(D[s], l)
            ri = bisect_right(D[s], r)

            if ri - li > 0:
                ans += 1

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

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

lr = [[0 for i in range(n+1)] for j in range(n+1)]


for i in range(m):
    l,r = map(int,input().split())
    lr[l][r] += 1

#pq = [[int(i) for i in input().split()]for j in range(q)]

dp = [[0 for i in range(n+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(i,n+1):
        dp[i][j] = dp[i][j-1]+lr[i][j]

ans_dp = [[0 for i in range(n+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(i,n+1):
        tmp = 0
        for k in range(j-i+1):
            tmp += dp[i+k][j]
        ans_dp[i][j] = tmp

for i in range(q):
    p,q = map(int,input().split())
    print(ans_dp[p][q])


### FIXED CODE ###

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

lr = [[0 for i in range(n+1)] for j in range(n+1)]
#lr = [[int(i) for i in input().split()]for j in range(m)]

st = [0] * (n+1)
ed = [0] * (n+1)

for i in range(m):
    l,r = map(int,input().split())
    lr[l][r] += 1

pq = [[int(i) for i in input().split()]for j in range(q)]

dp = [[0 for i in range(n+1)] for j in range(n+1)]

#print(lr)

for i in range(1,n+1):
    #print(i)
    for j in range(i,n+1):
        #print(i,j)
        dp[i][j] = dp[i][j-1]+lr[i][j]

for i in range(q):
    st = pq[i][0]
    ed = pq[i][1]
    tmp = 0
    for j in range(ed-st+1):
        tmp += dp[st+j][ed]
    print(tmp)
#print(dp)
### BUGGY CODE ###

N, M = map(int, input().split())
for i in range(M//N,0,-1):
  if M % i == 0:
    print(i)
    break

### FIXED CODE ###

N, M = map(int, input().split())
i = 1
lis = []
while M//i>=N and i<=M**0.5:
  if M % i == 0:
    lis.append(i)
  i += 1
for l in lis[::-1]:
  ans = M//l
  if M//ans>=N:
    lis.append(ans)
print(lis[-1])
### BUGGY CODE ###

n,*l=map(int,open(0).read().split())
p=0,0
d=p
for l in l:d+=max(l+d[-2],[d,p][len(d)&1][-1]),;p+=l+p[-2],
print(d[-1])

### FIXED CODE ###

n,*l=map(int,open(0).read().split());p=[0]*n;d=p[:]
for i,l in enumerate(l):p[i]+=l+p[i-2];d[i]=max(l+d[i-2],[d,p][i&1][i-1])
print(d[-1])
### BUGGY CODE ###

N=int(input())
a=list(map(int,input().split()))
ans=0
while(N!=0):
    cnt=a.count(a[0])
    if cnt>a[0]:
        ans+=cnt-a[0]
    elif cnt<a[0]:
        ans+=cnt
    x=a[0]
    for i in range(cnt):
        a.remove(x)
    N=len(a)
print(str(ans))

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))
dict={}
for s in aa:
    dict[s]=0
for l in a:
    dict[l]+=1
for i in dict.items():
    num=i[0]
    amount=i[1]
    """                                                           
    cnt=a.count(i)                                                
    if cnt>i:                                                     
        ans+=cnt-i                                                
    elif cnt<i:                                                   
        ans+=cnt                                                  
    """
    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount
print(str(ans))
### BUGGY CODE ###

import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
val_list = [False for _ in range(pow(10, n))]


def make_val(suretsu):
    val = 0
    for index in range(n):
        val += suretsu[n - index - 1] * pow(10, index)
    return val



for suretsu in itertools.permutations(range(1, n+1)):
    val = make_val(suretsu)
    val_list[val] = True

p_val = make_val(p)
q_val = make_val(q)

count = 0
min_val = min(p_val, q_val)
max_val = max(p_val, q_val)
for val in range(min_val, max_val+1):
    if val_list[val]:
        count += 1
print(count-1)

### FIXED CODE ###

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

def make_val(suretsu):
    val = 0
    for index in range(n):
        val += suretsu[n - index - 1] * pow(10, index)
    return val

p_val = make_val(p)
q_val = make_val(q)
min_val = min(p_val, q_val)
max_val = max(p_val, q_val)

count = 0
counting = False
p_rank = 0
q_rank = 0
for suretsu in itertools.permutations(range(1, n+1)):
    val = make_val(suretsu)
    if val < p_val:
        p_rank += 1
    if val < q_val:
        q_rank += 1
    p_rank += 1
    q_rank += 1

print(abs(p_rank-q_rank))
### BUGGY CODE ###

def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=sorted(A)
c=sorted(A,reverse=True)
D=[]
M=0
for i in range(N-K+1):
    x=1
    y=1
    for l in range(K-1):
        x=(x*(N-i-1-l))%(10**9+7)
        y=(y*(l+1))%(10**9+7)
    y=power(y,10**9+5)
    m=(x*y*(c[i]-b[i]))
    if m>0:
        m=m%(10**9+7)
    M+=m
    M%(10**9+7)

print(M%(10**9+7))







### FIXED CODE ###

def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=sorted(A)
c=sorted(A,reverse=True)
D=[]
M=0
x=1
y=1
for l in range(K-1):
    x=(x*(N-l-1))%(10**9+7)
    y=(y*(l+1))%(10**9+7)
y=power(y,10**9+5)
M+=(x*y*(c[0]-b[0]))%(10**9+7)
for i in range(1,N-K+1):
    y1=power(N-i,10**9+5)
    x=(x*y1)%(10**9+7)
    x=(x*(N-K-i+1))%(10**9+7)  
    m=(x*y*(c[i]-b[i]))
    if m>0:
        m=m%(10**9+7)
    M+=m
    M%(10**9+7)

print(M%(10**9+7))
### BUGGY CODE ###

import bisect

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

As.sort()

#print(As)

for _ in range(M):
    discount = As.pop(-1)

    if(discount == 0):
        break

    discount //= 2

    i = bisect.bisect_left(As, discount)
    As.insert(i, discount)
#    print(As)

print(sum(As))

### FIXED CODE ###

import bisect

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

As.sort()

#print(As)

for _ in range(M):
    discount = As.pop(-1)

    if(discount == 0):
        break

    discount //= 2

    i = bisect.bisect_left(As, discount)
    As.insert(i, discount)
#    print(As)

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

from collections import deque
import heapq
import copy
n, k = map(int, input().split())

v = deque(list(map(int, input().split())))
j = []
heapq.heapify(j)

def solve(hep, jue, c, end=k):
    if c==k:
        return sum(hep)
    result = [0]
    if len(jue)!=0:
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        heapq.heappush(x, y.pop())
        result.append(solve(x, y, c+1))
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        heapq.heappush(x, y.popleft())
        result.append(solve(x, y, c+1))

    if len(hep)!=0:
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        y.append(heapq.heappop(x))
        result.append(solve(x, y, c+1))
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        y.appendleft(heapq.heappop(x))
        result.append(solve(x, y, c+1))

    return max(result)


print(solve(j, v, 0))

### FIXED CODE ###

import heapq
n, k = map(int, input().split())
v = list(map(int, input().split()))

result = []
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        x = v[:i]+v[n-j:]
        c = k - (i + j)
        x.sort()
        for t in range(min(len(x), c)):
            if x[0]<0:
                x.pop(0)
            else:
                break
        result.append(sum(x))
print(max(result))
### BUGGY CODE ###

k,s = map(int,input().split())

count = 0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z == s:
      	count +=1
          
print(count)

### FIXED CODE ###

k,s = map(int,input().split())

count = 0
for x in range(k+1):
  for y in range(k+1):
    z = s-(x+y)
    if z >=0 and z <= k:
      #print(x,y,z)
      count += 1
          
print(count)
### BUGGY CODE ###

H,W = map(int,input().split())
S = [[] for _ in range(H)]
for i in range(H):
    S[i] = input()
left = [[0]*W for _ in range(H)]
right = [[0]*W for _ in range(H)]
up = [[0]*W for _ in range(H)]
down = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if(S[i][j]=="#"):
            left[i][j] = 0
        elif(j == 0):
            left[i][j]=1
        else:
            left[i][j]=left[i][j-1]+1
        if(S[i][W-j-1]=="#"):
            right[i][W-j-1]=0
        elif(j == 0):
            right[i][W-j-1]=1
        else:
            right[i][W-j-1]=right[i][W-j]+1
        if(S[i][j]=="#"):
            up[i][j] = 0
        elif(i==0):
            up[i][j] = 1
        else:
            up[i][j]=up[i-1][j]+1
        if(S[H-i-1][j]=="#"):
            down[H-i-1][j] = 0
        elif(i==0):
            down[H-i-1][j]=1
        else:
            down[H-i-1][j]=down[H-i][j]+1
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,left[i][j]+right[i][j]+up[i][j]+down[i][j]-3)

print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
S = [input() for _ in range(H)]
left = [[0]*W for _ in range(H)]
right = [[0]*W for _ in range(H)]
up = [[0]*W for _ in range(H)]
down = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if(S[i][j]=="."):
            if(j == 0):
                left[i][j] = 1
            else:
                left[i][j]=left[i][j-1]+1
for i in range(H):
    for j in range(W-1,-1,-1):                
        if(S[i][j]=="."):
            if(j == W-1):
                right[i][j]=1
            else:
                right[i][j]=right[i][j+1]+1
for i in range(H):
    for j in range(W):                   
        if(S[i][j]=="."):
            if(i == 0):
                up[i][j] = 1
            else:
                up[i][j]=up[i-1][j]+1
for i in range(H-1,-1,-1):
    for j in range(W):     
        if(S[i][j]=="."):
            if(i == H-1):
                down[i][j]=1
            else:
                down[i][j]=down[i+1][j]+1
ans = 0
X = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        X[i][j] = left[i][j]+right[i][j]+up[i][j]+down[i][j]-3
    ans = max(ans,max(X[i]))
print(ans)
### BUGGY CODE ###

# 最大公約数GCD(x,y)
def GCD(x,y):
    x,y=max(x,y),min(x,y)
    if x%y==0:
        return y
    else:
        return GCD(y,x%y)

def divide(g,p):
    if g%p!=0:
        return g
    if g%p==0:
        global n
        n+=1
        while g%p==0:
            g//=p
        return g

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

n=1 # gの素因数の個数

if g>=2:
    g=divide(g,2)
p=3 # 最初の奇素数
while g>1:
    g=divide(g,p)
    p+=2
print(n)

### FIXED CODE ###

# 最大公約数GCD(x,y)
def GCD(x,y):
    x,y=max(x,y),min(x,y)
    if x%y==0:
        return y
    else:
        return GCD(y,x%y)

def divide(g,p):
    if g%p!=0:
        return g
    if g%p==0:
        global n
        n+=1
        while g%p==0:
            g//=p
        return g

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

n=1 # gの素因数の個数

if g>=2:
    g=divide(g,2)
p=3 # 最初の奇素数
while g>1 and p<1000000:
    g=divide(g,p)
    p+=2
if g>1:
    n+=1
print(n)
### BUGGY CODE ###

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


def check(k, hs, mx, mn, r):
    if mx - mn > r:
        return r
    if k == 0:
        return min(r, mx - mn)
    for i, h in enumerate(hs):
        hs.remove(h)
        r = min(r, check(k - 1, hs[::], max(mx, h), min(mn, h), r))
        hs.insert(i, h)
    return r


def main():
    hs = [int(input()) for i in range(N)]
    print(check(K, hs, 0, 10 ** 9, 10 ** 9))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, K = list(map(int, input().split()))
    hs = [int(input()) for i in range(N)]
    hs.sort()
    i = 0
    r = 10 ** 9
    while True:
        if i + K > N:
            break
        r = min(r, hs[i + K - 1] - hs[i])
        i += 1
    print(r)


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


s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
left=""
right=""
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left=q2+left
            else:
                right=right+q2
        else:
            if q1=="1":
                right=right+q2
            else:
                left=q2+left 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join([left,s,right]) )

### FIXED CODE ###


s=input()
q=int(input())
queries = []
rev = [0]*q
flag=0
for i in range(q):
    query = list( input().split() )
    queries.append( query )
    if query==["1"]:
        flag+=1
    rev[i]=flag

n_rev = flag
from collections import deque
left=deque([])
right=deque([])
for r,query in zip(rev,queries):
    if query!=["1"]:
        q1 = query[1]
        q2 = query[2]
        if (r+n_rev)%2==0:
            if q1=="1":
                left.appendleft(q2)
            else:
                right.append(q2)
        else:
            if q1=="1":
                right.append(q2)
            else:
                left.appendleft(q2) 
#     print(i,left,s,right)
if n_rev%2==1:
    s=s[::-1]
print("".join(["".join(left),s,"".join(right)]) )
### BUGGY CODE ###

nk = input().split()
seisuuretu = input().split()

for i in range(len(seisuuretu)):
    seisuuretu[i] = int(seisuuretu[i])

all_seisuuretu = []

for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            all_seisuuretu.append(seisuuretu[start:end])

beautiful_list = []
for pattern in all_seisuuretu:
    beautiful_list.append(bin(sum(pattern))[2:])

list_max = []
for i in beautiful_list:
    list_max.append(len(i))
list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    for i in beautiful_list:
        try:
            if int(i[list_max]) == 1:
                count += 1
                temp.append(i)
        except:
            continue
    if count > int(nk[1]):
        list_max += 1
        beautiful_list = temp
    elif count == int(nk[1]):
        beautiful_list = temp
        for num in range(len(beautiful_list)):
            if num == 0:
                ronriseki = int(beautiful_list[num], 2)
            else:
                ronriseki = ronriseki & int(beautiful_list[num], 2)
        print(ronriseki)
        status = False
    elif list_max == -1:
        for num in range(len(beautiful_list)):
            if num == 0:
                ronriseki = int(beautiful_list[num], 2)
            else:
                ronriseki = ronriseki & int(beautiful_list[num], 2)
        print(ronriseki)
        status = False
    else:
        list_max += 1


### FIXED CODE ###

nk = input().split()
seisuuretu_2 = input().split()
nk1 = int(nk[1])

#seisuuretu = [int(i) for i in seisuuretu_2]
seisuuretu = list(map(int, seisuuretu_2))

list_max = set()
beautiful_list = []
for start in range(len(seisuuretu) + 1):
    for end in range(len(seisuuretu) + 1):
        if start < end:
            temp_pattern = bin(sum(seisuuretu[start:end]))[2:]
            beautiful_list.append(temp_pattern)
            list_max |= {len(temp_pattern),}

list_max = -max(list_max)

status = True
while status == True:
    temp = []
    count = 0
    for i in beautiful_list:
        try:
            if i[list_max] == "1":
                count += 1
                temp.append(i)
        except:
            continue
    if count > nk1:
        list_max += 1
        beautiful_list = temp
    elif count == nk1:
        num_count = True
        for num in temp:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        exit()
        status = False
    elif list_max == -1:
        num_count = True
        for num in beautiful_list:
            if num_count == True:
                ronriseki = int(num, 2)
            else:
                ronriseki = ronriseki & int(num, 2)
            num_count = False
        print(ronriseki)
        exit()
        status = False
    else:
        list_max += 1
### BUGGY CODE ###

h,w = map(int,input().split())
lis = [list(map(str,input().split("#"))) for i in range(h)]
li = []
for i in range(h):
  s = []
  for j in lis[i]:
    e = len(j)
    for n in range(len(j)):
      s.append(e)
    s.append(0)
  li.append(s)
l = []
for i in range(w):
  s = []
  cou = 0
  for j in range(h):
    if li[j][i] != 0:
      cou += 1
    else:
      cou = 0
    s.append(cou)
  for g in range(h-1):
    if s[-(2+g)] != 0 and s[-(2+g)] < s[-(1+g)]:
      s[-(2+g)] = s[-(1+g)]
  l.append(s)
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans,li[i][j] + l[j][i]-1)
print(ans)

### FIXED CODE ###

h,w = map(int,input().split())
tate = [[0]*w for i in range(h)]
yoko = [[0]*w for i in range(h)]
s = [str(input()) for i in range(h)]

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,j+1):
                yoko[i][k] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        yoko[i][k] = cnt
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,j):
                tate[k][i] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        tate[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j]-1)
print(ans)
### BUGGY CODE ###

s = list(input())

a_index_list = [i for i, v in enumerate(s) if v == min(s)]
z_index_list = [i for i, v in enumerate(s) if v == max(s)]

print(z_index_list[-1] - a_index_list[0] + 1)

### FIXED CODE ###

s = input()

first_A_find = s.find("A")
end_Z_find = s.rfind("Z") + 1

print(end_Z_find - first_A_find)
### BUGGY CODE ###

N,K=map(int,input().split())
i=0
while True:
    if K**i<N<K**(i+1):
        break
    else:
        i+=1
print(i+1)

### FIXED CODE ###

import math
N,K=map(int,input().split())
A=math.log(N,K)
print(int(A)+1)
### BUGGY CODE ###

text=input()
string=input()


#common_length[i]は、探索列がstring[i]で探索を終了したときに、
# string[i-common_lneght[i] + 1] 〜string[i]で構成される文字列が、探索価値を持つことを示す


len_string=len(string)
common_length=[0]*len_string
tmp=0
for i in range(1,len_string):
    if(string[i]==string[tmp]):
        common_length[i-1]=0
        tmp+=1
    else:
        common_length[i-1]=tmp
        tmp=0

if(string[-1]==string[tmp-1]):
    common_length[-1]=tmp




tmp=0

for i in range(len(text)):
    if(text[i]!=string[tmp]):
        while(text[i]!=string[tmp] or tmp==0):
            tmp=common_length[max([tmp-1,0])]
        if(text[i]==string[tmp]):
            tmp+=1
    else:
        tmp+=1
        if(tmp==len_string):
            print(i-tmp+1)
            tmp=common_length[-1]


### FIXED CODE ###

text=input()
string=input()


#common_length[i]は、探索列がstring[i]で探索を終了したときに、
# string[i-common_lneght[i] + 1] 〜string[i]で構成される文字列が、探索価値を持つことを示す


len_string=len(string)
common_length=[0]*len_string
tmp=0
tmp_tmp=0
for i in range(1,len_string):
    if(string[i]==string[tmp]):
        tmp_tmp=tmp
        while(string[i]==string[tmp_tmp] and tmp_tmp >0):
            tmp_tmp=common_length[max([tmp_tmp-1,0])]
        common_length[i-1]=tmp_tmp
        tmp+=1
    else:
        common_length[i-1]=tmp
        while(string[i]!=string[tmp] and tmp>0):
            tmp=common_length[max([tmp-1,0])]

if(string[-1]==string[tmp-1]):
    common_length[-1]=tmp
common_length[0]=0


tmp=0

for i in range(len(text)):
    if(text[i]!=string[tmp]):
        while(text[i]!=string[tmp] and tmp>0):
            tmp=common_length[max([tmp-1,0])]
        if(text[i]==string[tmp]):
            tmp+=1
    else:
        tmp+=1
        if(tmp==len_string):
            print(i-tmp+1)
            tmp=common_length[-1]
### BUGGY CODE ###

L,R = map(int,input().split())
result = 2020
R = min(R,L+4038)
for i in range(L,R):
    for j in range(L+1,R+1):
        result = min(result,i*j%2019)
print(result)

### FIXED CODE ###

L,R = map(int,input().split())
result = 2018
if R - L >= 2019:
    result = 0
else:
    for i in range(L,R):
        for j in range(L+1,R+1):
            result = min(result,i*j%2019)
print(result)
### BUGGY CODE ###

import heapq
import itertools
import sys
input = sys.stdin.readline

n, m, r = [ int(v) for v in input().split() ]
town_list = [ int(v)-1 for v in input().split() ]

road_matrix = [ [ 10**9 for j in range(n) ] for i in range(n) ]


for i in range(m):
	s, e, d = [ int(v) - 1 for v in input().split() ]
	road_matrix[s][e] = d + 1
	road_matrix[e][s] = d + 1


min_dist_matrix = []
for h in range(n):
	min_dist = [ min_dist_matrix[i][h] for i in range(h)] + road_matrix[h][h:]
	searched_point = []
	sarching_point = []
	j = h
	while len(searched_point) < n:
		searched_point.append(j)
		for i in range(n):
			if road_matrix[j][i] != 10**9 and i != h:
				heapq.heappush(sarching_point,(road_matrix[j][i],i))
				min_dist[i] = min(min_dist[i],min_dist[j] + road_matrix[j][i])
		sarching_point.sort()

		for k in range(len(sarching_point)):
			s = heapq.heappop(sarching_point)
			if s[1] not in searched_point:
				j = s[1]
				break

	min_dist_matrix.append(min_dist)


mindist = 10**9
for i in itertools.permutations(town_list,r):
	dist = 0
	for j in range(r-1):
		dist += min_dist_matrix[i[j]][i[j+1]]

	mindist = min(mindist,dist)
print(mindist)

### FIXED CODE ###

import itertools
import sys
input = sys.stdin.readline

n, m, r = [ int(v) for v in input().split() ]
town_list = [ int(v)-1 for v in input().split() ]

road_matrix = [ [ 10**9 for j in range(n) ] for i in range(n) ]


for i in range(m):
	s, e, d = [ int(v) - 1 for v in input().split() ]
	road_matrix[s][e] = d + 1
	road_matrix[e][s] = d + 1


for k in range(n):
	 for i in range(n):
		 for j in range(n):
			 road_matrix[i][j]  = min(road_matrix[i][k] + road_matrix[k][j], road_matrix[i][j])


mindist = 10**9
for i in itertools.permutations(town_list,r):
	dist = 0
	for j in range(r-1):
		dist += road_matrix[i[j]][i[j+1]]

	mindist = min(mindist,dist)
print(mindist)