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

import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().rstrip()

s = set()

a = set()
b = set()
c = set()

for i in range(0, N-2):
    if i in a:
        continue
    a.add(i)
    for j in range(i+1, N-1):
        # if j in b:
        #     continue
        # b.add(j)
        for k in range(j+1, N):
            # if k in c:
            #     continue
            # c.add(k)
            s.add(S[i]+S[j]+S[k])

print(len(s))


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().rstrip()

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    t1 = S.find(t[0])
    if t1 == -1:
        continue
    t2 = S.find(t[1], t1+1)
    if t2 == -1:
        continue
    t3 = S.find(t[2], t2+1)
    if t3 == -1:
        continue
    ans += 1

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

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

from math import gcd


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

lc = [0]
for aa in a:
    lc.append(gcd(lc[-1], aa))

if lc[-1] != 1:
    print('not coprime')
    exit()

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


if a[-1]==1:
    print('pairwise coprime')
    exit()

prime_numbers_list = eratosthenes(n)

count = [0]*len(prime_numbers_list)


for aa in a:
    for i, prime in enumerate(prime_numbers_list):
        if aa % prime ==0:
            count[i] += 1
            break

if max(count)>=2:
    print('setwise coprime')
else:
    print('pairwise coprime')




### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

from math import gcd
n = int(input())
a = list( map(int, input().split()))


g = 0
for aa in a:
    g = gcd(g,aa)
if g > 1:
    print('not coprime')
    exit()

MAXN = 10**6+10

def eratosthenes3(limit):
    sieve = [i for i in range(limit+1)]
    p = 2
    while p*p <= limit:
        if sieve[p] == p:
            for q in range(2*p,limit+1,p):
                if sieve[q] == q:
                    sieve[q] = p
        p += 1

    return sieve

sieve = eratosthenes3(MAXN)

st = set()
for aa in a:
    tmp = set()
    while aa > 1:
        tmp.add(sieve[aa])
        aa //= sieve[aa]
    for p in tmp:
        if p in st:
            print('setwise coprime')
            exit()
        st.add(p)
print('pairwise coprime')
### BUGGY CODE ###

N, M = map(int, input().split())
graph=[[0]*(N+1) for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    graph[a][b]=1
fl=False
for i in range(N):
    if graph[1][i]==1 and graph[i][N]==1:
        fl=True
if fl:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

N, M = map(int, input().split())
l1=[False]*(N+1)
l2=[False]*(N+1)


for i in range(M):
    a, b = map(int, input().split())
    if a==1:
        l1[b]=True
    elif b==N:
        l2[a]=True
        
fl=False
for i in range(N):
    if l1[i] and l2[i]:
        fl=True
    
if fl:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

import bisect
n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
for _ in range(m):
  m=A.pop()//2
  bisect.insort_left(A,m)
print(sum(A))

### FIXED CODE ###

import heapq
n,m=map(int,input().split())
A=list(map(int,input().split()))
hq=[]
for i in A:
  heapq.heappush(hq,-i)
for _ in range(m):
  m=-((-heapq.heappop(hq))//2)
  heapq.heappush(hq,m)
print(-sum(hq))
### BUGGY CODE ###

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

while M % N != 0:
    N += 1

print(M // N)

### FIXED CODE ###

from bisect import bisect_right
N, M = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


divisors = make_divisors(M)
print(divisors[bisect_right(divisors, M // N) - 1])
### BUGGY CODE ###

import math
def div(s):
    i=1
    while(i<=math.sqrt(s)):
        if(s%i==0):
            if(s//i==i):
                if(i!=1):
                    if(i in d):
                        return False
                    else:
                        d[i]=1
            else:
                if(i!=1):
                    if(i in d):
                        return False
                    else:
                        d[i]=1
                if(s//i!=1):
                    if(s//i in d):
                        return False
                    else:
                        d[s//i]=1
        i+=1
    #print(d,s)
    return True
                

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

d=dict()

setwise=False
pairWise=True
pairWise&=div(l[0])
pairWise&=div(l[1])
val=math.gcd(l[0],l[1])

for i in range(2,n):
    pairWise&=div(l[i])
    val=math.gcd(val,l[i])
if(pairWise):
    print('pairwise coprime')
elif(val==1):
    print('setwise coprime')
else:
    print('not coprime')


### FIXED CODE ###

import math
def div(s):
    i=1
    while(i<=math.sqrt(s)):
        if(s%i==0):
            if(s//i==i):
                if(i!=1):
                    if(i in d):
                        return False
                    else:
                        d[i]=1
            else:
                if(i!=1):
                    if(i in d):
                        return False
                    else:
                        d[i]=1
                if(s//i!=1):
                    if(s//i in d):
                        return False
                    else:
                        d[s//i]=1
        i+=1
    #print(d,s)
    return True
                

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

d=dict()

setwise=False
pairWise=True
pairWise&=div(l[0])
pairWise&=div(l[1])
val=math.gcd(l[0],l[1])

for i in range(2,n):
    pairWise&=div(l[i])
    val=math.gcd(val,l[i])
if(pairWise):
    print('pairwise coprime')
elif(val==1):
    print('setwise coprime')
else:
    print('not coprime')
### BUGGY CODE ###

N = int(input())

A_list = [int(_) for _ in input().split()]

ans = 0
for i in range(len(A_list)):
    if i <= N-1:
        if A_list[i] == 0:
            continue
        j = i+1
        ans += sum(map(lambda x:x*A_list[i], A_list[j:N]))%(10**9+7)
        ans = ans%(10**9+7)
print(ans)

### FIXED CODE ###

N = int(input())
A_list = [int(_) for _ in input().split()]

c = 10**9+7


def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


inv = modinv(2, c)

sum_of_a = sum(A_list) % c
sum_of_sq_a = sum([i**2 for i in A_list]) % c

ans = (sum_of_a**2 % c - sum_of_sq_a)*inv %c

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

N = int(input())
dic = []
for _ in range(N):
  A = input()
  if A in dic:
    dic.remove(A)
  else:
    dic.append(A)
print(len(dic))

### FIXED CODE ###

N = int(input())
dic = {}
for _ in range(N):
  A = input()
  if A in dic:
    del dic[A]
  else:
    dic[A]=0
print(len(dic))
### BUGGY CODE ###

S = input()
nQ_r = S.count('?')
nC_r = S.count('C')
nQ_l = 0
nA_l = 0
N = len(S)
mod = 10**9+7
ans = 0
for n, c in enumerate(S):
    if c=='C': nC_r-=1
    if c=='?': nQ_r-=1
    
    if n>0 and n<N-1 and (c=='B' or c=='?'):
        p = nQ_l*(3**(max(0, nQ_l-1))) + nA_l*(3**nQ_l)
        q = nQ_r*(3**(max(0, nQ_r-1))) + nC_r*(3**nQ_r)
        ans += p * q
        ans %= mod

    if c=='A': nA_l+=1
    if c=='?': nQ_l+=1

print(ans)

### FIXED CODE ###

S = input()
nQ_r = S.count('?')
nC_r = S.count('C')
nQ_l = 0
nA_l = 0
N = len(S)
mod = 10**9+7

pow3 = [1]*N
p = 1
for i in range(1,N):
    pow3[i] = p = p*3%mod

ans = 0
for n, c in enumerate(S):
    if c=='C': nC_r-=1
    if c=='?': nQ_r-=1
    
    if n>0 and n<N-1 and (c=='B' or c=='?'):
        p = ( nQ_l*pow3[max(0, nQ_l-1)] + nA_l*pow3[nQ_l] ) % mod
        q = ( nQ_r*pow3[max(0, nQ_r-1)] + nC_r*pow3[nQ_r] ) % mod
        ans += p * q
        ans %= mod

    if c=='A': nA_l+=1
    if c=='?': nQ_l+=1

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

N,K=map(int,input().split())
B=list(map(int,input().split()))
C=[]
for i in range(len(B)-K+1):
    tmp=0
    for j in range(K):
        tmp+=(1+B[i+j])/2
    C.append(tmp)
print(max(C))

### FIXED CODE ###

import itertools
N,K=map(int,input().split())
B=list(map(int,input().split()))
C=[0]+list(itertools.accumulate([(x+1)/2 for x in B]))

D=max(C[i]-C[i-K] for i in range(K,N+1))
print(D)
### BUGGY CODE ###

import itertools

N = int(input())
S = input()
delete_length = N - 3
pass_dict = {}

for c in itertools.combinations(range(N), delete_length):
    pass_word = ''
    for i in range(N):
        if i not in c:
            pass_word = pass_word + S[i]
    
    if pass_word not in pass_dict:
        pass_dict[pass_word] = 1
        
print(len(pass_dict))

### FIXED CODE ###

def I(): return int(input())
N = I()
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    if S.find(num[0])==-1:
        continue
    S1 = S[S.find(num[0])+1:]
    if S1.find(num[1])==-1:
        continue
    S2 = S1[S1.find(num[1])+1:]
    if S2.find(num[2])==-1:
        continue
    ans += 1
print(ans)
### BUGGY CODE ###

import sys
from collections import deque
import copy
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        if i == 0:
            S.append(s)
            continue
        flag = False
        for j in range(len(S)):
            if s == S[j]:
                flag = True
        if not flag:
            S.append(s)
    print(len(S))
    

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import deque
import copy
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        S.append(s)
    S.sort()
    count = N
    for i in range(1, len(S)):
        if S[i - 1] == S[i]:
            count -= 1
    print(count)
    

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

a,b=(int(x) for x in input().split())
count = 0
for x in range(a+1):
  for y in range(a+1):
    for z in range(a+1):
      if (x+y+z) == b:
        count+=1

print(count)

### FIXED CODE ###

import itertools
a,b=(int(x) for x in input().split())
l = range(a+1)
count = 0
m = [x+y for x,y in itertools.product(l,l) if (x+y)<=b]
for i in m:
  if b-i <= a:
    count+=1
print(count)
### BUGGY CODE ###

# coding: utf-8

input()

B_ = [int(i) for i in input().split()]

def f (B, ans):
  if len(B) == 0:
    return ans
  for i in range(len(B)):
    if B[i] <= len(B) and B[i] == i+1 :
      B2 = B[:]
      ans2 = ans[:]
      ans2.append(B2.pop(B[i]-1))
      result = f(B2, ans2)
      if result is not None: 
        return result

result = f(B_, [])
if result is None:
  result = [-1]
for s in result[::-1]:
  print(s)

### FIXED CODE ###

# coding: utf-8

N = int(input())

B = [int(i) for i in input().split()]

ans = []

while (len(B) > 0):
  for _ in range(len(B)):
    for i in list(range(len(B)))[::-1]:
      if B[i] == i+1:
        ans.append(i+1)
        B.pop(i)
        break
  break

if len(ans) != N:
  print(-1)
else:
  for i in ans[::-1]:
    print(i)
### BUGGY CODE ###

N,M=map(int,input().split())
R=list(range(N))
L=list(map(int,input().split()))
for i in range(M):
  t,u=map(int,input().split())
  a=L[t-1]
  b=L[u-1]
  if a==b:
    if t-1 in R:
      R.remove(t-1)
    if u-1 in R:
      R.remove(u-1)
  elif a>b:
    if u-1 in R:
      R.remove(u-1)
  else:
    if t-1 in R:
      R.remove(t-1)
print(len(R))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,M=MAP()
H=LIST()
L=[[0] for i in range(N)]
for i in range(M):
  a,b=MAP()
  a-=1
  b-=1
  L[a].append(H[b])
  L[b].append(H[a])
ans=0
for i in range(N):
  if max(L[i])<H[i]:
    ans+=1
print(ans)
### BUGGY CODE ###

S=input()                                               # 1行1列
Q=int(input())                                          # 1行1列
Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意

for query in Q_LIST:
	if query[0] == '1':
		S = S[::-1]
	if query[0] == '2':
		if query[1] == '1':
			S = query[2] + S 
		if query[1] == '2':
			S =  S + query[2]

print(S)

### FIXED CODE ###

def main():
	S=input()                                               # 1行1列
	Q=int(input())                                          # 1行1列
	Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意
	 
	dir = 0 # 0が正常

	S_HEAD = ''
	S_BACK = ''

	for query in Q_LIST:
		if query[0] == '1':
			if dir == 0:
				dir = 1
			else:
				dir = 0
	 
		if dir == 0:
			HEAD = '1'
			BACK = '2'
		else:
			HEAD = '2'
			BACK = '1'
	 
		if query[0] == '2':
			if query[1] == HEAD:
				S_HEAD = query[2] + S_HEAD
			if query[1] == BACK:
				S_BACK =  S_BACK + query[2]

	S = S_HEAD + S + S_BACK

	if dir == 0:
		print(S)
	else:
		print(S[::-1])

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

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
MOD = int(1e9) + 7

stair = []
for i in range(N):
    if i+1 in a:
        stair.append(False)
    else:
        stair.append(True)

# DP
dp = [0] * N
if stair[0]:
    dp[0] = 1
if N >= 2:
    if stair[1]:
        dp[1] = dp[0] + 1
    else:
        dp[1] = 0

for i in range(2, N):
    if not stair[i]:
        dp[i] = 0
        continue
    if stair[i-1] and stair[i-2]:
        dp[i] = (dp[i-1] + dp[i-2])%MOD
    elif stair[i-1]:
        dp[i] = dp[i-1]
    elif stair[i-2]:
        dp[i] = dp[i-2]

print(dp[N-1])



### FIXED CODE ###

import sys

n, m = map(int, input().split())
aaa = set()
if m != 0:
    for _ in range(m):
        aaa.add(int(input()))
    
    
dp = [0] * (n + 1) # 0 array
dp[0] = 1
dp[1] = 1 if 1 not in aaa else 0 # 入ってはいけない段に1が存在した場合は0
MOD = int(1e9) + 7

for i in range(2, n + 1):
    if i in aaa:
        continue
    dp[i] = (dp[i-2] + dp[i-1]) % MOD # 入ってはいけないところからの遷移の場合0を加算
print(dp[n])
### BUGGY CODE ###

n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
# 小さい順に調べていく
roads = []
for i in range(n-1):
    for j in range(i+1, n):
        roads.append((A[i][j], i, j))
roads = sorted(roads)

INF = 10**9*1
AD = [[INF]*n for _ in range(n)]
G = [[] for _ in range(n)]
edges = set()
from collections import deque
ans = 0
for a, s, e in roads:
    # s to e
    q = deque([[s, 0]])
    visited = [INF] * n
    visited[s] = 0
    while q:
        node, dist = q.popleft()
        if node == e:
            # sからeにたどり着いて
            if dist == a:
                # あたえられた距離と同じならばOK
                break
            elif dist < a:
                # あたえられた距離より小さいならばaは最短距離じゃないNG
                ans = -1
                break
        
        for nn, cost in G[node]:
            if dist+cost < visited[nn]:
                visited[nn] = dist+cost
                q.append([nn, dist+cost])
    else:
        # sからeにたどり着けなかったら最短距離確定
        AD[s][e] = a
        G[s].append((e, a))
        G[e].append((s, a))
        edges.add((a, s, e))
    if ans == - 1:
        break

if ans == -1:
    print(ans)
else:
    for a, s, e in edges:
        ans += a
    print(ans)


### FIXED CODE ###

n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
INF = 10**9 + 1
dp = [[INF]*n for _ in range(n)]

# コスト登録
for i, line in enumerate(A):
    for j, a in enumerate(line):
        dp[i][j] = a

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

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        d = dp[i][j]
        if d < A[i][j]:
            ans = -1
            break
        else:
            for k in range(n):
                if k == i or k == j:
                    continue
                if dp[i][k] + dp[k][j] == d:
                    break
            else:
                ans += d
    if ans == -1:
        break
print(ans)
### BUGGY CODE ###

import sys
def main():
    input = sys.stdin.readline
    H,W=map(int, input().split())
    A=[list(map(int, input().split())) for _ in range(H)]
    B=[list(map(int, input().split())) for _ in range(H)]

    mx=80*(80+80)
    C=[[A[i][j]-B[i][j] for j in range(W)] for i in range(H)]
    dp=[[[0]*(mx*2+1) for _ in range(W)] for __ in range(H)]
    dp[0][0][C[0][0]+mx]=1
    dp[0][0][-C[0][0]+mx]=1
    from collections import deque
    q=deque([(0,0)])
    while q:
        i,j=q.popleft()
        for d in range(mx*2):
            if i>0:
                if 0<=d-C[i][j]<=mx*2: dp[i][j][d] = max(dp[i][j][d], dp[i-1][j][d-C[i][j]])
                if 0<=d+C[i][j]<=mx*2: dp[i][j][d] = max(dp[i][j][d], dp[i-1][j][d+C[i][j]])
            if j>0:
                if 0<=d-C[i][j]<=mx*2: dp[i][j][d] = max(dp[i][j][d], dp[i][j-1][d-C[i][j]])
                if 0<=d+C[i][j]<=mx*2: dp[i][j][d] = max(dp[i][j][d], dp[i][j-1][d+C[i][j]])
        if i<H-1: q.append((i+1,j))
        if j<W-1: q.append((i,j+1))

    for ans in range(mx+1):
        if dp[H-1][W-1][mx+ans] or dp[H-1][W-1][mx-ans]:
            print(ans)
            break

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
def main():
    input = sys.stdin.readline
    H,W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]

    M = 160*80
    dp = [[0 for _ in range(W)] for __ in range(H)]
    dp[0][0] = 1 << (C[0][0] + M)
    for i in range(H):
        for j in range(W):
            for ni,nj in [(i,j+1),(i+1,j)]:
                if ni >= H or nj >= W: continue
                t = C[ni][nj]
                dp[ni][nj] |= dp[i][j] << t
                dp[ni][nj] |= dp[i][j] >> t
    
    a = dp[H-1][W-1]
    ans = 0
    while True:
        if a & (1 << (M+ans)) or a & (1 >> (M-ans)): break
        ans += 1
    print(ans)

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

def f7(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x)]


while(1):
    [N,M]=[int(x) for x in raw_input().split()]
    if N==0:
        break
    a=[0]
    for i in range(N):
        a.append(int(raw_input()))
    aa=a[:]
    #b=sorted([x+y for x in a for y in a])
    #c=[]
    #for i in range(1,len(b)):
    #    if b[i]>M:
    #        break
    #    elif b[i-1]!=b[i]:
    #        c.append(b[i-1])
    b=[x+y for x in a for y in aa]
    c=f7(b)
    c.sort()
    largest=0
    id=0
    for i in range(1,len(c)+1):
        if id==len(c) or largest==M:
            break
        while(id<len(c) and c[-i]+c[id]<=M):
            largest=max(largest,c[-i]+c[id])
            id+=1
    print largest

### FIXED CODE ###

import bisect

while(1):
    [N,M]=[int(x) for x in raw_input().split()]
    if N==0:
        break
    a=[0 for x in range(N+1)]
    for i in range(N):
        a[i+1]=int(raw_input())
    #b=sorted([x+y for x in a for y in a])
    #c=[]
    #for i in range(1,len(b)):
    #    if b[i]>M:
    #        break
    #    elif b[i-1]!=b[i]:
    #        c.append(b[i-1])
    b=[a[x]+a[y] for x in range(N+1) for y in range(x,N+1)]
    #c=f7(b)
    c=sorted(b)
    #print c
    largest=0
    id=0
    st=len(c)-bisect.bisect(c,M)+1
    #print st
    for i in range(st,len(c)+1):
        if id==len(c):
            break
        while(id<len(c) and c[-i]+c[id]<=M):
            #print c[-i],c[id],c[-i]+c[id]
            largest=max(largest,c[-i]+c[id])
            id+=1
    print largest
### BUGGY CODE ###

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

sortedx = x[:]
sortedx.sort()

for i in range(n):
    cpsortedx = sortedx[:]
    cpsortedx.remove(x[i])
    #print(x_i)
    print(cpsortedx[n//2-1])

### FIXED CODE ###

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

sortedx = x[:]
sortedx.sort()

for i in range(n):
    #ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if x[i] <= sortedx[n//2-1]:
        print(sortedx[n//2])
    else:
        print(sortedx[n//2-1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
move = pow(10, 100)
S = input()
ans = np.zeros(len(S), np.int64)
for i in range(len(S)):
    pre_pos = -1
    pre_pre_pos = -1
    pos = i
    move_count = 0
    while pre_pre_pos != pos:
        move_count += 1
        if (S[pos] == 'L'):
            pre_pre_pos = pre_pos
            pre_pos = pos
            pos -= 1
        else:
            pre_pre_pos = pre_pos
            pre_pos = pos
            pos += 1
    if move_count % 2 == 0:
        ans[pos] += 1
    else:
        ans[pre_pos] += 1


print(*list(ans))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
S = input()
ans = np.zeros(len(S), np.int64)
pos = 0
last_R = 0
while pos < (len(S)):
    if S[pos] == 'R':
        move_count = 0
        while S[pos] == 'R':  # Lを探す
            last_R = pos
            move_count += 1
            pos += 1
        # 'L'発見 S[pos] == L
        ans[pos] += (move_count)//2
        ans[pos-1] += (move_count - (move_count)//2)
    else:  # S[pos] == 'L':
        move_count = 0
        # print('found L')
        while pos < len(S):
            # print(pos, len(S))
            if S[pos] == 'L':  # 'R'を探す
                pos += 1
            else:
                break
        # R発見
        move_count = pos-1 - last_R
        # print(move_count, '=', pos, '-', last_R)
        ans[last_R] += (move_count)//2
        ans[last_R+1] += (move_count - (move_count)//2)


print(*list(ans))
### BUGGY CODE ###

import itertools

n, m, r = map(int, input().split())
list_r = [one_r-1 for one_r in map(int, input().split())]

dist = [[float("inf")] * n for _ in range(n)]
for i in range(n):
  dist[i][i] = 0
for i in range(m):
  a, b, c = map(int, input().split())
  dist[a-1][b-1] = c
  dist[b-1][a-1] = c
for k in range(n):
  for i in range(n):
    for j in range(n):
      if dist[i][j] > dist[i][k] + dist[k][j]:
        dist[i][j] = dist[i][k] + dist[k][j]

result = float("inf")
for one_cand in itertools.permutations(list_r):
  temp = 0
  for i in range(r-1):
    temp += dist[one_cand[i]][one_cand[i+1]]
  if temp < result:
    result = temp
print(result)

### FIXED CODE ###

from itertools import permutations
import sys

def main():
    
    N, M, R = map(int, sys.stdin.readline().split())
    r = [i - 1 for i in map(int, sys.stdin.readline().split())]
    
    d = [[float('inf')] * N for _ in range(N)]
    
    for i in range(N):
        d[i][i] = 0
        
    for i in range(M):
        a, b, c = map(int,sys.stdin.readline().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c
        
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
    
    ans = 10**12
    
    for each in permutations(r):
        t_dis = 0
        for i in range(R-1):
            t_dis += d[each[i]][each[i+1]]  
        
        ans = min(ans, t_dis)
    
    print(ans)

if __name__ == '__main__':
    main()