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

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

count = 0 # p_j > p_i である回数
for i in range(len(p_list)):
    p_max = min(p_list[:i+1])
    if p_list[i]==p_max:
        count = count + 1

print(count)


### FIXED CODE ###

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

count = 0 # p_j > p_i である回数
p_length = len(p_list)
p_min = p_list[0] # 現時点での最小値

for i in range(p_length):
    if p_list[i]<=p_min:
        p_min = p_list[i]
        count = count + 1 # カウントを１つ増やす
    else:
        continue

print(count)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N-1):
    for k in range(A[i] + i, N):
        if i + A[i] == k - A[k] :
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
plus_lis = [A[i] + i for i in range(N)]
minus_lis = [k - A[k] for k in range(N)]

ans_lis = [0] * 10 ** 6
for x in plus_lis:
    if x < 10 ** 6:
        ans_lis[x-1] += 1
for y in minus_lis:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)
### 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
for i in range(N-1):
    l = A[i]-1
    ans[l] +=1

for i in range(N):
    print(ans[i])
### BUGGY CODE ###

N, M= (int(i) for i in input().split())  
A = [int(i) for i in input().split()]

for i in range(M):
	B,C = [int(i) for i in input().split()]
	for g in range(B):
		A.append(C)
A.sort(reverse=True)
print(sum(A[:N]))

### FIXED CODE ###

import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]
bc.sort(key=lambda x: x[1],reverse=True)

heapq.heapify(a)

for i in range(m):
    b,c=bc[i]
    for g in range(b):
        _min = heapq.heappop(a)
        if _min<c:
            heapq.heappush(a,c)
        else:
            heapq.heappush(a,_min)
            break
print(sum(a))
### BUGGY CODE ###

N = int(input())
aA=sorted(set(int(_) for _ in input().split()))
N = len(aA)
def ggg(i,j):
    if i < j :
        i,j = j,i
    i %= j
    if i == 0:
        return j
    else:
        return ggg(j,i)

if len(aA) == 1:
    print(aA[0])
else:
    iMin = aA[0]
    iMax = aA[-1]
    if iMin  == 1:
        print(1)
    else:
        if max(i % iMin for i in aA) == 0:
            print(iMin)
            exit()
        else:
            iM = iMax
            for i in range(N):
                iA = aA[i]
                for j in range(i+1,N):
                    iMt = ggg(iA,aA[j])
                    if 0 < iMt and iMt < iM:
                        iM = iMt
                if iM == 1:
                    print(1)
                    exit()
            print(iM)


### FIXED CODE ###

#gcdか....
def fgcd(a,b):
    while b:
        a,b = b,a%b
    return a

N = int(input())
aA = sorted(set(int(_) for _ in input().split()))
b = aA[0]
for a in aA[1:]:
    b = fgcd(a,b)
print(b)
### BUGGY CODE ###

import copy
n,x = map(int,input().split())
a = list(map(int,input().split()))
l = copy.deepcopy(a)
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

### FIXED CODE ###

n,x = map(int,input().split())
a = list(map(int,input().split()))
l = [float("INF")]*n
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)
### BUGGY CODE ###

from queue import Queue
n, x, y = map(int, input().split())

links = [[] for i in range(n)]
for i in range(1, n):
        links[i-1].append(i)
        links[i].append(i-1)
links[x-1].append(y-1)
links[y-1].append(x-1)

ans = [0] * (n+1)
dist = [[1e11]*n for i in range(n)]
for i in range(n):
        used = [0] * n
        que = Queue()
        que.put([i, 0])
        while que.qsize():
                v, dis = que.get()
                used[v] = True
                for to in links[v]:
                        if not used[to]:
                                dist[i][to] = min(dist[i][to], dis+1)
                                que.put([to, dis+1])
        for a in dist[i]:
                if a!=1e11: ans[a] += 1
for i in range(n-1): print(ans[i+1]//2)

### FIXED CODE ###

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

ans = [0] * (n+1)
for i in range(1, n+1):
        for j in range(i+1, n+1):
                ans[min(j-i, abs(i-x)+1+abs(j-y))] += 1
for i in range(1, n): print(ans[i])
### BUGGY CODE ###

n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])

h_dif = []
ans = 10 ** 9 + 1

for i in range(1, n):
    h_dif.append(h[i]-h[i-1])
    if i >= k-1:
        ans = min(ans, sum(h_dif[i-k+1:i]))

print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
h = sorted([int(input()) for i in range(n)])

mind = 10 ** 9 + 1

for i in range(n-k+1):
    mind = min(mind, h[i+k-1] - h[i])

print(mind)
### BUGGY CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
a = MAP()
a.sort()

for i in range(m):
    a[len(a)-1] = a[len(a)-1]//2
    a.sort()

print(sum(a))

### FIXED CODE ###

import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
a = MAP()
a = [-i for i in a]
heapify(a)
for i in range(m):
    tmp = -heappop(a)
    heappush(a,-(tmp//2))
print(-sum(a))
### BUGGY CODE ###

from collections import Counter
n=int(input())
p=sorted(list(map(int,input().split())))
s=set()
m = 10**6+1
a=[True for _ in range(m)]

for x in p:
    if a[x]:
        s.add(x)
    i = 2
    y = i*x
    while y<m:
        a[y] = False
        i+=1
        y = i*x
 
c = Counter(p)
for (k,v) in c.items():
    if v>1:
        s.discard(k)
print(len(s))

### FIXED CODE ###

n=int(input())
p=sorted(list(map(int,input().split())))
s=set()
m = 10**6+1
a=[True for _ in range(m)]
prev = 0
for x in p:
    if prev == x:
        s.discard(x)
        continue
    if a[x]:
        s.add(x)
    i = 2
    y = i*x
    while y<m:
        a[y] = False
        i+=1
        y = i*x
    prev=x

print(len(s))
### BUGGY CODE ###

a, b, c, d = map(int, input().split())
count = 0
for i in range(a, b+1):
    if i % c != 0 and i % d != 0:
        count += 1
print(count)

### FIXED CODE ###

a, b, c, d = map(int, input().split())

def gcd(c, d):
    while d:
        c, d = d, c % d
    return c

lcm = c * d // gcd(c, d)
b_num = b - (b // c) - (b // d) + (b // lcm)
a_num = a - 1 - ((a - 1) // c) - ((a - 1) // d) + ((a - 1) // lcm)
print(int(b_num - a_num))
### BUGGY CODE ###

S = input()[::-1]

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while any([w in S for w in words]):
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break

print('YES' if len(S) == 0 else 'NO')

### FIXED CODE ###

S = input()[::-1]

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while True:
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break
    else:
        break

print('YES' if len(S) == 0 else 'NO')
### BUGGY CODE ###

s = str(input())
t = str(input())
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j] = dp[i-1][j-1] +1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

ans = ''
i = len(s)
j = len(t)
while (i>0) & (j>0):
    if dp[i][j] == dp[i-1][j]:
        i -=1
    elif dp[i][j] == dp[i][j-1]:
        j -=1
    else:
        ans = s[i-1] +ans
        i -=1
        j -=1
print(ans)

### FIXED CODE ###

s = str(input())
t = str(input())
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j] = dp[i-1][j-1] +1
        else:
            dp[i][j] = max(dp[i][j-1], dp[i-1][j])

ans = ''
i = len(s)
j = len(t)
while (i>0) & (j>0):
    if dp[i][j] == dp[i-1][j]:
        i -=1
    elif dp[i][j] == dp[i][j-1]:
        j -=1
    else:
        ans = s[i-1] +ans
        i -=1
        j -=1
print(ans)
### BUGGY CODE ###

#n = int(input())
#m = int(input())
#k = int(input())
#n, m = map(int, input().split())
r, g, b, n = map(int, input().split())
#a = list(map(int, input().split()))
#table = []
'''
for i in range h:
    temp = list(map(int, input().split()))
    table.append(temp)
'''
count = 0
for i in range(n//r+1):
    for j in range((n-r*i)//g+1):
        for k in range((n-r*i-g*j)//b+1):
            if r*i+g*j+b*k==n:
                count +=1
print(count)

### FIXED CODE ###

#n = int(input())
#m = int(input())
#k = int(input())
#n, m = map(int, input().split())
r, g, b, n = map(int, input().split())
#a = list(map(int, input().split()))
#table = []
'''
for i in range h:
    temp = list(map(int, input().split()))
    table.append(temp)
'''
count = 0
for i in range(n//r+1):
    for j in range((n-r*i)//g+1):
        if (n-r*i-g*j)%b == 0:
            count +=1
print(count)
### BUGGY CODE ###

import sys

input = sys.stdin.readline

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

es = []
for _ in range(N):
    s, t, x = map(int, input().split())
    es.append((s - x, 1, x))
    es.append((t - x, 0, x))

for _ in range(Q):
    d = int(input())
    es.append((d, 2, -1))

es.sort(key=lambda x: (x[0], x[1]))
st = set()
cur_min_stop = -1
check_needed = True
d_cnt = 0
for i, (time, typ, pos) in enumerate(es):
    # print(es)
    # print(st)
    # print(i, (time, typ, pos))
    if typ == 1:
        st.add(pos)
        if cur_min_stop == -1 or pos < cur_min_stop:
            cur_min_stop = pos
    elif typ == 0:
        st.remove(pos)
        if pos == cur_min_stop:
            check_needed = True
    else:
        if check_needed:
            if st:
                cur_min_stop = min(st)
            else:
                cur_min_stop = -1
            check_needed = False
        print(cur_min_stop)
        d_cnt += 1
        if d_cnt == Q:
            break


### FIXED CODE ###

# 理解する時間がなかったので、とりあえず写経
from bisect import bisect_left
from operator import itemgetter

N, Q = [int(i) for i in input().split()]
Construction = [tuple(int(i) for i in input().split()) for j in range(N)]
D = [int(input()) for _ in range(Q)]

ans = [-1] * Q
skip = [-1] * Q

Construction.sort(key=itemgetter(2))

for s, t, x in Construction:
    l = bisect_left(D, s - x)
    r = bisect_left(D, t - x)
    t = l
    while t < r:
        if skip[t] == -1:
            ans[t] = x  # lからr-1の時刻に出発した人は座標xの工事に引っかかる
            skip[t] = r  # lからr-1の時刻に出発した人はもう調べないようにする
            t += 1
        else:
            t = skip[t]  # tが指定する人はもう調べ終わっているので飛ばす
print(*ans, sep='\n')
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_zero = False
    res = 1

    for item in A_list:
        res *= item

        if item == 0:
            is_zero = True
            break
    else:
        if res > 10 ** 18:
            print(-1)
        else:
            print(res)

    if is_zero:
        print(0)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_zero = False
    is_over = False
    res = 1

    for item in A_list:
        if item == 0:
            is_zero = True
            break

    if is_zero:
        print(0)
    else:
        for item in A_list:
            res *= item

            if res > 10 ** 18:
                is_over = True
                break
        else:
            print(res)

        if is_over:
            print(-1)

if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
for i in A:
    ans *= i
if ans > a:
    print(-1)
else:
    print(ans)  

### FIXED CODE ###

N,*A = map(int,open(0).read().split())
a = 10**18
ans = 1
if 0 in A:
    print(0)
    
else:
    for i in A:
        ans *= i
        if ans > a:
            print(-1)
            exit()
    print(ans)
### BUGGY CODE ###

n = int(input())
n_list = [int(i) for i in input().split()]
ans = 0
mod = 10 ** 9 + 7
num_list = [n % mod for n in n_list]

while len(num_list) > 1:
    x = num_list[0]
    num_list.remove(x)
    ans += (x * (sum(num_list) % mod)) % mod
    ans = ans % mod

# for i in range(n-1):
#     for j in range(i+1,n):
#         ans += (num_list[i] * num_list[j]) % mod
#         ans = ans % mod

print (ans)

### FIXED CODE ###

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

s = sum(a**2 for a in n_list)
ans = sum(n_list) ** 2 - s

print((ans//2)%(10**9+7))
### BUGGY CODE ###


n=int(input()) 
L=list(map(int, input().split())) 
L.sort(reverse = True)
 
count = 0
            
for i in range(n-1):
  for k in range(i+1,n-1):
    a,b =L[i],L[k]
    L_temp = L[k+1:]
    count = count + sum([1 for x in L_temp if b+x>a])
    
print(count)

### FIXED CODE ###

import bisect
n=int(input()) 
L=list(map(int, input().split())) 
L.sort()

count = 0        
for i in range(n-2):
  a = L[i]
  for k in range(i+1,n-1):
    b = L[k]

    count += bisect.bisect_left(L, a + b) - k -1
print(count)
### BUGGY CODE ###

def main():
    import heapq
    hpop = heapq.heappop
    hpush = heapq.heappush
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    visit = [False]*n
    h = []
    heapq.heapify(h)
    for i in range(n):
        hpush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = hpop(h)
        i = -i
        jj = (j+1) % n
        if visit[j]:
            if a[j] != b[j]:
                print(-1)
                return 0
            visit[j-1] = True
            visit[jj] = True
            continue
        temp = i-a[j]
        temp2 = b[j-1]+b[jj]
        sho = temp//temp2
        if sho == 0:
            if a[j] != b[j]:
                print(-1)
                return 0
            visit[j-1] = True
            visit[j] = True
            visit[jj] = True
            continue
        cnt += sho
        b[j] -= temp2*sho
        hpush(h, (-b[j], j))
    print(cnt)


main()


### FIXED CODE ###

def main():
    from heapq import heappop as hpop
    from heapq import heappush as hpush
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    h = []
    for i in range(n):
        hpush(h, (-b[i], i))
    cnt = 0
    while h:
        i, j = hpop(h)
        i = -i
        jj = (j+1) % n
        temp = i-a[j]
        temp2 = b[j-1]+b[jj]
        sho = temp//temp2
        if sho == 0:
            if temp:
                print(-1)
                return 0
            continue
        cnt += sho
        b[j] -= temp2*sho
        hpush(h, (-b[j], j))
    print(cnt)
main()
### BUGGY CODE ###

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

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(n)]
for i in a:
    l[i - 1] += 1
print(*l, sep="\n")
### BUGGY CODE ###

def main():
    n = int(input())
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = 0

    for i, pi in enumerate(P):
        for pj in P[i+1:]:
            ans = max(ans, abs(pi[0] - pj[0])+abs(pi[1] - pj[1]))

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    P = [list(map(int, input().split())) for _ in range(n)]
    C0, C1 = [], []
    ans = 0

    for pi in P:
        C0.append(pi[0] - pi[1])
        C1.append(pi[0] + pi[1])

    C0min = min(C0)
    C0max = max(C0)
    C1min = min(C1)
    C1max = max(C1)

    print(max(C0max - C0min, C1max - C1min))


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

import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

def foo(x):
    sum = 0
    for y in a:
        sum += abs(y-x)
    return sum+b

a = []
b = 0
q = inn()
for i in range(q):
    x = inl()
    if len(x)==1:
        z = (len(a)-1)//2
        print("{} {}".format(a[z],foo(a[z])))
    else:
        z = x[1]
        if len(a)==0 or a[-1] <= z:
            a.append(z)
        elif z <= a[0]:
            a.insert(0,z)
        else:
            up = len(a)-1
            lo = 0
            while lo+1 < up:
                mid = (lo+up)//2
                if z < a[mid]:
                    up = mid
                else:
                    lo = mid
            a.insert(up,z)
        b += x[2]


### FIXED CODE ###

import heapq
#printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
#inm   = lambda:      map(int, input().split())
DBG = True  and False
#def ddprint(x):
#  if DBG:
#    print(x)

q = inn()
x = inl()
root = x[1]
b = x[2]
tl = []
tr = []
nl = nr = suml = sumr = 0
#ddprint("q " + str(q))
for i in range(1,q):
    #ddprint("i " + str(i))
    x = inl()
    if len(x)==1:
        z = sumr - suml - (root if nr>nl else 0) + b
        print("{} {}".format(root,z))
    else:
        a = x[1]
        b += x[2]
        if nl == nr:
            aa = -heapq.heappushpop(tl,-a)
            suml += a - aa
            if aa<root:
                aa,root = root,aa
            heapq.heappush(tr,aa)
            sumr += aa
            nr += 1
        else:
            aa = heapq.heappushpop(tr,a)
            sumr += a - aa
            if aa>root:
                aa,root = root,aa
            heapq.heappush(tl,-aa)
            suml += aa
            nl += 1
        #ddprint("b {} root {} nl {} nr {} suml {} sumr {}".format(b,root,nl,nr,suml,sumr))
        #ddprint(tl)
        #ddprint(tr)
### 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()))
b = [0]*n

for i in range(n-1):
    b[a[i]-1] += 1

for i in range(n):
    print(b[i])
### BUGGY CODE ###

s = input()
mod = 10 ** 9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
    memo[i+1] = memo[i] * 10 % 13
    if si == '?':
        for n in range(10):
            a = n * memo[i]
            for j in range(13):
                dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
    else:
        a = int(si) * memo[i]
        for j in range(13):
            dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
print(dp[len(s)][5])


### FIXED CODE ###

s = input()
mod = 10 ** 9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
    memo[i+1] = memo[i] * 10 % 13
    if si == '?':
        for n in range(10):
            a = n * memo[i]
            for j in range(13):
                dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
    else:
        a = int(si) * memo[i]
        for j in range(13):
            dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
print(dp[len(s)][5])
### BUGGY CODE ###

import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

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

def divi(n, d = []):
  res = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      if i in d or not d:
        res.append(i)
      if i != n // i:
        if n // i in d or not d:
          res.append(n // i)
  return res

def isprime(n):
  for i in range(2, n+1):
    if i*i <= n:
      if (n % i == 0):
        return False
  return True

def main():
  a, b = sorted(na())
  x = divi(a)
  y = divi(b, x)
  res = []
  for i, yy in enumerate(y):
    if not isprime(yy):
      continue
    res.append(yy)
  print(len(res))
main()

### FIXED CODE ###

import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

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

def isprime(n):
  if n == 2:
    return True
  if n % 2 == 0 or n < 2:
    return False
  for i in range(3, int(n**0.5)+1, 2):
    if (n % i == 0):
      return False
  return True

def main():
  a, b = sorted(na())
  x = divi(a)
  cnt = 1
  for bb in divi(b):
    if bb in x and isprime(bb):
      cnt += 1
  print(cnt)
main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())
n, q = f()
s = input()
for _ in range(q):
  l, r = f()
  print(s[l-1:r].count('AC'))

### FIXED CODE ###

f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])
### BUGGY CODE ###

import itertools
n,m,r=map(int,input().split());R=min(r,8)
d = [[10**12]*n for j in range(n)]
l=list(map(int,input().split()))
for i in range(r):
  l[i]-=1
for i in range(m):
  a,b,c=map(int,input().split())
  d[a-1][b-1]=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]
#print(d)
ans=30**8
for v in itertools.permutations(l, R):
  cnt=0
  for i in range(1,R):
    cnt+=d[v[i-1]][v[i]]
  ans=min(ans,cnt)
print(ans)

### FIXED CODE ###

import itertools
n,m,r=map(int,input().split());R=min(r,8)
d = [[10**12for i in range(n)]for j in range(n)]
l=list(map(int,input().split()))
for i in range(r):
  l[i]-=1
for i in range(m):
  a,b,c=map(int,input().split())
  d[a-1][b-1]=d[b-1][a-1] = c
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])
#print(d)
ans=10**12
for v in itertools.permutations(l, R):
  cnt=0
  for i in range(1,R):
    cnt+=d[v[i-1]][v[i]]
  ans=min(ans,cnt)
print(ans)