Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))

M = max(D)
cnt = [0 for i in range(N - 1)]

for d in D:
    cnt[d] += 1

if cnt[0] != 1:
    print(0)
    exit()

for c in cnt[:M]:
    if c == 0:
        print(0)
        exit()

res = 1
MOD = 998244353
for i in range(1, M + 1):
    for c in range(cnt[i]):
        res = (res * cnt[i - 1]) % MOD

print(res)


Fixed submission:
N = int(input())
D = list(map(int, input().split()))

M = max(D)
cnt = [0 for i in range(M + 1)]

for d in D:
    cnt[d] += 1

if D[0] != 0:
    print(0)
    exit()
if cnt[0] != 1 or 0 in cnt:
    print(0)
    exit()

res = 1
MOD = 998244353
for i in range(2, M + 1):
    res *= cnt[i - 1] ** cnt[i]
    res %= MOD

print(res)

Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))

M = max(D)
cnt = [0 for i in range(N - 1)]

for d in D:
    cnt[d] += 1

for c in cnt[:M]:
    if c == 0:
        print(0)
        exit()

res = 1
MOD = 998244353
for i in range(1, M + 1):
    res = (res * cnt[i - 1] ** cnt[i]) % MOD

print(res)


Fixed submission:
N = int(input())
D = list(map(int, input().split()))

M = max(D)
cnt = [0 for i in range(M + 1)]

for d in D:
    cnt[d] += 1

if D[0] != 0:
    print(0)
    exit()
if cnt[0] != 1 or 0 in cnt:
    print(0)
    exit()

res = 1
MOD = 998244353
for i in range(2, M + 1):
    res *= cnt[i - 1] ** cnt[i]
    res %= MOD

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

L = list(sorted(map(int, input().split()), key=lambda x: -x))

ret = 0


def is_ok(a, b, c):
    return a < b + c and b < a + c and c < a + b


for i in range(N - 2):
    for j in range(i + 1, N - 1):
        p = j + 1
        q = N + 1
        while q - p > 2:
            k = (p + q) // 2
            if is_ok(L[i], L[j], L[k]):
                p = k
            else:
                q = k

        if is_ok(L[i], L[j], L[p]):
            ret += p - j

print(ret)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(sorted(map(int, input().split())))

res = 0

for i in range(N):
    for j in range(i + 1, N):
        k = bisect_left(L, L[i] + L[j])

        res += k - j - 1

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

primes = [2]


def is_prime(n):
    for p in primes:
        if p * p > n:
            break
        if n % p == 0:
            return False

    return True


A, B = map(int, input().split())

G = int(fractions.gcd(A, B))

res = 1

if G % 2 == 0:
    res += 1
    G //= 2

for i in range(3, G, 2):
    if i > G:
        break
    if not is_prime(i):
        continue
    primes.append(i)
    if G % i == 0:
        res += 1
        G //= i

if G > 1 and is_prime(G) and G not in primes:
    res += 1

print(res)


Fixed submission:
import fractions

A, B = map(int, input().split())

G = fractions.gcd(A, B)

res = 1

for i in [2] + list(range(3, int(G ** 0.5) + 1, 2)):
    if G % i == 0:
        res += 1
        while G % i == 0:
            G //= i

if G > 2:
    res += 1

print(res)

Buggy python submission (verdict: Runtime Error):
import fractions

primes = [2]


def is_prime(n):
    for p in primes:
        if p * p > n:
            break
        if n % p == 0:
            return False

    return True


A, B = map(int, input().split())

G = fractions.gcd(A, B)

res = 1

if G % 2 == 0:
    res += 1
    G /= 2

for i in range(3, G, 2):
    if i > G:
        break
    if not is_prime(i):
        continue
    primes.append(i)
    if G % i == 0:
        res += 1
        G /= i

if G > 1 and is_prime(G) and G not in primes:
    res += 1

print(res)


Fixed submission:
import fractions

A, B = map(int, input().split())

G = fractions.gcd(A, B)

res = 1

for i in [2] + list(range(3, int(G ** 0.5) + 1, 2)):
    if G % i == 0:
        res += 1
        while G % i == 0:
            G //= i

if G > 2:
    res += 1

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions

A, B = map(int, input().split())

G = fractions.gcd(A, B)

res = 1

i = 2
while G > 1:
    if G % i == 0:
        res += 1
        while G % i == 0:
            G /= i
    else:
        if i == 2:
            i += 1
        else:
            i += 2

print(res)


Fixed submission:
import fractions

A, B = map(int, input().split())

G = fractions.gcd(A, B)

res = 1

for i in [2] + list(range(3, int(G ** 0.5) + 1, 2)):
    if G % i == 0:
        res += 1
        while G % i == 0:
            G //= i

if G > 2:
    res += 1

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(sorted(map(int, input().split()), key=lambda x: -x))

for _ in range(M):
    A[0] /= 2

    p = 0
    while p < N - 1 and A[p] < A[p + 1]:
        A[p], A[p + 1] = A[p + 1], A[p]
        p += 1

print(sum(map(int, A)))


Fixed submission:
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: -1 * int(x), input().split()))

heapq.heapify(A)
for _ in range(M):
    a = -1 * heapq.heappop(A)
    a //= 2
    heapq.heappush(A, -1 * a)

print(-1 * sum(A))
Buggy python submission (verdict: Runtime Error):
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: usize,
        b: usize
    }

    println!("{}", std::cmp::min(n * a, b))
}

Fixed submission:
N, A, B = map(int, input().split())
print(min(N * A, B))
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb


Fixed submission:
from scipy.misc import comb

N, K = map(int, input().split())

mod = 10 ** 9 + 7

for i in range(1, K + 1):
    a = comb(N - K + 1, i, exact=True)
    b = comb(K - 1, i - 1, exact=True)
    ret = a % mod * b % mod
    print(ret)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

N, K = map(int, input().split())

mod = 10 ** 9 + 7

for i in range(1, K + 1):
    a = comb(N - K + 1, i, exact=True)
    b = comb(K - 1, i - 1, exact=True)
    ret = a % mod * b % mod
    print(ret)


Fixed submission:
from scipy.misc import comb

N, K = map(int, input().split())

mod = 10 ** 9 + 7

for i in range(1, K + 1):
    a = comb(N - K + 1, i, exact=True)
    b = comb(K - 1, i - 1, exact=True)
    ret = a % mod * b % mod
    print(ret)
Buggy python submission (verdict: Runtime Error):
X, A = map(int, input.split())
print(0 if X < A else 10)

Fixed submission:
X, A = map(int, input().split())
print(0 if X < A else 10)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

cnt = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        t = N - (i * R + j * G)
        if 0 <= t and t % B == 0:
            cnt += 1
            
print(cnt)


Fixed submission:
R, G, B, N = map(int, input().split())

cnt = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        t = N - (i * R + j * G)
        if 0 <= t and t % B == 0:
            cnt += 1
            
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = _
V = list(map(int, input().split()))
C = list(map(int, input().split()))

print(sum(map(lambda p: max(0, p[0] - p[1]), zip(V, C))))


Fixed submission:
_ = input()
V = list(map(int, input().split()))
C = list(map(int, input().split()))

print(sum(map(lambda p: max(0, p[0] - p[1]), zip(V, C))))
Buggy python submission (verdict: Runtime Error):
from functools import reduce

N = int(input())
S = input()
K = int(input())

print(reduce(lambda x, y: x + (y if y == S[K] else '*'), S, ''))


Fixed submission:
from functools import reduce

N = int(input())
S = input()
K = int(input()) - 1

print(reduce(lambda x, y: x + (y if y == S[K] else '*'), S, ''))
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            res.append(j)
            B.pop(j - 1)
            break
    else:
        print(-1)
        exit()1

for r in res[::-1]:
    print(r)


Fixed submission:
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)

Buggy python submission (verdict: Runtime Error):
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * (K - 1))


Fixed submission:
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)

Buggy python submission (verdict: Runtime Error):
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * K - 1)


Fixed submission:
N = int(input())
B = list(map(int, input().split()))

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)
Buggy python submission (verdict: Runtime Error):
print('Christmas' + ' Eve' * (25) - int(input()))

Fixed submission:
print('Christmas' + ' Eve' * (25 - int(input())))

Buggy python submission (verdict: Runtime Error):
print('Christmas' + ' Eve' * (int(input()) - D))


Fixed submission:
print('Christmas' + ' Eve' * (25 - int(input())))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

N, M = map(int, input().split())

S = input()
T = input()

L = N * M // gcd(N, M)

X = ['.' for _ in range(L)]

for i in range(N):
    p = i * L // N
    X[p] = S[i]

for i in range(M):
    p = i * L // M
    if X[p] != '.' and X[p] != T[i]:
        print(-1)
        exit()

print(L)


Fixed submission:
from fractions import gcd

N, M = map(int, input().split())

S = input()
T = input()

G = gcd(N, M)

n = N // G
m = M // G

L = N * M // G

for i in range(0, G):
    a = i * n
    b = i * m

    if S[a] != T[b]:
        print(-1)
        exit()

print(L)
Buggy python submission (verdict: Runtime Error):
N = int(input())
query = [list(map(int, input().split())) for _ in range(N)]


def isvalid(i, j):
    p, q, h = query[0]
    H = h + abs(p - i) + abs(q - j)
    if H < 1:
        return -1
    for que in query[1:]:
        p, q, h = que
        if h != max(H - abs(p - i) - abs(q - j)):
            return -1
    return H


for i in range(101):
    for j in range(101):
        H = isvalid(i, j)
        if H != -1:
            print(i, j, H)
            exit()

           

Fixed submission:
N = int(input())
query = [list(map(int, input().split())) for _ in range(N)]


def isvalid(i, j):
    H = -1
    for p, q, h in query:
        if h != 0:
            H = h + abs(p - i) + abs(q - j)
            break

    for p, q, h in query:
        if H == -1 and h != 0:
            H = h + abs(p - i) + abs(q - j)

        if h != max(H - abs(p - i) - abs(q - j), 0):
            return -1
    return H


for i in range(101):
    for j in range(101):
        H = isvalid(i, j)
        if H >= 1:
            print(i, j, H)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

ret = 0

for a in range(1, N + 1):
    if 2 * a % K != 0:
        continue

    cnt = 0
    t = 1
    while t * K - a <= N:
        if t * K - a >= 1:
            cnt += 1
        t += 1

    ret += cnt ** 2

print(ret)


Fixed submission:
N, K = map(int, input().split())

x, y = 0, 0

for i in range(1, N + 1):
    if i % K == 0:
        x += 1
    if K % 2 == 0 and i % K == K // 2:
        y += 1

print(x ** 3 + y ** 3)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = sorted([int(input()) for _ in range(N)])

print(A[N-1] - A[0])

Fixed submission:
N = int(input())
A = sorted(map(int, input().split()))

print(A[N-1] - A[0])
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

S = input()
K = int(input())

q = []

for i in range(len(S)):
    for j in range(i, len(S) + 1):
        heapq.heappush(q, S[i:j])

last = ''
while K > 0:
    s = heapq.heappop(q)
    if s != last:
        K -= 1
        last = s

print(last)


Fixed submission:
import heapq

S = input()
K = int(input())

q = []

for i in range(len(S)):
    for j in range(i, min(len(S), i + K) + 1):
        heapq.heappush(q, S[i:j])

last = ''
while K > 0:
    s = heapq.heappop(q)
    if s != last:
        K -= 1
        last = s

print(last)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = map(int, input().split())

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S)

ret = 0
for s in set(S):
    cnt = S.count(s)
    ret += cnt * (cnt - 1) / 2
print(int(ret))


Fixed submission:
N = int(input())
A = map(int, input().split())

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S) + [None]
ret = 0
cnt = 1
for i in range(1, N + 2):
    if S[i] != S[i - 1]:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
    else:
        cnt += 1

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = map(int, input().split())

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S)

ret = 0
for s in set(S):
    cnt = S.count(s)
    ret += cnt * (cnt - 1) / 2
print(int(ret))


Fixed submission:
N = int(input())
A = map(int, input().split())

S = [0]

for a in A:
    S.append(S[len(S) - 1] + a)

S = sorted(S) + [None]
ret = 0
cnt = 1
for i in range(1, N + 2):
    if S[i] != S[i - 1]:
        ret += cnt * (cnt - 1) // 2
        cnt = 1
    else:
        cnt += 1

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

for i in range(A, B+1):
    if i < A+K or i > B-K:
        print(i)


Fixed submission:
A, B, K = map(int, input().split())
ret = set(range(A, min(A + K, B)))
ret.update(range(max(A, B - K + 1), B + 1))

for r in sorted(ret):
    print(r)
Buggy python submission (verdict: Runtime Error):
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])

N = int(input())

R = []
for _ in range(N):
    x, y = map(int, input().split())
    R.append(Point(x, y))

B = []
for _ in range(N):
    x, y = map(int, input().split())
    B.append(Point(x, y))

E = [[] for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if r.x < b.x and r.y < b.y:
            E[i].append(j)


class BipartiteMatching:
    def __init__(self, max_u: int, max_v: int, edges):
        self.max_u = max_u
        self.max_v = max_v
        self.edges = edges  # u->vの隣接行列
        self.__match = None

    def dfs(self, v: int, visited: set) -> bool:
        for u in self.edges[v]:
            if u in visited:
                continue
            visited.add(u)

            if self.__match[u] == -1 or self.dfs(self.__match[u], visited):
                self.__match[u] = v
                return True
        return False

    def execute(self):
        self.__match = [-1 for _ in range(self.max_u)]
        return sum(self.dfs(u, set()) for u in range(self.max_u))


print(BipartiteMatching(N, E).execute())


Fixed submission:
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])
# Edge = namedtuple('Edge', ['from', 'to'])

N = int(input())

R = []
for _ in range(N):
    x, y = map(int, input().split())
    R.append(Point(x, y))

B = []
for _ in range(N):
    x, y = map(int, input().split())
    B.append(Point(x, y))

E = [[] for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if r.x < b.x and r.y < b.y:
            E[i].append(j)

match = [-1 for _ in range(N)]


def dfs(v: int, visited: set) -> bool:
    for u in E[v]:
        if u in visited:
            continue
        visited.add(u)

        if match[u] == -1 or dfs(match[u], visited):
            match[u] = v
            return True
    return False


def bipartite_matching():
    return sum(dfs(i, set()) for i in range(N))


print(bipartite_matching())
Buggy python submission (verdict: Runtime Error):
m,a,r,c,h = [0,0,0,0,0]
N = int(input())

for i in range(N):


Fixed submission:
m, a, r, c, h = [0] * 5

N = int(input())

for _ in range(N):
    s = input()[0]

    if s == 'M':
        m += 1
    elif s == 'A':
        a += 1
    elif s == 'R':
        r += 1
    elif s == 'C':
        c += 1
    elif s == 'H':
        h += 1
print(m * a * r + 
      m * a * c +
      m * a * h + 
      m * r * c + 
      m * r * h + 
      m * c * h + 
      a * r * c + 
      a * r * h +
      a * c * h +
      r * c * h)
Buggy python submission (verdict: Runtime Error):
k = int(input().replace(' ', '')) ** (1 / 2)
print('Yes' if int(k) ** int(k) == k ** k else 'No')

Fixed submission:
k = int(input().replace(' ', '')) ** (1 / 2)
print('Yes' if int(k) == k else 'No')

Buggy python submission (verdict: Runtime Error):
N = input()

print('Yes' if sum(map(int, list(N))) % int(N) == 0 else 'No')

Fixed submission:
k = int(input().replace(' ', '')) ** (1 / 2)
print('Yes' if int(k) == k else 'No')
Buggy python submission (verdict: Runtime Error):
print('<' if input() < input() else '>')

Fixed submission:
X, Y = input().split()
print('<' if X < Y else ('>' if X > Y else '='))
Buggy python submission (verdict: Runtime Error):
print('YES' if input() == input()[::-1])

Fixed submission:
print('YES' if input() == input()[::-1] else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
i = 0

for t in set(T):
    if D.count(t) < T.count(t):
        print('NO')
        exit()
        
print('YES')


Fixed submission:
N = int(input())
D = sorted(map(int, input().split()))
M = int(input())
T = sorted(map(int, input().split()))
i = 0
for t in T:
    while D[i] < t:
        i += 1
    if D[i] == t:
        i += 1
    else:
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
i = 0

for t in set(T):
    if D.count(t) < T.count(t):
        print('NO')
        exit()
        
print('YES')


Fixed submission:
N = int(input())
D = sorted(map(int, input().split()))
M = int(input())
T = sorted(map(int, input().split()))
i = 0
for t in T:
    while D[i] < t:
        i += 1
    if D[i] == t:
        i += 1
    else:
        print('NO')
        exit()
print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        a = 4 * h * n - h * N - n * N
        if a == 0:
            break
        w = int((h * n * N) / a)
        if w > 0 and 4 / N == 1 / h + 1 / n + 1 / w:
            print(h, n, w)
            exit()


Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        a = 4 * h * n - h * N - n * N
        if a == 0:
            break
        w = int((h * n * N) / a)
        if w > 0 and 4 / N == 1 / h + 1 / n + 1 / w:
            print(h, n, w)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
V = int(input())
A = [list(map(int, input().split())) for _ in range(V)]

ret = 0
for i in range(V):
    for j in range(i+1, V):
        f = True
        for k in range(V):
            if i == k or j == k:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            elif A[i][j] == A[i][k] + A[k][j]:
                f = False
        if f:
            ret += A[i][j]

print(ret)


Fixed submission:
V = int(input())
A = [list(map(int, input().split())) for _ in range(V)]

ret = 0
for i in range(V):
    for j in range(i+1, V):
        f = True
        for k in range(V):
            if i == k or j == k:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            elif A[i][j] == A[i][k] + A[k][j]:
                f = False
        if f:
            ret += A[i][j]

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
V = int(input())
A = []
for _ in range(V):
    A.append(list(map(int, input().split())))

ret = 0
for i in range(V):
    for j in range(i+1, V):
        f = True
        for k in range(V):
            if i == k or j == k:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            elif A[i][j] == A[i][k] + A[k][j]:
                f = False
        if f:
            ret += A[i][j]

print(ret)


Fixed submission:
V = int(input())
A = [list(map(int, input().split())) for _ in range(V)]

ret = 0
for i in range(V):
    for j in range(i+1, V):
        f = True
        for k in range(V):
            if i == k or j == k:
                continue
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            elif A[i][j] == A[i][k] + A[k][j]:
                f = False
        if f:
            ret += A[i][j]

print(ret)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        if i < N:
            P[i], P[i + 1] = P[i + 1], P[i]

print(res)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        if i < N - 1:
            P[i], P[i + 1] = P[i + 1], P[i]

print(res)

Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        P[i], P[i + 1] = P[i + 1], P[i]

print(res)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))

res = 0
for i in range(N):
    if P[i] == i + 1:
        res += 1
        if i < N - 1:
            P[i], P[i + 1] = P[i + 1], P[i]

print(res)