Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import numpy as np
  import sys
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines
  N,K = map(int,readline().split())
  A = np.array(readline().split(),np.int64)
  AA = np.cumsum(A)
  L = AA
  for i in range(N-1):
    AA = AA - A[i]
    L = np.concatenate([L,AA[i+1:]])
  ans = 0
  remains = []
  for i in range(40):
    bit = 1 << (39 - i)
    l = []
    cnt = 0
    for j in range(len(L)):
      if bit & L[j] == bit:
        cnt += 1
        l.append(L[j])
    if cnt >= K:
      ans += bit
      L = l
  print(ans)
main()

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))
L = []
for i in range(N):
  for j in range(i+1,N+1):
    L.append(sum(A[i:j]))
L.sort(reverse=True)
ans = 0
remains = []
for i in range(40):
  bit = 1 << (39 - i)
  l = []
  cnt = 0
  #print(bit)
  for j in range(len(L)):
    if bit & L[j] == bit:
      cnt += 1
      l.append(L[j])
  if cnt >= K:
    ans += bit
    L = l
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N,K = map(int,readline().split())
A = np.array(readline().split(),np.int64)
AA = np.cumsum(A)
#print(AA)
L = AA
for i in range(N-1):
  AA = AA - A[i]
  L = np.concatenate([L,AA[i+1:]])

ans = 0
remains = []
for i in range(40):
  bit = 1 << (39 - i)
  l = []
  cnt = 0
  for j in range(len(L)):
    if bit & L[j] == bit:
      cnt += 1
      l.append(L[j])
  if cnt >= K:
    ans += bit
    L = l
print(ans)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))
L = []
for i in range(N):
  for j in range(i+1,N+1):
    L.append(sum(A[i:j]))
L.sort(reverse=True)
ans = 0
remains = []
for i in range(40):
  bit = 1 << (39 - i)
  l = []
  cnt = 0
  #print(bit)
  for j in range(len(L)):
    if bit & L[j] == bit:
      cnt += 1
      l.append(L[j])
  if cnt >= K:
    ans += bit
    L = l
print(ans)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
cost = 1001
for i in range(N):
  c,t = map(int,input().split())
  if t<=T:cost=min(m,c)
print("TLE" if cost==1001 else m)


Fixed submission:
n,tl = map(int,input().split())
cost = []
time = []
cost2 = []
for i in range(n):
  c,t = map(int,input().split())
  cost.append(c)
  time.append(t)
for y,z in zip(cost,time):
  if z<=tl:
    cost2.append(y)    
print("TLE" if min(time)>tl else min(cost2))

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
cost = 1001
for i in range(n):
  c,t = map(int,input().split())
  if t<=T:cost=min(m,c)
print("TLE" if cost==1001 else m)

Fixed submission:
n,tl = map(int,input().split())
cost = []
time = []
cost2 = []
for i in range(n):
  c,t = map(int,input().split())
  cost.append(c)
  time.append(t)
for y,z in zip(cost,time):
  if z<=tl:
    cost2.append(y)    
print("TLE" if min(time)>tl else min(cost2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
for i in range(n,1000):
  if i[0]==i[1]==i[2]:
    return i
print(i)
  

Fixed submission:
n = int(input())
for i in range(n,1000):
  I = str(i)
  if I[0]==I[1]==I[2]:
    print(i)
    break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  tmp = 0
  ans = 0
  for i in range(S1):
    tmp = max(tmp,V1.count(V1_s[i]))
  ans += len(V1) - tmp
  tmp = 0
  for i in range(S2):
    tmp = max(tmp,V2.count(V2_s[i]))
  ans += len(V2) - tmp
  print(ans)

Fixed submission:
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  V1_l = [0] * ((10 ** 5) + 1)
  V2_l = [0] * ((10 ** 5) + 1)
  for i in range(N // 2):
    V1_l[V1[i]] += 1
  for i in range(N // 2):
    V2_l[V2[i]] += 1
  S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
  S2_MAX = [V2_l.index(max(V2_l)),max(V2_l)]
  if S1_MAX[0] != S2_MAX[0]:
    print(N - S1_MAX[1] - S2_MAX[1])
  else:
    V2_l.pop(S2_MAX[0])
    S2_MAX_s = [V2_l.index(max(V2_l)),max(V2_l)]
    ans1 = N - S1_MAX[1] - S2_MAX_s[1]
    V1_l.pop(S1_MAX[0])
    S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
    ans2 = N - S1_MAX[1] - S2_MAX[1]
    print(min(ans1,ans2))
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
cnt = 0
for i in range(len(S)):
  if cnt > 30:
    break
  if S[i] != T[i]:
    X = S[i]
    S = S.replace(S[i],"X")
    S = S.replace(T[i],X)
    S = S.replace("X",T[i])
    cnt += 1
  print(S)
print("Yes" if S == T else "No")

Fixed submission:
S = input()
T = input()
cnt = 0
for i in range(len(S)):
  if cnt > 30:
    break
  if S[i] != T[i]:
    X = S[i]
    S = S.replace(S[i],"X")
    if T[i] in S:
      S = S.replace(T[i],X)
    S = S.replace("X",T[i])
    cnt += 1
print("Yes" if S == T else "No")
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
key = []
for i in range(len(S)):
  if S[i] != "1":
    key.append([i,S[i]])
    break
if K < key[0][0]:
  print(1)
else:
  print(key[0][1])



Fixed submission:
S = input()
K = int(input())
key = []
if S.count("1") == len(S):
  print(1)
else:
  for i in range(len(S)):
    if S[i] != "1":
      key.append([i,S[i]])
      break
  if K - 1 < key[0][0]:
    print(1)
  else:
    print(key[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import bisect
from operator import itemgetter
N, M, Q = map(int,input().split())
LR = [list(map(int,input().split())) for _ in range(M)]
PQ = [list(map(int,input().split())) for _ in range(Q)]
LR.sort(key=itemgetter(0))
LR = np.array(LR)
#print(LR)
#print(PQ)
for i in range(Q):
  ans = 0
  key = bisect.bisect_left(LR[:,0],PQ[i][0])
  ans += np.sum(LR[key:] <= PQ[i][1], axis = 0)[1]
  print(ans)

Fixed submission:
import numpy as np
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N,M,Q = map(int,readline().split())
lines = readlines()
L,R = np.array([line.split() for line in lines[:M]],np.int32).T
P,Q = np.array([line.split() for line in lines[M:]],np.int32).T

cnt = np.zeros((N+1,N+1),dtype=np.int32)
np.add.at(cnt,(L,R),1)

np.cumsum(cnt,axis=0,out=cnt)
np.cumsum(cnt,axis=1,out=cnt)
P -= 1
x = cnt[Q,Q] - cnt[Q,P] - cnt[P,Q] + cnt[P,P]
print(*x,sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
#print(A)
C = np.cumsum(A)
#print(C)
ans = np.sum(C % M == 0)
for i in range(N-1):
  C -= A[i]
  C = C[1:]
  #print(C)
  ans += np.sum(C % M == 0)
print(ans)

Fixed submission:
from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
A = np.insert(A,0,0)
C = np.cumsum(A)
C %= M
ans = 0
d = defaultdict(int)
for i in range(N+1):
  ans += d[C[i]]
  d[C[i]] += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
C = np.cumsum(A)
ans = np.sum(C % M == 0)
for i in range(N-1):
  C -= A[i]
  X = bisect.bisect_left(C,M)
  C = C[X:]
  if X == N:break
  ans += np.sum(C % M == 0)
print(ans)

Fixed submission:
from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N,M = map(int,readline().split())
A = np.array(readline().split(),np.int64)
A = np.insert(A,0,0)
C = np.cumsum(A)
C %= M
ans = 0
d = defaultdict(int)
for i in range(N+1):
  ans += d[C[i]]
  d[C[i]] += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
print(0+count.s("+")-count.s("-"))

Fixed submission:
s = input()
print(0+s.count("+")-s.count("-"))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
count=0
flag=False
while any(a%2==0 for a in A):
  count+=1
  flag=False
  for i in range(n):
    if A[i]%2==0 and flag==False:
      A[i]//=2
      flag=True
    else:
      A[i]*=3
print(count)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in A:
  while i%2==0:
    i//=2
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
K = int(input())
sub = []
for i in range(1,len(S)+1):
  for j in range(len(S)-i+1):
    sub.append(S[j:j+i])
sub = sorted(set(sub))    
print(sub[K-1])

Fixed submission:
S = input()
K = int(input())
sub = []
for i in range(len(S)):
  range = 1
  while range < K + 1 and len(S) >= (i + range):
    sub.append(S[i:i+range])
    range += 1
sub = sorted(set(sub))
print(sub[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]
#print(A)
cnt = -1
for i in range(N-1):
  for j in range(i+1,N):
    if comb(A[i], A[j], exact=True) > cnt:
      ans = [A[i], A[j]]
      cnt = comb(A[i], A[j], exact=True)
print(*ans)

Fixed submission:
import bisect
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
#print(A)
X = A[-1]
key = bisect.bisect_left(A,A[-1] // 2)
if key + 1 == N:
  Y = key - 1
elif key - 1 == -1:
  Y = key + 1
else:
  if (A[-1] / 2) - A[key-1]  <= A[key] - (A[-1] / 2):
    Y = A[key-1]
  else:
    Y = A[key]
print(X,Y)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
list = list(l for l in range(a,b+1))
if b-a+1 < k*2:
  print(*list,sep="\n")
else:
  print(*list[:k],sep="\n")
  print(*list[-k:],sep="\n")

Fixed submission:
a,b,k = map(int,input().split())
x = range(a,b+1) 
if b-a+1 < k*2:
  print(*x,sep="\n")
else:
  print(*x[:k],sep="\n")
  print(*x[-k:],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
list = list(l for l in range(a,b+1))
if b-a+1 < k*2:
  for i in range(a,b+1):
    print(i,end="\n")
else:
  for j in range(k):
    print(list[j],end="\n")
  for k in range(k-1,-1,-1):
    if k==0:
      k = -1
      print(list[k],end="\n")
    else:
      k = k*(-1)-1
      print(list[k],end="\n")

    

Fixed submission:
a,b,k = map(int,input().split())
x = range(a,b+1) 
if b-a+1 < k*2:
  print(*x,sep="\n")
else:
  print(*x[:k],sep="\n")
  print(*x[-k:],sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
cost=0
for i in range(n):
  cost=0
  A=a[:]
  if i==0:
    A[i]=0
  else:
    A[i]=A[i-1]
  cost+=abs(A[0]-0)
  for j in range(n-1):
    cost+=abs(A[j+1]-A[j])
  cost+=abs(0-A[-1])
  print(cost,end="\n")

Fixed submission:
n=int(input())
A=[0]+list(map(int,input().split()))+[0]
cost=sum(abs(A[i+1]-A[i]) for i in range(n+1))
for i in range(1,n+1):
    print(cost-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

N = int(input())
M = []
A = []
R = []
C = []
H = []
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

for _ in range(N):
  tmp = input()[0]
  if tmp == "M":
    M.append(tmp)
  elif tmp == "A":
    A.append(tmp)
  elif tmp == "R":
    R.append(tmp)
  elif tmp == "C":
    C.append(tmp)
  elif tmp == "H":
    H.append(tmp)
X = [len(M),len(A),len(R),len(C),len(H)]
Y = sum(X)
if Y == 0:
  print(0)
  exit()
Sum = cmb(X[0]+X[1]+X[2]+X[3]+X[4],3)

count_A = 0
for x in X:
  if x >= 3:
    count += 1

count_B = 0
for i in X:
  if i >= 2:
    count_B += cmb(i,2) * (Y - i)

print(Sum - count_A - count_B)



Fixed submission:
N = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0

for _ in range(N):
  tmp = input()[0]
  if tmp == "M":
    M += 1
  elif tmp == "A":
    A += 1
  elif tmp == "R":
    R += 1
  elif tmp == "C":
    C += 1
  elif tmp == "H":
    H += 1

ans = 0
ans += M * A * C
ans += M * A * R
ans += M * A * H
ans += M * R * C
ans += M * R * H
ans += M * C * H
ans += A * R * C
ans += A * R * H
ans += A * C * H
ans += R * C * H

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y = map(int,input().split())
if X == Y:
  print(-1)
  exit()
for x in range(X,10**18+1,X):
  if x % Y != 0:
    print(x)
    exit()
print(-1)

Fixed submission:
X,Y = map(int,input().split())
if  X == Y:
  print(-1)
  exit()
if X > Y and X % Y == 0:
  print(-1)
  exit()
for x in range(X,10**18+1,X):
  if x % Y != 0:
    print(x)
    exit()
Buggy python submission (verdict: Runtime Error):
s = input()
s[3] = "8"
print(s)

Fixed submission:
s = input()
print("2018"+s[4:])
Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
LR = [list(map(int,input().split())) for _ in range(Q)]

def isPrime(n):
  if n < 2:
    return False
  i = 2
  while i*i <= n:
    if n%i == 0:
      return False
    i += 1
  return True

def Eratosthenes(n):

    dp = [False]*n
    dp[0] = dp[1] = True
    prime = []
    for i in range(2,n):
        if dp[i]:
            continue
        prime.append(i)
        for j in range(i*2,n,i):
          dp[j] = True
    return prime

cnt = 0
for i in range(Q):
  E = Eratosthenes(LR[i][1]+1)
  #print(E)
  for j in E:
    if j >= LR[i][0] and isPrime(j) and isPrime((j + 1)//2):
      cnt += 1
  print(cnt)
  cnt = 0

Fixed submission:
Q = int(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
flg = [False] * (10**5+1)

def isPrime(n):
  if n < 2:
    return False
  i = 2
  while i*i <= n:
    if n%i == 0:
      return False
    i += 1
  return True

def Eratosthenes(n):
    dp = [False]*n
    dp[0] = dp[1] = True
    prime = []
    for i in range(2,n):
        if dp[i]:
            continue
        prime.append(i)
        for j in range(i*2,n,i):
          dp[j] = True
    return prime

Era = Eratosthenes(10**5+1)
for e in Era:
  flg[e] = True

cnt = []
tmp = 0
for i in range(10**5+1):
  if flg[i] and flg[(i+1)//2]:
    tmp += 1
  cnt.append(tmp)

for i in range(Q):
  print(cnt[LR[i][1]] - cnt[LR[i][0]-1])
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split)
print("Left" if A + B > C + D else "Balanced" if A + B == C + D else "Right")

Fixed submission:
A,B,C,D = map(int,input().split())
print("Left" if A + B > C + D else "Balanced" if A + B == C + D else "Right")
Buggy python submission (verdict: Runtime Error):
n = input()
print("Yes" if n%sum(map(int,n))==0 else "No")


Fixed submission:
n = input()
print("Yes" if int(n)%sum(map(int,n))==0 else "No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
print("Yes" if n%sum(map(int,n))==0 else "No")


Fixed submission:
n = input()
print("Yes" if int(n)%sum(map(int,n))==0 else "No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
print("Yes" if sum(map(int,n))%n==0 else "No")


Fixed submission:
n = input()
print("Yes" if int(n)%sum(map(int,n))==0 else "No")
Buggy python submission (verdict: Runtime Error):
S = list(input())
if S[0] != "A":
  S.insert(0,"A")
if S[4] != "A":
  S.insert(4,"A")
if S[6] != "A":
  S.insert(6,"A")
if S[-1] != "A":
  S.append("A")
s = ""
for i in S:
  s += i
print("YES" if s == "AKIHABARA" else "NO")

Fixed submission:
S = list(input())
if S[0] != "A":
  S.insert(0,"A")
if len(S) < 5:
  print("NO")
  exit()
if S[4] != "A":
  S.insert(4,"A")
if len(S) < 7:
  print("NO")
  exit()
if S[6] != "A":
  S.insert(6,"A")
if len(S) < 5:
  print("NO")
  exit()
if len(S) < 8:
  print("NO")
  exit()
if S[-1] != "A":
  S.append("A")
s = ""
for i in S:
  s += i
print("YES" if s == "AKIHABARA" else "NO")
Buggy python submission (verdict: Runtime Error):
n = input()
print("Yes" if n[0]=n[1]=n[2]=n[3] or n[0]=n[1]=n[2] or n[1]=n[2]=n[3] else "No")

Fixed submission:
n = input()
print("Yes" if n[0]==n[1]==n[2]==n[3] or n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else "No")

Buggy python submission (verdict: Runtime Error):
n = input()
print("Yes" if n[0]=n[1]=n[2]=n[3] or n[0]=n[1]=n[2] or n[0]=n[2]=n[3] or n[0]=n[1]=n[3] else "No")

Fixed submission:
n = input()
print("Yes" if n[0]==n[1]==n[2]==n[3] or n[0]==n[1]==n[2] or n[1]==n[2]==n[3] else "No")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
second = []
third = []
ans = 0
for i in range(N):
  second.append(N - bisect.bisect_right(B,A[i]))
  third.append(N - bisect.bisect_right(C,B[i]))
for i in range(0,N):
  if second[i] == 0:
    continue
  ans += sum(third[-second[i]:])
print(ans)

Fixed submission:
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())))
ans = 0
for i in range(N):
  ans += bisect.bisect_left(A,B[i]) * (N - bisect.bisect_right(C,B[i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
x = ["x"]
if len(s) == 1:
  print(0)
  exit()
ans = 0
while len(s) > 1:
  if s[0] == s[-1]:
    s = s[1:len(s)-1]
  else:
    if s[0] == "x":
      s = s + x
      ans += 1
    elif s[-1] == "x":
      s = x + s
      ans += 1
    else:
      print(-1)
      exit()
print(ans)

Fixed submission:
s = input()
if len(s) == 1:
  print(0)
  exit()
l = 0
r = len(s) - 1
cnt = 0
while l < r:
  if s[l] == s[r]:
    l += 1
    r -= 1
  else:
    if s[l] == "x":
      l += 1
      cnt += 1
    elif s[r] == "x":
      r -= 1
      cnt += 1
    else:
      print(-1)
      exit()
print(cnt)
Buggy python submission (verdict: Runtime Error):
N,A = map(int,input().split())
print((N**N)-A)

Fixed submission:
N = int(input())
A = int(input())
print((N**2)-A)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if 9 in N:
  print("YES")
else:
  print("NO")


Fixed submission:
N = input()
if "9" in N:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n =int(input())
A = {0}
for i in range(n):
  a = {int(input())}
  if i==0:
    A = A|a
  else:
    A = A^a
print(len(A)-1)


Fixed submission:
n =int(input())
A = set()
for i in range(n):
  A ^= {int(input())}
print(len(A))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  import numpy as np
  import itertools
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import dijkstra
  import sys
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines

  N, M, R= map(int, readline().split())
  r = list(map(int,input().split()))
  lines = readlines()
  edge = np.array([line.split() for line in lines], dtype = np.int64).T
  #print(r)
  #print(edge)
  graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
  ans = float("inf")

  for town in itertools.permutations(r,R):
    #print(town)
    tmp = 0
    for i in range(R-1):
      distance_mat = dijkstra(graph, directed = False, indices = town[i]-1)
      tmp += distance_mat[town[i+1]-1]
    ans = min(ans,tmp)
  print(int(ans))
main()

Fixed submission:
def main():
  import numpy as np
  import itertools
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import dijkstra
  import sys
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines

  N, M, R= map(int, readline().split())
  r = list(map(int,input().split()))
  lines = readlines()
  edge = np.array([line.split() for line in lines], dtype = np.int64).T
  #print(r)
  #print(edge)
  graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
  ans = float("inf")
  distance_mat = {}
  for i in r:
    distance_mat[i-1] = (dijkstra(graph, directed = False, indices = i-1))

  for town in itertools.permutations(r,R):
    #print(town)
    tmp = 0
    for i in range(R-1):
      tmp += distance_mat[town[i]-1][town[i+1]-1]
    ans = min(ans,tmp)
  print(int(ans))
main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import itertools
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, M, R= map(int, readline().split())
r = list(map(int,input().split()))
lines = readlines()
edge = np.array([line.split() for line in lines], dtype = np.int64).T
graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
ans = float("inf")

for town in itertools.permutations(r,R):
  tmp = 0
  for i in range(R-1):
    distance_mat = dijkstra(graph, directed = False, indices = town[i]-1)
    tmp += distance_mat[town[i+1]-1]
  ans = min(ans,tmp)

print(int(ans))

Fixed submission:
def main():
  import numpy as np
  import itertools
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import dijkstra
  import sys
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines

  N, M, R= map(int, readline().split())
  r = list(map(int,input().split()))
  lines = readlines()
  edge = np.array([line.split() for line in lines], dtype = np.int64).T
  #print(r)
  #print(edge)
  graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))
  ans = float("inf")
  distance_mat = {}
  for i in r:
    distance_mat[i-1] = (dijkstra(graph, directed = False, indices = i-1))

  for town in itertools.permutations(r,R):
    #print(town)
    tmp = 0
    for i in range(R-1):
      tmp += distance_mat[town[i]-1][town[i+1]-1]
    ans = min(ans,tmp)
  print(int(ans))
main()
Buggy python submission (verdict: Runtime Error):
n = input()
print("Yes" if n==n[::-] else "No")

Fixed submission:
N = input()
print("Yes" if N[0]==N[2] or N[0]==N[1]==N[2] else "No")
Buggy python submission (verdict: Runtime Error):
a,*b,c = input()split()
print(a+str(len(b))+c)

Fixed submission:
s = input()
print(s[0]+str(len(s)-2)+s[-1])
Buggy python submission (verdict: Runtime Error):
import fractions
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))[::-1]
#print(A)
if A[0] < K:
  print("IMPOSSIBLE")
  exit()
else:
  G = fractions.gcd(A[0],A[1])
  for g in range(2,N):
    G = fractions.gcd(G,A[g])
  print(G)
  if K % G != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")



Fixed submission:
import fractions
from functools import reduce
N,K = map(int,input().split())
A = list(map(int,input().split()))
if max(A) < K:
  print("IMPOSSIBLE")
elif N == 1:
  if A[0] == K:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")
else:
  G = fractions.gcd(A[0],A[1])
  for g in range(2,N):
    G = fractions.gcd(G,A[g])
  if K % G != 0:
    print("IMPOSSIBLE")
  else:
    print("POSSIBLE")

Buggy python submission (verdict: Runtime Error):
import fractions
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))[::-1]
#print(A)
if A[0] < K:
  print("IMPOSSIBLE")
  exit()
else:
  G = fractions.gcd(A[0],A[1])
  for g in range(1,N):
    G = fractions.gcd(G,A[g])
  print(G)
  if K % G != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")
      
    



Fixed submission:
import fractions
from functools import reduce
N,K = map(int,input().split())
A = list(map(int,input().split()))
if max(A) < K:
  print("IMPOSSIBLE")
elif N == 1:
  if A[0] == K:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")
else:
  G = fractions.gcd(A[0],A[1])
  for g in range(2,N):
    G = fractions.gcd(G,A[g])
  if K % G != 0:
    print("IMPOSSIBLE")
  else:
    print("POSSIBLE")
Buggy python submission (verdict: Runtime Error):
list = list(map(int,input().split()))
print(min(sum(list)-a,sum(list)-b,sum(list)-c))


Fixed submission:
a,b,c = sorted(map(int,input().split()))
print(a+b)

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
print(min(sum(a+b),sum(b+c),sum(c+a)))

Fixed submission:
a,b,c = sorted(map(int,input().split()))
print(a+b)