import sys

input=sys.stdin.readline

N=int(eval(input()))

dist=[list(map(int,input().split())) for i in range(N)]

ans=sum([sum(dist[i]) for i in range(N)])

for i in range(N):

    dist[i][i]=float('inf')

ans//=2

def main(ans):

    for i in range(N):

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

            Min=min(list(map(sum,list(zip(dist[i],dist[j])))))

            if Min<dist[i][j]:

                return -1

            if Min==dist[i][j]:

                ans-=dist[i][j] 

    return ans

print((main(ans)))
import numpy as np

N=int(eval(input()))

A=[np.array(list(map(int,input().split()))) for i in range(N)]

ans=sum([sum(A[i]) for i in range(N)])

ans//=2

for i in range(N):

    A[i][i]=10**10

def main(ans):

    for i in range(N):

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

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

            if Min<A[i][j]:

                return -1

            if Min==A[i][j]:

                ans-=A[i][j]

    return ans

print((main(ans)))
import sys

input = sys.stdin.readline
N = int(eval(input()))
dist = [list(map(int, input().split())) for i in range(N)]
ans = sum([sum(dist[i]) for i in range(N)])
for i in range(N):
    dist[i][i] = float("inf")
ans //= 2


def main(ans):
    for i in range(N):
        for j in range(i + 1, N):
            Min = min(list(map(sum, list(zip(dist[i], dist[j])))))
            if Min < dist[i][j]:
                return -1
            if Min == dist[i][j]:
                ans -= dist[i][j]
    return ans


print((main(ans)))

import numpy as np

N = int(eval(input()))
A = [np.array(list(map(int, input().split()))) for i in range(N)]
ans = sum([sum(A[i]) for i in range(N)])
ans //= 2
for i in range(N):
    A[i][i] = 10**10


def main(ans):
    for i in range(N):
        for j in range(i + 1, N):
            Min = np.min(A[i] + A[j])
            if Min < A[i][j]:
                return -1
            if Min == A[i][j]:
                ans -= A[i][j]
    return ans


print((main(ans)))

-import sys +import numpy as np -input = sys.stdin.readline -dist = [list(map(int, input().split())) for i in range(N)] -ans = sum([sum(dist[i]) for i in range(N)]) +A = [np.array(list(map(int, input().split()))) for i in range(N)] +ans = sum([sum(A[i]) for i in range(N)]) +ans //= 2 -    dist[i][i] = float("inf") -ans //= 2 +    A[i][i] = 10**10 -            Min = min(list(map(sum, list(zip(dist[i], dist[j]))))) -            if Min < dist[i][j]: +            Min = np.min(A[i] + A[j]) +            if Min < A[i][j]: -            if Min == dist[i][j]: -                ans -= dist[i][j] +            if Min == A[i][j]: +                ans -= A[i][j]