from numpy import *

N = int(eval(input()))

A = array([input().split() for _ in range(N)], dtype=int64).reshape(N,N)



fill_diagonal(A, 10**9)



ans = 0

for i in range(N):

  for j in range(i+1,N):

    d = min(A[i]+A[j])

    if A[i][j] < d:

      ans += A[i][j]

    elif d < A[i][j]:

      print((-1))

      exit()



print(ans)

import numpy as np

N = int(eval(input()))

A = np.array([input().split() for _ in range(N)], dtype=np.int64)



np.fill_diagonal(A, 10**9)



ans = 0

for i in range(N):

  for j in range(i+1,N):

    d = np.min(A[i]+A[j])

    if A[i][j] < d:

      ans += A[i][j]

    elif d < A[i][j]:

      print((-1))

      exit()



print(ans)

from numpy import *

N = int(eval(input()))
A = array([input().split() for _ in range(N)], dtype=int64).reshape(N, N)
fill_diagonal(A, 10**9)
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        d = min(A[i] + A[j])
        if A[i][j] < d:
            ans += A[i][j]
        elif d < A[i][j]:
            print((-1))
            exit()
print(ans)

import numpy as np

N = int(eval(input()))
A = np.array([input().split() for _ in range(N)], dtype=np.int64)
np.fill_diagonal(A, 10**9)
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        d = np.min(A[i] + A[j])
        if A[i][j] < d:
            ans += A[i][j]
        elif d < A[i][j]:
            print((-1))
            exit()
print(ans)

-from numpy import * +import numpy as np -A = array([input().split() for _ in range(N)], dtype=int64).reshape(N, N) -fill_diagonal(A, 10**9) +A = np.array([input().split() for _ in range(N)], dtype=np.int64) +np.fill_diagonal(A, 10**9) -        d = min(A[i] + A[j]) +        d = np.min(A[i] + A[j])