Buggy python submission (verdict: Time Limit Exceeded):
#restoring read network
import numpy as np
from scipy.sparse import csr_matrix 
from scipy.sparse.csgraph import floyd_warshall
def main():
    n=int(input())
    mat=np.array([[0 for i in range(n)] for j in range(n)],dtype=np.int)
    data=np.array([[0 for i in range(n)] for j in range(n)],dtype=np.int)
    for _ in range(n):
        x=list(map(int,input().split()))
        for j in range(n):
            mat[_][j]=x[j]
            data[_][j]=x[j]

    csr=csr_matrix(mat)
    csr=floyd_warshall(csr)
    if np.array_equal(csr,data):
        ans=0
        for i in range(n):
            for j in range(i+1,n):
                ans+=data[i][j]*int(all(data[i][j]<data[i][k]+data[k][j] for k in range(i))&all(data[i][j]<data[i][k]+data[k][j] for k in range(i+1,j))&all(data[i][j]<data[i][k]+data[k][j] for k in range(j+1,n)))     
        print(ans)            
    else:
        print(-1)
if __name__=="__main__":
    main()


Fixed submission:
n=int(input())

mat=[[0 for i in range(n)] for j in range(n)]
data=[[0 for i in range(n)] for j in range(n)]
for _ in range(n):
    x=list(map(int,input().split()))
    for j in range(n):
        mat[_][j]=x[j]
        data[_][j]=x[j]
def warshall_floyd(d):
    #d[i][j]=i番目の頂点からj番目の頂点までの最短距離
    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])
    return d

newmat=warshall_floyd(mat)
if newmat==data:
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=data[i][j]*int(all(data[i][j]<data[i][k]+data[k][j] for k in range(i))&all(data[i][j]<data[i][k]+data[k][j] for k in range(i+1,j))&all(data[i][j]<data[i][k]+data[k][j] for k in range(j+1,n)))     
    print(ans)      
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
#restoring read network
ans=0
import numpy as np
from scipy.sparse import csr_matrix 
from scipy.sparse.csgraph import floyd_warshall
n=int(input())
mat=np.array([[0 for i in range(n)] for j in range(n)],dtype=np.int)
data=np.array([[0 for i in range(n)] for j in range(n)],dtype=np.int)
for _ in range(n):
    x=list(map(int,input().split()))
    for j in range(n):
        mat[_][j]=x[j]
        data[_][j]=x[j]
        
csr=csr_matrix(mat)
csr=floyd_warshall(csr)
if np.array_equal(csr,data):
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            cnt=0
            for k in range(n):
                if data[i][j]>=data[i][k]+data[k][j]:
                    cnt+=1
            if cnt==2:
                ans+=data[i][j]                
    print(ans)            
else:
    print(-1)

Fixed submission:
n=int(input())

mat=[[0 for i in range(n)] for j in range(n)]
data=[[0 for i in range(n)] for j in range(n)]
for _ in range(n):
    x=list(map(int,input().split()))
    for j in range(n):
        mat[_][j]=x[j]
        data[_][j]=x[j]
def warshall_floyd(d):
    #d[i][j]=i番目の頂点からj番目の頂点までの最短距離
    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])
    return d

newmat=warshall_floyd(mat)
if newmat==data:
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=data[i][j]*int(all(data[i][j]<data[i][k]+data[k][j] for k in range(i))&all(data[i][j]<data[i][k]+data[k][j] for k in range(i+1,j))&all(data[i][j]<data[i][k]+data[k][j] for k in range(j+1,n)))     
    print(ans)      
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
#restoring read network
ans=0
import numpy as np
from scipy.sparse import csr_matrix 
from scipy.sparse.csgraph import floyd_warshall
n=int(input())
mat=np.array([[0 for i in range(n)] for j in range(n)],dtype=np.int)
data=np.array([[0 for i in range(n)] for j in range(n)],dtype=np.int)
for _ in range(n):
    x=list(map(int,input().split()))
    for j in range(n):
        mat[_][j]=x[j]
        data[_][j]=x[j]
        
csr=csr_matrix(mat)
csr=floyd_warshall(csr)
if np.array_equal(csr,data):
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            cnt=0
            for k in range(n):
                if data[i][j]>=data[i][k]+data[k][j]:
                    cnt+=1
            if cnt==2:
                ans+=data[i][j]                
    print(ans)            
else:
    print(-1)

Fixed submission:
n=int(input())

mat=[[0 for i in range(n)] for j in range(n)]
data=[[0 for i in range(n)] for j in range(n)]
for _ in range(n):
    x=list(map(int,input().split()))
    for j in range(n):
        mat[_][j]=x[j]
        data[_][j]=x[j]
def warshall_floyd(d):
    #d[i][j]=i番目の頂点からj番目の頂点までの最短距離
    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])
    return d

newmat=warshall_floyd(mat)
if newmat==data:
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=data[i][j]*int(all(data[i][j]<data[i][k]+data[k][j] for k in range(i))&all(data[i][j]<data[i][k]+data[k][j] for k in range(i+1,j))&all(data[i][j]<data[i][k]+data[k][j] for k in range(j+1,n)))     
    print(ans)      
else:
    print(-1)