Buggy python submission (verdict: Time Limit Exceeded):
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)


Fixed submission:
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)


for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    route_set = set()
    costs = []
    for i in range(N):
        for j in range(i + 1, N):
            route_set.add(dp[i][j])
            costs.append(dp[i][j])

    route_set = route_set - set(map(sum, combinations(costs, r=2)))
    print(sum([cost for cost in costs if cost in route_set]))
else:
    print(-1)


Fixed submission:
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
from itertools import product, combinations
import numpy as np

N = int(input())

dp = np.zeros(shape=(N, N), dtype=int)

for i in range(N):
    dp[i] = np.array(list(map(int, input().split(' '))))

original = dp.copy()

for k, i in product(range(N), repeat=2):
    dp[i] = np.minimum(dp[i], dp[i][k] + dp[k])

if np.all(dp == original):
    route_set = set()
    costs = []
    for i in range(N):
        for j in range(i + 1, N):
            route_set.add(dp[i][j])
            costs.append(dp[i][j])

    route_set = route_set - set(map(sum, combinations(costs, r=2)))
    print(sum([cost for cost in costs if cost in route_set]))
else:
    print(-1)


Fixed submission:
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product, combinations
import numpy as np

N = int(input())

dp = np.zeros(shape=(N, N), dtype=int)

for i in range(N):
    dp[i] = np.array(list(map(int, input().split(' '))))

original = dp.copy()

for k, i in product(range(N), repeat=2):
    dp[i] = np.minimum(dp[i], dp[i][k] + dp[k])

if np.all(dp == original):
    route_set = set()
    costs = []
    for i in range(N):
        for j in range(i + 1, N):
            route_set.add(dp[i][j])
            costs.append(dp[i][j])

    route_set = route_set - set(map(sum, combinations(costs, r=2)))
    print(sum([cost for cost in costs if cost in route_set]))
else:
    print(-1)


Fixed submission:
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from itertools import product
import numpy as np

N = int(input())

dp = np.zeros(shape=(N, N), dtype=int)

for i in range(N):
    dp[i] = np.array(list(map(int, input().split(' '))))

original = dp.copy()

for k, i in product(range(N), repeat=2):
    dp[i] = np.minimum(dp[i], dp[i][k] + dp[k])

if not np.all(dp == original):
    print(-1)
else:
    costs = []
    for i in range(N):
        for j in range(i + 1, N):
            costs.append(dp[i][j])
    costs.sort()
    duplicated = set()
    for i in range(len(costs) - 1):
        if costs[i] in duplicated:
            continue
        for j in range(i + 1, len(costs)):
            if costs[j] in duplicated:
                continue
            index = bisect.bisect_left(costs, costs[i] + costs[j])
            if index < len(costs) and costs[index] == costs[i] + costs[j]:
                duplicated.add(costs[index])
    print(sum([cost for cost in costs if cost not in duplicated]))


Fixed submission:
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product, combinations
import numpy as np

N = int(input())

dp = np.zeros(shape=(N, N), dtype=int)

for i in range(N):
    dp[i] = np.array(list(map(int, input().split(' '))))

original = dp.copy()

for k, i in product(range(N), repeat=2):
    dp[i] = np.minimum(dp[i], dp[i][k] + dp[k])

if not np.all(dp == original):
    print(-1)
else:
    costs = []
    for i in range(N):
        for j in range(i + 1, N):
            costs.append(dp[i][j])
    sum_set = set(map(sum, combinations(costs, r=2)))
    result = 0
    for cost in costs:
        if cost not in sum_set:
            result += cost
    print(result)


Fixed submission:
import copy
from itertools import product, combinations

N = int(input())

dp = []
for _ in range(N):
    dp.append(list(map(int, input().split(' '))))

original = copy.deepcopy(dp)

for k, i, j in product(range(N), repeat=3):
    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

if dp == original:
    cost = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(N):
                if k == i or k == j:
                    continue
                if dp[i][j] == dp[i][k] + dp[k][j]:
                    break
            else:
                cost += dp[i][j]
    print(cost)
else:
    print(-1)