Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

MOD = 998244353
N, A, B, K =map(int,input().split())

f = Factorial(N, MOD)

res = 0

for i in range(N + 1):
    if (K - A * i) % B == 0:
        j = (K - A * i) // B
        res += f.comb(N, i) * f.comb(N, j)
        res %= MOD
        
print(res)

Fixed submission:
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

def ex_euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1
    while c1:
        a0, a1 = a1, a0 - c0 // c1 * a1
        b0, b1 = b1, b0 - c0 // c1 * b1
        c0, c1 = c1, c0 % c1
    return c0, a0, b0

MOD = 998244353
N, A, B, K =map(int,input().split())

f = Factorial(N, MOD)
c, a, b = ex_euclid(A, B)

if K == 0:
    print(1)

elif K % c != 0:
    print(0)

else:
    lo = -10**18
    hi = 10**18
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if a * K // c + mid * B // c >= 0:
            hi = mid
        else:
            lo = mid
    x0 = a * K // c + hi * B // c

    lo = -10**18
    hi = 10**18
    while hi - lo > 1:
        mid = (hi + lo) // 2
        if b * K // c - mid * A // c >= 0:
            lo = mid
        else:
            hi = mid
    y0 = b * K // c - lo * A // c

    res = 0
    x = x0
    y = (K - A * x0) // B

    while True:
        res += f.comb(N, x) * f.comb(N, y)
        res %= MOD
        if y == y0:
            break
        x += B // c
        y -= A // c

    print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
c = []
for i in range(1,n-1):
  r = []
  for t in s[:i+1]:
    if t in s[i+1:]:
      r += [t]
  c += [len(set(r))]
print(max(c))

Fixed submission:
n = int(input())
s = input()
c = []
for i in range(1,n):
  r = []
  for t in s[:i]:
    if t in s[i:]:
      r += [t]
  c += [len(set(r))]
print(max(c))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

ans = 0

for i in range(N):
    x = i
    y = 0
    
    for j in range(N**2):
        dx = j//N
        dy = j%N
        
        if S[(x+dx)%N][(y+dy)%N]!=S[(x+dy)%N][(y+dx)%N]:
            break
    else:
        ans += N
        
print(ans)

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]

ans = 0

for k in range(N):
    symmetry = True
    
    for i in range(N-1):
        for j in range(i+1,N):
            
            if S[(k+i)%N][j]!=S[(k+j)%N][i]:
                symmetry = False
                
    if symmetry:
        ans += N
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
List = [x for x in range(a,b+1) if x <= a+k-1 or x >= b-k+1]
for x in List: print(x)

Fixed submission:
a,b,k = map(int,input().split())
X = [i for i in range(a,a+k) if i <= b]
Y = [i for i in range(b-k+1,b+1) if a <= i]
Z = sorted(list(set(X+Y)))
for z in Z: print(z)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
S = [list(map(int,input().split())) for i in range(Q)]
P = [None]*(H*W)
for i in range(H):
    for j in range(W):
        P[A[i][j]-1] = [i,j]
for q in range(Q):
    mp = 0
    left = S[q][0]-1
    for d in range((S[q][1]-S[q][0])//D):
        mp += abs(P[left][0]-P[left+D][0])+abs(P[left][1]-P[left+D][1])
        left += D
    print(mp)

Fixed submission:
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
S = [list(map(int,input().split())) for i in range(Q)]
P = [None]*(H*W+1)
for i in range(H):
    for j in range(W):
        P[A[i][j]] = [i,j]

Accum = [0]*(H*W+1)
accum = 0

for i in range(D+1,H*W+1):
    Accum[i] = Accum[i-D]+abs(P[i][0]-P[i-D][0])+abs(P[i][1]-P[i-D][1])

for s in S:
    print(Accum[s[1]]-Accum[s[0]])

Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
S = [list(map(int,input().split())) for i in range(Q)]
P = [None]*(H*W)
for i in range(H):
    for j in range(W):
        P[A[i][j]-1] = [i,j]
for q in range(Q):
    mp = 0
    left = S[q][0]-1
    for d in range((S[q][1]-S[q][0])//D):
        mp += abs(P[left][0]-P[left+D][0])+abs(P[left][1]-P[left+D][1])
        left += D
    print(mp)

Fixed submission:
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
S = [list(map(int,input().split())) for i in range(Q)]
P = [None]*(H*W+1)
for i in range(H):
    for j in range(W):
        P[A[i][j]] = [i,j]

Accum = [0]*(H*W+1)
accum = 0

for i in range(D+1,H*W+1):
    Accum[i] = Accum[i-D]+abs(P[i][0]-P[i-D][0])+abs(P[i][1]-P[i-D][1])

for s in S:
    print(Accum[s[1]]-Accum[s[0]])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lowid= 0
highid = N-1
print(0,flush=True)
lowsex = input()
if lowsex=='Vacant':
    exit()
print(N-1,flush=True)
highsex = input()
if highsex=='Vacant':
    exit()
while highid-lowid>1:
    midid = (lowid+highid)//2
    print(midid,flush=True)
    midsex = input()
    if midsex=='Vacant':
        exit()
    if (midid-lowid)%2==1 and midsex==lowsex:
        highid = midid
        highsex = midsex
    elif (midid-lowid)%2==0 and midsex!=lowsex:
        highid = midid
        highsex = midsex
    else:
        lowid = midid
        lowsex = midsex

Fixed submission:
N = int(input())
lowid= 0
highid = N-1
print(0)
lowsex = input()
if lowsex=='Vacant':
    exit()
print(N-1)
highsex = input()
if highsex=='Vacant':
    exit()
while highid-lowid>1:
    midid = (lowid+highid)//2
    print(midid)
    midsex = input()
    if midsex=='Vacant':
        exit()
    if (midid-lowid)%2==1 and midsex==lowsex:
        highid = midid
        highsex = midsex
    elif (midid-lowid)%2==0 and midsex!=lowsex:
        highid = midid
        highsex = midsex
    else:
        lowid = midid
        lowsex = midsex

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lowid= 0
highid = N-1
print(0,flush=True)
lowsex = input()
if lowsex=='Vacant':
    exit()
print(N-1,flush=True)
highsex = input()
if highsex=='Vacant':
    exit()
while high-low>1:
    midid = (lowid+highid)//2
    print(midid,flush=True)
    midsex = input()
    if midsex=='Vacant':
        exit()
    if (midid-lowid)%2==1 and midsex==lowsex:
        highid = midid
        highsex = midsex
    elif (midid-lowid)%2==0 and midsex!=lowsex:
        highid = midid
        highsex = midsex
    else:
        lowid = midid
        lowsex = midsex

Fixed submission:
N = int(input())
lowid= 0
highid = N-1
print(0)
lowsex = input()
if lowsex=='Vacant':
    exit()
print(N-1)
highsex = input()
if highsex=='Vacant':
    exit()
while highid-lowid>1:
    midid = (lowid+highid)//2
    print(midid)
    midsex = input()
    if midsex=='Vacant':
        exit()
    if (midid-lowid)%2==1 and midsex==lowsex:
        highid = midid
        highsex = midsex
    elif (midid-lowid)%2==0 and midsex!=lowsex:
        highid = midid
        highsex = midsex
    else:
        lowid = midid
        lowsex = midsex
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
A = list(map(int,input().split()))

high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)

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

high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)

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

high = 10**18
low = -1

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = -1

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)

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

high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))

if N >= 24:
    print(0)

else:
    res = 0
    for bit in range(2**N):
        d = [0 for _ in range(24)]
        for i in range(N):
            if (bit >> i) & 1:
                d[D[i]] += 1
            else:
                d[(24 - D[i]) % 24] += 1
        md = 25
        tmp = 0
        for i in range(24):
            if d[i] > 1:
                md = 0
                break
            elif d[i] == 1:
                md = min(md, i - tmp)
                tmp = i
        md = min(24 - tmp, md)
        res = max(res, md)
    print(res)

Fixed submission:
from copy import deepcopy

N = int(input())
D = list(map(int,input().split()))
T = [0 for _ in range(13)]
ans = 0

for i in range(N):
    if D[i]==0:
        print(0)
        break
    T[D[i]] += 1
    if T[D[i]] >=3:
        print(0)
        break
        
else:
    C = [0]
    S = []
    for j in range(13):
        if T[j]==2:
            C.append(j)
            C.append(-j)
        elif T[j]==1:
            S.append(j)

    for j in range(2**len(S)):
        CC = deepcopy(C)
        for k in range(len(S)):
            if ((j >> k) & 1):
                CC.append(S[k])
            else:
                CC.append(-S[k])
                
        mind = 25
        for p in range(N):
            for q in range(p+1,N+1):
                mind = min(mind,min(abs(CC[p]-CC[q]),24-abs(CC[p]-CC[q])))
        ans = max(ans,mind)
        
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

count = 0
for i in range(n):
    b = bisect.bisect(B,A[i])
    for j in range(b,n):
        c = bisect.bisect(C,B[j])
        count += n-c

print(count)

Fixed submission:
import bisect

n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

count = 0

for i in range(n):
    a = bisect.bisect_left(A,B[i])
    c = bisect.bisect_right(C,B[i])
    count += a*(n-c)
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = ''
for i in range(len(s)):
    if s[i]!='x':
        t += s[i]
for i in range(len(t)):
    if t[i]!=t[-1-i]:
        print(-1)
        break
else:
    ans = 0
    L = []
    R = []
    prevl = -1
    prevr = len(s)
    for i in range(len(s)):
        if s[i]!='x':
            L.append(i-prevl-1)
            prevl = i
        if s[-1-i]!='x':
            R.append(prevr-(len(s)-1-i)-1)
            prevr = len(s)-1-i
    L.append(len(s)-prevl-1)
    R.append(prevr)
    for i in range(len(L)):
        ans += abs(L[i]-R[i])
    print(ans//2)

Fixed submission:
s = input()
t = ''
for i in range(len(s)):
    if s[i]!='x':
        t += s[i]
for i in range(len(t)):
    if t[i]!=t[-1-i]:
        print(-1)
        break
else:
    ans = 0
    L = []
    R = []
    prevl = -1
    prevr = len(s)
    for i in range(len(s)):
        if s[i]!='x':
            L.append(i-prevl-1)
            prevl = i
        if s[-1-i]!='x':
            R.append(prevr-(len(s)-1-i)-1)
            prevr = len(s)-1-i
    L.append(len(s)-prevl-1)
    R.append(prevr)
    for i in range(len(L)):
        ans += abs(L[i]-R[i])
    print(ans//2)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

n,k = map(int,input().split())
P = sorted([list(map(int,input().split())) for i in range(n)])

area = float('inf')

for x1,x2 in combinations(range(n),2):
  for y1,y2 in combinations(range(n),2):
    
    point = 0
    for i in range(n):
      if (min(P[x1][0],P[x2][0])<= P[i][0] <=max(P[x1][0],P[x2][0]) 
      and min(P[y1][1],P[y2][1])<= P[i][1] <=max(P[y1][1],P[y2][1])):
        point += 1
    if point==k:
      area = min(area,abs(P[x1][0]-P[x2][0])*abs(P[y1][1]-P[y2][1]))
      
print(area)

Fixed submission:
from itertools import combinations

n,k = map(int,input().split())
Px = sorted([list(map(int,input().split())) for i in range(n)])
Py = sorted(Px,key=lambda p:p[1])

area = float('inf')

for x1 in range(n-1):
    for x2 in range(x1+1,n):
        for y1 in range(n-1):

            point = 0
            for y in range(y1,n):
                if Px[x1][0]<=Py[y][0]<=Px[x2][0]:
                    point += 1
                    if point == k:
                        area = min(area,(Px[x2][0]-Px[x1][0])*(Py[y][1]-Py[y1][1]))
                        break

print(area)
Buggy python submission (verdict: Runtime Error):
A = input()
char = [0 for _ in range(26)]

for i in range(len(A)):
    char[ord(A[i])-96] += 1

ans = 1

for i in range(25):
    for j in range(i+1,26):
        ans += char[i]*char[j]

print(ans)

Fixed submission:
A = input()
char = [0 for _ in range(26)]

for i in range(len(A)):
    char[ord(A[i])-97] += 1

ans = 1

for i in range(25):
    for j in range(i+1,26):
        ans += char[i]*char[j]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
town = [list(map(int,input().split()))+[i] for i in range(N)]

townx = sorted(town)
towny = sorted(town,key = lambda t : t[1])

heap = []
heapq.heapify(heap)

for i in range(N-1):
    heapq.heappush(heap,[abs(townx[i][0]-townx[i+1][0]),townx[i][2],townx[i+1][2]])
    heapq.heappush(heap,[abs(towny[i][1]-towny[i+1][1]),towny[i][2],towny[i+1][2]])

uf = UnionFind(N)
ans = 0

while heap:
    cost,t1,t2 = heapq.heappop(heap)
    if uf.same(t1,t2):
        continue
    uf.union(t1,t2)
    ans += cost
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
town = [list(map(int,input().split()))+[i] for i in range(N)]

townx = sorted(town)
towny = sorted(town,key = lambda t : t[1])

road = []

for i in range(N-1):
    road.append([abs(townx[i][0]-townx[i+1][0]),townx[i][2],townx[i+1][2]])
    road.append([abs(towny[i][1]-towny[i+1][1]),towny[i][2],towny[i+1][2]])

road.sort()

uf = UnionFind(N)
ans = 0

for r in road:
    cost,t1,t2 = r
    if uf.same(t1,t2):
        continue
    uf.union(t1,t2)
    ans += cost
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
I = [tuple(map(int, input().split())) for _ in range(N)]
w0 = I[0][0]

dp = [[[0 for k in range(N * 3 + 1)] for j in range(N + 1)] for i in range(N + 1)]

for i in range(N):
    w, v = I[i]
    for j in range(N):
        for k in range(3 * N + 1):
            if k - (w - w0) >= 0:
                dp[i + 1][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k - (w - w0)] + v)
            else:
                dp[i + 1][j + 1][k] = dp[i][j + 1][k]

res = 0


for j in range(N + 1):
    for k in range(3 * N + 1):
        if w0 * j + k <= W:
            res = max(res, dp[N][j][k])

print(res)

Fixed submission:
N,W = map(int,input().split())
item = [list(map(int,input().split())) for i in range(N)]
w = item[0][0]

dp = [[[0 for k in range(3*N+1)] for j in range(N+1)] for i in range(N+1)]

for i in range(1,N+1):
    for j in range(1,i+1):
        for k in range(3*j+1):
            if item[i-1][0]-w <= k:
                dp[i][j][k] = max(dp[i-1][j-1][k-(item[i-1][0]-w)]+item[i-1][1],dp[i-1][j][k])
            else:
                dp[i][j][k] = dp[i-1][j][k]
                
ans = 0
for j in range(N+1):
    for k in range(3*N+1):
        if j*w+k <= W:
            ans = max(ans,dp[N][j][k])
            
print(ans)
Buggy python submission (verdict: Runtime Error):
5
1 1 1 1 1

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

A.sort()

B = [0 for _ in range(N)]
b = 0
for i in range(N):
    b += A[i]
    B[i] = b

ans = 1
for i in range(N-1):
    if 2*B[i]>=A[i+1]:
        ans += 1
    else:
        ans = 1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A == B:
	print('Draw')
elif A == 1:
	pirnt('Alice')
elif B == 1:
	print('Bob')
elif A > B:
	print('Alice')
else:
	print('Bob')          


Fixed submission:
A, B = map(int, input().split())
if A == B:
	print('Draw')
elif A == 1:
	print('Alice')
elif B == 1:
	print('Bob')
elif A > B:
	print('Alice')
else:
	print('Bob')

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A == B:
	print('Draw)
elif A == 1:
	pirnt('Alice')
elif B == 1:
	print('Bob')
elif A > B:
	print('Alice')
else:
	print('Bob')          

Fixed submission:
A, B = map(int, input().split())
if A == B:
	print('Draw')
elif A == 1:
	print('Alice')
elif B == 1:
	print('Bob')
elif A > B:
	print('Alice')
else:
	print('Bob')
Buggy python submission (verdict: Runtime Error):
A, op, B = map(int, input().split())
if op == '+':
  print(A + B)
else:
  print(A - B)

Fixed submission:
A, op, B = input().split()
A = int(A)
B = int(B)
if op == '+':
  print(A + B)
else:
  print(A - B)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())
D = defaultdict(bool)
B = []

for _ in range(N):
    a,b = map(lambda x: int(x)-1,input().split())
    D[(a,b)] = True
    B.append((a,b))

ans = [0 for _ in range(10)]

for a,b in B:
    for i in range(9):
        ix,iy = divmod(i,3)
        if a-ix<0 or b-iy<0:
            continue
        black_count = 0
        for j in range(9):
            jx,jy = divmod(j,3)
            if H<=a-ix+jx or W<=b-iy+jy:
                break
            if D[(a-ix+jx,b-iy+jy)]:
                if -ix+jx<0 or (-ix+jx==0 and -iy+jy<0):
                    break
                black_count += 1
        else:
            ans[black_count] += 1

ans[0] = (H-2)*(W-2)-sum(ans)
print(*ans,sep='\n')

Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())
D = defaultdict(bool)
B = []

for _ in range(N):
    a,b = map(lambda x: int(x)-1,input().split())
    D[(a,b)] = True
    B.append((a,b))

ans = [0 for _ in range(10)]

for a,b in B:
    for i in range(9):
        ix,iy = divmod(i,3)
        if a-ix<0 or b-iy<0:
            continue
        black_count = 0
        for j in range(9):
            jx,jy = divmod(j,3)
            if H<=a-ix+jx or W<=b-iy+jy:
                break
            if (a-ix+jx,b-iy+jy) in D:
                if -iy+jy<0 or (-iy+jy==0 and -ix+jx<0):
                    break
                black_count += 1
        else:
            ans[black_count] += 1

ans[0] = (H-2)*(W-2)-sum(ans)
print(*ans,sep='\n')
Buggy python submission (verdict: Runtime Error):
N,A = map(int,input().split())
x = list(map(int,input().split()))
X = sum(x)

dp = [[[0 for k in range(X+1)] for j in range(N+1)] for i in range(N)]

for i in range(N):
    for j in range(i+1):
        dp[i][1][x[j]] += 1

for i in range(N-1):
    for j in range(1,i+2):
        for k in range(X+1):
            if 1 <= k-x[i+1] <= X:
                dp[i+1][j+1][k] = dp[i][j+1][k] + dp[i][j][k-x[i+1]]
            else:
                dp[i+1][j+1][k] = dp[i][j+1][k]

ans = 0
for j in range(1,N+1):
    ans += dp[N-1][j][A*j]

print(ans)

Fixed submission:
N,A = map(int,input().split())
x = list(map(int,input().split()))
X = sum(x)

dp = [[[0 for k in range(X+1)] for j in range(N+1)] for i in range(N)]

for i in range(N):
    for j in range(i+1):
        dp[i][1][x[j]] += 1

for i in range(N-1):
    for j in range(1,i+2):
        for k in range(X+1):
            if 1 <= k-x[i+1] <= X:
                dp[i+1][j+1][k] = dp[i][j+1][k] + dp[i][j][k-x[i+1]]
            else:
                dp[i+1][j+1][k] = dp[i][j+1][k]

ans = 0
for j in range(1,N+1):
    if 1 <= A*j <= X:
        ans += dp[N-1][j][A*j]

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
N = len(s)
for i in range(N-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        break
    if i<N-1 and s[i]==s[i+2]:
        print(i+1,i+3)
else:
    print(-1,-1)

Fixed submission:
s = input()
N = len(s)
for i in range(N-1):
    if s[i]==s[i+1]:
        print(i+1,i+2)
        break
    if i<N-2 and s[i]==s[i+2]:
        print(i+1,i+3)
        break
else:
    print(-1,-1)