Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
adjacency_list = [list(map(int, input().split())) for i in range(n)]

egde = []
for u in range(n):
    for v in range(u):
        egde.append([adjacency_list[u][v], u, v])
egde.sort()
ans = 0
INF = 10 ** 10
for d, u, v in egde:
    d2 = INF
    for w in range(n):
        if w == u or w == v:
            continue
        d2 = min(d2, adjacency_list[u][w] + adjacency_list[w][v])
    if d < d2:
        ans += d
    elif d > d2:
        print(-1)
        exit()

print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
adjacency_list = [list(map(int, input().split())) for i in range(n)]
egde = []
for u in range(n):
    for v in range(u):
        egde.append([adjacency_list[u][v], u, v])
egde.sort()

ans = 0
for d, u, v in egde:
    for w in range(n):
        d2 = adjacency_list[u][w] + adjacency_list[w][v]
        if d == d2:
            if w == u or w == v:
                continue
            break
        elif d > d2:
            print(-1)
            exit()
    else:
        ans += d

print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
adjacency_list = [list(map(int, input().split())) for i in range(n)]
egde = []
for u in range(n):
    for v in range(u):
        egde.append([adjacency_list[u][v], u, v])
egde.sort()

ans = 0
for d, u, v in egde:
    for w in range(n):
        d2 = adjacency_list[u][w] + adjacency_list[w][v]
        if d == d2:
            if w == u or w == v:
                continue
            break
        elif d > d2:
            print(-1)
            exit()
    else:
        ans += d

print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
adjacency_list = [list(map(int, input().split())) for i in range(n)]
egde = []
for u in range(n):
    for v in range(u):
        egde.append([adjacency_list[u][v], u, v])
egde.sort()

ans = 0
for d, u, v in egde:
    for w in range(n):
        if w == u or w == v:
            continue
        d2 = adjacency_list[u][w] + adjacency_list[w][v]
        if d == d2:
            break
        elif d > d2:
            print(-1)
            exit()
    else:
        ans += d

print(ans)


Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
adjacency_list = [list(map(int, input().split())) for i in range(n)]
egde = []
for u in range(n):
    for v in range(u):
        egde.append([adjacency_list[u][v], u, v])
egde.sort()

ans = 0
for d, u, v in egde:
    for w in range(n):
        if w == u or w == v:
            continue
        d2 = adjacency_list[u][w] + adjacency_list[w][v]
        if d > d2:
            print(-1)
            exit()
        elif d == d2:
            break
    else:
        ans += d

print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
adjacency_list = [list(map(int, input().split())) for i in range(n)]
egde = []
for u in range(n):
    for v in range(u):
        egde.append([adjacency_list[u][v], u, v])
egde.sort()

ans = 0
for d, u, v in egde:
    for w in range(n):
        if w == u or w == v:
            continue
        if d > adjacency_list[u][w] + adjacency_list[w][v]:
            print(-1)
            exit()
        elif d == adjacency_list[u][w] + adjacency_list[w][v]:
            break
    else:
        ans += d

print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]

ans = sum([sum(line) for line in graph]) // 2
for a in range(n):
    for b in range(n):
        if a == b:
            break
        for c in range(n):
            if a == c or b == c:
                continue
            if graph[a][b] > graph[a][c] + graph[c][b]:
                print(-1)
                exit()
            elif graph[a][b] == graph[a][c] + graph[c][b]:
                ans -= graph[a][b]

print(ans)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]

ans = sum([sum(line) for line in graph])
for a in range(n):
    for b in range(n):
        if a == b:
            continue
        for c in range(n):
            if a == c or b == c:
                continue
            if graph[a][b] > graph[a][c] + graph[c][b]:
                print(-1)
                exit()
            elif graph[a][b] == graph[a][c] + graph[c][b]:
                ans -= graph[a][b]

print(ans // 2)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline
n = int(input())
G = np.array([list(map(int, input().split())) for _ in range(n)], dtype=float)
use = np.ones((n,n),dtype=bool)
impossible = np.zeros((n,n),dtype=bool)
for w in range(n):
    D = sum(np.meshgrid(G[w], G[w]))
    D[w] = np.inf
    D[:,w] = np.inf
    use &= ~(G == D)
    impossible |= G > D
if impossible.any():
    print(-1)
else:
    print(int(np.sum(G[use]) / 2))