import itertools

import sys



sys.setrecursionlimit(10000)

INF = float('inf')



N = int(sys.stdin.readline())

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





def solve():

    # 消していいやつ

    useless = [[0] * N for _ in range(N)]



    # 1 つ経由するのだけ考えれば OK

    for st, en in itertools.combinations(list(range(N)), r=2):

        for via in range(N):

            if via in [st, en]:

                continue

            if A[st][via] + A[via][en] < A[st][en]:

                return -1

            if A[st][via] + A[via][en] == A[st][en]:

                useless[st][en] = True

                useless[en][st] = True

    return sum([A[s][e] for s, e in itertools.product(list(range(N)), repeat=2) if not useless[s][e]]) // 2





print((solve()))

import sys



import numpy as np



sys.setrecursionlimit(10000)

INF = float('inf')



N = int(sys.stdin.readline())

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

A = np.array(A, dtype=float) + np.diag([np.inf] * N)



useless = np.zeros((N, N), dtype=bool)

impossible = np.zeros((N, N), dtype=bool)

for via in range(N):

    # R[i][j]: i -> via -> j の距離

    R = sum(np.meshgrid(A[via], A[via]))

    useless |= R == A

    impossible |= R < A



if (impossible ^ np.eye(N, dtype=bool)).sum():

    print((-1))

else:

    print((int(A[~useless].sum() // 2)))

import itertools
import sys

sys.setrecursionlimit(10000)
INF = float("inf")
N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


def solve():
    # 消していいやつ
    useless = [[0] * N for _ in range(N)]
    # 1 つ経由するのだけ考えれば OK
    for st, en in itertools.combinations(list(range(N)), r=2):
        for via in range(N):
            if via in [st, en]:
                continue
            if A[st][via] + A[via][en] < A[st][en]:
                return -1
            if A[st][via] + A[via][en] == A[st][en]:
                useless[st][en] = True
                useless[en][st] = True
    return (
        sum(
            [
                A[s][e]
                for s, e in itertools.product(list(range(N)), repeat=2)
                if not useless[s][e]
            ]
        )
        // 2
    )


print((solve()))

import sys
import numpy as np

sys.setrecursionlimit(10000)
INF = float("inf")
N = int(sys.stdin.readline())
A = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
A = np.array(A, dtype=float) + np.diag([np.inf] * N)
useless = np.zeros((N, N), dtype=bool)
impossible = np.zeros((N, N), dtype=bool)
for via in range(N):
    # R[i][j]: i -> via -> j の距離
    R = sum(np.meshgrid(A[via], A[via]))
    useless |= R == A
    impossible |= R < A
if (impossible ^ np.eye(N, dtype=bool)).sum():
    print((-1))
else:
    print((int(A[~useless].sum() // 2)))

-import itertools +import numpy as np - - -def solve(): -    # 消していいやつ -    useless = [[0] * N for _ in range(N)] -    # 1 つ経由するのだけ考えれば OK -    for st, en in itertools.combinations(list(range(N)), r=2): -        for via in range(N): -            if via in [st, en]: -                continue -            if A[st][via] + A[via][en] < A[st][en]: -                return -1 -            if A[st][via] + A[via][en] == A[st][en]: -                useless[st][en] = True -                useless[en][st] = True -    return ( -        sum( -            [ -                A[s][e] -                for s, e in itertools.product(list(range(N)), repeat=2) -                if not useless[s][e] -            ] -        ) -        // 2 -    ) - - -print((solve())) +A = np.array(A, dtype=float) + np.diag([np.inf] * N) +useless = np.zeros((N, N), dtype=bool) +impossible = np.zeros((N, N), dtype=bool) +for via in range(N): +    # R[i][j]: i -> via -> j の距離 +    R = sum(np.meshgrid(A[via], A[via])) +    useless |= R == A +    impossible |= R < A +if (impossible ^ np.eye(N, dtype=bool)).sum(): +    print((-1)) +else: +    print((int(A[~useless].sum() // 2)))