Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
N_ = int(N**0.5)+2
for i in range(1,N+1):
    ans = 0
    for x in range(1,N_):
        for y in range(1,N_):
            if N <= x*y:
                break
            for z in range(1,N_):
                tmp = x**2+y**2+z**2+x*y+y*z+z*x
                if N <= tmp:
                    break
                if tmp == i:
                    ans += 1

    print(ans)


Fixed submission:
from collections import Counter
N = int(input())
N_ = int(N**0.5)+2

counter = Counter()
for x in range(1,N_):
    for y in range(1,N_):
        if N <= x**2+y**2+x*y:
            break
        for z in range(1,N_):
            tmp = x**2+y**2+z**2+x*y+y*z+z*x
            if N < tmp:
                break
            counter[tmp] += 1

for i in range(1,N+1):
    print(counter[i])
Buggy python submission (verdict: Runtime Error):
from math import randint
for i in range(365):
  print(randint(1,2))

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

for d in range(1,D+1):
    ans = [1,0]
    for i in range(1,27):
        satisfaction = 0
        satisfaction += s[d-1][i-1]
        for j in range(1,27):
            if i != j:
                satisfaction -= c[j-1]*(d-last[j])
        if ans[1] <= satisfaction:
            ans = [i,satisfaction]
    last[ans[0]] = d
    print(ans[0])

Buggy python submission (verdict: Runtime Error):
from math import randint()
for i in range(365):
  print(randint(1,26))

Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

for d in range(1,D+1):
    ans = [1,0]
    for i in range(1,27):
        satisfaction = 0
        satisfaction += s[d-1][i-1]
        for j in range(1,27):
            if i != j:
                satisfaction -= c[j-1]*(d-last[j])
        if ans[1] <= satisfaction:
            ans = [i,satisfaction]
    last[ans[0]] = d
    print(ans[0])
Buggy python submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

satisfaction = 0
for d in range(1,D+1):
    satisfaction += s[d-1][t[d-1]-1]
    last[t[d-1]] = d
    for i in range(26):
        satisfaction -= c[d-1]*(d-last[t[d-1]])
    print(satisfaction)


Fixed submission:
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]

last = {}
for i in range(1,27):
    last[i] = 0

satisfaction = 0
for d in range(1,D+1):
    satisfaction += s[d-1][t[d-1]-1]
    last[t[d-1]] = d
    for i in range(1,27):
        satisfaction -= c[i-1]*(d-last[i])
    print(satisfaction)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
counter = Counter(A)
s = sorted(set(A))
if len(A) == 1:
    print(1)
else:
    lst = []
    ans = 0
    for i in range(len(s)):
        m = s[i]/2
        flg = True
        for p in lst:
            if s[i]%p == 0:
                flg = False
                break
            elif m < p:
                break
        if flg:
            lst.append(s[i])
            if counter[s[i]] == 1:
                ans += 1
    print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
s = set(A)
counter = Counter(A)
A.sort()
ans = [1]*(10**6+1)
for i in range(1,10**6+1):
    if i in s and ans[i]:
        tmp = i
        cnt = 2
        while tmp*cnt <= 10**6:
            ans[tmp*cnt] = 0
            cnt += 1
    else:
        ans[i] = 0
    if counter[i] != 1:
        ans[i] = 0
print(sum(ans)-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
counter = Counter(A)
s = sorted(set(A))
if len(A) == 1:
    print(1)
else:
    lst = []
    ans = 0
    for i in range(len(s)):
        # m = int(s[i]**0.5)+1
        flg = True
        for p in lst:
            if s[i]%p == 0:
                flg = False
                break
            # elif m < p:
            #     break
        if flg:
            lst.append(s[i])
            if counter[s[i]] == 1:
                ans += 1
    print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
s = set(A)
counter = Counter(A)
A.sort()
ans = [1]*(10**6+1)
for i in range(1,10**6+1):
    if i in s and ans[i]:
        tmp = i
        cnt = 2
        while tmp*cnt <= 10**6:
            ans[tmp*cnt] = 0
            cnt += 1
    else:
        ans[i] = 0
    if counter[i] != 1:
        ans[i] = 0
print(sum(ans)-1)
Buggy python submission (verdict: Runtime Error):
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)
                cnt += 1
print(ans)

Fixed submission:
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

#i文字目以降のRGBの数
RGB = [[0]*(N+1) for i in range(3)]
for i in range(N-1,-1,-1):
    if S[i] == "R":
        RGB[0][i] = RGB[0][i+1]+1
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]
    elif S[i] == "G":
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]+1
        RGB[2][i] = RGB[2][i+1]
    else:
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]+1

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += RGB[2][j]
            if j+(j-i) < N and S[j+(j-i)] == "B":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += RGB[0][j]
            if j+(j-i) < N and S[j+(j-i)] == "R":
                ans -= 1
        elif (S[i] == "R" and S[j] == "B") or (S[i] == "B" and S[j] == "R"):
            ans += RGB[1][j]
            if j+(j-i) < N and S[j+(j-i)] == "G":
                ans -= 1
print(ans)

Fixed submission:
N = int(input())
S = input()

#i文字目以降のRGBの数
RGB = [[0]*(N+1) for i in range(3)]
for i in range(N-1,-1,-1):
    if S[i] == "R":
        RGB[0][i] = RGB[0][i+1]+1
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]
    elif S[i] == "G":
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]+1
        RGB[2][i] = RGB[2][i+1]
    else:
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]+1

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += RGB[2][j]
            if j+(j-i) < N and S[j+(j-i)] == "B":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += RGB[0][j]
            if j+(j-i) < N and S[j+(j-i)] == "R":
                ans -= 1
        elif (S[i] == "R" and S[j] == "B") or (S[i] == "B" and S[j] == "R"):
            ans += RGB[1][j]
            if j+(j-i) < N and S[j+(j-i)] == "G":
                ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import Counter

def main():
    N,X,Y = list(map(int,input().split()))

    counter = Counter()
    for i in range(1,N+1):
        distance = [float("inf")]*(N+1)
        q = deque()
        q.append(i)
        distance[i] = 0
        while q:
            p = q.popleft()
            if p != 1 and p != N:
                if distance[p+1] == float("inf"):
                    if distance[p]+1 < distance[p+1]:
                        distance[p+1] = distance[p]+1
                        q.append(p+1)
                        counter[distance[p]+1] += 1
                if distance[p-1] == float("inf"):
                    if distance[p]+1 < distance[p-1]:
                        distance[p-1] = distance[p]+1
                        q.append(p-1)
                        counter[distance[p]+1] += 1
            elif p == 1:
                if distance[p+1] == float("inf"):
                    if distance[p]+1 < distance[p+1]:
                        distance[p+1] = distance[p]+1
                        q.append(p+1)
                        counter[distance[p]+1] += 1
            else:
                if distance[p-1] == float("inf"):
                    if distance[p]+1 < distance[p-1]:
                        distance[p-1] = distance[p]+1
                        q.append(p-1)
                        counter[distance[p]+1] += 1
            if p == X:
                if distance[p]+1 < distance[Y]:
                    distance[Y] = distance[p]+1
                    q.append(Y)
                    counter[distance[p]+1] += 1
            if p == Y:
                if distance[p]+1 < distance[X]:
                    distance[X] = distance[p]+1
                    q.append(X)
                    counter[distance[p]+1] += 1

    for i in range(1,N):
        print(counter[i]//2)

if __name__ == "__main__":
    main()

Fixed submission:
from collections import Counter

def main():
    N,X,Y = list(map(int,input().split()))

    counter = Counter()
    for i in range(1,N):
        for j in range(i+1,N+1):
            d = min(j-i,abs(X-i)+abs(Y-j)+1)
            counter[d]+=1
    for i in range(1,N):
        print(counter[i])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
H,N = list(map(int,input().split()))
INF = 10 ** 12

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(magics[i][0]):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])


Fixed submission:
H,N = list(map(int,input().split()))

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(min(magics[i][0],H+1)):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])

Buggy python submission (verdict: Runtime Error):
H,N = list(map(int,input().split()))
INF = 10 ** 12

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(magics[i][0]):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])


Fixed submission:
H,N = list(map(int,input().split()))

magics = []
for i in range(N):
    magics.append(list(map(int,input().split())))

#どう考えてもTLEだけどとりあえず
DP = [10**9]*(H+1)
DP[0] = 0
for i in range(N):
    for j in range(min(magics[i][0],H+1)):
        DP[j] = min(DP[j],magics[i][1])
    for j in range(magics[i][0],H+1):
        DP[j] = min(DP[j],DP[j-magics[i][0]]+magics[i][1])

print(DP[H])
Buggy python submission (verdict: Runtime Error):
import math

N_str = input()
N = int(N_str)
digit = int(math.log10(N))+1

digit = len(N_str)

memo = [0]*26
for i in range(26):
    memo[i] = 5**(i+1)

if N % 2 == 0:
    ans = 0
    for j in range(26):
        ans += (N//memo[j])//2
    print(ans)
else:
    print(0)

Fixed submission:
import math

N = int(input())

memo = [0]*26
for i in range(26):
    memo[i] = 5**(i+1)

if N % 2 == 0:
    ans = 0
    for j in range(26):
        ans += (N//memo[j])//2
    print(ans)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y = list(map(int,input().rstrip().split()))
    
if (2*Y-X)%3 == 0:
    a = (2*Y-X)//3
    b = Y-2*a

    a_kaijo = 1
    for i in range(1,a+1):
        a_kaijo *= i
    b_kaijo = 1
    for i in range(1,b+1):
        b_kaijo *= i
    total_kaijo = 1
    for i in range(1,a+b+1):
        total_kaijo *= i
    print(total_kaijo//(a_kaijo*b_kaijo))
    
else:
    print(0)

Fixed submission:
def main():
    X,Y = list(map(int,input().split()))
    mod = 1000000007

    a = (2*Y-X)//3
    b = Y-2*a
    s = (X+Y)//3
    if (2*Y-X)%3 == 0 and 0 <= a and 0 <= b:
        ans = 1
        for n in range(s-min(a,b)+1,s+1):
            ans = (ans*n)%mod
        div = 1
        for n in range(2,min(a,b)+1):
            div = (div*n)%mod

        ans = (ans*pow(div,1000000005,mod))%mod
        print(ans)
    else:
        print(0)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
L,R = list(map(int, input().split()))

if R-L > 2019:
    print(0)
else:
    i_mod = 2019
    j_mod = 2019
    for k in range(L,R+1):
        mod = k%2019
        if mod < i_mod:
            j_mod = i_mod
            i_mod = mod
        elif mod < j_mod: #要るかこれ？
            j_mod = mod
print(i_mod*j_mod)

Fixed submission:
L,R = list(map(int, input().split()))
 
if R-L > 673:
    print(0)
else:
    min_mod = 2019
    for i in range(L,R):
        i_mod = i%2019
        for j in range(i+1,R+1):
            j_mod = j%2019
            mod = (i_mod*j_mod)%2019
            if mod < min_mod:
                min_mod = mod
        
    print(min_mod)
Buggy python submission (verdict: Runtime Error):
import math

A,B,C,D = list(map(int, input().split()))

C_div = B//C - (A-1)//C
D_div = B//D - (A-1)//D
CandD = int(C*D/math.gcd(C, D))
CandD_div = B//CandD - (A-1)//CandD

print(B-(A-1)-C_div-D_div+CandD_div)

Fixed submission:
import fractions

A,B,C,D = list(map(int, input().split()))

C_div = B//C - (A-1)//C
D_div = B//D - (A-1)//D
CandD = int(C*D/fractions.gcd(C, D))
CandD_div = B//CandD - (A-1)//CandD

print(B-(A-1)-C_div-D_div+CandD_div)
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int, input().split()))

combination = [1,1,2]
for i in range(3,N):
    combination.append(combination[i-1]+combination[i-2])

a = 0
ans = 1
lst = []

next_a = int(input())
lst.append(combination[next_a-a-1])
a = next_a

for i in range(M-1):
    next_a = int(input())
    if next_a-a == 1:
        ans = 0
        break
    lst.append(combination[next_a-a-2])
    a = next_a
    
next_a = N
lst.append(combination[next_a-a-1])

for tmp in lst:
    ans *= tmp
print(ans%1000000007)

Fixed submission:
N,M = list(map(int, input().split()))

combination = [1,1,2]
for i in range(3,N+1):
    combination.append(combination[i-1]+combination[i-2])

a = 0
ans = 1
lst = []

if M > 0:
    next_a = int(input())
    lst.append(combination[next_a-a-1])
    a = next_a
    for i in range(M-1):
        next_a = int(input())
        if next_a-a == 1:
            ans = 0
            break
        elif next_a-a == 0:
            continue
        lst.append(combination[next_a-a-2])
        a = next_a

    next_a = N
    lst.append(combination[next_a-a-1])
else:
    lst.append(combination[N])
    
for tmp in lst:
    ans *= tmp
print(ans%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W = list(map(int,input().split()))
A = [["#"]*(W+2)]
for i in range(H):
    A.append(list("#"+input()+"#"))
A.append(["#"]*(W+2))

queue = deque()
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j] == "#":
            queue.append((i,j,0))

ans = 0
while queue:
    point = queue.popleft()
    ans = max(ans,point[2])
    for y,x in ((1,0),(0,1),(-1,0),(0,-1)):
        if A[point[0]+y][point[1]+x] == ".":
            A[point[0]+y][point[1]+x] = "#"
            queue.append((point[0]+y,point[1]+x,point[2]+1))
print(ans)

Fixed submission:
from collections import deque

def main():
    H,W = list(map(int,input().split()))
    A = [["#"]*(W+2)]
    for i in range(H):
        A.append(list("#"+input()+"#"))
    A.append(["#"]*(W+2))

    queue = deque()
    for i in range(1,H+1):
        for j in range(1,W+1):
            if A[i][j] == "#":
                queue.append((i,j,0))

    ans = 0
    while queue:
        point = queue.popleft()
        ans = max(ans,point[2])
        for y,x in ((1,0),(0,1),(-1,0),(0,-1)):
            if A[point[0]+y][point[1]+x] == ".":
                A[point[0]+y][point[1]+x] = "#"
                queue.append((point[0]+y,point[1]+x,point[2]+1))
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
menu = []
for i in range(5):
    menu.append(int(input()))

menu_kiriage = []
min_reminder = 10
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i

total = 0
for i in range(5):
    if min_menu == i:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10 if menu[i]%10 != 0 else menu[i]
        
print(total)

Fixed submission:
menu = []
for i in range(5):
    menu.append(int(input()))

min_reminder = 10
min_menu = 5
for i in range(5):
    reminder = menu[i]%10
    if reminder < min_reminder and reminder != 0:
        min_reminder = reminder
        min_menu = i
 
total = 0
for i in range(5):
    if min_menu == i or menu[i]%10 == 0:
        total += menu[i]
    else:
        total += menu[i]+10-menu[i]%10
        
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
s = ['_']
s.extend(list(input()))
t = ['.']
t.extend(list(input()))
N = len(s)
M = len(t)
DP = [[[0,[]] for j in range(M+1)] for i in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if s[i-1] == t[j-1]:
            DP[i][j] = deepcopy(DP[i-1][j-1])
            DP[i][j][0] += 1
            DP[i][j][1].append(s[i-1])
        else:
            DP[i][j] = deepcopy(DP[i-1][j]) if DP[i-1][j][0] >= DP[i][j-1][0] else deepcopy(DP[i][j-1])
print(*DP[N][M][1],sep="")



Fixed submission:
from copy import deepcopy
s = ['_']
s.extend(list(input()))
t = ['.']
t.extend(list(input()))
N = len(s)
M = len(t)
DP = [[0]*(M+1) for i in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if s[i-1] == t[j-1]:
            DP[i][j] = DP[i-1][j-1]+1
        else:
            DP[i][j] = max(DP[i-1][j],DP[i][j-1])

i = N
j = M
ans = []
while i != 0 and j != 0:
    if DP[i-1][j] < DP[i][j] and DP[i][j-1] < DP[i][j]:
        ans.append(s[i-1])
        i -= 1
        j -= 1
    elif DP[i-1][j] == DP[i][j]:
        i -= 1
    elif DP[i][j-1] == DP[i][j]:
        j -= 1

print(*reversed(ans),sep="")
Buggy python submission (verdict: Runtime Error):
year = int(input())
if year == 3 or year == 5 or year == 7:
  print(YES)
else:
  print(NO)

Fixed submission:
year = int(input())
if year == 3 or year == 5 or year == 7:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
str_list = list(input())
min = 1000
for i in range(len(list)-2):
  str = str_list[i]+str_list[i+1]+str_list[i+2]
  dif = abs(int(str)-753)
  if dif < min:
    min = dif
print(min)

Fixed submission:
str_list = list(input())
min = 1000
for i in range(len(str_list)-2):
  str = str_list[i]+str_list[i+1]+str_list[i+2]
  dif = abs(int(str)-753)
  if dif < min:
    min = dif
print(min)
Buggy python submission (verdict: Runtime Error):
print(1110-int(input))

Fixed submission:
print(1110-int(input()))
Buggy python submission (verdict: Runtime Error):
N,C = list(map(int,input().split()))

discomforts = [[0]*(N+1)]
for _ in range(C):
    discomforts.append([0,*map(int,input().split())])
print(discomforts)
grid = [[0]*(N+1)]
for _ in range(N):
    grid.append([0,*map(int,input().split())])

color_counts = [[0]*(C+1) for i in range(3)]

for i in range(1,N+1):
    for j in range(1,N+1):
        color_counts[(i+j)%3][grid[i][j]] += 1

ans = float('inf')
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if c0 != c1 and c1 != c2 and c2 != c0:
                total = 0
                for i in range(1,C+1):
                    total += discomforts[i][c0]*color_counts[0][i]
                    total += discomforts[i][c1]*color_counts[1][i]
                    total += discomforts[i][c2]*color_counts[2][i]
                ans = min(ans,total)
print(ans)

Fixed submission:
N,C = list(map(int,input().split()))

discomforts = [[0]*(N+1)]
for _ in range(C):
    row = [0]
    row.extend(list(map(int,input().split())))
    discomforts.append(row)
grid = [[0]*(N+1)]
for _ in range(N):
    row = [0]
    row.extend(list(map(int,input().split())))
    grid.append(row)

color_counts = [[0]*(C+1) for i in range(3)]

for i in range(1,N+1):
    for j in range(1,N+1):
        color_counts[(i+j)%3][grid[i][j]] += 1

ans = float('inf')
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if c0 != c1 and c1 != c2 and c2 != c0:
                total = 0
                for i in range(1,C+1):
                    total += discomforts[i][c0]*color_counts[0][i]
                    total += discomforts[i][c1]*color_counts[1][i]
                    total += discomforts[i][c2]*color_counts[2][i]
                ans = min(ans,total)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
from scipy.sparse.csgraph import dijkstra

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

connections = np.zeros((N,N))
for i in range(M):
    A,B,C = list(map(int,input().split()))
    A,B = A-1,B-1
    
    connections[A][B] = C
    connections[B][A] = C

connections = dijkstra(connections)

def explore(unvisited,total,start):
    if unvisited:
        ret = math.inf
        for town in unvisited:
            ret = min(ret,explore(unvisited-set([town]),
                total+connections[start][town],town))
        return ret
    else:
        return total

ans = math.inf
targets = set(r)
for s in r:
    ans = min(ans,explore(targets-set([s]),0,s))
print(int(ans))

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import dijkstra

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

connections = np.zeros((N,N))
for i in range(M):
    A,B,C = list(map(int,input().split()))
    A,B = A-1,B-1
    
    connections[A][B] = C
    connections[B][A] = C

connections = dijkstra(connections)

def explore(unvisited,total,start):
    if unvisited:
        ret = float('inf')
        for town in unvisited:
            ret = min(ret,explore(unvisited-set([town]),
                total+connections[start][town],town))
        return ret
    else:
        return total

ans = float('inf')
targets = set(r)
for s in r:
    ans = min(ans,explore(targets-set([s]),0,s))
print(int(ans))