qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main():
    n = int(input())
    a_lst = [int(input()) for _ in range(n)]
    a_lst.sort()

    count = 0
    tmp = 0
    number = a_lst[0]
    
    for i in range(n):
        if a_lst[i] == number:
            tmp += 1
            
            if i == n - 1:
                if tmp % 2 != 0:
                    count += 1
        
        else:
            number = a_lst[i]

            if tmp == 0:
                count += 1

            else:
                if tmp % 2 == 0:
                    tmp = 0
                    continue
                else:
                    count += 1
                    tmp = 0

    print(count)


if __name__ == '__main__':
    main()

Fixed code:
def main():
    n = int(input())
    a_lst = [int(input()) for _ in range(n)]
    a_lst.sort()

    count = 0
    tmp = 0
    number = a_lst[0]

    for i in range(n):

        if a_lst[i] == number:
            tmp += 1

            if i == n - 1:
                if tmp % 2 != 0:
                    count += 1

        else:
            number = a_lst[i]

            if tmp % 2 == 0:
                tmp = 1
                continue
            else:
                count += 1
                tmp = 1

    if n > 1:
        if a_lst[-1] != a_lst[-2]:
            count += 1

    print(count)


if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
dic = {}
for i in range(N):
  A = int(input())
  if A not in dic:
    dic[A]=0
  else:
    dic[A]^=1
print(sum(dic.values()))

Fixed code:
N = int(input())
dic = {}
for i in range(N):
  A = int(input())
  if A not in dic:
    dic[A]=1
  else:
    dic[A]^=1
print(sum(dic.values()))
Buggy code:
N = int(input())
from collections import Counter
c = []
for i in range(N):
    c.append(int(input()))

c=Counter(c)
print(sum([1 for k, v in c.items() if v % 2 == 0]))

Fixed code:
N = int(input())
from collections import Counter
c = []
for i in range(N):
    c.append(int(input()))

c=Counter(c)
print(sum([1 for k, v in c.items() if v % 2 != 0]))
Buggy code:
import collections
n=int(input())
lst=[int(input()) for i in range(n)]
xs=list(set(lst))
ans=0
lst=collections.Counter(lst)
for i in xs:
  if lst[i]%=1:
    ans+=1

print(ans)

Fixed code:
import collections
n=int(input())
lst=[int(input()) for i in range(n)]
xs=list(set(lst))
ans=0
lst=collections.Counter(lst)
for i in xs:
  if lst[i]%2==1:
    ans+=1

print(ans)
Buggy code:
N = int(input())

arr = [ int(input()) for i in range(N)]

arr.sort()
cnt = 0
num = 1

a = arr[0]

for i in range(1,N):
  if arr[i] == a:
    num += 1
  else:
    num = 1
    if num % 2 == 1:
      cnt += 1
printx(int(cnt))

Fixed code:
N = int(input())

arr = [ int(input()) for i in range(N)]

arr.sort()
cnt = 0
num = 1

a = arr[0]

for i in range(1,N):
  if arr[i] == a:
    num += 1
  else:
    if num % 2 == 1:
      cnt += 1
    num = 1
    a = arr[i]
if num % 2 == 1:
  cnt += 1

print(int(cnt))
Buggy code:
import collections
n = int(input())
c = collections.Counter([int(input()) for _ in range(n)])
ans = 0
for cnt in c.values():
    if cnt %2 != 1:
        ans += 1
print(ans)

Fixed code:
import collections
n = int(input())
c = collections.Counter([int(input()) for _ in range(n)])
ans = 0
for cnt in c.values():
    if cnt %2 != 0:
        ans += 1
print(ans)
Buggy code:
n=int(input())
a=sorted[int(input()) for _ in range(n)]
ans=0
k=1
for i in range(n):
  if a[i]==a[i-1]:
    k+=1
  else:
    ans+=k%2
    k=1
if a[n-2]==a[n-1]:
  ans+=k%2
print(ans)

Fixed code:
n=int(input())
a=sorted([int(input()) for _ in range(n)])
ans=0
k=1
for i in range(1,n):
  if a[i]==a[i-1]:
    k+=1
  else:
    ans+=k%2
    k=1
ans+=k%2
print(ans)
Buggy code:
n = int(input())
l = {}
for i in range(n):
  a = int(input())
  if a in l:
    l[a] +=1
  else:
    l[a] = 1
ans = 0
for i in l.values():
    if i % 2 == 0:
        ans += 1
print(ans)

Fixed code:
n = int(input())
l = {}
for i in range(n):
  a = int(input())
  if a in l:
    l[a] +=1
  else:
    l[a] = 1
ans = 0
for i in l.values():
    if i % 2 == 1:
        ans += 1
print(ans)
Buggy code:
n = int(input())
paper = {}
for _ in range(n):
    x = int(input())
    if x in paper:
        paper[x] += 1
    else:
        paper[x] = 1
count = 0
for i in paper.values():
    if i % 2 == 0: count += 1
print(count)

Fixed code:
n = int(input())
paper = {}
for _ in range(n):
    x = int(input())
    if x in paper:
        paper[x] += 1
    else:
        paper[x] = 1
count = 0
for i in paper.values():
    if i % 2 != 0: count += 1
print(count)
Buggy code:
d={}
for _ in[0]*int(input()):
    i=input()
    d[i]=d.get(i,0)^1
    print("d[i]", d[i])
print(sum(d.values()))

Fixed code:
d={}
for _ in[0]*int(input()):
    i=input()
    d[i]=d.get(i,0)^1
print(sum(d.values()))
Buggy code:
#073-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
a=[]
for i in range(n):
    t=I()
    a.append(t)
b=list[set(a)]
c={}
for i in b:
    c[i]=0
for i in a:
    c[a]+=1
for i in c.keys():
    if c[i]%2==1:
        cnt+=1
print(cnt)

Fixed code:
#073-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
a=[]
for i in range(n):
    t=I()
    a.append(t)
b=list(set(a))
c={}
cnt=0
for i in b:
    c[i]=0
for i in a:
    c[i]+=1
for i in c.keys():
    if c[i]%2==1:
        cnt+=1
print(cnt)
Buggy code:
n=int(input())
s=set()

for i in range(n):
    a=int(input())
    if a in s:
        s.remove(a)
    else:
        s.append(a)

print(len(s))



Fixed code:
n=int(input())
s=set()

for i in range(n):
    a=int(input())
    if a in s:
        s.remove(a)
    else:
        s.add(a)

print(len(s))
Buggy code:
import collections
start = time.time()
n=int(input())
a=[input() for i in range(n)]
a_coll=dict(collections.Counter(a))
ans=0
for b in a_coll:
    if a_coll[b]%2==1:
        ans+=1
print(ans)


Fixed code:
import collections
n=int(input())
a=[input() for i in range(n)]
a_coll=dict(collections.Counter(a))
ans=0
for b in a_coll:
    if a_coll[b]%2==1:
        ans+=1
print(ans)
Buggy code:
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 0
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)

Fixed code:
n = int(input())
a = []
for i in range(n):
    s = int(input())
    a.append(s)
a.sort()
i = 0
cnt = 0
while i < n:
    j = i+1
    chk = 1
    if j >= n:
        cnt += 1 
        break
    while a[i] == a[j]:
        chk += 1
        j += 1
        if j >= n:
            break
    if chk%2 == 1:
        cnt += 1 
    i = j
print(cnt)
Buggy code:
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)

pre = sorted_A[0]
if len(sorted_A) == 1:
    print(1)
else:
    count = 0
    for i in range(1, len(sorted_A)):
        if sorted_A[i] == pre:
            count += 1
        else:
            if count % 2 == 1:
                ans += 1
            pre = sorted_A[i]
            count = 1
print(ans)

Fixed code:
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)

pre = sorted_A[0]
ans = 0
if len(sorted_A) == 1:
    print(1)
else:
    count = 1
    for i in range(1, len(sorted_A)):
        if sorted_A[i] == pre:
            count += 1
            if i == len(sorted_A)-1:
                if count % 2 == 1:
                    ans += 1
        else:
            if i == len(sorted_A)-1:
                ans += 1
            if count % 2 == 1:
                ans += 1
            pre = sorted_A[i]
            count = 1
    print(ans)
Buggy code:
n = int(input())
a = [int(input()) for _ in range(n)]

a.sort()

ans = 0
tmp = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        tmp += 1
        if i == n-2:
            ans += tmp % 2
            tmp = 1
    else:
        ans += tmp % 2
        tmp = 1

if tmp%2 == 1:
    ans += 1

print(ans)

Fixed code:
n = int(input())
a = [int(input()) for _ in range(n)]

a.sort()

ans = 0
tmp = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        tmp += 1
        if i == n-2:
            ans += tmp % 2
            tmp = 0
    else:
        ans += tmp % 2
        tmp = 1

if tmp%2 == 1:
    ans += 1

print(ans)
Buggy code:
n = int(input())

d = {}
for i in range(n):
    a = int(input())
    if a in d:
        d[a] ^= 1
print(sum(d.values()))

Fixed code:
n = int(input())

d = {}
for i in range(n):
    a = int(input())
    if a in d:
        d[a] ^= 1
    else:
        d[a] = 1
print(sum(d.values()))
Buggy code:
N = int(input())
A = [int(input()) for _ in range(N)]
A=sorted(A)
 
ans=0
cnt=1
tmp=A[0]
 
for i in range(1,N):
    if A[i]==tmp:
        cnt+=1
    elif A[i]!=tmp and cnt%2!=0:
        cnt=1
        ans+=1
    tmp=A[i]
if cnt%2 ==1:
  ans+=1
print(ans)

Fixed code:
N = int(input())
A = [int(input()) for _ in range(N)]
A=sorted(A)
 
ans=0
cnt=1
tmp=A[0]
 
for i in range(1,N):
    if A[i]==tmp:
        cnt+=1
    else:
        if cnt%2!=0:
            ans+=1
        cnt=1
    tmp=A[i]
    
if cnt%2==1:
    ans+=1
print(ans)
Buggy code:
import collections
N = int(input())
a = [int(input()) for i in range(N)]
c = collections.Counter(a)
tmp = c.values()
count=0
for i in range(len(tmp)):
  if i%2!=0:
    count+=1
print(count)


Fixed code:
import collections
N = int(input())
a = [int(input()) for i in range(N)]
c = collections.Counter(a)
tmp = list(c.values())
count=0
for i in range(len(tmp)):
  if tmp[i]%2!=0:
    count+=1
print(count)
Buggy code:
n=int(input())
d={}
for x in range(n):
  s=int(input())
  if s in d:
    if d[s]==0:
      d[s]=1
    else:
      d[s]=0
      
  if s not in d:
    d[s]=1
  
ans=0
for y in d:
  if d[y]==1:
    ans+=1
    

Fixed code:
n=int(input())
d={}
for x in range(n):
  s=int(input())
  if s in d:
    if d[s]==0:
      d[s]=1
    else:
      d[s]=0
      
  if s not in d:
    d[s]=1
  
ans=0
for y in d:
  if d[y]==1:
    ans+=1
    
print(ans)
Buggy code:
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()

odd = 0
count = 1
a = A[0]
for i in A[1:]:
  print(i,a)
  if i == a:
    count += 1
  else:
    a = i
    if count % 2 == 1:
      odd += 1
    count = 1
if count % 2 == 1:
      odd += 1
print(odd)

Fixed code:
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()

odd = 0
count = 1
a = A[0]
for i in A[1:]:
  if i == a:
    count += 1
  else:
    a = i
    if count % 2 == 1:
      odd += 1
    count = 1
if count % 2 == 1:
      odd += 1
print(odd)
Buggy code:
N = int(input())
a_list = [int(input())for _ in range(N)]

count_dct = {}
for input_num in a_list:
    if input_num in count_dct.keys():
        count_dct[input_num] += 1
    else:
        count_dct[input_num] = 1
        
counter = 0
for i, j in count_dct.items():
    if j%2 == 1:
        counter +=1
    else:
        pass

Fixed code:
N = int(input())
a_list = [int(input())for _ in range(N)]

count_dct = {}
for input_num in a_list:
    if input_num in count_dct.keys():
        count_dct[input_num] += 1
    else:
        count_dct[input_num] = 1
        
counter = 0
for i, j in count_dct.items():
    if j%2 == 1:
        counter +=1
    else:
        pass
    
print(counter)
Buggy code:
n,m,r=map(int,input().split())
road=list(map(int,input().split()))
cost=[[float("inf")]*n for i in range(n)]
for i in range(n):
    cost[i][i]=0
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    cost[a][b]=c
    cost[b][a]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
import itertools
ans=float("inf")
for i in itertools.permutations(road):
    tmp=0
    for j in range(len(i)-1):
        tmp+=cost[i[j]-1][i[j+1]-1]
    if tmp<ans:
        ans=tmp
print(ans)

Fixed code:
n,m,r=map(int,input().split())
road=list(map(int,input().split()))
cost=[[float("inf")]*n for i in range(n)]
for i in range(n):
    cost[i][i]=0
for i in range(m):
    
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    cost[a][b]=c
    cost[b][a]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
import itertools
ans=float("inf")
for i in itertools.permutations(road):
    tmp=0
    for j in range(len(i)-1):
        tmp+=cost[i[j]-1][i[j+1]-1]
    if tmp<ans:
        ans=tmp
print(ans)
Buggy code:
n, m, r = map(int, input().split())
R = tuple(map(lambda x: int(x), input().split()))
INF = 10**9
dp = [[INF]*(n+1) for _ in range(n+1)]

for _ in range(m):
    a, b, c = map(int, input().split())

    dp[a][b] = c
    dp[b][a] = c

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

from itertools import permutations
ans = INF
for p in permutations(R):
    dist = 0
    for i in range(r-1):
        dist += dp[p[i]][p[i+1]]
    ans = min(ans, dist)
print(ans)

Fixed code:
n, m, r = map(int, input().split())
R = tuple(map(lambda x: int(x)-1, input().split()))
INF = 10**9
dp = [[INF]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dp[a][b] = c
    dp[b][a] = c

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

from itertools import permutations
ans = INF
for p in permutations(R):
    dist = 0
    for i in range(r-1):
        dist += dp[p[i]][p[i+1]]
    ans = min(ans, dist)
print(ans)
Buggy code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))



n,m,r=mp()
l=lmp()
d = [[float("inf")]*(n+1) for i in range(n+1)] 
for i in range(m):
    x,y,z = map(int,input().split())
    d[x][y] = z
    d[y][x] = z
for i in range(n+1):
    d[i][i] = 0
for k in range(n+1):
        for i in range(n+1):
            for j in range(n+1):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])


ans=0
for i in range(r-1):
    ans+=d[l[i]][l[i+1]]
print(ans)

Fixed code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))



n,m,r=mp()
l=lmp()
d = [[float("inf")]*(n+1) for i in range(n+1)] 
for i in range(m):
    x,y,z = map(int,input().split())
    d[x][y] = z
    d[y][x] = z
for i in range(n+1):
    d[i][i] = 0
for k in range(n+1):
        for i in range(n+1):
            for j in range(n+1):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])

lis=list(itertools.permutations(l))
ans=float("inf")
for k in range(len(lis)):
    c=0
    for i in range(r-1):
        c+=d[lis[k][i]][lis[k][i+1]]
    ans=min(ans,c)
print(ans)
Buggy code:
import itertools

MAX_DIS = 10**10
N,M,R = map(int,input().split(" "))
r_list = list(map(int,input().split(" ")))
roads = [[MAX_DIS for i in range(N)] for i in range(N)]
for i in range(N):
    roads[i][i] = 0
print(roads)
for i in range(M):
    A,B,C = map(int,input().split(" "))
    roads[A-1][B-1] = C
    roads[B-1][A-1] = C
for i in range(N):
    for j in range(N):
        for k in range(N):
            roads[i][j] = min(roads[i][j],roads[i][k]+roads[k][j])
min_dis = MAX_DIS
for directions in itertools.permutations(r_list):
    distance  = 0
    for dir in range(1,len(directions)):
        distance += roads[directions[dir-1]-1][directions[dir]-1]
    if distance < min_dis:
        min_dis =distance
print(min_dis)


Fixed code:
import itertools

MAX_DIS = 10**10
N,M,R = map(int,input().split(" "))
r_list = list(map(int,input().split(" ")))
roads = [[MAX_DIS]*N for i in range(N)]
for i in range(N):
    roads[i][i] = 0
for i in range(M):
    A,B,C = map(int,input().split(" "))
    roads[A-1][B-1] = C
    roads[B-1][A-1] = C
for k in range(N):
    for i in range(N):
        for j in range(N):
            roads[i][j] = min(roads[i][j],roads[i][k]+roads[k][j])
min_dis = MAX_DIS
for directions in itertools.permutations(r_list):
    distance  = 0
    for dir in range(1,len(directions)):
        distance += roads[directions[dir-1]-1][directions[dir]-1]
    if distance < min_dis:
        min_dis =distance
print(min_dis)
Buggy code:
#!/usr/bin/env python3

from itertools import permutations
from numba import jit
import numpy as np

HUGE = 10 ** 18

def main():
    n, m, r = map(int, input().split())
    togo = list(map(int, input().split()))
    adj_mat = [[HUGE for j in range(n)] for i in range(n)]
    for i in range(n):
        adj_mat[i][i] = HUGE
    for i in range(m):
        a, b, c = map(int, input().split())
        a0 = a - 1
        b0 = b - 1
        adj_mat[a0][b0] = c
        adj_mat[b0][a0] = c
    adj_mat = np.array(adj_mat)

    wf(adj_mat, n)

    res = HUGE
    for way in permutations(togo):
        assert len(way) > 1
        x = 0
        for i in range(len(way) - 1):
            x += adj_mat[way[i] - 1][way[i + 1] - 1]
        res = min(res, x)

    print(res)

@jit(nopython=True)
def wf(adj_mat, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                adj_mat[i][j] = min(adj_mat[i][j], adj_mat[i][k] + adj_mat[k][j])

if __name__ == "__main__":
    main()


Fixed code:
#!/usr/bin/env python3

from itertools import permutations
import numpy as np

HUGE = 10 ** 18

def main():
    n, m, r = map(int, input().split())
    togo = list(map(int, input().split()))
    adj_mat = [[HUGE for j in range(n)] for i in range(n)]
    for i in range(n):
        adj_mat[i][i] = HUGE
    for i in range(m):
        a, b, c = map(int, input().split())
        a0 = a - 1
        b0 = b - 1
        adj_mat[a0][b0] = c
        adj_mat[b0][a0] = c
    adj_mat = np.array(adj_mat)

    wf(adj_mat, n)

    res = HUGE
    for way in permutations(togo):
        assert len(way) > 1
        x = 0
        for i in range(len(way) - 1):
            x += adj_mat[way[i] - 1][way[i + 1] - 1]
        res = min(res, x)

    print(res)

def wf(adj_mat, n):
    for k in range(n):
        for i in range(n):
            adj_mat[i, :] = np.minimum(adj_mat[i, :], adj_mat[i][k] + adj_mat[k, :])

if __name__ == "__main__":
    main()
Buggy code:
import itertools

n,m,r=map(int,input().split())
D=[[10**10]*n for _ in range(n)]
R=list(map(int,input().split()))
for i in range(m):
    a,b,c=map(int,input().split())
    D[a-1][b-1]=c
    D[b-1][a-1]=c
A=[]
for v in itertools.permutations(R,r):
    ans=0
    for i in range(r-1):
        ans+=D[v[i]-1][v[i+1]-1]
    A.append(ans)
print(min(A))

Fixed code:
import itertools

n,m,r=map(int,input().split())
D=[[10**10]*n for _ in range(n)]
for i in range(n):
    D[i][i]=0
R=list(map(int,input().split()))
for i in range(m):
    a,b,c=map(int,input().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):
            D[i][j]=min(D[i][j],D[i][k]+D[k][j])

A=[]
for v in itertools.permutations(R,r):
    ans=0
    for i in range(r-1):
        ans+=D[v[i]-1][v[i+1]-1]
    A.append(ans)
print(min(A))
Buggy code:
import itertools
n,m,r=map(int,input().split())
point=list(map(int,input().split()))
g=[[10**9]*n for i in range(n)]
for _ in range(m):
  u,v,c=map(int,input().split())
  g[u-1][v-1]=g[v-1][u-1]=c
for k in range(n):
  for i in range(n):
    for j in range(n):
      g[i][j]=min(g[i][j],g[i][k]+g[k][j])
for i in range(n):
  g[i][i]=0
ans=10**18
for v in itertools.permutations([int(i) for i in range(r)]):
  tmp=0
  for i in range(r-1):
    tmp+=g[v[i]][v[i+1]]
  ans=min(ans,tmp)
print(ans)

Fixed code:
import itertools
n,m,r=map(int,input().split())
point=list(map(int,input().split()))
g=[[10**9]*n for i in range(n)]
for _ in range(m):
  u,v,c=map(int,input().split())
  g[u-1][v-1]=g[v-1][u-1]=c
for k in range(n):
  for i in range(n):
    for j in range(n):
      g[i][j]=min(g[i][j],g[i][k]+g[k][j])
for i in range(n):
  g[i][i]=0
ans=10**18
for v in itertools.permutations(point):
  tmp=0
  for i in range(r-1):
    tmp+=g[v[i]-1][v[i+1]-1]
  ans=min(ans,tmp)
print(ans)
Buggy code:
import itertools

def warshall_floyd(g):
    for k in range(len(g)):
        for i in range(len(g)):
            for j in range(len(g)):
                graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j])
    return g

n,m,r = map(int,input().split())
lst = list(map(int,input().split()))
graph = [[0]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
d = warshall_floyd(graph)
res = float('inf')

for l in itertools.permutations(lst):
    cnt = 0
    for i in range(1, len(l)):
        cnt += d[lst[i-1]-1][lst[i]-1]
    res = min(res, cnt)
print(res)

Fixed code:
import itertools
def warshall_floyd(g):
    for k in range(len(g)):
        for i in range(len(g)):
            for j in range(len(g)):
                g[i][j] = min(g[i][j], g[i][k]+g[k][j])
    return g

n,m,r = map(int,input().split())
lst = list(map(int,input().split()))
graph = [[float('inf')]*n for _ in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for i in range(n):
    graph[i][i] = 0
d = warshall_floyd(graph)

res = float('inf')
for l in itertools.permutations(lst):
    cnt = 0
    for i in range(1, len(l)):
        cnt += d[l[i-1]-1][l[i]-1]
    res = min(res, cnt)
print(res)
Buggy code:
import itertools

n,m,r_ = map(int, input().split( ))

r = list(map(int, input().split( )))
for i in range(r_):
  	r[i] -=1
d = [[10**10 for _ in range(n)] for i in range(n)]

for i in range(m):
    ai,bi,ci = map(int, input().split( ))
    ai-=1
    bi-=1
    d[ai][bi] = d[bi][ai] = ci
ans= 10**10
for l in itertools.permutations(r,r_):
    tmp = 0
    for i in range(r_-1):
        tmp += d[l[i]][l[i+1]]
    ans = min(ans, tmp)

print(ans)

Fixed code:
import itertools
 
n,m,r_ = map(int, input().split( ))
 
r = list(map(int, input().split( )))
for i in range(r_):
  	r[i] -= 1
d = [[10**10 for _ in range(n)] for i in range(n)]
 
for i in range(m):
    ai,bi,ci = map(int, input().split( ))
    ai-=1
    bi-=1
    d[ai][bi] = d[bi][ai] = ci

for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j] = min(d[i][k]+d[k][j],d[i][j])
ans= 100000000000000
for l in itertools.permutations(r,r_):
    tmp = 0
    for i in range(r_-1):
        tmp += d[l[i]][l[i+1]]
    ans = min(ans, tmp)
 
print(ans)
Buggy code:
from itertools import permutations
N, M, R, *L = map(int, open('0').read().split())
city = L[:R]
inf = L[R:]
dist = [[10**10]*N for i in range(N)]
for x,y,c in zip(*[iter(inf)]*3):
  dist[x-1][y-1] = c
  dist[y-1][x-1] = c
for i in range(N):
  dist[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])

ans = 10**10
for m in permutations(city):
  n = 0
  for i in range(R-1):
    n += dist[m[i]-1][m[i+1]-1]
  ans = min(ans,n)
  print(n,m)
print(ans)  
  

Fixed code:
from itertools import permutations
N, M, R, *L = map(int, open(0).read().split())
city = L[:R]
inf = L[R:]
dist = [[10**10]*N for i in range(N)]
for x,y,c in zip(*[iter(inf)]*3):
  dist[x-1][y-1] = c
  dist[y-1][x-1] = c
for i in range(N):
  dist[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])

ans = 10**10
for m in permutations(city):
  n = 0
  for i in range(R-1):
    n += dist[m[i]-1][m[i+1]-1]
  ans = min(ans,n)
print(ans)