N = int(eval(input()))

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

cnt = 0

for i in range(N):

    for j in range(N):

        cnt += A[i][j]

flg = 0

B = [[0 for _ in range(N)] for _ in range(N)]

for k in range(N):

    for i in range(N):

        for j in range(N):

            if A[i][j]>A[i][k]+A[k][j]:

                flg = -1

                break

            elif A[i][j]==A[i][k]+A[k][j] and A[i][k]*A[k][j]>0 and B[i][j]==0:

                cnt -= A[i][j]

                B[i][j]=1

        if flg==-1:break

    if flg==-1:break

if flg==-1:

    print((-1))

else:

    print((cnt//2))          
N = int(eval(input()))

A = [[0 for _ in range(N+1)]]

for _ in range(N):

    a = list(map(int,input().split()))

    a.insert(0,0)

    A.append(a)

tot = 0

for i in range(1,N):

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

        tot += A[i][j]

for i in range(1,N):

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

        for k in range(1,N+1):

            if k!=i and k!=j:

                if A[i][j]>A[i][k]+A[k][j]:

                    tot = -1

                    break

                elif A[i][j]==A[i][k]+A[k][j]:

                    tot -= A[i][j]

                    break

        if tot<0:break

    if tot<0:break

print(tot)
N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
    for j in range(N):
        cnt += A[i][j]
flg = 0
B = [[0 for _ in range(N)] for _ in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                flg = -1
                break
            elif (
                A[i][j] == A[i][k] + A[k][j] and A[i][k] * A[k][j] > 0 and B[i][j] == 0
            ):
                cnt -= A[i][j]
                B[i][j] = 1
        if flg == -1:
            break
    if flg == -1:
        break
if flg == -1:
    print((-1))
else:
    print((cnt // 2))

N = int(eval(input()))
A = [[0 for _ in range(N + 1)]]
for _ in range(N):
    a = list(map(int, input().split()))
    a.insert(0, 0)
    A.append(a)
tot = 0
for i in range(1, N):
    for j in range(i, N + 1):
        tot += A[i][j]
for i in range(1, N):
    for j in range(i + 1, N + 1):
        for k in range(1, N + 1):
            if k != i and k != j:
                if A[i][j] > A[i][k] + A[k][j]:
                    tot = -1
                    break
                elif A[i][j] == A[i][k] + A[k][j]:
                    tot -= A[i][j]
                    break
        if tot < 0:
            break
    if tot < 0:
        break
print(tot)

-A = [list(map(int, input().split())) for _ in range(N)] -cnt = 0 -for i in range(N): -    for j in range(N): -        cnt += A[i][j] -flg = 0 -B = [[0 for _ in range(N)] for _ in range(N)] -for k in range(N): -    for i in range(N): -        for j in range(N): -            if A[i][j] > A[i][k] + A[k][j]: -                flg = -1 -                break -            elif ( -                A[i][j] == A[i][k] + A[k][j] and A[i][k] * A[k][j] > 0 and B[i][j] == 0 -            ): -                cnt -= A[i][j] -                B[i][j] = 1 -        if flg == -1: +A = [[0 for _ in range(N + 1)]] +for _ in range(N): +    a = list(map(int, input().split())) +    a.insert(0, 0) +    A.append(a) +tot = 0 +for i in range(1, N): +    for j in range(i, N + 1): +        tot += A[i][j] +for i in range(1, N): +    for j in range(i + 1, N + 1): +        for k in range(1, N + 1): +            if k != i and k != j: +                if A[i][j] > A[i][k] + A[k][j]: +                    tot = -1 +                    break +                elif A[i][j] == A[i][k] + A[k][j]: +                    tot -= A[i][j] +                    break +        if tot < 0: -    if flg == -1: +    if tot < 0: -if flg == -1: -    print((-1)) -else: -    print((cnt // 2)) +print(tot)