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

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
	print(a.count(i+1))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = [0]*(n+1)
for i in range(len(a)):
	ans[a[i-1]] += 1
ans.pop(0)
for j in range(n):
	print(ans[j])
### BUGGY CODE ###

#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
#??????????????????

def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p

if __name__ == "__main__":
    line = input()
    truck_num = int(line.split(" ")[1])
    line_num = int(line.split(" ")[0])
    cargos = []
    for i in range(line_num):
        cargos.append(int(input()))
    print(cal(truck_num,cargos))

### FIXED CODE ###

#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_D
#??????????????????

def cal(truck_num, cargos):
    p = 0
    
    for i in range(len(cargos) - truck_num + 1):
        if not i == 0 and p < sum(cargos[:i + 1]):
            continue
        if truck_num > 1:
            r = max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:]))
            if i == 0:
                p = r
            elif p > r:
                p = r
        else:
            return sum(cargos)
    return p

def check(truck_num, carogs, target_load):
    
    cur_truck = 1
    cur_weight = 0
    for weight in cargos:
        cur_weight += weight
        if cur_weight > target_load:
            cur_weight = weight
            cur_truck += 1
            if cur_truck > truck_num:
                return False
    return True

def solve(truck_num, cargs):

    max_load = sum(cargos)
    min_load = max(cargos)
    #print(min_load, max_load)
    while min_load < max_load:
        target_load = int((min_load + max_load)/2)
        if check(truck_num, cargos, target_load):
            max_load = target_load
        else:
            min_load = target_load + 1
        #print(min_load, max_load)
        
    return max_load

if __name__ == "__main__":
    line = input()
    truck_num = int(line.split(" ")[1])
    line_num = int(line.split(" ")[0])
    cargos = [int(input()) for i in range(line_num)]
    print(solve(truck_num,cargos))
### BUGGY CODE ###

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

mod = 10 ** 9 + 7

def gcd(x, y):
    x, y = max(x, y), min(x, y)
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

def lcm(x, y):
    return x * y // gcd(x, y)

l = 1
for i in range(len(A)):
    l = lcm(A[i], l)

B = 0
for i in range(len(A)):
    B += l // A[i]

print(B % mod)

### FIXED CODE ###

mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
l=a[0]
for i in range(1,n):
  l=lcm(l,a[i])
ans=0
l%=mod
for i in range(n):
  ans+=l*pow(a[i],mod-2,mod)
  ans%=mod
print(ans)
### BUGGY CODE ###

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

# 昇順にする
L.sort()

count=0
for i in range(N):
    for j in range(i+1,N):
        for n in range(j+1,N):
            if L[n]<L[i]+L[j]:
                count+=1
            else:
                break
print(count)







### FIXED CODE ###

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

# 昇順にする
L.sort()

import bisect
count=0
for i in range(N):
    for j in range(i+1,N):
        # 2分探索を使うことでn^2*log(n)の探索で終わる,このindexは新たにL[i]+L[j]が挿入できるindexなので、このindex-1が条件を満たす最大のcのindex
        maximum_index = bisect.bisect_left(L,L[i]+L[j])
        count+= maximum_index-1 - j 
print(count)
### BUGGY CODE ###

#!/home/matsumotokazuho/.pyenv/shims/pypy
# import math
# from copy import deepcopy
# from operator import itemgetter
# from collections import defaultdict
# from collections import Counter
# from collections import deque
# import pprint
# import itertools
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H, W = map(int, input().split())
Board = [list(input().rstrip()) for _ in range(H)]

# q = deque()
q = []
# for i, j in itertools.product(range(H), range(W)):
for i in range(H):
    for j in range(W):
        if Board[i][j] == '#':
            # Board[i][j] = 0
            q.append((i, j))

ans = 0
while q:
    qq = []
    ans += 1
    for yx in q:
        for d in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            y, x = [i+j for i, j in zip(yx, d)]
            if y < 0 or H - 1 < y or x < 0 or W - 1 < x:
                pass
            elif Board[y][x] == '.':
                # Board[y][x] = Board[q[0][0]][q[0][1]] + 1
                Board[y][x] = '#'
                qq.append((y, x))
    q = qq

# ans = max(list(itertools.chain.from_iterable(Board)))
# ans = max(itertools.chain.from_iterable(Board))
# pprint.pprint(Board)
print(ans-1)


### FIXED CODE ###

#!/home/matsumotokazuho/.pyenv/shims/pypy
# import math
# from copy import deepcopy
# from operator import itemgetter
# from collections import defaultdict
# from collections import Counter
# from collections import deque
# import pprint
# import itertools
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H, W = map(int, input().split())
Board = [list(input().rstrip()) for _ in range(H)]

# q = deque()
q = []
# for i, j in itertools.product(range(H), range(W)):
for i in range(H):
    for j in range(W):
        if Board[i][j] == '#':
            # Board[i][j] = 0
            q.append((i, j))

ans = 0
while q:
    qq = []
    ans += 1
    for yx in q:
        for d in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            y = yx[0] + d[0]
            x = yx[1] + d[1]
            # y, x = [i+j for i, j in zip(yx, d)]
            if y < 0 or H - 1 < y or x < 0 or W - 1 < x:
                pass
            elif Board[y][x] == '.':
                # Board[y][x] = Board[q[0][0]][q[0][1]] + 1
                Board[y][x] = '#'
                qq.append((y, x))
    q = qq

# ans = max(list(itertools.chain.from_iterable(Board)))
# ans = max(itertools.chain.from_iterable(Board))
# pprint.pprint(Board)
print(ans-1)
### BUGGY CODE ###

S=input()
count = 0
while S.find('01')!=-1:
    S_list=list(S)
    i_pop = S.find('01')
    S_list.pop(i_pop)
    S_list.pop(i_pop)
    S = ''.join(S_list)
    count +=2
while S.find('10')!=-1:
    S_list=list(S)
    i_pop = S.find('10')
    S_list.pop(i_pop)
    S_list.pop(i_pop)
    S = ''.join(S_list)
    count +=2
print(count)

### FIXED CODE ###

S = input()
n_zero = 0
n_one = 0
for i in S:
    if i == '0':
        n_zero += 1
    else:
        n_one += 1
print(min(n_one, n_zero)*2)
### BUGGY CODE ###

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

dp = [0]*N
for i in range(1,N):
    tmp = []
    for j in range(1,K+1):
        if i-j<0:
            continue
        tmp.append(dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = min(tmp)
print(dp[-1])

### FIXED CODE ###

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

dp = [0]*N
for i in range(1,N):
    tmp = 10**10
    for j in range(1,min(i+1,K+1)):
        tmp = min(tmp,dp[i-j]+abs(h[i]-h[i-j]))
    dp[i] = tmp
print(dp[-1])
### BUGGY CODE ###

def main():
    s = input()
    q = int(input())
    reverse_count = 0
    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            reverse_count += 1
        else:
            if reverse_count % 2:
                if query[1] == "1":
                    s += query[2]
                else:
                    s = query[2] + s
            else:
                if query[1] == "1":
                    s = query[2] + s
                else:
                    s += query[2]
    print(s[::-1] if reverse_count % 2 else s)


if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    s = input()
    q = int(input())
    reverse_count = 0
    left = []
    right = []
    for _ in range(q):
        query = list(input().split())
        if query[0] == "1":
            reverse_count += 1
        else:
            if reverse_count % 2:
                if query[1] == "1":
                    right.append(query[2])
                else:
                    left.append(query[2])
            else:
                if query[1] == "1":
                    left.append(query[2])
                else:
                    right.append(query[2])
    print("".join(right[::-1]) + s[::-1] + "".join(left) if reverse_count % 2
          else "".join(left[::-1]) + s + "".join(right))


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

n,m = map(int,input().split())
count_ac = 0
count_wa = 0
l = []
memo_n = []
for i in range(m):
    t = tuple(input().split())
    l.append(t)
    if t[1] == 'AC' and t[0] not in memo_n:
        memo_n.append(t[0])
        count_ac += 1
        count_wa += l.count((t[0],'WA'))

print(str(count_ac) + " " + str(count_wa))

### FIXED CODE ###

n,m = map(int,input().split())
ac = [0]*n
wa = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1]:
        continue
    if s == 'AC':
        ac[p-1] = 1
    else:
        wa[p-1] += 1
count_ac = 0
count_wa = 0
for i in range(n):
    count_ac += ac[i]
    if ac[i]:
        count_wa += wa[i]
print(str(count_ac) + " " + str(count_wa))
### BUGGY CODE ###

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

ans = 10**9
for i in range(N-(K-1)):
	x = X[i:i+K]
	if (x[0] <= 0 and x[K-1] <= 0) or (x[0] >= 0 and x[K-1] >= 0):
		res = max(abs(x[0]),x[K-1])
	else:
		res = min(abs(x[0])*2 + x[K-1], x[K-1]*2 + abs(x[0]))
	ans = min(ans,res)
print(ans)

### FIXED CODE ###

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

ans = 10**9
for i in range(N-K+1):
    ans = min(ans,X[i+K-1]-X[i]+min(abs(X[i]),abs(X[i+K-1])))
print(ans)
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
for i in range(N):
  if i==0:
    print(sorted(A[i+1:])[-1])
  if i!=0 and i!=N-1:
    li1=sorted(A[:i])[-1]
    li2=sorted(A[i+1:])[-1]
    print(max(li1,li2))
  if i==N-1:
    print(sorted(A[:i])[-1])

### FIXED CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
AA=sorted(A,reverse=True)
for i in range(N):
  if AA[0]!=A[i]:
    print(AA[0])
  else:
    print(AA[1])
### BUGGY CODE ###

S = input()
Q = int(input())

query_list = [input().split() for _ in range(Q)]

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

print(S)


### FIXED CODE ###

import collections
S = input()
Q = int(input())

query_list = [input().split() for _ in range(Q)]

T_cnt_list = collections.deque([0])
left = ''
right = ''

for i, query in enumerate(query_list):
    if query[0] == '1':
        T_cnt_list.append(1+T_cnt_list[-1])

    else:
        T_cnt_list.append(T_cnt_list[-1])

        if query[1] == '1' and T_cnt_list[i+1]%2 == 0:
            left = query[2] + left

        elif query[1] == '1' and T_cnt_list[i+1]%2 == 1:
            right = right + query[2]

        elif query[1] == '2' and T_cnt_list[i+1]%2 == 0:
            right = right + query[2]

        elif query[1] == '2' and T_cnt_list[i+1]%2 == 1:
            left = query[2] + left

if T_cnt_list[-1]%2 == 0:
    print(left + S + right)
else:
    print(right[::-1] + S[::-1] + left[::-1])
### BUGGY CODE ###

N = int(input())
edges = [[] for i in range(N-1)]
for i in range(N-1):
    edges[i]=list(map(int, input().split()))

##print('edges=',edges)
def connected(v):
    children = []
    for edge in edges:
        if edge[0] == v:
            children.append([edge[1],edge[2]])
        elif edge[1] == v:
            children.append([edge[0],edge[2]])

    return children

Q,K = map(int, input().split())
##print('Q=',Q)
depth = [0]*(N+1)
def DFS(v, p, d):
    depth[v] = d
    for child in connected(v):
        if child[0] == p:
            continue
        DFS(child[0], v, d+child[1])

DFS(K,-1,0)
for i in range(Q):
    xi, yi = map(int, input().split())
    print(depth[xi]+depth[yi])


### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)

N = int(input())
edges = []
connected = [[] for i in range(100010)]
for i in range(N-1):
    x=list(map(int, input().split()))
    x[0] -= 1
    x[1] -= 1
    edges.append(x)
    connected[x[0]].append([x[1], x[2]])
    connected[x[1]].append([x[0], x[2]])

Q,K = map(int, input().split())
K -= 1
depth = [0]*100010
def DFS(v, p, d):
    depth[v] = d
    for child in connected[v]:
        if child[0] == p:
            continue
        DFS(child[0], v, d+child[1])

DFS(K,-1,0)
for i in range(Q):
    xi, yi = map(int, input().split())
    print(depth[xi-1]+depth[yi-1])
### BUGGY CODE ###

def merge(a, left, mid, right):
    x = 0
    n1 = mid - left
    n2 = right - mid
    l = []
    r = [] 
    for i in range(n1):
        l.append(a[left + i])
    for i in range(n2):
        r.append(a[mid + i])
    l.append(float("inf"))
    r.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        x += 1
    return x

def mergeSort(a, left, right,x):
    if left+1 < right:
        mid = int((left + right)/2)
        mergeSort(a, left, mid,x)
        mergeSort(a, mid, right,x)
        x[0] += merge(a, left, mid, right)

n = int(input())
s = list(map(int,input().split()))
x = [0]
mergeSort(s,0,n,x)
print(*s)
print(x[0])




### FIXED CODE ###


def merge(a, left, mid, right):
    x = 0
    l = a[left:mid] + [float("inf")]
    r = a[mid:right] + [float("inf")]
    i = 0
    j = 0
    for k in range(left,right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        x += 1
    return x

def mergeSort(a, left, right,x):
    if left+1 < right:
        mid = int((left + right)/2)
        mergeSort(a, left, mid,x)
        mergeSort(a, mid, right,x)
        x[0] += merge(a, left, mid, right)

n = int(input())
s = list(map(int,input().split()))
x = [0]
mergeSort(s,0,n,x)
print(*s)
print(x[0])
### BUGGY CODE ###

X, Y = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
    print(0)
    exit()
    
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
    print(0)
    exit()    

ans = 1
for i in range(1, n+1):
    ans *= ((n+m+1-i) * pow(i, mod-2, mod)) % mod
print(ans%mod)

### FIXED CODE ###

X, Y = map(int, input().split())
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
    print(0)
    exit()
    
n = (2 * Y - X) // 3
m = (2 * X - Y) // 3
if n < 0 or m < 0:
    print(0)
    exit()    

ans = 1
for i in range(1, n+1):
    ans *= (n+m+1-i) * pow(i, mod-2, mod)
    ans %= mod
    
print(ans)
### BUGGY CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

k = int(input())

result = 0

for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      n = gcd(a, b)
      m = gcd(n, c)
      result += m

print(result)

### FIXED CODE ###

import math
import itertools

k = int(input())
result = 0

for a in range(1, k+1):
  for b in range(a+1, k+1):
    for c in range(b+1, k+1):
      r = math.gcd(math.gcd(a, b), c)
      r *= 6
      result += r

for a in range(1, k+1):
  for b in range(a+1, k+1):
    r = math.gcd(a, b)
    r *= 6
    result += r
    
for a in range(1, k+1):
  result += a

print(result)
### BUGGY CODE ###

s = list(input())
K = int(input())

lst = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
#        print ('i, j=', i, j)
        lst += [s[i:j]]

lst.sort()
#print (lst)
k = 0
flag = 0
ans = str()
check = True
while check:
    if ans != lst[flag]:
        #print ('k', k)
        k += 1
    ans = lst[flag]
    #print ('ans=', ans)
    flag += 1
    if k == K:
        for l in ans:
            print (l, end ='')
        check = not check
print ()


### FIXED CODE ###

#全探索-->len(s) = 50程度までしか通らない
s = list(input())
K = int(input())

lst = []
for i in range(len(s)):
    for j in range(i+1, min(len(s)+1, i+1+K)):
#        print ('i, j=', i, j)
        lst += [s[i:j]]

lst.sort()
#print (lst)
k = 0
flag = 0
ans = str()
check = True
while check:
    if ans != lst[flag]:
        #print ('k', k)
        k += 1
    ans = lst[flag]
    #print ('ans=', ans)
    flag += 1
    if k == K:
        ans = ''.join(ans)
        print(ans)
        check = not check
### BUGGY CODE ###

def main():
  from bisect import bisect_left
  n,m=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  for _ in range(m):
    b,c=map(int,input().split())
    index = bisect_left(a,c)
    b=index if b>=index else b
    a=[c]*b+a[b:]
    a.sort()
  print(sum(a))
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  n,m=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  bc=[list(map(int,input().split())) for _ in range(m)]
  for i in range(n):
    bc.append([1,a[i]])
  bc.sort(key=lambda x:x[1],reverse=True)
  ans,cnt=0,0
  for i in range(n):
    ans+=bc[i][0]*bc[i][1]
    cnt+=bc[i][0]
    if cnt>=n:
      ans-=(cnt-n)*bc[i][1]
      break
  print(ans)
if __name__=='__main__':
  main()
### BUGGY CODE ###

from collections import deque
import copy
def solve(maze, start, end):
  memo = []
  q = deque()
  q.append([start,[]])
  ans = 0
  while q:
    cur, path = q.popleft()
    if cur == end:
      ans = path
      break
    elif cur in memo:
      continue
    else:
      memo.append(cur)
      for y, x in zip((0,0,1,-1),(1,-1,0,0)):
        if maze[cur[0]+y][cur[1]+x] == ".":
          q.append([[cur[0]+y,cur[1]+x],copy.deepcopy(path)+[cur]])
  return ans


H, W = map(int, input().split())
Maze = [["#"]*(W+2)]+[["#"]+list(input())+["#"] for _ in range(H)] + [["#"]*(W+2)]
Ans = 0
for sy in range(1, H+1):
  for sx in range(1, W+1):
    if Maze[sy][sx] == "#":
      continue
    memo = [[False]*(W+2) for _ in range(H+2)]
    for ey in range(sy, H+1):
      for ex in range(1, W+1):
        if Maze[ey][ex] == "#" or memo[ey][ex]:
          continue
        P = solve(Maze, [sy, sx], [ey,ex])
        Ans = max(Ans, len(P))
        for p in P:
          memo[p[0]][p[1]] = True
print(Ans)

### FIXED CODE ###

H, W = map(int, input().split())
S = [input() for _ in range(H)]


def f(i, j):
    t = [[-1] * W for _ in range(H)]
    t[i][j] = 0
    q = [(i, j)]
    while q:
        y, x = q.pop(0)
        if y - 1 >= 0 and S[y - 1][x] != '#' and t[y - 1][x] == -1:
            t[y - 1][x] = t[y][x] + 1
            q.append((y - 1, x))
        if y + 1 < H and S[y + 1][x] != '#' and t[y + 1][x] == -1:
            t[y + 1][x] = t[y][x] + 1
            q.append((y + 1, x))
        if x - 1 >= 0 and S[y][x - 1] != '#' and t[y][x - 1] == -1:
            t[y][x - 1] = t[y][x] + 1
            q.append((y, x - 1))
        if x + 1 < W and S[y][x + 1] != '#' and t[y][x + 1] == -1:
            t[y][x + 1] = t[y][x] + 1
            q.append((y, x + 1))
    return max(max(tt) for tt in t)


result = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            result = max(result, f(i, j))
print(result)
### BUGGY CODE ###

import math

v = int(input())
sum = 0

for i in range(1, v + 1):
    for j in range(1, v + 1):
        for k in range(1, v + 1):
            if i == 1 or j == 1 or k == 1:
                sum += 1
            else:
                sum += math.gcd(math.gcd(i, j), k)

print(sum)

### FIXED CODE ###

from math import gcd

v = int(input())
sum = 0

for i in range(1, v + 1):
    for j in range(1, v + 1):
        for k in range(1, v + 1):
            sum += gcd(gcd(i, j), k)

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

n = int(input())
graph = [[] for i in range(n + 1)]
cost = [[[] for i in range(n + 1)] for j in range(n + 1)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)
    cost[u][v] = w
    cost[v][u] = w
ans = [] * (n + 1)


def dfs(a):
    dist = [-1] * (n + 1)
    stack = [a]
    dist[a] = 0
    while stack:
        v = stack.pop()
        for w in graph[v]:
            if dist[w] == -1:
                dist[w] = dist[v] + cost[w][v]
                dist[w] %= 2
                stack.append(w)
            else:
                continue
    return dist


dist = dfs(1)
print(*dist[1:], sep="\n")


### FIXED CODE ###

import sys

input = sys.stdin.readline

n = int(input())
graph = [[] for i in range(n + 1)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append((v, w))
    graph[v].append((u, w))


def dfs(a):
    dist = [-1] * (n + 1)
    stack = [a]
    dist[a] = 0
    while stack:
        v = stack.pop()
        for b, w in graph[v]:
            if dist[b] == -1:
                dist[b] = (dist[v] + w) % 2
                stack.append(b)
            else:
                continue
    return dist


dist = dfs(1)
print(*dist[1:], sep="\n")
### BUGGY CODE ###

import itertools

def warshall_floyd(d):
  for k in range(n):
    for i in range(n):
      for j in range(n):
        d[i][j] = min(d[i][j], d[i][k] + d[k][j])
  return d


n, m, r = map(int, input().split())
list_r = list(map(int, input().split()))
list_cand = itertools.permutations(list_r)
dist = [[float("inf") if i != j else 0 for j in range(n)] for i in range(n)]
for i in range(m):
  a, b, c = map(int, input().split())
  dist[a-1][b-1] = c
  dist[b-1][a-1] = c
min_dist = warshall_floyd(dist)

result = 10**100
for one_cand in list_cand:
  temp = 0
  for i in range(r-1):
    temp += min_dist[one_cand[i]-1][one_cand[i+1]-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()
### BUGGY CODE ###

import math
from functools import reduce
import itertools

limit_num = int(input())

def gcd(*numbers):
	return reduce(math.gcd, *numbers)

result = 0

for num in list(itertools.product(range(1, limit_num + 1), repeat=3)):
	result += gcd(num)

print(str(result))


### FIXED CODE ###

import math
from functools import reduce
import itertools

def gcd(*numbers):
	return reduce(math.gcd, *numbers)

limit_num = int(input())
result_list = []
for num in itertools.product(range(1, limit_num + 1), repeat=3):
	result_list.append(gcd(num))

print(sum(result_list))