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

n = int(input())

arr = [[0]*10 for _ in range(10)]
count = 0

for i in range(1,10):
  for j in range(1,10):
    arr[i][j] = len([k for k in range(1,n+1) if (str(k)[0] == str(i) and str(k)[-1] == str(j))])

for i in range(1,10):
  for j in range(1,10):
    count += arr[i][j]*arr[j][i]
print(count)

### FIXED CODE ###

n = int(input())

arr = [[list() for _ in range(10)] for _ in range(10)]
count = 0

for i in range(1,n+1):
  arr[int(str(i)[0])][int(str(i)[-1])].append(i)

for i in range(1,10):
  for j in range(1,10):
    arr[i][j] = len(arr[i][j])

for i in range(1,10):
  for j in range(1,10):
    count += arr[i][j]*arr[j][i]
print(count)
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline().rstrip('\n')

def calc(N, S):
    A = {}
    for s in S.split():
        x = int(s)
        if x in A:
            A[x] = 0
        else:
            A[x] = 1
        for a in A:
            if a == x:
                continue
            if x % a == 0:
                A[x] = 0
            if a % x == 0:
                A[a] = 0
    n = 0
    for a in A:
        n += A[a]
    return n
    

N = int(input())
S = input()
print(calc(N, S))

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline().rstrip('\n')
    

def calc(N, A):
    A.sort()
    M = A[N - 1] + 1
    b = [False for _ in range(M)]
    tmp = -1
    d = set()
    for a in A:
        if a == tmp:
            d.add(a)
            continue
        for i in range(a * 2, M, a):
            b[i] = True
        tmp = a
    n = 0
    for a in A:
        if not a in d:
            n += (0 if b[a] else 1)
    return n

N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))
### BUGGY CODE ###

import sys

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
ans = []
for i in range(n):
    if i % 2 == 0:
        ans.insert(0, a[i])
    else:
        ans.append(a[i])

if len(a) % 2 == 0:
    ans.reverse()
print(' '.join(map(str,ans)))


### FIXED CODE ###

import sys

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

odd = a[1::2]
even = a[0::2]
odd.reverse()
ans = odd+even

if(len(a) % 2 != 0):
    ans.reverse()

print(' '.join(map(str, ans)))
### BUGGY CODE ###

from collections import deque
N,Q=map(int,input().split())
nondirtree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    nondirtree[a-1].append(b-1)
    nondirtree[b - 1].append(a - 1)
points=[list(map(int,input().split())) for _ in range(Q)]
#print(points)
v=0
d=deque()
d.append(v)
seen=[0]*N
seen[0]=1
score=[0]*N
ans=[0]*N
while len(d)!=0:
    v=d.popleft()
    for j in nondirtree[v]:
        if seen[j]==0:
            dirtree[v].append(j)
            seen[j]=1
            d.append(j)
    #print(d,seen,dirtree)
    #input(
#print(dirtree)
for i in range(Q):
    score[points[i][0]-1]=score[points[i][0]-1]+points[i][1]
#print(score)
v=0
d=deque()
d.append(v)
ans[0]=score[0]
while len(d)!=0:
    v=d.popleft()
    for j in dirtree[v]:
        ans[j]=ans[v]+score[j]
        d.append(j)
    #input()
    #print(ans)
print(*ans,sep=" ")


### FIXED CODE ###

from collections import deque
N,Q=map(int,input().split())
nondirtree=[[] for _ in range(N)]
dirtree=[[] for _ in range(N)]
rootflag=[0]*N
rootflag[0]=1
for i in range(N-1):
    a,b=map(int,input().split())
    nondirtree[a-1].append(b-1)
    nondirtree[b - 1].append(a - 1)
points=[list(map(int,input().split())) for _ in range(Q)]
#print(points)
v=0
d=deque()
d.append(v)
seen=[0]*N
seen[0]=1
score=[0]*N
ans=[0]*N
while len(d)!=0:
    v=d.popleft()
    for j in nondirtree[v]:
        if seen[j]==0:
            dirtree[v].append(j)
            seen[j]=1
            d.append(j)
    #print(d,seen,dirtree)
    #input(
#print(dirtree)
for i in range(Q):
    score[points[i][0]-1]=score[points[i][0]-1]+points[i][1]
#print(score)
v=0
d=deque()
d.append(v)
ans[0]=score[0]
while len(d)!=0:
    v=d.popleft()
    for j in dirtree[v]:
        ans[j]=ans[v]+score[j]
        d.append(j)
    #input()
    #print(ans)
print(*ans,sep=" ")
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, f, t, w=1):
        self.E[f].append((t, w))
        self.E[t].append((f, w))


def solve(N: int, x: "List[int]", y: "List[int]"):

    g = Graph(N)
    for xx, yy in zip(x, y):
        g.add_edge(xx-1, yy-1)

    white = [-1]*N
    black = [-1]*N

    def rec(node, pre):
        if white[node] > 0:
            return white[node], black[node]

        # nodeを黒と塗る場合
        bbb = 1
        www = 1
        for t, _ in g.E[node]:
            if t != pre:
                w, b = rec(t, node)
                bbb *= w
                bbb %= MOD
                www *= (w+b) % MOD
                www %= MOD
        black[node] = bbb % MOD
        white[node] = www % MOD
        return white[node], black[node]

    w, b = rec(0, -1)
    print((w+b) % MOD)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N - 1)  # type: "List[int]"
    y = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import defaultdict
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, f, t, w=1):
        self.E[f].append((t, w))
        self.E[t].append((f, w))


def solve(N: int, x: "List[int]", y: "List[int]"):

    g = Graph(N)
    for xx, yy in zip(x, y):
        g.add_edge(xx-1, yy-1)

    white = [-1]*N
    black = [-1]*N

    def rec(node, pre):
        if white[node] > 0:
            return white[node], black[node]

        # nodeを黒と塗る場合
        bbb = 1
        www = 1
        for t, _ in g.E[node]:
            if t != pre:
                w, b = rec(t, node)
                bbb *= w
                bbb %= MOD
                www *= (w+b) % MOD
                www %= MOD
        black[node] = bbb % MOD
        white[node] = www % MOD
        return white[node], black[node]

    w, b = rec(0, -1)
    print((w+b) % MOD)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N - 1)  # type: "List[int]"
    y = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


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

# input
N = int(input())
S = input()

# process
R = []
G = []
B = []
for i, s in enumerate(list(S)):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)

ans = len(R)*len(G)*len(B)
for r in R:
    for g in G:
        i, j = r, g
        if i > j:
            i, j = j, i
        
        s = j-i
        if s%2 == 0:
            if i+s//2 in B:
                ans -= 1
        if i-s in B:
            ans -= 1
        if j+s in B:
            ans -= 1
            
# output
print(ans)


### FIXED CODE ###

# input
N = int(input())
S = input()

# process
ans = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
    for j in range(N):
        if i-j<0 or i+j >= N:
            break
        x = S[i-j]
        y = S[i]
        z = S[i+j]

        if x!= y and x != z and y != z:
            ans -= 1
            
# output
print(ans)
### BUGGY CODE ###

N,M=map(int, input().split())
TO = set([])
FM = set([])
ans = 'IMPOSSIBLE'
for i in range(M):
    f,t = map(int, input().split())
    if f == 1:
        TO.add(t)
    elif t == N:
        FM.add(f)
#    print(TO,FM,TO & FM)
    if len(TO & FM)>0:
      ans = 'POSSIBLE'
print(ans)

### FIXED CODE ###

N,M=map(int, input().split())
TO = set([])
FM = set([])
for i in range(M):
    f,t = map(int, input().split())
    if f == 1:
        TO.add(t)
    elif t == N:
        FM.add(f)
if len(TO & FM)>0:
    ans = 'POSSIBLE'
else:
    ans = 'IMPOSSIBLE'
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
ans = max([i for i in range(1, m//n+1) if not m%i])
print(ans)


### FIXED CODE ###

n, m = map(int, input().split())
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
if is_prime(m):
    print(1)
else:
    for i in range(m//n, 0, -1):
        if not m%i:
            print(i)
            break
### BUGGY CODE ###

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

arr = [0] * N

for i in range(len(A)):
    arr[i] = A.count(i+1)

for v in arr:
    print(v)


### FIXED CODE ###

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

arr = [0] * N

for i in A:
    arr[i-1] += 1

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

dp_t = dict()
dp_p = dict()


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    max_comb = (0, 0)
    max_num = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            c = comb(a[i], a[j])
            if max_num < c:
                max_num = c
                max_comb = (a[i], a[j])
    print("%d %d" % max_comb)


def comb(n, r):
    t = 1
    if n in dp_t:
        t = dp_t[n]
    else:
        t = compute_kai(n)
    p = 1
    if (n, r) in dp_p:
        p = dp_p[(n, r)]
    else:
        pr = 1
        if r in dp_t:
            pr = dp_t[r]
        else:
            pr = compute_kai(r)
        if n - r in dp_t:
            p = dp_t[n - r]
        else:
            p = compute_kai(n -r)
        p *= pr
        dp_p[(n, r)] = p
    return t // p


def compute_kai(n):
    if n in dp_t:
        return dp_t[n]
    else:
        t = 1
        for i in range(n):
            t *= (n - i)
        dp_t[n] = t
        return t


if __name__ == '__main__':
    main()


### FIXED CODE ###

dp_t = dict()
dp_p = dict()


def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    t = a[0] // 2
    p = a[-1]
    if n == 2:
        print("%d %d" % (a[0], a[1]))
        return
    i = 1
    while a[i] > t:
        i += 1
        if i >= n:
            i -= 1
            break
    if abs(a[i - 1] - t) > abs(a[i] - t):
        p = a[i]
    else:
        p = a[i - 1]
    print("%d %d" % (a[0], p))


def main1():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    a.sort(reverse=True)
    max_comb = (0, 0)
    max_num = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            c = comb(a[i], a[j])
            if max_num < c:
                max_num = c
                max_comb = (a[i], a[j])
    print("%d %d" % max_comb)


def comb(n, r):
    t = 1
    if n in dp_t:
        t = dp_t[n]
    else:
        t = compute_kai(n)
    p = 1
    if (n, r) in dp_p:
        p = dp_p[(n, r)]
    else:
        pr = 1
        if r in dp_t:
            pr = dp_t[r]
        else:
            pr = compute_kai(r)
        if n - r in dp_t:
            p = dp_t[n - r]
        else:
            p = compute_kai(n -r)
        p *= pr
        dp_p[(n, r)] = p
    return t // p


def compute_kai(n):
    if n in dp_t:
        return dp_t[n]
    else:
        t = 1
        for i in range(n):
            t *= (n - i)
        dp_t[n] = t
        return t


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

# -*- coding: utf-8 -*-
# D

# BFSで各点から到達可能な最も遠いところを探索する
# 1回探索はO(HW)なのでO(HHWW)
# BFSなのでdeque / queue使う・・・微妙に1つだけTLE残る

# 全ての地点から全ての地点への最短経路を求める

'''
3 5
...#.
.#.#.
.#...
'''

import sys
# from collections import deque
import queue


stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
# data = [ns() for _ in range(H)]

data = [list("#" * (W + 2))]
# 周りを'#'で埋めておく
for _ in range(H):
    data.append(["#"] + list(input()) + ["#"])
data += [list("#" * (W + 2))]


def judge(h, w, dist):
    if data[h][w] == '#' or dist[h][w] > -1:
        return False
    else:
        return True


def bfs(h, w):
    dist = [[-1] * (W+2) for i in range(H+2)]
    # q = deque()
    q = queue.Queue()

    max_dist = 0
    dist[h][w] = 0
    # q.append((h, w, 0))
    q.put((h, w, 0))

    # while len(q) > 0:
    while not q.empty():
        # h, w, val = q.popleft()
        h, w, val = q.get()
        dist[h][w] = val
        max_dist = max(max_dist, val)

        m = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        for dx, dy in m:
            h_new, w_new = h + dx, w + dy
            if judge(h_new, w_new, dist):
                q.put((h_new, w_new, val+1))

    return max_dist


ans = 0
for h in range(H+2):
    for w in range(W+2):
        if data[h][w] == '.':
            res = bfs(h, w)
            if ans < res:
                ans = res

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# D

# BFSで各点から到達可能な最も遠いところを探索する
# 1回探索はO(HW)なのでO(HHWW)
# BFSなのでdeque / queue使う・・・微妙に1つだけTLE残る

# 全ての地点から全ての地点への最短経路を求める

'''
3 5
...#.
.#.#.
.#...
'''

import sys
from collections import deque

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
# data = [ns() for _ in range(H)]

data = [list("#" * (W + 2))]
# 周りを'#'で埋めておく
for _ in range(H):
    data.append(["#"] + list(input()) + ["#"])
data += [list("#" * (W + 2))]


def bfs(h, w):
    dist = [[-1] * (W+2) for _ in range(H+2)]
    q = deque()

    max_dist = 0
    dist[h][w] = 0
    q.append((h, w, 0))

    # while len(q) > 0:
    while len(q) > 0:
        h, w, val = q.popleft()

        m = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        for dx, dy in m:
            h_new, w_new = h + dx, w + dy
            if data[h_new][w_new] == '.' and dist[h_new][w_new] == -1:
                q.append((h_new, w_new, val+1))
                dist[h_new][w_new] = val + 1
                max_dist = max(max_dist, val + 1)

    return max_dist


ans = 0
for h in range(H+2):
    for w in range(W+2):
        if data[h][w] == '.':
            res = bfs(h, w)
            if ans < res:
                ans = res

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

import sys
import heapq
sys.setrecursionlimit(10**6)

def input():
    return sys.stdin.readline()[:-1]

n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
k = 0

pqs = []
edge = [[] for _ in range(n)]
for i in range(m):
    x, y = [int(item) for item in input().split()]
    edge[x].append(y)
    edge[y].append(x)

def dfs(n):
    kind[n] = k
    heapq.heappush(pqs[k], a[n])
    for item in edge[n]:
        if kind[item] != -1:
            continue
        dfs(item)

kind = [-1] * n
for i, item in enumerate(kind):
    if item == -1:
        pqs.append([])
        dfs(i)
        k += 1

if k == 1:
    print(0)
    exit()
    
ans = 0
for i in range(k):
    val = heapq.heappop(pqs[i])
    ans += val
pqs = sum(pqs, [])
pqs.sort()
for i in range(k-2):
    if i > len(pqs) - 1:
        print("Impossible")
        exit()
    ans += pqs[i]
print(ans)

### FIXED CODE ###

import sys
from heapq import heappush, heappop
sys.setrecursionlimit(10**6)

def input():
    return sys.stdin.readline()[:-1]

n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
k = 0

pqs = []
edge = [[] for _ in range(n)]
for i in range(m):
    x, y = [int(item) for item in input().split()]
    edge[x].append(y)
    edge[y].append(x)

def dfs(n):
    kind[n] = k
    heappush(pqs[k], a[n])
    for item in edge[n]:
        if kind[item] == -1:
            dfs(item)

kind = [-1] * n
for i, item in enumerate(kind):
    if item == -1:
        pqs.append([])
        dfs(i)
        k += 1

if k == 1:
    print(0)
    exit()
    
ans = 0
for i in range(k):
    val = heappop(pqs[i])
    ans += val
pqs = [flatten for inner in pqs for flatten in inner] 
pqs.sort()
for i in range(k-2):
    if i > len(pqs) - 1:
        print("Impossible")
        exit()
    ans += pqs[i]
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
a = [int(input()) for i in range(m)]
dp=[0]*(n+1)
for i in range(n,-1,-1):
  if i not in a:
    if i==n or i==n-1:
      dp[i]=1
    else:
      dp[i]=dp[i+1]+dp[i+2]
print(dp[0]%1000000007)

### FIXED CODE ###

n,m=map(int,input().split())
a = [int(input()) for i in range(m)]
dp=[0]*(n+1)
if m==0:
  for i in range(n,-1,-1):
    if i==n or i==n-1:
      dp[i]=1
    else:
      dp[i]=dp[i+1]+dp[i+2]
  print(dp[0]%1000000007)
else:
  j=-1
  for i in range(n,-1,-1):
    if i==a[j]:
      if m>j*(-1):
        j-=1
    else:
      if i==n or i==n-1:
        dp[i]=1
      else:
        dp[i]=dp[i+1]+dp[i+2]
  print(dp[0]%1000000007)
### BUGGY CODE ###

n,x,y=map(int,input().split())
def dist(i,j):
  return min(abs(j-i),abs(y-j)+1+abs(x-i),abs(y-i)+1+abs(x-j))
distmap=[]
for l in range(2,n+1):
  distmap[len(distmap):len(distmap)]=[dist(k,l) for k in range(1,l)]
[print(distmap.count(m)) for m in range(1,n)]

### FIXED CODE ###

n,x,y=map(int,input().split())
def dist(i,j):
  if i>=j:
    d=0
  else:
    d=min(abs(j-i),abs(y-j)+1+abs(x-i),abs(y-i)+1+abs(x-j))
  return d
distmap=[0]*n
for l in range(2,n+1):
  for k in range(1,l):
    distmap[dist(k,l)]+=1
print('\n'.join(map(str,distmap[1:])))
### BUGGY CODE ###

from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import connected_components

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

for _ in range(M):
    x, y, z = map(int, input().split())
    matr[x - 1, y - 1] = matr[y - 1, x - 1] = 1

matr = matr.tocsr()
print(connected_components(matr, return_labels=False))


### FIXED CODE ###

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components

N, M = map(int, input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int64).T

matr = csr_matrix(([1 for _ in range(M)], (edge[:2] - 1)), (N, N))
print(connected_components(matr, return_labels=False))
### BUGGY CODE ###

from collections import Counter

def prime_decomposition(n):
	i=2
	table=[]
	while i*i <= n:
		while n%i == 0:
			n /= i
			table.append(i)
		i += 1
	if n > 1:
		table.append(n)
	return table

n=int(input())
a=list(map(int,input().split()))
ans_table = []
for i in a:
	ans_table.extend(prime_decomposition(i))
print(Counter(ans_table)[2])

### FIXED CODE ###

N=input()
lst=map(int,input().split())
ans=0
for i in lst:
	while i%2 == 0:
		i //= 2
		ans += 1
print(ans)
### BUGGY CODE ###

def solve():
    s = input()
    ans = 0
    
    for i in range(len(s)+1):
        left = 0
        right = 0
        for j in range(i-1, -1, -1):
            if s[j] == '<':
                left += 1
            else:
                break
        for j in range(i, len(s)):
            if s[j] == '>':
                right += 1
            else:
                break
        ans += max(left, right)
    
    print(ans)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    s_arr = input().replace('><', '> <').split()
    ans = 0
    
    for s in s_arr:
        left = s.count('<')
        right = len(s) - left
        if left < right:
            left -= 1
            ans += left * (left + 1) // 2 + right * (right + 1) // 2
        else:
            right -= 1
            ans += left * (left + 1) // 2 + right * (right + 1) // 2
    
    print(ans)

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

import copy

class warshallFloyd:
    def __init__(self, adj):
        # math.infはpython3.5以降のみ使用可能
        self.inf = 10 ** 9
        self.dis = copy.deepcopy(adj)
        for i in range(len(adj)):
            for j in range(len(adj)):
                if i != j and adj[i][j] == 0:
                    self.dis[i][j] = self.inf

    # 全ての頂点間の最短距離を算出、
    def search(self):
        for k in range(len(self.dis)):
            for i in range(len(self.dis)):
                for j in range(len(self.dis)):
                    if self.dis[i][j] > self.dis[i][k] + self.dis[k][j]:
                        self.dis[i][j] = self.dis[i][k] + self.dis[k][j]
        return self.dis


def func(n, m, r, adj):
    war = warshallFloyd(adj)
    dis = war.search()

    def depth(visited, prev, last):
        if last == 0:
            # print("visited:{} prev:{}, last:{}".format(
                # visited, r[prev], last))
            return 0
        add = war.inf
        for i in range(len(visited)):
            if not visited[i]:
                _visited = copy.deepcopy(visited)
                _visited[i] = True
                add = min(add, dis[r[prev]][r[i]] + depth(_visited, i, last - 1))
                # print("add:{}".format(add))
        return add

    _min = 10 ** 10
    for i in range(len(r)):
        # iをスタートとする
        visited = [False for _ in range(len(r))]
        visited[i] = True
        _min = min(_min, depth(visited, i, len(r) - 1))
    return str(_min)

n, m, R = [int(i) for i in input().split()]
r = [int(i) - 1 for i in input().split()]
adj = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in input().split()]
    adj[a - 1][b - 1] = c
    adj[b - 1][a - 1] = c
print(func(n, m, r, adj))
"""
print("2 vs "+func(3, 3, [0, 1, 2], [[0, 1, 4], [1, 0, 1], [4, 1, 0]]))
print("4 vs "+func(3, 3, [0, 2], [[0, 2, 6], [2, 0, 2], [6, 2, 0]]))
print("3 vs "+func(4, 6, [1, 2, 3], [[0, 4, 6, 1], [4, 0, 3, 2], [6, 3, 0, 1], [1, 2, 1, 0]]))
# print("print(func({}, {}, {}, {}))".format(n, m, r, adj))
"""


### FIXED CODE ###

import itertools
n, m, R = map(int, input().split())
r = list(map(int, input().split()))
dis = [[float("inf") for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dis[a - 1][b - 1] = c
    dis[b - 1][a - 1] = c

def war(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dis[i][j] > dis[i][k] + dis[k][j]:
                    dis[i][j] = dis[i][k] + dis[k][j]
    return dis
dis = war(dis)
_min = float("inf")
it = itertools.permutations(r)
for iterR in it:
    _dis = 0
    start = iterR[0] - 1
    for end in iterR[1:]:
        _dis += dis[start][end - 1]
        start = end - 1
    _min = min(_min, _dis)
print(_min)