Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n = int(sys.stdin.readline().rstrip())
A = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(n, n)

def main():
    B = floyd_warshall(csr_matrix(A), directed=False)
    if np.any(A - B > 0):
        return -1

    will_subtract = []
    for v in range(n-1):
        for u in range(v+1, n):
            d = B[v, u]
            for w in range(v):
                if B[v, w] + B[w, u] == d:
                    will_subtract.append(d)
                    break
            else:
                for w in range(v+1, u):
                    if B[v, w] + B[w, u] == d:
                        will_subtract.append(d)
                        break
                else:
                    for w in range(u+1, n):
                        if B[v, w] + B[w, u] == d:
                            will_subtract.append(d)
                            break

    ans = np.sum(B) // 2 - sum(will_subtract)
    return int(ans)

if __name__ == '__main__':
    ans = main()
    print(ans)

Fixed submission:
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n = int(sys.stdin.readline().rstrip())
A = np.array(sys.stdin.read().split(), dtype=np.float64).reshape(n, n)

def main():
    B = floyd_warshall(csr_matrix(A), directed=False).astype(np.int64)
    if np.any(B < A):
        return -1
        
    np.fill_diagonal(A, np.inf)
    
    total_length = 0
    for v in range(n-1):
        for u in range(v+1, n):
            detours = A[v] + A[u]
            if np.all(detours > B[v, u]):
                total_length += B[v, u]

    return total_length

if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
from itertools import combinations


n = int(sys.stdin.readline().rstrip())
A = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(n, n)

def main():
    B = floyd_warshall(A, directed=False)
    if np.any(A - B > 0):
        return -1

    will_subtract = []
    for v, u in combinations(range(n), 2):
        d = B[v, u]
        for w in range(n):
            if w != v and w != u:
                if B[v, w] + B[w, u] == d:
                    will_subtract.append(d)
    
    ans = np.sum(B) // 2 - sum(will_subtract)
    return int(ans)

if __name__ == '__main__':
    ans = main()
    print(ans)

Fixed submission:
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n = int(sys.stdin.readline().rstrip())
A = np.array(sys.stdin.read().split(), dtype=np.float64).reshape(n, n)

def main():
    B = floyd_warshall(csr_matrix(A), directed=False).astype(np.int64)
    if np.any(B < A):
        return -1
        
    np.fill_diagonal(A, np.inf)
    
    total_length = 0
    for v in range(n-1):
        for u in range(v+1, n):
            detours = A[v] + A[u]
            if np.all(detours > B[v, u]):
                total_length += B[v, u]

    return total_length

if __name__ == '__main__':
    ans = main()
    print(ans)