Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03142 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [set() for i in range(n+1)]

for a, b in A:
    T[a].append(b)
    RT[b].add(a)

D = [0] * (n+1)
P = [0] * (n+1)
used = [0] * (n+1)

def dfs(p, i, depth):
    if used[i]:
        return None
    D[i] = depth
    P[i] = p
    used[i] = True
    for t in tuple(T[i]):
        RT[t].remove(i)
    for t in tuple(T[i]):
        if not RT[t]:
            dfs(i, t, depth+1)

def root(i):
    if not RT[i]:
        return i
    return root(tuple(RT[i])[0])

dfs(0, root(1), 1)
for p in P[1:]:
    print(p)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
import heapq as q

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]

for a, b in A:
    T[a].append(b)
    RT[b].append(a)

D = [0] * (n+1)
P = [0] * (n+1)
used = [False] * (n+1)

def bfs(p):
    Q = []
    q.heappush(Q, (-1, 0, p))
    while Q:
        depth, p, v = Q.heappop(Q)
        if used[v]:
            continue
        used[v] = True
        D[v] = depth
        P[v] = p
        for t in T[v]:
            q.heappush(Q, (depth - 1, p, t))

def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])

bfs(root(1))
for p in P[1:]:
    print(p)

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]

for a, b in A:
    T[a].append(b)
    RT[b].append(a)

D = [0] * (n+1)
P = [0] * (n+1)

def dfs(p, i, depth):
    if depth > D[i]:
        D[i] = depth
        P[i] = p
    for t in T[i]:
        dfs(i, t, depth+1)

def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])

dfs(0, root(1), 1)
for p in P[1:]:
    print(p)
Problem p03157 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

H, W = [int(i) for i in input().split()]
S = [[j for j in input()]for i in range(H)]

INF = int(1e12)

def dfs(h, w, p):
    b_cnt = 0
    w_cnt = 0
    if h < 0 or h >= H or w < 0 or w >= W:
        return 0, 0
    if S[h][w] == p or S[h][w] == 'x':
        return 0, 0
    if S[h][w] == '#':
        b_cnt += 1
    elif S[h][w] == '.':
        w_cnt += 1
    t = S[h][w]
    S[h][w] = 'x'

    for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        res = dfs(h + dh, w + dw, t)
        b_cnt += res[0]
        w_cnt += res[1]

    return (b_cnt, w_cnt)

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            b_cnt, w_cnt = dfs(h, w, '.')
            ans += b_cnt * w_cnt

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
S = [[j for j in input()]for i in range(H)]

INF = int(1e12)

def dfs(h, w, p):
    b_cnt = 0
    w_cnt = 0
    if h < 0 or h >= H or w < 0 or w >= W:
        return 0, 0
    if S[h][w] == p or S[h][w] == 'x':
        return 0, 0
    if S[h][w] == '#':
        b_cnt += 1
    elif S[h][w] == '.':
        w_cnt += 1
    t = S[h][w]
    S[h][w] = 'x'

    for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        res = dfs(h + dh, w + dw, t)
        b_cnt += res[0]
        w_cnt += res[1]

    return (b_cnt, w_cnt)

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            b_cnt, w_cnt = dfs(h, w, '.')
            ans += b_cnt * w_cnt

print(ans)
Problem p03166 (python)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(m)]

E = [[] for i in range(n+1)]

for a, b in X:
    E[a].append(b)

memo = [-1] * (n+1)

def dfs(i):
    if memo[i] != -1:
        return memo[i] + 1
    if not E[i]:
        return 0

    memo[i] = max(dfs(e) for e in E[i])
    return memo[i] + 1

print(max(dfs(i) for i in range(1, n+1)))

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for j in range(m)]

E = [[] for i in range(n+1)]

for a, b in X:
    E[a].append(b)

memo = [-1] * (n+1)

def dfs(i):
    if memo[i] != -1:
        return memo[i] + 1
    if not E[i]:
        return 0

    memo[i] = max(dfs(e) for e in E[i])
    return memo[i] + 1

print(max(dfs(i) for i in range(1, n+1)))
Problem p03196 (python)

Fixed submission:
from collections import defaultdict
from math import sqrt

n, p = [int(i) for i in input().split()]

A = defaultdict(int)

def factorize(n):    
    i = 2
    
    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] += 1

    return A

factorize(p)
ans = 1
for k, v in A.items():
    if v >= n:
        ans *= k ** (v // n)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(input()) for i in range(n)]
B = [i % 2 for i in A]

print('first' if sum(B) % 2 != 0 or (any(b == 1 for b in B) and (max(A) - min(A)) <= 1) else 'second')
Problem p03200 (python)

Fixed submission:
S = input()

ans = 0
f = -1

for i, s in enumerate(S):
    if f != -1 and s == 'W':
        ans += i - f
        f += 1
    elif f == -1 and s == 'B':
        f = i

print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c.keys():
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]

A.sort()
m = 1 << 30
used = [False] * n
ans = 0

def search(ok, ng, n):
    if abs(ok-ng) <= 1:
            return ok
    mid = (ok+ng) // 2
    if A[mid] < n or (A[mid] == n and used[mid]):
        return search(mid, ng, n)
    else:
        return search(ok, mid, n)

for i in range(30):
    for j in range(n):
        if used[j] or A[j] >= m:
            continue
        a = search(-1, n, m - A[j]) + 1
        if a >= n:
            continue
        if A[a] == m - A[j]:
            if a == j:
                a += 1
                if a >= n or not A[a] == A[j]:
                    continue
            used[a] = True
            used[j] = True
            ans += 1
    m >>= 1

print(ans)
Problem p03210 (python)

Fixed submission:
n = int(input())
print('YES' if n == 3 or n == 5 or n == 7 else 'NO')

Buggy submission (verdict: Runtime Error):
from math import log10

n = int(input())
m = int(log10(n)) + 1

ans = 0

def dfs(i, s):
    if i == m:
        if not '0' in all(a in str(int(s)) a in '753') and int(s) <= n:
            return 1
        return 0
    res = 0
    for a in '0357':
        res += dfs(i+1, s + a)
    return res

print(dfs(0, ''))
Problem p03231 (python)

Fixed submission:
from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

SA = set()
SB = set()

for i in range(0, g, g//n):
    SA.add(i)

for i in range(0, g, g//m):
    SB.add(i)

SC = SA & SB

for s in SC:
    if S[s//(g//n)] != T[s//(g//m)]:
        print(-1)
        exit()

print(g)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

try:

    L = [''] * g

except:
    print(-1)

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

for i, s in zip(range(0, g, g//n), S):
    L[i] = s

for i, t in zip(range(0, g, g//m), T):
    L[i] = t
    
A = []
B = []

for i in range(0, g, g//n):
    A.append(L[i])

for i in range(0, g, g//m):
    B.append(L[i])

if ''.join(A) == S and ''.join(B) == T:
    print(g)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

L = [''] * g
if S[0] != T[0]:
    print(-1)
    exit()

try:
    for i, s in zip(range(0, g, g//n), S):
        L[i] = s

    for i, t in zip(range(0, g, g//m), T):
        L[i] = t
        
    A = []
    B = []

    for i in range(0, g, g//n):
        A.append(L[i])

    for i in range(0, g, g//m):
        B.append(L[i])

    if ''.join(A) == S and ''.join(B) == T:
        print(g)
    else:
        print(-1)

except:
    print(-1)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

n, m = [int(i) for i in input().split()]
S = input()
T = input()

g = n * m // gcd(n, m)

L = [''] * g
if S[0] != T[0]:
    print(-1)
    exit()

for i, s in zip(range(0, g, g//n), S):
    L[i] = s

for i, t in zip(range(0, g, g//m), T):
    L[i] = t
    
A = []
B = []

for i in range(0, g, g//n):
    A.append(L[i])

for i in range(0, g, g//m):
    B.append(L[i])

if ''.join(A) == S and ''.join(B) == T:
    print(g)
else:
    print(-1)
Problem p03240 (python)

Fixed submission:
n = int(input())
X = [[int(i) for i in input().split()] for j in range(n)]

X.sort(key=lambda x:x[2], reverse=True)

for h in range(101):
    for w in range(101):
        x, y, z = X[0]
        d = z + abs(x-w) + abs(y-h)
        for x, y, z in X:
            d2 = z + abs(x-w) + abs(y-h)
            if z == 0:
                if d2 < d:
                    break 
            elif d2 != d:
                break
        else:
            print(w, h, d)
            exit()

Buggy submission (verdict: Runtime Error):
n = int(input())
X = [[int(i) for i in input().split()] for j in range(n)]

x_s = 0
x_e = 100
y_s = 0
y_e = 100

for x, y, z in X:
    for x2, y2, z2 in X:
        if (x, y) == (x2, y2):
            continue
        d = abs(x-x2) + abs(y-y2)
        if d == z - z2:            
            if x < x2:
                x_e = min(x_e, x) #左側
            elif x > x2:
                x_s = max(x_s, x) #右側
            if y < y2:
                y_e = min(y_e, y) #上川
            else y > y2:
                y_s = max(y_s, y) #下側

        else:
            if x < x2:
                x_s = max(x_s, x) #左側
            elif x > x2:
                x_e = min(x_e, x) #右側
            if y < y2:
                y_s = max(y_s, y) #上川
            elif y > y2:
                y_e = min(y_e, y) #下側

x, y, z = X[0]
print(x_e, y_e, z + abs(x_e - x) + abs(y_e - y))
Problem p03255 (python)

Fixed submission:
n, p = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = []
S = [0]

for x in X:
    S.append(S[-1] + x)

for t in range(1, n+1):
    cur = n - t
    time = 5
    tmp = time * (S[-1] - S[cur]) + (t + n) * p
    cur -= t
    while True:
        tmp += time * (S[cur+t] - S[max(0,cur)])
        if cur <= 0:
            break
        cur -= t
        time += 2

    ans.append(tmp)

print(min(ans))

Buggy submission (verdict: Runtime Error):
n, p = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

memo = [[-1] * (n+1) for i in range(n+1)]

def dfs(i, k):
    if memo[i][k] != -1:
        return memo[i][k]
    elif i == 0:
        return min(p + (k+2) ** 2 * X[i] + p, (k + 1) ** 2 * X[i] + p + X[i] + p + 4 * X[i] + p)

    memo[i][k] = min(dfs(i-1, k+1) + p + (k+2) ** 2 * (X[i] - X[i-1]),
                    dfs(i-1, 1) + (k + 1) ** 2 * X[i] + p + X[i] + p + 4 * (X[i] - X[i-1]))

    return memo[i][k]

print(dfs(n-1, 0) + X[-1])
Problem p03263 (python)

Fixed submission:
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]

ans = []
dx = -1
w = 0

for h in range(H):
    dx *= -1
    for j in range(W):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            a = [h+1, w+1]
            if w + dx < 0 or w + dx >= W:
                if h + 1 == H:
                    break
                A[h+1][w] += 1
                a += [h+2, w+1]
            else:
                w += dx
                A[h][w] += 1
                a += [h+1, w+1]
            ans.append(a)
            
        elif 0 <= w + dx < W:
            w += dx
            
            
        

print(len(ans))
for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]

ans = []
dx = -1
w = 0

for h in range(H):
    dx *= -1
    for j in range(W):
        if A[h][w] % 2 == 1:
            A[h][w] -= 1
            a = [h+1, w+1]
            if w + dx < 0 or w + dx >= W:
                if h + 1 == H:
                    break
                A[h+1][w] += 1
                a += [h+2, w+1]
            else:
                A[h][w+dx] += 1
                a += [h+1, w+1+dx]
            ans.append(a)
        w += dx
        
print(len(ans))
for a in ans:
    print(*a)
Problem p03266 (python)

Fixed submission:
n, k = [int(i) for i in input().split()]

ans = [0, 0]
d = k // 2

for i in range(1, n+1):
    if k % 2 == 0 and i % k == d:
        ans[0] += 1
    if i % k == 0:
        ans[1] += 1

print(ans[0] ** 3 + ans[1] ** 3)

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]

ans = [0, 0]

for i in range(1, n+1):
    if k % 2 == 0 and i % k == d:
        ans[0] += 1
    if i % k == 0:
        ans[1] += 1

print(ans[0] ** 3 + ans[1] ** 3)
Problem p03352 (python)

Fixed submission:
x = int(input())

def is_power(a, b):
  while a % b == 0:
    a = a / b
  if a == 1:
    return True
  return False

def is_perfect_power(n):
    for i in range(n//2, 1, -1):
        if is_power(n, i):
            return True
    return False

ans = 1

for i in range(x, 1, -1):
    if is_perfect_power(i):
        ans = i
        break

print(ans)

Buggy submission (verdict: Runtime Error):
from sympy import perfect_power

x = int(input())

ans = 1

for i in range(x, 1, -1):
    if perfect_power(i):
        ans = i
        break

print(ans)
Problem p03362 (python)

Fixed submission:
n = int(input())

def prime():
    p = [2]
    m = 3
    while m < 1400:
        for i in p:
            if m % i == 0:
                break
        else:
            p.append(m)
        m += 2
    return p

ans = []
p = prime()
q = p[1:]

while len(ans) < n:
    for i, q_ in enumerate(q):
        if q_ % 5 == 1:
            ans.append(q_)
            del q[i]
            break

print(' '.join([str(s) for s in ans]))

Buggy submission (verdict: Runtime Error):
n = int(input())

def prime():
    p = [2]
    m = 3
    while m < 1400:
        for i in p:
            if m % i == 0:
                break
        else:
            p.append(m)
        m += 2
    return p

ans = []
q = p[1:]

while len(ans) < n:
    for i, q_ in enumerate(q):
        if q_ % 5 == 1:
            ans.append(q_)
            del q[i]
            break

print(' '.join([str(s) for s in ans]))
Problem p03363 (python)

Fixed submission:
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]

a_ = [0]

for i in range(n):
    a_.append(a_[i] + a[i])

cnt = 0

def sum(i):
    return int((i + 1) / 2 * i)

for i in Counter(a_).values():
    cnt += sum(i-1)

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]

cnt = 0

for i in range(n):
    i_ = (n+i)%n
    for k in range(n):
        for l in range(n):
            if s[(i_+k)%n][l] != s[(i_+l)%n][k]:
                break
        else:
            continue
        break
    else:
        cnt += 1

print(cnt*n)
Problem p03364 (python)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry(s_):
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return False
    return True

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry(s_):
        cnt += 1

print(cnt*n)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry():


for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                break
        else:
            continue
        break
    else:
        cnt += 1

print(cnt*n)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry(s_):
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return false
    return true

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry(s_):
        cnt += 1

print(cnt*n)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry():
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return false
    return true

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry():
        cnt += 1

print(cnt*n)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry():
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return false
    return true

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry()
        cnt += 1

print(cnt*n)
Problem p03427 (python)

Fixed submission:
N_list = [int (i) for i in list(input())]
digit = 0
dflag = False
max = 0
for i in N_list:
    max += i

for i in N_list:
    if i == 9:
        dflag = True
    else:
        break

    digit += 1

if dflag:
    N_list[digit-1] -=1
    for i in range(digit, len(N_list)):
        N_list[i] = 9

else:
    N_list[digit] -=1
    for i in range(digit+1, len(N_list)):
        N_list[i] = 9

sum = 0

for i in N_list:
    sum += i

if sum > max:
    max = sum
print (max)

Buggy submission (verdict: Runtime Error):
N = [int(x) for x in input()]
print(max(sum(N), N[0]-1+9*len(N))
Problem p03764 (python)

Fixed submission:
n, m = [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]
Y = [0] + [int(i) for i in input().split()]

p = 10 ** 9 + 7

xsum = 0
ysum = 0

for i in range(1, n+1):
  xsum += (2*i-n-1) * X[i] 
  
for i in range(1, m+1):
  ysum += (2*i-m-1) * Y[i] 

print(xsum * ysum % p)

Buggy submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]

p = 10 ** 9 + 7

ans = 0
xc = n // 2
yc = m // 2
n -= 1
m -= 1
h = Y[-1] - Y[0]
w = X[-1] - X[0]

if n % 2 == 0 and m % 2 == 0:
    ans = n * m * h * w

elif n % 2 == 1 and m % 2 == 1:
    xd = X[xc] - X[xc-1]
    yd = Y[yc] - Y[yc-1]
    ans = n * (m+1) * d * (h - yd) + (n+1) * m * d * (w - xd) + (n+1) * (m+1) * yd * xd + n * m * (w - xd) * (h - yd)

elif n % 2 == 1:
    d = X[xc] - X[xc-1]
    ans = (n * (m+1) * d + (w - d)) * h

elif n % 2 == 1:
    d = Y[yc] - Y[yc-1]
    ans = ((n+1) * m * d + (h - d)) * w

print(ans % p)
Problem p03829 (python)

Fixed submission:
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * X[i+1] - X[i], b)

print(ans)

Buggy submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * X[i+1] - b)

print(ans)
Problem p04000 (python)

Fixed submission:
h, w, n = [int(i) for i in input().split()]
if n == 0:
  a = b = [0] 
else:
  a, b = zip(*
  [[int(i) for i in input().split()] for j in range(n)])

board = { }

ans = [0] * 10
ans[0] = max(0, (h-2)) * max(0, (w-2))

for a, b in zip(a, b):
  for i in range(max(2, a-1), min(h, a+2)):
    for j in range(max(2, b-1), min(w, b+2)):
      try:
        ans[board.get((i, j), 0)] -= 1
        board[(i, j)] = board.get((i, j), 0) + 1
        ans[board[(i, j)]] += 1
      except:
        pass

for i in range(10):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
h, w, n = [int(i) for i in input().split()]
if n == 0:
  for i in range(10):
    print(0)
    exit(0)
a, b = zip(*
  [[int(i) for i in input().split()] for j in range(n)])

board = [[0]*(w+1) for i in range(h+1)]

ans = [0] * 10
ans[0] = min(0, (h-2)) * min(0, (w-2))

for a, b in zip(a, b):
  for i in range(max(2, a-1), min(h, a+2)):
    for j in range(max(2, b-1), min(w, b+2)):
      try:
        ans[board[i][j]] -= 1
        board[i][j] += 1
        ans[board[i][j]] += 1
      except:
        pass

for i in range(10):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
h, w, n = [int(i) for i in input().split()]
a, b = zip(*
  [[int(i) for i in input().split()] for j in range(n)])

board = [[0]*(w+1) for i in range(h+1)]

ans = [0] * 10
ans[0] = (h-2) * (w-2)

for a, b in zip(a, b):
  for i in range(max(2, a-1), min(h, a+2)):
    for j in range(max(2, b-1), min(w, b+2)):
      try:
        ans[board[i][j]] -= 1
        board[i][j] += 1
        ans[board[i][j]] += 1
      except:
        pass

for i in range(0, 10):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
h, w, n = [int(i) for i in input().split()]
a, b = zip(*
  [[int(i) for i in input().split()] for j in range(n)])

board = [[0]*(w+1) for i in range(h+1)]

ans = [0] * 9
ans[0] = (h-2) * (w-2)

for a, b in zip(a, b):
  for i in range(max(2, a-1), min(h, a+2)):
    for j in range(max(2, b-1), min(w, b+2)):
      try:
        ans[board[i][j]] -= 1
        board[i][j] += 1
        ans[board[i][j]] += 1
      except:
        pass

for i in range(0, 9):
  print(ans[i])