Problem p03600 (python)

Fixed submission:
import numpy as np

n = int(input())
a = np.array([np.array(input().split(), dtype=np.uint64) for _ in range(n)], dtype=np.uint64)

for i in range(n):
  a[i,i] = 1e9 + 1

ans = 0
for u in range(n):
    for v in range(u + 1, n): 
        dist = a[u,v]
        cd = np.min(a[u] + a[v])
        if dist > cd:
            print(-1)
            exit(0)
        if dist < cd:
            ans += dist
 
print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(0, n)] 

ans = 0
for u in range(n):
    for v in range(u + 1, n): 
        dist = a[u][v]
        cd = min([a[u][i] + a[i][v] for i in [x for x in range(0, n) if x != u and x != v]])
        if dist > cd:
            print(-1)
            exit(0)
        if dist < cd:
            ans += dist

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
at = list(map(list, zip(*a)))

if a != at: 
    print(-1)
    exit(0)

import itertools
from array import array

aa = array('L', itertools.chain(*a))

ans = 0
for u in range(n):
    un = u * n
    for v in range(u + 1, n): 
        dist = aa[un + v]
        cd = min([aa[un + i] + aa[i * n + v] for i in range(n) if i != u and i !=v])
        if dist > cd:
            print(-1)
            exit(0)
        if dist < cd:
            ans += dist

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
at = list(map(list, zip(*a)))

if a != at: 
    print(-1)
    exit(0)

import itertools
from array import array

aa = array('L', itertools.chain(*a))

ans = 0
for u in range(n):
    un = u * n
    for v in range(u + 1, n): 
        dist = aa[un + v]
        cd = min([aa[un + i] + aa[i * n + v] for i in range(n) if i != u and i !=v])        if dist > cd:
            print(-1)
            exit(0)
        if dist < cd:
            ans += dist

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
at = list(map(list, zip(*a)))

if a != at: 
    print(-1)
    exit(0)

import itertools
from array import array

aa = array('L', itertools.chain(*a))

ans = 0
for u in range(n):
    un = u * n
    for v in range(u + 1, n): 
        dist = aa[un + v]
        cd = min([aa[un + i] + aa[i * n + v] for i in range(n) if i != u and i !=v]))])
        if dist > cd:
            print(-1)
            exit(0)
        if dist < cd:
            ans += dist

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(0, n)] 
at = list(map(list, zip(*a)))

if a != at: 
    print(-1)
    exit(0)

dr = list()
for u in range(n):
    for v in range(u + 1, n): 
        dist = a[u][v]
        cd = min([a[u][i] + a[i][v] for i in [x for x in range(0, n) if x != u and x != v]])
        if dist > cd:
            print(-1)
            exit(0)
        if dist < cd:
            dr.append(a[u][v])

print(sum(dr))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(0, n)] 
at = list(map(list, zip(*a)))

if a != at: 
    print(-1)
    exit(0)

for u in range(0, n): 
    for v in range(u + 1, n): 
        for i in range(0, n): 
            if a[u][v] > a[u][i] + a[i][v]:
                print(-1)
                exit(0)

dr = list()
for u in range(0, n): 
    for v in range(u + 1, n): 
        if a[u][v] < min([a[u][i] + a[i][v] for i in [x for x in range(0, n) if x != u and x != v]]):
            dr.append(a[u][v])

print(sum(dr))