N = int(eval(input()))

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



INF = 10 ** 9 + 1

for i in range(N):

    A[i][i] = INF



ans = 0

for i in range(N):

    Ai = A[i]

    for j in range(i):

        d = min(list(map(sum, list(zip(Ai, A[j])))))



        if A[i][j] > d:

            print('-1')

            exit()

        elif A[i][j] < d:

            ans += A[i][j]



print(ans)

N = int(eval(input()))

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



# Warshall-Floyd法

dist = [list(A[i]) for i in range(N)]

via = [[None for i in range(N)] for j in range(N)]

for k in range(N):

    for i in range(N):

        for j in range(N):

            d = dist[i][k] + dist[k][j]

            if dist[i][j] >= d:

                dist[i][j] = d

                if i != k and j != k:

                    via[i][j] = k



ans = 0

for i in range(N):

    for j in range(i):

        if dist[i][j] < A[i][j]:

            ans = -1

            break



        if via[i][j] == None:

            ans += dist[i][j]



    if ans == -1:

        break



print(ans)

N = int(eval(input()))
A = [list(map(int, input().split())) for i in range(N)]
INF = 10**9 + 1
for i in range(N):
    A[i][i] = INF
ans = 0
for i in range(N):
    Ai = A[i]
    for j in range(i):
        d = min(list(map(sum, list(zip(Ai, A[j])))))
        if A[i][j] > d:
            print("-1")
            exit()
        elif A[i][j] < d:
            ans += A[i][j]
print(ans)

N = int(eval(input()))
A = [list(map(int, input().split())) for i in range(N)]
# Warshall-Floyd法
dist = [list(A[i]) for i in range(N)]
via = [[None for i in range(N)] for j in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            d = dist[i][k] + dist[k][j]
            if dist[i][j] >= d:
                dist[i][j] = d
                if i != k and j != k:
                    via[i][j] = k
ans = 0
for i in range(N):
    for j in range(i):
        if dist[i][j] < A[i][j]:
            ans = -1
            break
        if via[i][j] == None:
            ans += dist[i][j]
    if ans == -1:
        break
print(ans)

-INF = 10**9 + 1 -for i in range(N): -    A[i][i] = INF +# Warshall-Floyd法 +dist = [list(A[i]) for i in range(N)] +via = [[None for i in range(N)] for j in range(N)] +for k in range(N): +    for i in range(N): +        for j in range(N): +            d = dist[i][k] + dist[k][j] +            if dist[i][j] >= d: +                dist[i][j] = d +                if i != k and j != k: +                    via[i][j] = k -    Ai = A[i] -        d = min(list(map(sum, list(zip(Ai, A[j]))))) -        if A[i][j] > d: -            print("-1") -            exit() -        elif A[i][j] < d: -            ans += A[i][j] +        if dist[i][j] < A[i][j]: +            ans = -1 +            break +        if via[i][j] == None: +            ans += dist[i][j] +    if ans == -1: +        break