Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[list(input()) for _ in range(n)]
v=0

for a in range(n):
    for b in range(n):
        m=[[0]*n for _ in range(n)]
        for i in range(n):
            for j in range(n):
                m[(i+a)%n][(j+b)%n]=l[i][j]

        f=True
        for i in range(n):
            for j in range(n):
                if m[j][i]!=m[i][j]:
                    f=False
                    break
            if not f:
                break
        else:
            v+=1

print(v)


Fixed submission:
import numpy as np
n=int(input())
l=np.array([list(input()) for _ in range(n)])
ans=0

for _ in range(n):
    l=np.roll(l,1,axis=1)
    if (l==l.T).all():ans+=n

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,c=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

rev=[None]*(n+1)
norm=[None]*(n+1)
rev[0]=(0,0)
norm[0]=(0,0)
ans=0

# normal rotation
for i in range(1,n+1):
    x,v=l[i-1]
    norm[i]=(x,v+norm[i-1][1])

# reverse rotation
for i in range(1,n+1)[::-1]:
    x,v=l[i-1]
    if i==n:
        rev[i]=(c-x,v)
    else:
        rev[i]=(c-x,v+rev[i+1][1])

for i in range(n+1):
    for j in range(n-i+1):
        cost=min(norm[i][0]+2*rev[-j][0],2*norm[i][0]+rev[-j][0])
        ans=max(ans,rev[-j][1]+norm[i][1]-cost)

print(ans)

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

rev=[None]*(n+1)
norm=[None]*(n+1)
revmax=[None]*(n+1)

rev[0]=(0,0)
revmax[0]=(0,0)
norm[0]=(0,0)
ans=0

# normal rotation
for i in range(1,n+1):
    x,v=l[i-1]
    norm[i]=(x,v+norm[i-1][1])

# reverse rotation
for i in range(1,n+1)[::-1]:
    x,v=l[i-1]
    if i==n:
        rev[i]=(c-x,v)
    else:
        rev[i]=(c-x,v+rev[i+1][1])

for i in range(1,n+1):
    revmax[-i]=(max(revmax[-i+1][0],rev[-i][1]-2*rev[-i][0]),max(revmax[-i+1][1],rev[-i][1]-rev[-i][0]))

for i in range(n+1):
    v1=norm[i][1]-norm[i][0]+revmax[i-n][0]
    v2=norm[i][1]-2*norm[i][0]+revmax[i-n][1]
    ans=max(ans,v1,v2)

print(ans)
Buggy python submission (verdict: Runtime Error):
l=["".join(i) for i in itertools.permutations("abc")]
if input() in l:
  print("Yes")
else:
  print("No")

Fixed submission:
import itertools
l=["".join(i) for i in itertools.permutations("abc")]
if input() in l:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
for j in sorted(s[-i+1:]):
  if j>s[-i]:break
print(s[:-i]+j)

Fixed submission:
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
  for j in sorted(s[-i+1:]):
    if j>s[-i]:break
  print(s[:-i]+j)

Buggy python submission (verdict: Runtime Error):
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
for j in sorted(s[i+1:]):
  if j>s[i]:break
print(s[:i]+j)

Fixed submission:
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
  for j in sorted(s[-i+1:]):
    if j>s[-i]:break
  print(s[:-i]+j)

Buggy python submission (verdict: Runtime Error):
alph={chr(i) for i in range(97,123)}
s=input()
n=len(s)

if n<26:
  print(s+sorted(alph-set(s))[0])
else:
  for i in range(n-1)[::-1]:
    if s[i]<s[i+1]:
      break
    if i==0:
      print(-1)
      exit()
for j in sorted(s[i+1:]):
  if j>s[i]:
    break
print(s[:i]+j)

Fixed submission:
a={chr(i) for i in range(97,123)}
s=input()
n=len(s)
if n<26:
  print(s+sorted(a-set(s))[0])
else:
  for i in range(2,27):
    if s[-i]<s[-i+1]:
      break
    if i==26:
      print(-1)
      exit()
  for j in sorted(s[-i+1:]):
    if j>s[-i]:break
  print(s[:-i]+j)
Buggy python submission (verdict: Runtime Error):
N=int(input())
l=[list(map(int,input().split())) for _ in range(N)]
m=[list(map(int,input().split())) for _ in range(N)]
o=[[i for (i,j) in enumerate(m) if j[0]>k[0] and j[1]>k[1]] for k in l]
s=set()
for i in p:
  for l in i:
    if not l in s:
      s.add(l)
      break
print(len(s))

Fixed submission:
n=int(input())
a={tuple(map(int,input().split())):False for _ in range(n)}
b=sorted([tuple(map(int,input().split())) for _ in range(n)])

ak=sorted(a.keys(),key=lambda x:x[1])[::-1]

for i in b:
  for j in ak:
    if i[0]<j[0] or i[1]<j[1] or a[j]:continue
    else:
      a[j]=True
      break

print(sum(a.values()))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=0
for i in range(a,b+1):
	o=str(i)
  	if o==o[::-1]:c+=1
print(c)



Fixed submission:
a,b=map(int,input().split())
c=0
for i in range(a,b+1):
  o=str(i)
  if o==o[::-1]:
    c+=1
print(c)

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=0
for i in range(a,b+1)
	o=str(i)
  	if o==o[::-1]:c+=1
print(c)

Fixed submission:
a,b=map(int,input().split())
c=0
for i in range(a,b+1):
  o=str(i)
  if o==o[::-1]:
    c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
l=map(int,input().split())
N=min(l)
M=max(l)
if N==1 and M==1:
  print(1)
elif N==1:
  print(M-2)
else:
  print((M-2)*(N-2))

Fixed submission:
l=list(map(int,input().split()))
N=min(l)
M=max(l)
if N==1 and M==1:
  print(1)
elif N==1:
  print(M-2)
else:
  print((M-2)*(N-2))
Buggy python submission (verdict: Runtime Error):
def solve():
    N, A, B = map(int, input().split())
    ans = []

    if A+B-1<=N<=A*B:
        for i in range(1, B+1)[::-1]:
            ans.append(i)
        for i in range(B+1, B+A):
            ans.append(i)
        s = A+B-1
        while 1:
            for i in range(s+1, s+B+1)[::-1]:
                ans.append(i)
                if i==N:
                    return ans
            s += B
            if s + B > N:
                s = N - B
    else:
        print(-1)

print(*solve())


Fixed submission:
N, A, B = map(int, input().split())
ans = []
 
if A+B-1<=N<=A*B:
    S = N-A
    cur = N
    ans = []
    for i in range(A+1):
        num = min(B-1, S)+1
        S -= num-1
        for j in range(num):
            ans.append(cur-num+1+j)
        cur -= num
    ans = ans[::-1][1:]
    print(*ans)
else:
    print(-1)

from bisect import bisect


def LIS(L):
    INF, N = 10**12, len(L)
    seq = [INF] * N
    for i in L:
        seq[bisect(seq, i)] = i
    return N - seq.count(INF)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,d=map(int,input().split())

l={}
m={}
for i in range(1,h+1):
  *a,=map(int,input().split())
  l[i]={j+1:k for (j,k) in enumerate(a)}
  for (j,k) in enumerate(a):
    m[k]=(i,j+1)

for _ in range(int(input())):
  a,b=map(int,input().split())
  v=0
  for i in range(a,b,d):
    x1,y1=m[i]
    x2,y2=m[i+d]
    v+=abs(x1-x2)+abs(y1-y2)
  print(v)

Fixed submission:
h,w,d=map(int,input().split())

m={}
for i in range(1,h+1):
  for (j,k) in enumerate(map(int,input().split())):
    m[k]=(i,j+1)

s=[0 for _ in range(1+h*w)]
for i in range(d+1,1+h*w):
  s[i]=s[i-d]+abs(m[i][0]-m[i-d][0])+abs(m[i][1]-m[i-d][1])

for _ in range(int(input())):
  a,b=map(int,input().split())
  print(s[b]-s[a])
Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
h,w=map(int,input().split())
l=[]
v=0

for _ in range(h):
  b=[0 if i=="." else 1 for i in input()]
  v+=b.count(1)
  l.extend([b])

heap=[]
heappush(heap,(1,0,0))
while h:
  d,x,y=heappop(heap)
  if x==w-1 and y==h-1:break
  for (dx,dy) in zip([1,0],[0,1]):
    ax=x+dx
    ay=y+dy
    if 0<=ax<w and 0<=ay<h and not l[ay][ax]:
      heappush(heap,(d+1,ax,ay))

if x==w-1 and y==h-1:
  print(h*w-v-d)
else:
  print(-1)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
l=[]
v=0

for _ in range(h):
  b=[0 if i=="." else 1 for i in input()]
  v+=b.count(1)
  l.extend([b])

dq=deque([])
dq.append((0,0,1))

while dq:
  x,y,d=dq.popleft()
  if x==w-1 and y==h-1:break
  for (dx,dy) in zip([-1,1,0,0],[0,0,-1,1]):
    nx=x+dx
    ny=y+dy
    if 0<=nx<w and 0<=ny<h and not l[ny][nx]:
      l[ny][nx]=2
      dq.append((nx,ny,d+1))

if x==w-1 and y==h-1:
  print(h*w-v-d)
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
h,w=map(int,input().split())
l=[]
v=0

for _ in range(h):
  b=[0 if i=="." else 1 for i in input()]
  v+=b.count(1)
  l.extend([b])

heap=[]
heappush(heap,(1,0,0))
while h:
  d,x,y=heappop(heap)
  if x==w-1 and y==h-1:break
  for (dx,dy) in zip([1,0],[0,1]):
    ax=x+dx
    ay=y+dy
    if 0<=ax<w and 0<=ay<h and not l[ay][ax]:
      heappush(heap,(d+1,ax,ay))

print(h*w-v-d)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
l=[]
v=0

for _ in range(h):
  b=[0 if i=="." else 1 for i in input()]
  v+=b.count(1)
  l.extend([b])

dq=deque([])
dq.append((0,0,1))

while dq:
  x,y,d=dq.popleft()
  if x==w-1 and y==h-1:break
  for (dx,dy) in zip([-1,1,0,0],[0,0,-1,1]):
    nx=x+dx
    ny=y+dy
    if 0<=nx<w and 0<=ny<h and not l[ny][nx]:
      l[ny][nx]=2
      dq.append((nx,ny,d+1))

if x==w-1 and y==h-1:
  print(h*w-v-d)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
if a+b>c+d:print("Left")
elif a+b==c+d:print("Balanced")
else print("Right")

Fixed submission:
a,b,c,d=map(int,input().split())
if a+b>c+d:print("Left")
elif a+b==c+d:print("Balanced")
else:print("Right")
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,raw_input().split())
print(sum([i for i in range(1,N+1) if A<=sum(map(int,str(i)))<=B]))

Fixed submission:
N,A,B=map(int,input().split())
print(sum([i for i in range(1,N+1) if A<=sum(map(int,str(i)))<=B]))
Buggy python submission (verdict: Runtime Error):
a="".join(list(sorted(input())))
b="".join(list(sorted(input()))[::-1])
u=list(sorted(a,b))
if u[0]==a:
  print("Yes")
else:
  print("No")

Fixed submission:
a="".join(list(sorted(input())))
b="".join(list(sorted(input()))[::-1])
u=list(sorted([a,b]))
if u[0]==u[1]:
  print("No")
elif u[0]==a:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a="".join(sorted(input()))
b="".join(sorted(input())[::-1])
u=sorted(a,b)
if u[0]==a:
  print("Yes")
else:
  print("No")

Fixed submission:
a="".join(list(sorted(input())))
b="".join(list(sorted(input()))[::-1])
u=list(sorted([a,b]))
if u[0]==u[1]:
  print("No")
elif u[0]==a:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
*s,=map(len,input().split("T"))
n=len(s)
ix,iy=map(int,input().split())
state=[(0,1),(1,0),(-1,0),(0,-1)]

def chk(x,y,turn,pos):
    if pos<n:
        tx,ty=turn
        nx,ny=x+tx*s[pos],y+ty*s[pos]
        if turn==(1,0) or turn==(-1,0):
            a=chk(nx,ny,(0,1),pos+1)
            b=chk(nx,ny,(0,-1),pos+1)
        elif turn==(0,1) or turn==(0,-1):
            a=chk(nx,ny,(1,0),pos+1)
            b=chk(nx,ny,(-1,0),pos+1)
        if a or b:
            return True
        else:
            return False         
    else:
        if x==ix and y==iy:
            return True
        else:
            return False

if chk(0,0,(1,0),0):
    print("Yes")
else:
    print("No")    


Fixed submission:
s=input()
x,y=map(int,input().split())
*l,=map(len,s.split("T"))
n=len(l)

def f(pos,start):
  dp={0}
  for i in range(start,n,2):
    tmp=set()
    for j in dp:
      if i==0:
        tmp.add(j+l[i])
      else:
        tmp.add(j+l[i])
        tmp.add(j-l[i])
    dp=tmp
  return pos in dp

if f(x,0) and f(y,1):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=list(sorted(d.items(),key=lambda x:x[1]))[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)


Fixed submission:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=list(sorted(d.items(),key=lambda x:x[1]))[len(d.items())-K:]
for i in e:
  c+=i[1]
print(c)


Fixed submission:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[len(d.items())-K:]
for i in e:
  c+=i[1]
print(c)


Fixed submission:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
d={}
l=map(int,input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=list(sorted(d.items(),key=lambda x:x[1]))[len(d)-K:]
for i in e:
  c+=e[1]

Fixed submission:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
print(min(N*a,B))

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate as ac
o=[]
f=lambda l,r,v:lambda x:v if l<=x<=r else v+(l-x) if 0<=x<=l else v+(x-r)

o.extend([f(0,0,0)])
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=ac([0]+a)

for (i,(t,v)) in enumerate(zip(a,b)):
  o.extend([f(c[i],c[i+1],v)])
o.extend([f(c[-1],c[-1],0)])
v=lambda s:min(map(lambda x:x(0.5*s),o))

S=0
for i in range(2*c[-1]):
  S+=0.25*(v(i)+v(i+1))
print(S)

Fixed submission:
from itertools import accumulate as ac
o=[]
f=lambda l,r,v:lambda x:v if l<=x<=r else v+(l-x) if 0<=x<=l else v+(x-r)

o.extend([f(0,0,0)])
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=ac([0]+a)

for (i,(t,v)) in enumerate(zip(a,b)):
  o.extend([f(c[i],c[i+1],v)])
o.extend([f(c[-1],c[-1],0)])
v=lambda s:min(map(lambda x:x(0.5*s),o))

S=0
for i in range(2*c[-1]):
  S+=0.25*(v(i)+v(i+1))
print(S)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate as ac
o=[]
f=lambda l,r,v:lambda x:v if l<=x<=r else v+(l-x) if 0<=x<=l else v+(x-r)
v=lambda s:min(map(lambda x:x(s),o))

o.extend([f(0,0,0)])
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=ac([0]+a)

for (i,(t,v)) in enumerate(zip(a,b)):
  o.extend([f(c[i],c[i+1],v)])
o.extend([f(c[-1],c[-1],0)])

S=0
for i in range(2*c[-1]):
  S+=0.25*(v(0.5*i)+v(0.5*(i+1)))
print(S)

Fixed submission:
from itertools import accumulate as ac
o=[]
f=lambda l,r,v:lambda x:v if l<=x<=r else v+(l-x) if 0<=x<=l else v+(x-r)

o.extend([f(0,0,0)])
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
*c,=ac([0]+a)

for (i,(t,v)) in enumerate(zip(a,b)):
  o.extend([f(c[i],c[i+1],v)])
o.extend([f(c[-1],c[-1],0)])
v=lambda s:min(map(lambda x:x(0.5*s),o))

S=0
for i in range(2*c[-1]):
  S+=0.25*(v(i)+v(i+1))
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for n in range(1,3501):
  for h in range(1,3501):
    a=N*n*h
    b=4*n*h-N*(n+h)
    if b>0 and a%b==0:
      w=a//b
      print(n,h,w)
      exit()

Fixed submission:
N=int(input())
for n in range(1,3501):
  for h in range(1,3501):
    a=N*n*h
    b=4*n*h-N*(n+h)
    if b>0 and a%b==0:
      w=a//b
      print(n,h,w)
      exit()
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
inf=float("inf")
A=[list(map(int,input().split())) for _ in range(N)]

def calc():
    ans=0
    for i in range(N):
        for j in range(N):
            used=True
            for k in range(N):
                if i==k or k==j:continue
                if A[i][j]>A[i][k]+A[k][j]:
                    return -1
                elif A[i][j]==A[i][k]+A[k][j]:
                    used=False
            if used:
                ans+=A[i][j]
    return ans//2
                
print(calc())


Fixed submission:
n=int(input())
l=[list(map(int,input().split()))    for _ in range(n)]

def chk():
  v=0
  for j in range(n):
    for i in range(n):
      f=True
      for k in range(n):
        if l[i][j]>l[i][k]+l[k][j]:
          return -1
        if l[i][j]==l[i][k]+l[k][j] and i!=k and k!=j:
          f=False
      if f:v+=l[i][j]
  return v//2
print(chk())

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
inf=float("inf")
A=[list(map(int,input().split())) for _ in range(N)]

def calc():
    ans=sum(map(sum,A))//2
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if i>=j or i==k or k==j:continue
                if A[i][j]==A[i][k]+A[k][j]:
                    ans-=A[i][j]
                elif A[i][j]>A[i][k]+A[k][j]:
                    return -1
      
    return ans
                
print(calc())

Fixed submission:
n=int(input())
l=[list(map(int,input().split()))    for _ in range(n)]

def chk():
  v=0
  for j in range(n):
    for i in range(n):
      f=True
      for k in range(n):
        if l[i][j]>l[i][k]+l[k][j]:
          return -1
        if l[i][j]==l[i][k]+l[k][j] and i!=k and k!=j:
          f=False
      if f:v+=l[i][j]
  return v//2
print(chk())

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[list(map(int,input().split()))    for _ in range(n)]

def chk():
  v=0
  for j in range(n):
    for i in range(n):
      f=True
      for k in range(n):
        if l[i][j]>l[i][k]+l[k][j]:
          return -1
        if l[i][j]==l[i][k]+l[k][j] and i!=k and k!=j:
          f=False
      if f:v+=l[i][j]
  return v//2
print(chk())

Fixed submission:
n=int(input())
l=[list(map(int,input().split()))    for _ in range(n)]

def chk():
  v=0
  for j in range(n):
    for i in range(n):
      f=True
      for k in range(n):
        if l[i][j]>l[i][k]+l[k][j]:
          return -1
        if l[i][j]==l[i][k]+l[k][j] and i!=k and k!=j:
          f=False
      if f:v+=l[i][j]
  return v//2
print(chk())
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

N,M,R=map(int,input().split())
*r,=map(int,input().split())
inf=float("inf")
d=[[inf]*N for _ in range(N)]

for _ 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])

ans=inf
for i in permutations(r):
    v=0
    for j in range(R-1):
        v+=d[i[j]-1][i[j+1]-1]
    ans=min(ans,v)

print(ans)

Fixed submission:
from itertools import permutations as p
N,M,R=map(int,input().split())
r=map(int,input().split())
inf=float("inf")
l=[[inf if i!=j else 0 for i in range(N)] for j in range(N)]

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

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

ans=inf
for i in p(r):
  v=0
  for j in range(R-1):
    v+=l[i[j]-1][i[j+1]-1]
  ans=min(ans,v)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
*l,=map(int,input().split())
v=0
for i in range(n-1):
  if l[i]==i+1:
    l[i],l[i+1]=l[i+1],l[i]
    v+=1
if l[N-1]==N:
  l[N-2],l[N-1]=l[N-1],l[N-2]
  v+=1
    
print(v)

Fixed submission:
n=int(input())
*l,=map(int,input().split())
v=0
for i in range(n-1):
  if l[i]==i+1:
    l[i],l[i+1]=l[i+1],l[i]
    v+=1
if l[n-1]==n:
  l[n-2],l[n-1]=l[n-1],l[n-2]
  v+=1
    
print(v)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce
l = [int(input()) for _ in range(int(input()))]
o = reduce(lambda x, y: int(x * y / gcd(x, y)), l)
print(o)

Fixed submission:
from fractions import gcd
l = [int(raw_input()) for _ in range(int(raw_input()))]
o = reduce(lambda x, y: int(x * y / gcd(x, y)), l)
print o

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fraction import gcd
l=[int(input()) for _ in range(int(input()))]
o=reduce(lambda x,y:int(x*y/gcd(x,y)),l)
print(o)

Fixed submission:
from fractions import gcd
l = [int(raw_input()) for _ in range(int(raw_input()))]
o = reduce(lambda x, y: int(x * y / gcd(x, y)), l)
print o

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from math import gcd
l=[int(input()) for _ in range(int(input()))]
o=reduce(lambda x,y:int(x*y/gcd(x,y)),l)
print(o)

Fixed submission:
from fractions import gcd
l = [int(raw_input()) for _ in range(int(raw_input()))]
o = reduce(lambda x, y: int(x * y / gcd(x, y)), l)
print o
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

d=defaultdict(list)

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

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

# Kを中心とした距離を求める
dists=[None]*(N+1)
isused=[False]*(N+1)
dists[K]=0
isused[K]=True

def dfs(n):
    for i,j in d[n]:
        if isused[i]:continue
        isused[i]=True
        dists[i]=dists[n]+j
        dfs(i)

dfs(K)
for _ in range(Q):
    x,y=map(int,input().split())
    print(dists[x]+dists[y])


Fixed submission:
from collections import deque
n=int(input())
l=[[] for _ in [0]*n]
for _ in [0]*(n-1):
  a,b,c=map(int,input().split())
  l[a-1].extend([(b-1,c)])
  l[b-1].extend([(a-1,c)])

q,k=map(int,input().split())
dst=[0 for _ in [0]*n]
que=deque([])
v,p,d=k-1,-1,0
que.append((v,p,d))
while que:
  v,p,d=que.pop()
  dst[v]=d
  for i,j in l[v]:
    if i==p:continue
    que.append((i,v,d+j))

for _ in [0]*q:
  x,y=map(int,input().split())
  print(dst[x-1]+dst[y-1])
Buggy python submission (verdict: Runtime Error):
k = int(input())
n = k+1
x = k*(n+1)

print(n)
l = [x] + [0]*(n-1)
print(*l)

Fixed submission:
k = int(input())

size = 50
l = [(k//size)+size-1]*size
if k%size:
    for i in range(k%size):
        l[i] += size-(k%size-1)
    for j in range(k%size, size):
        l[j] -= k%size

print(size)
print(*l)