Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(nums):
  return reduce(lcm, nums)

n = int(input())
a = list(map(int, input().split()))
m = lcm_list(a) - 1
ans = 0
for i in range(n):
  ans += m % a[i]

print(ans)

Fixed submission:
from functools import reduce


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

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

def lcm_list(nums):
  return reduce(lcm, nums)
n = int(input())

a = list(map(int, input().split()))




m = lcm_list(a) - 1


ans = 0
for i in range(n):
  ans += m % a[i]
  
  
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(nums):
  return reduce(lcm, nums)

n = int(input())
a = list(map(int, input().split()))
m = lcm_list(a) - 1
ans = 0
for i in range(n):
  ans += m % a[i]

print(ans)

Fixed submission:
from functools import reduce


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

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

def lcm_list(nums):
  return reduce(lcm, nums)
n = int(input())

a = list(map(int, input().split()))




m = lcm_list(a) - 1


ans = 0
for i in range(n):
  ans += m % a[i]
  
  
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_list(nums):
  return reduce(lcm, nums)
n = int(input())

a = list(map(int, input().split()))




m = lcm_list(a) - 1


ans = 0
for i in range(n):
  ans += m % a[i]
  
  
print(ans)

Fixed submission:
from functools import reduce


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

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

def lcm_list(nums):
  return reduce(lcm, nums)
n = int(input())

a = list(map(int, input().split()))




m = lcm_list(a) - 1


ans = 0
for i in range(n):
  ans += m % a[i]
  
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict


N = int(input())
S = input()

X = S[:N]
Y = S[N:]
Y = Y[::-1]

dx = defaultdict(int)
dy = defaultdict(int)

for bit in range(1 << N):
    red = ""
    blue = ""
    for i in range(N):
        if bit & (1 << i):
            red += X[i]
        else:
            blue += X[i]

    dx[(red, blue)] += 1

for bit in range(1 << N):
    red = ""
    blue = ""
    for i in range(N):
        if bit & (1 << i):
            red += Y[i]
        else:
            blue += Y[i]

    dy[(red, blue)] += 1

# 前後が同じになる組がいくつできるか。
ans = 0
for k,v in dx.items():
    ans += dy[k] * v

print(ans)

Fixed submission:

from collections import defaultdict


def main():
        
    N = int(input())
    S = input()

    X = S[:N]
    Y = S[N:]
    Y = Y[::-1]

    dx = defaultdict(int)
    dy = defaultdict(int)

    for bit in range(1 << N):
        red = ""
        blue = ""
        for i in range(N):
            if bit & (1 << i):
                red += X[i]
            else:
                blue += X[i]

        dx[(red, blue)] += 1

    for bit in range(1 << N):
        red = ""
        blue = ""
        for i in range(N):
            if bit & (1 << i):
                red += Y[i]
            else:
                blue += Y[i]

        dy[(red, blue)] += 1

    # 前後が同じになる組がいくつできるか。
    ans = 0
    for k,v in dx.items():
        ans += dy[k] * v

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = input()


ans = 3 * 10 ** 5
for  i in range(n):
  tmp = s[:i].count("W") + s[i+1:].count("E")
  if ans > tmp:
    ans = tmp
    
print(ans)

Fixed submission:
n = int(input())

s = input()


a = [0] * (n+1)
b = [0] * (n+1)
ans = 3 * 10 ** 5

aN = s.count("E")
for i in range(n):
  if s[i] == "E":
    a[i+1] = a[i] + 1
    b[i+1] = b[i]
  else:
    a[i+1] = a[i]
    b[i+1] = b[i] + 1
  #print(ans, aN-a[i+1]+b[i])  
  ans = min(ans, aN-a[i+1]+b[i])
  
  
  
print((ans))
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = []
for i in range(1,len(s)):
  for j in range(len(s)):
    if j+i > len(s): break

    ans.append(s[j:j+i])

ans = list(sorted(set(ans))) #setはsortedではソートできる。リストでソートしてsetに帰ると順序は保証されない

print((ans[k-1]))

Fixed submission:
s = input()
k = int(input())
ans = []
for i in range(1,k+1):
  for j in range(len(s)):
    if j+i > len(s): break

    ans.append(s[j:j+i])


ans = list(sorted(set(ans))) #setはsortedではソートできる。リストでソートしてsetにすると順序は保証されない

if k != 1:
  print((ans[k-1]))
else:
  print(min(list(s)))
Buggy python submission (verdict: Time Limit Exceeded):
def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

max_comb = 0
n = 0
r = 0
n = a[0]
for j in range(1, N):
  if max_comb < nCr(a[0],a[j]):
    max_comb = nCr(a[0],a[j])
    r = a[j]
    
ans = str(n) + " " + str(r)
print(ans)
 

Fixed submission:

N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

tmp = 10 ** 9
ans = 1
for i in range(1,N):
  if abs(a[0]/2 - a[i]) < tmp:
    tmp = abs(a[0]/2 - a[i])
    ans = a[i]

    
s = str(a[0]) + " " + str(ans)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
def nCr(n,r):
  if n < 0 or r < 0 or n < r: return 0
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n
  
  # 分子のn*(n-1)*...がr個分続くやつ
  numerator = [n-r+k+1 for k in range(r)]
  # 分母：r!=r*(r-1)*...*3*2の要素
  denominator = [k+1 for k in range(r)]
  
  # 分母の要素で割れる部分を割っていく部分
  for p in range(2, r+1):
    # 分母は1,2,3,...rのようになっており、1は意味がないのでスキップした形か
    pivot = denominator[p-1]
    if pivot > 1:
      # 分子のX番目と分母のX-offset番目が共通の約数を持つということだと思う。piv分ずれているのだから、pivの倍数というところか
      offset = (n-r) % p
      for k in range(p-1, r, p):
        # 約分できる要素について割る
        numerator[k - offset]  /= pivot
        denominator[k] /= pivot
        
  ret = 1
  for k in range(r):
    if numerator[k] > 1: ret *= int(numerator[k])
      
  return ret


N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

max_comb = 0
n = 0
r = 0
for i in range(N):
  for j in range(i+1, N):

    if max_comb < nCr(a[i],a[j]):
      max_comb = nCr(a[i],a[j])
      n = a[i]
      r = a[j]
    
ans = str(n) + " " + str(r)
print(ans)
 

Fixed submission:

N = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

tmp = 10 ** 9
ans = 1
for i in range(1,N):
  if abs(a[0]/2 - a[i]) < tmp:
    tmp = abs(a[0]/2 - a[i])
    ans = a[i]

    
s = str(a[0]) + " " + str(ans)
print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
C = []
S = []
F = []
for i in range(n-1):
  c,s,f = map(int, input().split())
  C.append(c)
  S.append(s)
  F.append(f)  
  
for i in range(n):
  t = 0
  for j in range(i,n-1):
    if t < S[j]:
      t = S[j]
    elif t % F[j] == 0:
      ;#到着タイミングと発車タイミングが同じなので待ち時間0
    else:
      t = t + F[j] - (t % F[j])  
    t += C[j]
  print(t)

Fixed submission:
n = int(input())
C = []
S = []
F = []
for i in range(n-1):
  c,s,f = map(int, input().split())
  C.append(c)
  S.append(s)
  F.append(f)  
  
for i in range(n):
  t = 0
  for j in range(i,n-1):
    if t < S[j]:
      t = S[j]
    elif t % F[j] == 0:
      pass#到着タイミングと発車タイミングが同じなので待ち時間0
    else:
      t = t + F[j] - (t % F[j])  
    t += C[j]
  print(t)
Buggy python submission (verdict: Runtime Error):
s = input()

if len(s) == 1:


tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

if len(tmp) == 0:
        #元から全部同じ
        print(len(s))
else:
        print(min(tmp))

Fixed submission:
s = input()



tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

if len(tmp) == 0:
        #元から全部同じ
        print(len(s))
else:
        print(min(tmp))

Buggy python submission (verdict: Runtime Error):
s = input()

tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

print(max(tmp))

Fixed submission:
s = input()



tmp = []
for i in range(len(s)-1):
        if s[i] != s[i+1]:
                tmp.append(max(i+1,len(s)-(i+1)))

if len(tmp) == 0:
        #元から全部同じ
        print(len(s))
else:
        print(min(tmp))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = list(map(int, input().split()))


checked = []
ans = 0
for i in a:
  if i not in checked:
    #多すぎる場合はその数になるまで取り除く
    if a.count(i) >= i:
      ans += a.count(i) - i
    else:
      #その値以下の数しかないので配列から取り除く
      ans += a.count(i)
    checked.append(i) 
print(ans)

Fixed submission:
n = int(input())

a = list(map(int, input().split()))


checked = []
ans = 0
cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1

for k in cnt_a.keys():
  if cnt_a[k] >= k:
    ans += cnt_a[k] - k
  else:
    ans += cnt_a[k]
    
print(ans)
Buggy python submission (verdict: Runtime Error):
"""
n=1の時、山札とＹの初期手札が答え
n>=2の時、
・Ｘは得点の最大化を狙う
・Ｙは得点の最小化を狙う＝Ｘの邪魔をする
山札内の得点の最大化をできるカードをＸが選んでも、Ｙはそれを邪魔する動きをとるので、真に最大化すること(Xの狙いを達成すること)はできない
→選べるのはＹの初期値＆山札最後（Ｘがすべて取る）か、最後とその一つ手前の比較（Ｘが一枚残してすべて取る）のどちらかにするのがましな選択



"""


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

a = list(map(int, input().split()))

if n == 1:
        print(abs(a[-1] - y))
else:
        print(max(abs(y-a[-1], abs(a[-1] - a[-2]))))

Fixed submission:
"""
n=1の時、山札とＹの初期手札が答え
n>=2の時、
・Ｘは得点の最大化を狙う
・Ｙは得点の最小化を狙う＝Ｘの邪魔をする
山札内の得点の最大化をできるカードをＸが選んでも、Ｙはそれを邪魔する動きをとるので、真に最大化すること(Xの狙いを達成すること)はできない
→選べるのはＹの初期値＆山札最後（Ｘがすべて取る）か、最後とその一つ手前の比較（Ｘが一枚残してすべて取る）のどちらかにするのがましな選択



"""


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

a = list(map(int, input().split()))

if n == 1:
        print(abs(a[-1] - y))
else:
        print(max(abs(y-a[-1]), abs(a[-1] - a[-2])))
Buggy python submission (verdict: Runtime Error):
S = input()


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":
            #末尾にxを追加し削除
            l += 1
            cnt += 1
        elif S[r] == "x":
            r -= 1
            cnt += 1
        else:
            print(-1)
            exit()


print(cnt)

Fixed submission:
S = input()


l = 0
r = len(S)-1
cnt = 0
while l < r:
    #print(l,r)
    if S[l] == S[r]:
        l += 1
        r -= 1
    else:
        if S[l] == "x":
            #末尾にxを追加し削除
            l += 1
            cnt += 1
        elif S[r] == "x":
            r -= 1
            cnt += 1
        else:
            print(-1)
            exit()


print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):



N,K = map(int, input().split())
XY = [tuple(map(int, input().split())) for _ in range(N)]

"""
辺の上に点が乗っていても四角形の中に含まれると見なされるので、辺はいずれかの点の上を通るように引くと面積を小さくできる
各点のx,yをsetで持っておいて、全探索できるか？
→ N <= 50なので4つの辺の選び方が50**4、この範囲にK個以上入っているかでさらに *50なので間に合うか微妙？
小さい値で ^5 なので、間に合うかも
"""

LR = [] # left,right
TB = [] # top, bottom
for x,y in XY:
    LR.append(x)
    TB.append(y)


LR = list(set(LR))
LR.sort()
TB = list(set(TB))
TB.sort()


def more_than_K(l,r,t,b):
    cnt = 0
    for x,y in XY:
        if l <= x <= r and b <= y <= t:
            cnt += 1
    return cnt >= K

ans = float("inf")
for p in range(len(LR)):
    for q in range(p+1, len(LR)):
        for r in range(len(TB)):
            for s in range(r+1, len(TB)):

                if more_than_K(LR[p], LR[q], TB[s], TB[r]):
                    ans = min(ans, (LR[q] - LR[p]) * (TB[s] - TB[r]))


print(ans)


Fixed submission:



N,K = map(int, input().split())
XY = [tuple(map(int, input().split())) for _ in range(N)]

"""
辺の上に点が乗っていても四角形の中に含まれると見なされるので、辺はいずれかの点の上を通るように引くと面積を小さくできる
各点のx,yをsetで持っておいて、全探索できるか？
→ N <= 50なので4つの辺の選び方が50**4、この範囲にK個以上入っているかでさらに *50なので間に合うか微妙？
小さい値で ^5 なので、間に合うかも
"""

LR = [] # left,right
TB = [] # top, bottom
for x,y in XY:
    LR.append(x)
    TB.append(y)


LR = list(set(LR))
LR.sort()
TB = list(set(TB))
TB.sort()


def more_than_K(l,r,t,b):
    cnt = 0
    for x,y in XY:
        if l <= x <= r and b <= y <= t:
            cnt += 1
    return cnt >= K

ans = float("inf")
for p in range(len(LR)):
    for q in range(p+1, len(LR)):
        for r in range(len(TB)):
            for s in range(r+1, len(TB)):

                if more_than_K(LR[p], LR[q], TB[s], TB[r]):
                    ans = min(ans, (LR[q] - LR[p]) * (TB[s] - TB[r]))


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
def main():
    N = int(input())
    checked = [[False for _ in range(3500)] for _ in range(3500)]
    for h in range(1, 3501):
        for n in range(1,3501):
            if checked[h-1][n-1] == False:

                checked[h-1][n-1] = True
                checked[n-1][h-1] = True
                
                a = N*h*n
                b = 4*n*h - N*n - N*h 
                if a >= b and b >  0 and a%b == 0:
                    w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                    if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                        print(h,n,w)
                        exit()
                else:
                    continue
            else:
                continue

if __name__ == "__main__":
    main()

Fixed submission:
from fractions import Fraction
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(h,3501):
            a = N*h*n
            b = 4*n*h - N*n - N*h 
            if a >= b and b >  0 and a%b == 0:
                w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                    print(h,n,w)
                    exit()
            else:
                continue

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(1,3501):
            a = N*h*n
            b = 4*n*h - N*n - N*h 
            if a >= b and b >  0 and a%b == 0:
                w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                    print(h,n,w)
                    exit()
            else:
                continue

if __name__ == "__main__":
    main()

Fixed submission:
from fractions import Fraction
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(h,3501):
            a = N*h*n
            b = 4*n*h - N*n - N*h 
            if a >= b and b >  0 and a%b == 0:
                w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                    print(h,n,w)
                    exit()
            else:
                continue

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
from collections import deque
import math

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

# 作りうる水の量を洗い出す
waters = set()
waters.add(100*A)
if 200*B <= F:
    waters.add(200*B)
q = deque([100*A, 200*B])

while q:
    w = q.popleft()
    # 容器に入れられる量より多いならパス
    if w > F: continue
    for n in [100*A, 200*B]:
        if w + n <= F:
            waters.add(w + n)
            q.append(w + n)

waters = list(waters)
waters.sort()

# 砂糖もFまでなのでとりうる量作れるやん
sugars = set()
sugars.add(C)
sugars.add(D)
q = deque([C,D])
while q:
    s = q.popleft()
    if s > F: continue
    for n in [C,D]:
        if s + n <= F:
            sugars.add(s+n)
            q.append(s+n)
sugars = list(sugars)
sugars.sort()

# 最大濃度
max_conc = 0
# 最大濃度の時の水と砂糖
total = 0
sugar = 0

for w in waters:
    for s in sugars:
        conc = 0
        # 容量を超えたらアウト
        if w+s > F: break
        # 解けきれない量でもアウト
        if s > w * Fraction(E,100): break

        conc = Fraction(s, s+w)
        if conc > max_conc:
            max_conc = conc
            total = s+w
            sugar = s

print(total, sugar)

Fixed submission:



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

# 作りうる水の量を洗い出す
waters = set()

for i in range(F//(100*A) + 1):
    for j in range((F-100*A*i)//(100*B) + 1):
        w = 100*A*i + 100*B*j
        if w != 0:
            waters.add(w)
waters = list(waters)
waters.sort()


sugars = set()
# Cを何回入れるか
for i in range(F//C + 1):
    # Dを何回いれるか
    for j in range((F - C*i) // D + 1):
        s = i*C + j*D
  
        sugars.add(s)


sugars = list(sugars)
sugars.sort()

# 最大濃度
max_conc = 0
# 最大濃度の時の水と砂糖
total = 0
sugar = 0

best_w = best_s = best_r = -1
for water in sorted(waters):
    for sugar in sorted(sugars):
        if water + sugar > F: break
        if water*E < sugar*100: break
        rate = sugar / (water + sugar)
        if rate > best_r:
            best_r = rate
            best_w = water
            best_s = sugar
print(best_s+best_w, best_s)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [None for _ in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#ワーシャルフロイド法で条件を満たすものがあるか確認
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()

ans = 0
for i in range(N-1):
    for j in range(i,N):
        is_edge = True
        for k in range(N):
            if i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]: # A[i][j]はiとjのノードを直接結ぶものではない
                is_edge = False
        if is_edge:
            ans += A[i][j]

print(ans) 

Fixed submission:
N = int(input())

A = [None for _ in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#ワーシャルフロイド法で条件を満たすものがあるか確認
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()

ans = 0
for i in range(N-1):
    for j in range(i,N):
        is_edge = True
        for k in range(N):
            if i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]: # A[i][j]はiとjのノードを直接結ぶものではない
                is_edge = False
        if is_edge:
            ans += A[i][j]

print(ans)

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

A = [None for _ in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#ワーシャルフロイド法で条件を満たすものがあるか確認
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()

ans = 0
for i in range(N):
    for j in range(N):
        is_edge = True
        for k in range(N):
            if i == j or i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]: # A[i][j]はiとjのノードを直接結ぶものではない
                is_edge = False
        if is_edge:
            ans += A[i][j]

print(ans//2) # A[i][j]とA[j][i]が重複してたされているから２で割る

Fixed submission:
N = int(input())

A = [None for _ in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#ワーシャルフロイド法で条件を満たすものがあるか確認
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()

ans = 0
for i in range(N-1):
    for j in range(i,N):
        is_edge = True
        for k in range(N):
            if i == k or j == k:
                continue
            if A[i][j] == A[i][k] + A[k][j]: # A[i][j]はiとjのノードを直接結ぶものではない
                is_edge = False
        if is_edge:
            ans += A[i][j]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools


N,M,R = map(int, input().split())
rs = list(map(int, input().split()))

INF = float("inf")
es = [[INF for _ in range(N)]  for _ in range(N)]
for i in range(N):
  es[i][i] = 0

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



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

ans = INF
for route in itertools.permutations(rs):
  tmp = 0
  for a,b in zip(route, route[1:]):
    tmp += es[a-1][b-1]
  ans = min(ans, tmp)

print(ans)

Fixed submission:
import itertools
n,m,r = map(int, input().split())
towns = list(map(int, input().split()))
INF = float("inf")
cost = [[INF] * n for _ in range(n)]
#同じ場所にはコスト0で移動（というか移動しないので０）
for i in range(n):
    cost[i][i] = 0

for i in range(m):
    a,b,c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = 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])


ans = INF

for node in itertools.permutations(range(r)): #町移動順の全組み合わせを作成
    tmp = 0
    for x, y in zip(node, node[1:]):
        s, g = towns[x], towns[y] 
        tmp += cost[s-1][g-1] # 町ｓからｇまでの最短距離を足していく
    ans = min(ans, tmp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,m,r = map(int, input().split())
towns = list(map(int, input().split()))
INF = float("inf")
cost = [[INF] * n for _ in range(n)]
#同じ場所にはコスト0で移動（というか移動しないので０）
for i in range(n):
    cost[i][i] = 0

for i in range(m):
    a,b,c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = 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])


ans = INF

for node in itertools.permutations(range(r)): #町移動順の全組み合わせを作成
    tmp = 0
    for x, y in zip(node, node[1:]):
        s, g = towns[x], towns[y] 
        tmp += cost[s-1][g-1] # 町ｓからｇまでの最短距離を足していく
    ans = min(ans, tmp)

print(ans)

Fixed submission:
import itertools
n,m,r = map(int, input().split())
towns = list(map(int, input().split()))
INF = float("inf")
cost = [[INF] * n for _ in range(n)]
#同じ場所にはコスト0で移動（というか移動しないので０）
for i in range(n):
    cost[i][i] = 0

for i in range(m):
    a,b,c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = 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])


ans = INF

for node in itertools.permutations(range(r)): #町移動順の全組み合わせを作成
    tmp = 0
    for x, y in zip(node, node[1:]):
        s, g = towns[x], towns[y] 
        tmp += cost[s-1][g-1] # 町ｓからｇまでの最短距離を足していく
    ans = min(ans, tmp)

print(ans)
Buggy python submission (verdict: Runtime Error):
x,t= map(int, input().split())
pritn(max(x-t,0))

Fixed submission:
x,t= map(int, input().split())
print(max(x-t,0))