Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = [tuple(map(int, input().split())) for _ in range(N)]
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        for c in range(N):
            if c == a or c == b:
                continue
            if matr[a][b] == matr[a][c] + matr[c][b]:
                break
        else:
            ans += matr[a][b]
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype=np.int64)
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        eq = (matr[a, b] == (matr[a] + matr[:, b]))
        eq[a] = eq[b] = False
        if not np.any(eq):
            ans += matr[a, b]
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N = int(input())

matr = [tuple(map(int, input().split())) for _ in range(N)]
way = floyd_warshall(matr).astype(int)
if np.any(way < matr):
    print(-1)
    exit()

ans = 0
for a, b in itertools.combinations(range(N), 2):
    for c in range(N):
        if c == a or c == b:
            continue
        if matr[a][b] == matr[a][c] + matr[c][b]:
            break
    else:
        ans += matr[a][b]
print(ans)


Fixed submission:
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype=np.int64)
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        eq = (matr[a, b] == (matr[a] + matr[:, b]))
        eq[a] = eq[b] = False
        if not np.any(eq):
            ans += matr[a, b]
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N = int(input())

matr = [tuple(map(int, input().split())) for _ in range(N)]
way = floyd_warshall(matr).astype(int)
if np.any(way < matr):
    print(-1)
    exit()

way.tolist()
ans = 0
for a, b in itertools.combinations(range(N), 2):
    for c in range(N):
        if c == a or c == b:
            continue
        if matr[a][b] == matr[a][c] + matr[c][b]:
            break
    else:
        ans += matr[a][b]
print(ans)


Fixed submission:
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype=np.int64)
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        eq = (matr[a, b] == (matr[a] + matr[:, b]))
        eq[a] = eq[b] = False
        if not np.any(eq):
            ans += matr[a, b]
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from sys import exit

N = int(input())

matr = [tuple(map(int, input().split())) for _ in range(N)]
way = floyd_warshall(matr).astype(int)
if np.any(way < matr):
    print(-1)
    exit()

ans = 0
for a, b in itertools.combinations(range(N), 2):
    for c in set(range(N)) - {a, b}:
        if matr[a][b] == matr[a][c] + matr[c][b]:
            break
    else:
        ans += matr[a][b]
print(ans)


Fixed submission:
import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def main():
    N = int(input())
    matr = np.array([tuple(map(int, input().split())) for _ in range(N)], dtype=np.int64)
    way = floyd_warshall(matr).astype(int)
    if np.any(way < matr):
        print(-1)
        exit()

    ans = 0
    for a, b in itertools.combinations(range(N), 2):
        eq = (matr[a, b] == (matr[a] + matr[:, b]))
        eq[a] = eq[b] = False
        if not np.any(eq):
            ans += matr[a, b]
    print(ans)


if __name__ == "__main__":
    main()