Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        x = 4 * h * n - N * n - N * h
        if x != 0 and N * h * n % x == 0:
            w = N * h * n // x
            if w >= 1:
                print(h, n, w)
                exit()


Fixed submission:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        x = 4 * h * n - N * n - N * h
        if x != 0 and N * h * n % x == 0:
            w = N * h * n // x
            if w >= 1:
                print(h, n, w)
                exit()
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

import numpy as np

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

a = np.array(a)

g = csr_matrix(a)
dist = floyd_warshall(g)

bl = dist == a

if bl.all():
    sm = dist.sum()
    for u in range(n):
        for v in range(n):
            if u == v:
                continue
            rmv = [u, v]
            i_rmv = np.ones(n, dtype=bool)
            i_rmv[rmv] = False

            mn = np.min(dist[u, i_rmv] + dist[v, i_rmv])
            if mn == dist[u, v]:
                sm -= dist[u, v]

    ans = int(sm) // 2
    print(ans)

else:
    print(-1)


Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

import numpy as np

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

a = np.array(a)

g = csr_matrix(a)
dist = floyd_warshall(g)

bl = dist == a

if bl.all():
    sm = dist.sum()
    INF = 10 ** 18 + 1
    inf = np.array([INF] * n)
    inf = np.diag(inf)
    dist += inf
    for u in range(n):
        for v in range(n):
            if u == v:
                continue

            mn = np.min(dist[u] + dist[v])
            if mn == dist[u, v]:
                sm -= dist[u, v]

    ans = int(sm) // 2
    print(ans)

else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

import numpy as np

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

a = np.array(a)

g = csr_matrix(a)
dist = floyd_warshall(g)

bl = dist == a

if bl.all():
    sm = a.sum()
    for u in range(n):
        for v in range(n):
            if v == u:
                continue
            for w in range(n):
                if w == u or w == v:
                    continue
                if dist[u][v] == dist[u][w] + dist[w][v]:
                    sm -= dist[u][v]

    ans = int(sm) // 2
    print(ans)

else:
    print(-1)


Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

import numpy as np

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

a = np.array(a)

g = csr_matrix(a)
dist = floyd_warshall(g)

bl = dist == a

if bl.all():
    sm = dist.sum()
    INF = 10 ** 18 + 1
    inf = np.array([INF] * n)
    inf = np.diag(inf)
    dist += inf
    for u in range(n):
        for v in range(n):
            if u == v:
                continue

            mn = np.min(dist[u] + dist[v])
            if mn == dist[u, v]:
                sm -= dist[u, v]

    ans = int(sm) // 2
    print(ans)

else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))

a.sort()
l = 0
r = 0
ans = 0
cnt = [0, 0, 0]
while l < n and r < n:
    a_l = {a[l] - 1, a[l], a[l] + 1}
    a_r = {a[r] - 1, a[r], a[r] + 1}
    l_r = a_l & a_r

    if l_r:
        for ele in l_r:
            diff = ele - a[l]
            if diff == 0:
                cnt[1] += 1
            elif diff < 0:
                cnt[0] += 1
            else:
                cnt[2] += 1
        r += 1

    else:
        ans = max(ans, max(cnt))
        l += 1
        if l < n:
            diff = a[l] - a[l-1]
            if diff == 0:
                cnt = cnt
            elif diff == 1:
                cnt = cnt[1:] + [0]
            elif diff == 2:
                cnt = cnt[2] + [0, 0]
            else:
                cnt = [0, 0, 0]

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
keys = c.keys()

st = set()
for key in keys:
    for i in (-1, 0, 1):
        st.add(key + i)

ans = 0
for x in st:
    cnt = c[x-1] + c[x] + c[x+1]
    ans = max(ans, cnt)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

ans = 0
for ele in a:
    m = np.sum(a - 1 == ele)
    s = np.sum(a == ele)
    p = np.sum(a + 1 == ele)
    cnt = m + s + p

    ans = max(ans, cnt)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
keys = c.keys()

st = set()
for key in keys:
    for i in (-1, 0, 1):
        st.add(key + i)

ans = 0
for x in st:
    cnt = c[x-1] + c[x] + c[x+1]
    ans = max(ans, cnt)

print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

from numpy import lcm


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-


def gcd(x, y):
    while x % y:
        x, y = y, x % y
    return y


def lcm(x, y):
    return x * y // gcd(x, y)


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

from math import gcd


def lcm(x, y):
    return x * y // gcd(x, y)


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-


def gcd(x, y):
    while x % y:
        x, y = y, x % y
    return y


def lcm(x, y):
    return x * y // gcd(x, y)


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

g = [[0] * n for _ in range(n)]

for a, b in ab:
    g[a-1][b-1] = 1
    g[b-1][a-1] = 1

ans = "IMPOSSIBLE"
for i, ele in enumerate(g[0]):
    if ele:
        if g[i][-1] == 1:
            ans = "POSSIBLE"
            break

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

import numpy as np

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

start = np.zeros(n)
end = np.zeros(n)
for a, b in ab:
    if a == 1:
        start[b-1] = 1
    if b == n:
        end[a-1] = 1

ans = np.any((start * end))
print("POSSIBLE" if ans else "IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))

b = []
for ele in a:
    b.append(ele)
    b = b[::-1]

print(*b)


Fixed submission:
# -*- coding: utf-8 -*-

from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque()
for i, ele in enumerate(a):
    if i % 2:
        b.appendleft(ele)
    else:
        b.append(ele)

if n % 2:
    b.reverse()

print(*b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

pushed = set()
cnt = 0
push= 1
while True:
    if push in pushed:
        cnt = -1
        break
    pushed.add(push)
    push = a[push]
    cnt += 1
    if push == 2:
        break

print(cnt)
    


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

pushed = set()
cnt = 0
push= 1
while True:
    if push in pushed:
        cnt = -1
        break
    pushed.add(push)
    push = a[push-1]
    cnt += 1
    if push == 2:
        break

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))

ans = -float("inf")
for i in range(n, 2 * n + 1):
    fh = a[:i].copy()
    fh.sort(reverse=True)
    sh = a[i:].copy()
    sh.sort()
    score = sum(fh[:n]) - sum(sh[:n])
    ans = max(ans, score)

print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

import heapq

n = int(input())
a = list(map(int, input().split()))

fh_sum = 0
fh = []
sh_sum = 0
sh = []
for i in range(n):
    heapq.heappush(fh, a[i])
    fh_sum += a[i]
    heapq.heappush(sh, -a[-(i+1)])
    sh_sum += a[-(i+1)]

fh_sums = [fh_sum]
sh_sums = [sh_sum]
for k in range(n, 2 * n):
    fh_sum += a[k]
    heapq.heappush(fh, a[k])
    fh_sum -= heapq.heappop(fh)
    fh_sums.append(fh_sum)
    sh_sum += a[-(k+1)]
    heapq.heappush(sh, -a[-(k+1)])
    sh_sum += heapq.heappop(sh)
    sh_sums.append(sh_sum)

sh_sums = sh_sums[::-1]

ans = -float("inf")
for fh_sum, sh_sum in zip(fh_sums, sh_sums):
    score = fh_sum - sh_sum
    ans = max(ans, score)

print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

cnt = [0] * n

for i in range(m):
    cnt[ab[i][0] - 1] += 1
    cnt[ab[i][1] - 1] += 1

for i in range(n):
    print(cnt(i))


Fixed submission:
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

cnt = [0] * n

for i in range(m):
    cnt[ab[i][0] - 1] += 1
    cnt[ab[i][1] - 1] += 1

for i in range(n):
    print(cnt[i])
Buggy python submission (verdict: Runtime Error):
n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[[-1] * (3 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 0
w1 = wv[0][0]

for i, (w, v) in enumerate(wv):
    for j in range(i + 1):
        for k in range(3 * n + 1):
            if dp[i][j][k] != -1:
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
                w_diff = w - w1
                if j + 1 <= n and k + w_diff <= 3 * n:
                    dp[i+1][j+1][k+w_diff] = max(dp[i+1][j+1][k+w_diff], dp[i][j][k] + v)

ans = 0
for j in range(n + 1):
    w_diff_mx = W - w1 * j
    for k in range(w_diff_mx + 1):
        ans = max(ans, dp[n][j][k])

print(ans)


Fixed submission:
n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[[-1] * (3 * n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
dp[0][0][0] = 0
w1 = wv[0][0]

for i, (w, v) in enumerate(wv):
    for j in range(i + 1):
        for k in range(3 * n + 1):
            if dp[i][j][k] != -1:
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
                w_diff = w - w1
                if j + 1 <= n and k + w_diff <= 3 * n:
                    dp[i+1][j+1][k+w_diff] = max(dp[i+1][j+1][k+w_diff], dp[i][j][k] + v)

ans = 0
for j in range(n + 1):
    w_diff_mx = min(W - w1 * j, 3 * n)
    for k in range(w_diff_mx + 1):
        ans = max(ans, dp[n][j][k])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

power = 1
for i in range(1, n + 1):
    power *= i

mod = 10 ** 9 + 7
ans = power % mod
print(ans)


Fixed submission:
n = int(input())

from math import factorial

power = factorial(n)
mod = 10 ** 9 + 7
ans = power % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

INF = 40 * 100 + 1
ab_max = 10 * n

dp = [[[INF] * (ab_max + 1) for _ in range(ab_max + 1)] for _ in range(n + 1)]
dp[0][0][0] = 0

for i, (a, b, c) in enumerate(abc, 1):
    for j in range(ab_max + 1):
        for k in range(ab_max + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j - a >= 0 and k - b >= 0:
                if dp[i-1][j-a][k-b] != INF:
                    dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a][k-b] + c)


ans = INF
for j in range(1, ab_max + 1):
    for k in range(1, ab_max + 1):
        if j * mb == k * ma:
            ans = min(ans, dp[n][j][k])

if ans == INF:
    ans = -1

print(ans)


Fixed submission:
n, ma, mb = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(n)]

INF = 40 * 100 + 1
ab_max = 10 * n

dp = [[[INF] * (ab_max + 1) for _ in range(ab_max + 1)] for _ in range(n + 1)]
dp[0][0][0] = 0

for i, (a, b, c) in enumerate(abc, 1):
    for j in range(ab_max + 1):
        for k in range(ab_max + 1):
            dp[i][j][k] = dp[i-1][j][k]
            if j - a >= 0 and k - b >= 0:
                if dp[i-1][j-a][k-b] != INF:
                    dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a][k-b] + c)


ans = INF
for j in range(1, ab_max + 1):
    for k in range(1, ab_max + 1):
        if j * mb == k * ma:
            ans = min(ans, dp[n][j][k])

if ans == INF:
    ans = -1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

from itertools import combinations_with_replacement

cwr = combinations_with_replacement(range(0, k + 1), 3)
ans = 0

for x, y, z in cwr:
    if x + y + z == s:
        st = set([x, y, z])
        if len(st) == 1:
            ans += 1
        elif len(st) == 2:
            ans += 3
        else: #len(st) == 3
            ans += 6

print(ans)


Fixed submission:
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            ans += 1

print(ans)

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

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                ans += 1

print(ans)


Fixed submission:
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]

graph = [[0] * n for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

dist, pre = floyd_warshall(csr_matrix(graph), return_predecessors=True)

edges = set()
for s in range(n):
    for g in range(s + 1, n):
        while g != s:
            par_g = pre[s][g]
            edge = sorted([par_g, g])
            edge = tuple(edge)
            edges.add(edge)
            g = par_g

ans = m - len(edges)
print(ans)


Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]

graph = [[0] * n for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

dist = floyd_warshall(csr_matrix(graph))

ans = 0
for a, b, c in abc:
    a -= 1
    b -= 1

    if dist[a][b] != c:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    x, y = map(int, input().split())

    if 0 <= x <= y or x <= y <= 0:
        ans = abs(abs(x) - abs(y))

    elif x < 0 < y or y < 0 < x:
        ans = abs(abs(x) - abs(y)) + 1

    elif y < x < 0 or 0 < y < x:
        ans = abs(abs(x) - abs(y)) + 2

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y = map(int, input().split())

    if 0 <= x <= y or x <= y <= 0:
        ans = abs(abs(x) - abs(y))

    elif x <= 0 <= y or y <= 0 <= x:
        ans = abs(abs(x) - abs(y)) + 1

    elif y < x < 0 or 0 < y < x:
        ans = abs(abs(x) - abs(y)) + 2

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

import numpy as np
from scipy.spatial.distance import cdist
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense

xs, ys, xt, yt = map(int, readline().split())
n = int(readline())
xyr = np.array(read().split(), np.int64)
xyr = np.append(xyr, [xs, ys, 0, xt, yt, 0])
xyr = xyr.reshape((-1, 3))

xy = xyr[:, :2]
dist = cdist(xy, xy)
r = xyr[:, 2]
dist = np.maximum(dist - r - r.reshape((-1, 1)), 0)
g = csgraph_from_dense(dist, null_value=np.inf)

ans = dijkstra(g, indices=n)[n+1]
print(ans)


Fixed submission:
from math import sqrt
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

xs, ys, xt, yt = map(int, input().split())
n = int(input())
xyr = [list(map(int, input().split())) for _ in range(n)]

xyr.append([xs, ys, 0])
xyr.append([xt, yt, 0])

row = []
col = []
cost = []

for i, (xi, yi, ri) in enumerate(xyr):
    for j, (xj, yj, rj) in enumerate(xyr[i+1:], i+1):
        row.append(i)
        col.append(j)
        dist = max(0, sqrt((xi - xj) ** 2 + (yi - yj) ** 2) - ri - rj)
        cost.append(dist)

g = csr_matrix((cost, (row, col)), shape=(n + 2, n + 2))
d = dijkstra(g, directed=False, indices=n)
ans = d[n+1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

xs, ys, xt, yt = map(int, input().split())
n = int(input())
xyr = [list(map(int, input().split())) for _ in range(n)]

xyr.append([xs, ys, 0])
xyr.append([xt, yt, 0])

row = []
col = []
cost = []

for i, (xi, yi, ri) in enumerate(xyr):
    for j, (xj, yj, rj) in enumerate(xyr):
        row.append(i)
        col.append(j)
        dist = max(0, sqrt((xi - xj) ** 2 + (yi - yj) ** 2) - ri - rj)
        cost.append(dist)

g = csr_matrix((cost, (row, col)), shape=(n + 2, n + 2))
d = dijkstra(g, indices=n)
ans = d[n+1]
print(ans)


Fixed submission:
from math import sqrt
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

xs, ys, xt, yt = map(int, input().split())
n = int(input())
xyr = [list(map(int, input().split())) for _ in range(n)]

xyr.append([xs, ys, 0])
xyr.append([xt, yt, 0])

row = []
col = []
cost = []

for i, (xi, yi, ri) in enumerate(xyr):
    for j, (xj, yj, rj) in enumerate(xyr[i+1:], i+1):
        row.append(i)
        col.append(j)
        dist = max(0, sqrt((xi - xj) ** 2 + (yi - yj) ** 2) - ri - rj)
        cost.append(dist)

g = csr_matrix((cost, (row, col)), shape=(n + 2, n + 2))
d = dijkstra(g, directed=False, indices=n)
ans = d[n+1]
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n, m = map(int, input().split())
l = []
for _ in range(n):
    k, *ls = map(int, input().split())
    l.append(ls)

uf = UnionFind(m)

for li in l:
    for e1, e2 in zip(li, li[1:]):
        e1 -= 1
        e2 -= 1
        uf.unite(e1, e2)

p = uf.find_set(l[0][0])
ans = "YES"
for e, *_ in l:
    e -= 1
    if uf.find_set(e) != p:
        ans = "NO"

print(ans)


Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n, m = map(int, input().split())
l = []
for _ in range(n):
    k, *ls = map(int, input().split())
    l.append(ls)

uf = UnionFind(m)

for li in l:
    for e1, e2 in zip(li, li[1:]):
        e1 -= 1
        e2 -= 1
        uf.unite(e1, e2)

p = uf.find_set(l[0][0] - 1)
ans = "YES"
for e, *_ in l:
    if uf.find_set(e - 1) != p:
        ans = "NO"

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

cnt = [0] * 9
for v in d.values():
    cnt[v] += 1

cnt[0] = (h - 2) * (w - 2) - sum(cnt[1:])
print(*cnt, sep="\n")


Fixed submission:
from collections import defaultdict

h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

cnt = [0] * 10
for v in d.values():
    cnt[v] += 1

cnt[0] = (h - 2) * (w - 2) - sum(cnt[1:])
print(*cnt, sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, x = map(int, input().split())
a = list(map(int, input().split()))

rec = [[0] * n for _ in range(n)]
for i in range(n):
    mn = a[i]
    for j in range(n):
        mn = min(mn, a[i-j])
        rec[i][j] = mn

rec = np.array(rec, dtype=np.int32)

ans = float("inf")
for j in range(n):
    second = rec[:, j].sum() + j * x
    ans = min(ans, second)

print(ans)


Fixed submission:
import numpy as np

n, x = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype=np.int32)

rec = np.zeros((n, n), dtype=np.int32)
for i in range(n):
    a_tmp = np.concatenate([a[i::-1], a[-1:i:-1]])
    np.minimum.accumulate(a_tmp, out=rec[i])

ans = float("inf")
for j in range(n):
    second = rec[:, j].sum() + j * x
    ans = min(ans, second)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, x = map(int, input().split())
a = list(map(int, input().split()))

rec = [[0] * n for _ in range(n)]
for i in range(n):
    mn = a[i]
    for j in range(n):
        mn = min(mn, a[i-j])
        rec[i][j] = mn

sm_li = []
for j in range(n):
    sm = 0
    for i in range(n):
        sm += rec[i][j]
    sm_li.append(sm)

ans = float("inf")
for j in range(n):
    second = sm_li[j] + j * x
    ans = min(ans, second)

print(ans)


Fixed submission:
import numpy as np

n, x = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype=np.int32)

rec = np.zeros((n, n), dtype=np.int32)
for i in range(n):
    a_tmp = np.concatenate([a[i::-1], a[-1:i:-1]])
    np.minimum.accumulate(a_tmp, out=rec[i])

ans = float("inf")
for j in range(n):
    second = rec[:, j].sum() + j * x
    ans = min(ans, second)

print(ans)