# 63





n = int(eval(input()))

dp = [[int(x) for x in input().split()] for y in range(n)]

del_l = []

ans = 0



for i in range(n):

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

        ans += dp[i][j]



for i in range(n-1):

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

        for k in range(n):

            if k in (i,j):

                continue

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

                print("-1")

                exit()

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

                ans -= dp[i][j]

                break



print(ans)
# 63





n = int(eval(input()))

dp = [[int(x) for x in input().split()] for y in range(n)]

del_l = []

ans = 0



for i in range(n-1):

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

        for k in range(n):

            if k in (i,j):

                continue

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

                print("-1")

                exit()

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

                break

        else:

            ans += dp[i][j]



print(ans)
# 63
n = int(eval(input()))
dp = [[int(x) for x in input().split()] for y in range(n)]
del_l = []
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += dp[i][j]
for i in range(n - 1):
    for j in range(i + 1, n):
        for k in range(n):
            if k in (i, j):
                continue
            if dp[i][j] > dp[i][k] + dp[k][j]:
                print("-1")
                exit()
            elif dp[i][j] == dp[i][k] + dp[k][j]:
                ans -= dp[i][j]
                break
print(ans)

# 63
n = int(eval(input()))
dp = [[int(x) for x in input().split()] for y in range(n)]
del_l = []
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        for k in range(n):
            if k in (i, j):
                continue
            if dp[i][j] > dp[i][k] + dp[k][j]:
                print("-1")
                exit()
            elif dp[i][j] == dp[i][k] + dp[k][j]:
                break
        else:
            ans += dp[i][j]
print(ans)

-for i in range(n): -    for j in range(i + 1, n): -        ans += dp[i][j] -                ans -= dp[i][j] +        else: +            ans += dp[i][j]