Problem:


Score : 400 points

Problem Statement

We have a grid with H rows and W columns. At first, all cells were painted white.

Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.

Compute the following:

For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

Constraints

3 \leq H \leq 10^9

3 \leq W \leq 10^9

0 \leq N \leq min(10^5,H×W)

1 \leq a_i \leq H (1 \leq i \leq N)

1 \leq b_i \leq W (1 \leq i \leq N)

(a_i, b_i) \neq (a_j, b_j) (i \neq j)

Input

The input is given from Standard Input in the following format:

H W N
a_1 b_1
:
a_N b_N

Output

Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

Sample Input 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

Sample Output 1

0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

Sample Input 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2

4
26
22
10
2
0
0
0
0
0

Sample Input 3

1000000000 1000000000 0

Sample Output 3

999999996000000004
0
0
0
0
0
0
0
0
0



Sample input:
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4


Sample output:
0
0
0
2
4
0
0
0
0
0

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
rows=[]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
    rows.append(ab[i-1][0])
  if i==N-1:
    r_b.append(N)
    rows.append(ab[N-1][0])

cols=[[ab[j][1] for j in range(r_b[i],r_b[i+1])] for i in range(len(r_b)-1)]

rN=len(cols)

ched_box=[[[[False]*3 for k in range(3)] for j in range((len(cols[i]) if i<rN else 0))] for i in range(3)]

area_n=[0]*9

for rn in range(rN):
  cN=len(cols[rn])
  row=rows[rn]
  if rn!=0:
    ched_box[0]=ched_box[1]
    ched_box[1]=ched_box[2]
    if rn<rN-2:
      ched_box[2]=[[[False]*3 for k in range(3)] for j in range(len(cols[rN+2]))]
  if (rows[rn+1]==row+1 if rn<rN-1 else False):
    row1=row+1
    if (rows[rn+2]==row+2 if rn<rN-2 else False):
      row2=row+2
    else:
      row2=None
  elif (rows[rn+1]==row+2 if rn<rN-1 else False):
    row1=row+2
    row2=None
  else:
    row1=None
    row2=None
  
  for cn in range(cN):
    col=cols[rn][cn]
       
    for boxr in range(3):
      for boxc in range(3):
        if col-2+boxc<1 or col+boxc>W or row-2+boxr<1 or row+boxr>H:
          ched_box[rn][cn][boxr][boxc]=True
    find_ab=[]
    for chr in range(rn,min(rn+3,rN)):
      if chr==rn:
        ch_col=set(cols[chr][cn+1:min(cn+3,cN)])
        for chc in range(min(col+1,W),min(col+3,W+1)):
          if chc in ch_col:
            find_ab.append([row,chc])
      else:
        if rows[chr] in [row+1,row+2]:
          ch_col=set(cols[chr])
          for chc in range(max(col-2,1),min(col+3,W+1)):
            if chc in ch_col:
              find_ab.append([row+chr-rn,chc])

Submission status: Runtime Error

Solution code:
def p_range(start,end,max_n):
  ss=max(start,0)
  ee=min(max_n+1,end)
  return range(ss,ee)

H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
rows=[]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
    rows.append(ab[i-1][0])
rows.append(ab[N-1][0])
r_b.append(N)

cols=[[ab[j][1] for j in range(r_b[i],r_b[i+1])] for i in range(len(r_b)-1)]

rN=len(cols)

ched_box=[[[[False]*3 for k in range(3)] for j in range(len(cols[i]))] for i in range(rN)]

area_n=[0]*9

for rn in range(rN):
  cN=len(cols[rn])
  row=rows[rn]
  if (rows[rn+1]==row+1 if rn<rN-1 else False):
    row1=row+1
    if (rows[rn+2]==row+2 if rn<rN-2 else False):
      row2=row+2
    else:
      row2=None
  elif (rows[rn+1]==row+2 if rn<rN-1 else False):
    row1=row+2
    row2=None
  else:
    row1=None
    row2=None
  
  for cn in range(cN):
    col=cols[rn][cn]
       
    for boxr in range(3):
      for boxc in range(3):
        if col-2+boxc<1 or col+boxc>W or row-2+boxr<1 or row+boxr>H:
          ched_box[rn][cn][boxr][boxc]=True
    find_ab=[]
    for chr in range(rn,min(rn+3,rN)):
      if chr==rn:
        ch_col=set(cols[chr][cn+1:min(cn+3,cN)])
      else:
        if rows[chr] in [row+1,row+2]:
          ch_col=set(cols[chr])
        else:
          ch_col=set([])
      for chc in range(col-2,col+3):
        if chc in ch_col:
          find_ab.append([row+chr-rn,chc])
    
    for boxr in range(3):
      for boxc in range(3):
        if not ched_box[rn][cn][boxr][boxc]:
          count=1
          for i in range(3):
            for j in range(3):
              if [row-2+boxr+i,col-2+boxc+j] in find_ab:
                count+=1
                if row-2+boxr+i==row1:
                  rn_tmp=rn+1
                elif row-2+boxr+i==row2:
                  rn_tmp=rn+2
                else:
                  rn_tmp=rn
                ched_box[rn_tmp][cols[rn_tmp].index(col-2+boxc+j)][2-i][2-j]=True
          area_n[count-1]+=1

print((W-2)*(H-2)-sum(area_n))
for i in range(9):
  print(area_n[i])

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]


checked=[[[[False]*3 for k in range(3)]  for j in range(len(ab[i]))] for i in range(min(3,len(ab)))]

area_n=[0 for i in range(1,10)]  
if N is 0:
  ab=[]



for r_n in range(len(ab)/2):
  if r_n!=0:
    checked[0]=checked[1]
    if len(checked)>=3:
      checked[1]=checked[2]
    if r_n<len(ab)-2 and len(checked)==3:
      checked[2]=[[[False]*3 for k in range(3)]  for j in range(len(ab[r_n+2]))]

  row=ab[r_n][0][0]
  
  ch_list_min_add=[0,0]
  
  for c_n in range(len(ab[r_n])):
    col=ab[r_n][c_n][1]

    if row<=2:
      for box_r in range(3-row):
        for box_c in range(3):
          checked[0][c_n][box_r][box_c]=True
    if row>=H-1:
      for box_r in range(H+1-row,3):
        for box_c in range(3):
          checked[0][c_n][box_r][box_c]=True
    if col<=2:
      for box_r in range(3):
        for box_c in range(3-col):
          checked[0][c_n][box_r][box_c]=True
    if col>=W-1:
      for box_r in range(3):
        for box_c in range(W+1-col,3):
          checked[0][c_n][box_r][box_c]=True
    ch_p_rc=[[],[]]
    min_flag=[True,True]
    ch_start_add=ch_list_min_add[:]
    for ch_r in range(row,min(row+3,H+1)):
      if ch_r==row:
        ch_c=min(col+1,W)
        while(ch_c <min(col+min(3,len(ab[r_n])-c_n),W+1)):
          for j in range(min(c_n+1,len(ab[r_n])-1),min(c_n+3,len(ab[r_n]))):
            if ch_c<ab[r_n][j][1]:
              ch_c=ab[r_n][j][1]
              break
            if ab[r_n][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n,j])
              ch_c+=1
              break
            if j==min(c_n+3,len(ab[r_n]))-1:
              ch_c=min(col+3,W+1)
              
      elif ch_r==row+1 and (ab[r_n+1][0][0]==row+1 if r_n<len(ab)-1 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
          for j in range(ch_start_add[0],len(ab[r_n+1])):
            if ch_c<ab[r_n+1][j][1]:
              ch_c=ab[r_n+1][j][1]
              ch_start_add[0]=j
              if min_flag[0]:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if ab[r_n+1][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+1,j])
              ch_c+=1
              ch_start_add[0]=min(j+1,len(ab[r_n+1])-1)
              if min_flag[0] and ch_c>col-2:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if j==len(ab[r_n+1])-1:
              ch_c=min(col+3,W+1)
      elif ch_r==row+2 and (ab[r_n+1][0][0]==row+2 if r_n<len(ab)-1 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
           for j in range(ch_start_add[0],len(ab[r_n+1])):
            if ch_c<ab[r_n+1][j][1]:
              ch_c=ab[r_n+1][j][1]
              ch_start_add[0]=j
              if min_flag[0]:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if ab[r_n+1][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+1,j])
              ch_c+=1
              ch_start_add[0]=min(j+1,len(ab[r_n+1])-1)
              if min_flag[0] and ch_c>col-2:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if j==len(ab[r_n+1])-1:
              ch_c=min(col+3,W+1)
      elif ch_r==row+2 and (ab[r_n+2][0][0]==row+2 if r_n<len(ab)-2 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
          for j in range(ch_start_add[1],len(ab[r_n+2])):
            if ch_c<ab[r_n+2][j][1]:
              ch_c=ab[r_n+2][j][1]
              ch_start_add[1]=j
              if min_flag[1]:
                min_flag[1]=False
                ch_list_min_add[1]=j
              break
            if ab[r_n+2][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+2,j])
              ch_c+=1
              ch_start_add[1]=min(j+1,len(ab[r_n+2])-1)
              if min_flag[1] and ch_c>col-2:
                min_flag[1]=False
                ch_list_min_add[1]=j
              break
            if j==len(ab[r_n+2])-1:
              ch_c=min(col+3,W+1)

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]

checked=[[[[False]*3 for k in range(3)]  for j in range(len(ab[i]))] for i in range(3)]

area_n=[0 for i in range(1,10)]  

for r_n in range(len(ab)):
  if r_n!=0:
    checked[0]=checked[1]
    checked[1]=checked[2]
    if r_n<len(ab)-2:
      checked[2]=[[[False]*3 for k in range(3)]  for j in range(len(ab[r_n+2]))]

  row=ab[r_n][0][0]
  
  ch_list_min_add=[0,0]
  
  for c_n in range(len(ab[r_n])):
    col=ab[r_n][c_n][1]

    if row<=2:
      for box_r in range(3-row):
        for box_c in range(3):
          checked[0][c_n][box_r][box_c]=True
    if row>=H-1:
      for box_r in range(H+1-row,3):
        for box_c in range(3):
          checked[0][c_n][box_r][box_c]=True
    if col<=2:
      for box_r in range(3):
        for box_c in range(3-col):
          checked[0][c_n][box_r][box_c]=True
    if col>=W-1:
      for box_r in range(3):
        for box_c in range(W+1-col,3):
          checked[0][c_n][box_r][box_c]=True
    ch_p_rc=[[],[]]
    min_flag=[True,True]
    ch_start_add=ch_list_min_add[:]
    for ch_r in range(row,min(row+3,H+1)):
      if ch_r==row:
        ch_c=min(col+1,W)
        while(ch_c <min(col+min(3,len(ab[r_n])-c_n),W+1)):
          for j in range(min(c_n+1,len(ab[r_n])-1),min(c_n+3,len(ab[r_n]))):
            if ch_c<ab[r_n][j][1]:
              ch_c=ab[r_n][j][1]
              break
            if ab[r_n][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n,j])
              ch_c+=1
              break
            if j==min(c_n+3,len(ab[r_n]))-1:
              ch_c=min(col+3,W+1)
              
      elif ch_r==row+1 and (ab[r_n+1][0][0]==row+1 if r_n<len(ab)-1 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
          for j in range(ch_start_add[0],len(ab[r_n+1])):
            if ch_c<ab[r_n+1][j][1]:
              ch_c=ab[r_n+1][j][1]
              ch_start_add[0]=j
              if min_flag[0]:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if ab[r_n+1][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+1,j])
              ch_c+=1
              ch_start_add[0]=min(j+1,len(ab[r_n+1])-1)
              if min_flag[0] and ch_c>col-2:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if j==len(ab[r_n+1])-1:
              ch_c=min(col+3,W+1)
      elif ch_r==row+2 and (ab[r_n+1][0][0]==row+2 if r_n<len(ab)-1 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
           for j in range(ch_start_add[0],len(ab[r_n+1])):
            if ch_c<ab[r_n+1][j][1]:
              ch_c=ab[r_n+1][j][1]
              ch_start_add[0]=j
              if min_flag[0]:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if ab[r_n+1][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+1,j])
              ch_c+=1
              ch_start_add[0]=min(j+1,len(ab[r_n+1])-1)
              if min_flag[0] and ch_c>col-2:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if j==len(ab[r_n+1])-1:
              ch_c=min(col+3,W+1)
      elif ch_r==row+2 and (ab[r_n+2][0][0]==row+2 if r_n<len(ab)-2 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
          for j in range(ch_start_add[1],len(ab[r_n+2])):
            if ch_c<ab[r_n+2][j][1]:
              ch_c=ab[r_n+2][j][1]
              ch_start_add[1]=j
              if min_flag[1]:
                min_flag[1]=False
                ch_list_min_add[1]=j
              break
            if ab[r_n+2][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+2,j])
              ch_c+=1
              ch_start_add[1]=min(j+1,len(ab[r_n+2])-1)
              if min_flag[1] and ch_c>col-2:
                min_flag[1]=False
                ch_list_min_add[1]=j
              break
            if j==len(ab[r_n+2])-1:
              ch_c=min(col+3,W+1)

    for box_r in range(3):
      for box_c in range(3):
        if not checked[0][c_n][box_r][box_c]:
          checked[0][c_n][box_r][box_c]=True
          count=1
          for ch_r in range(row,row+box_r+1):
            for ch_c in range(col+box_c-2 if ch_r!=row else col+1,col+box_c+1):
              if [ch_r,ch_c] in ch_p_rc[0]:
                add=ch_p_rc[1][ch_p_rc[0].index([ch_r,ch_c])]

                checked[add[0]-r_n][add[1]][box_r+row-ch_r][box_c+col-ch_c]=True
                count+=1
       
                
          area_n[count-1]+=1
          
print((H-2)*(W-2)-sum(area_n))
for i in range(9):
  print(area_n[i])

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

max_r_n=0
for i in range(1,len(r_b)):
  if max_r_n<r_b[i]-r_b[i-1]:
    max_r_n=r_b[i]-r_b[i-1]
  

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]

checked=[[[[False]*3 for k in range(3)]  for j in range(len(ab[i]))] for i in range(3)]

area_n=[0 for i in range(1,10)]  

for r_n in range(len(ab)):
  if r_n!=0:
    checked[0]=checked[1]
    checked[1]=checked[2]
    if r_n<len(ab)-2:
      checked[2]=[[[False]*3 for k in range(3)]  for j in range(len(ab[r_n+2]))]

  row=ab[r_n][0][0]
  
  ch_list_min_add=[0,0]
  
  for c_n in range(len(ab[r_n])):
    col=ab[r_n][c_n][1]

    if row<=2:
      for box_r in range(3-row):
        for box_c in range(3):
          checked[0][c_n][box_r][box_c]=True
    if row>=H-1:
      for box_r in range(H+1-row,3):
        for box_c in range(3):
          checked[0][c_n][box_r][box_c]=True
    if col<=2:
      for box_r in range(3):
        for box_c in range(3-col):
          checked[0][c_n][box_r][box_c]=True
    if col>=W-1:
      for box_r in range(3):
        for box_c in range(W+1-col,3):
          checked[0][c_n][box_r][box_c]=True
    ch_p_rc=[[],[]]
    min_flag=[True,True]
    ch_start_add=ch_list_min_add[:]
    for ch_r in range(row,min(row+3,H+1)):
      if ch_r==row:
        ch_c=min(col+1,W)
        while(ch_c <min(col+min(3,len(ab[r_n])-c_n),W+1)):
          for j in range(min(c_n+1,len(ab[r_n])-1),min(c_n+3,len(ab[r_n]))):
            if ch_c<ab[r_n][j][1]:
              ch_c=ab[r_n][j][1]
              break
            if ab[r_n][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n,j])
              ch_c+=1
              break
            if j==min(c_n+3,len(ab[r_n]))-1:
              ch_c=min(col+3,W+1)
              
      elif ch_r==row+1 and (ab[r_n+1][0][0]==row+1 if r_n<len(ab)-1 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
          for j in range(ch_start_add[0],len(ab[r_n+1])):
            if ch_c<ab[r_n+1][j][1]:
              ch_c=ab[r_n+1][j][1]
              ch_start_add[0]=j
              if min_flag[0]:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if ab[r_n+1][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+1,j])
              ch_c+=1
              ch_start_add[0]=min(j+1,len(ab[r_n+1])-1)
              if min_flag[0] and ch_c>col-2:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if j==len(ab[r_n+1])-1:
              ch_c=min(col+3,W+1)
      elif ch_r==row+2 and (ab[r_n+1][0][0]==row+2 if r_n<len(ab)-1 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
           for j in range(ch_start_add[0],len(ab[r_n+1])):
            if ch_c<ab[r_n+1][j][1]:
              ch_c=ab[r_n+1][j][1]
              ch_start_add[0]=j
              if min_flag[0]:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if ab[r_n+1][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+1,j])
              ch_c+=1
              ch_start_add[0]=min(j+1,len(ab[r_n+1])-1)
              if min_flag[0] and ch_c>col-2:
                min_flag[0]=False
                ch_list_min_add[0]=j
              break
            if j==len(ab[r_n+1])-1:
              ch_c=min(col+3,W+1)
      elif ch_r==row+2 and (ab[r_n+2][0][0]==row+2 if r_n<len(ab)-2 else False):
        ch_c=max(col-2,1)
        while(ch_c<min(col+3,W+1)):
          for j in range(ch_start_add[1],len(ab[r_n+2])):
            if ch_c<ab[r_n+2][j][1]:
              ch_c=ab[r_n+2][j][1]
              ch_start_add[1]=j
              if min_flag[1]:
                min_flag[1]=False
                ch_list_min_add[1]=j
              break
            if ab[r_n+2][j]==[ch_r,ch_c]:
              ch_p_rc[0].append([ch_r,ch_c])
              ch_p_rc[1].append([r_n+2,j])
              ch_c+=1
              ch_start_add[1]=min(j+1,len(ab[r_n+2])-1)
              if min_flag[1] and ch_c>col-2:
                min_flag[1]=False
                ch_list_min_add[1]=j
              break
            if j==len(ab[r_n+2])-1:
              ch_c=min(col+3,W+1)

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

max_r_n=0
for i in range(1,len(r_b)):
  if max_r_n<r_b[i]-r_b[i-1]:
    max_r_n=r_b[i]-r_b[i-1]
  

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]

checked=[[[[False]*3 for k in range(3)]  for j in range(len(ab[i]))] for i in range(ab)]

area_n=[0 for i in range(1,10)]

Submission status: Runtime Error

Solution code:
H,W,N=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab.sort()

r_b=[0]
for i in range(1,N):
  if ab[i][0]!=ab[i-1][0]:
    r_b.append(i)
r_b.append(N)

max_r_n=0
for i in range(1,len(r_b)):
  if max_r_n<r_b[i]-r_b[i-1]:
    max_r_n=r_b[i]-r_b[i-1]
  

ab=[ab[r_b[i]:r_b[i+1]] for i in range(len(r_b)-1)]

if N is 0:
  ab=[]

checked=[[[[False]*3 for k in range(3)]  for j in range(len(ab[i]))] for i in range(3)]

area_n=[0 for i in range(1,10)]

Submission status: Runtime Error

Solution code:
from collections import defaultdict as de
h,w,n=map(int,input().split())
s=[0]*10
c=de(int)
d=[]
for i in range(n):
    a,b=map(int,input().split())
    c[(a,b)]=1
    d.append([a,b])
for e,f in d:
    for i in range(3):
        for j in range(3):
            if 0<=e-i and e+2-i<h:
                if 0<=f-j and f+2-j<w:
                    p=0
                    for t in range(e-i,e+3-i):
                        for u in range(f-j,f+3-j):
                            p+=c[(t,u)]
                    else:
                        s[p]+=1
else:
    s=s[0]+[s[i]//i for i in range(1,10)]
    s[0]=(h-8)*(w-8)-sum(s)
    for i in s:
        print(i)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(W: int, H: int, N: int, a: "List[int]", b: "List[int]"):
    ret = [0] * 10
    grid = [[False] * W for _ in range(H)]
    ret[0] = (H - 2) * (W - 2)
    for i in range(N):
        lx = max(0, a[i] - 3)
        rx = min(W - 2, a[i])
        ly = max(0, b[i] - 3)
        ry = min(H - 2, b[i])
        for bx in range(lx, rx):
            for by in range(ly, ry):
                cnt = 0
                for x in range(0, 3):
                    for y in range(0, 3):
                        #print(a[i] - 1, b[i] - 1, bx + x, by + y)
                        if grid[by + y][bx + x]:
                            cnt += 1
                ret[cnt] -= 1
                ret[cnt + 1] += 1
        #print(b[i] - 1, a[i] - 1, H, W)
        grid[b[i] - 1][a[i] - 1] = True
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(H, W, N, a, b)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
H, W, N = map(int, input().split())
d = 10**9+1
L = []
S = set()
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
Map = np.zeros([5, 5], dtype = 'int')
ans = [0]*10
for i in S:
    a, b = i
    for i in range(-2, 3):
        for j in range(-2, 3):
            a1, b1 = a+i, b+j"""
            if (1<=a1<=H) and (1<=b1<=W):
                if (a1, b1) in S:
                    Map[i+2, j+2] = 1
                else:
                    Map[i+2, j+2] = 0
            else:
                Map[i+2, j+2] = -100
    for i in range(-1, 2):
        for j in range(-1, 2):
            k = 1#Map[i+1:i+4, j+1:j+4].sum()
            if k>=0:
                ans[k]+=1
for i in range(1, 10)[::-1]:
    ans[i] //=i
ans[0] = (W-2)*(H-2)-sum(ans)
for i in ans:
    print(i)"""

Submission status: Runtime Error

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
from collections import defaultdict
H, W, N = map(int, input().split())
square = set()
dot = defaultdict(lambda : 0)
for i in range(N):
    a, b = map(lambda x: int(x)-1, input().split())
    dot[[a, b]] = 1
    for y in range(a-2, a+1):
        for x in range(b-2, b+1):
            if 0 <= y < H-2 and 0 <= x < W-2:
                square.add([y, x])
ans = [0] * 10
for y, x in square:
    c = 0
    for i in range(y, y+3):
        for j in range(x, x+3):
            c += dot[[i, j]]
    ans[c] += 1
ans[0] += ans[0] + (H-2) * (W-2) - len(square)
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
d=[[0]*(w+1) for i in range(h+1)]
t=[[0]*(w+1) for i in range(h+1)]
for i in range(n):
    y,x=map(int,input().split())
    d[y][x]=1
for i in range(1,h+1):
    for j in range(1,w+1):
        t[i][j]=t[i][j-1]
        if d[i][j]==1:
            t[i][j]+=1
ans=[0]*10
for i in range(3,h+1):
    for j in range(3,w+1):
        p=(t[i][j]-t[i][j-3])+(t[i-1][j]-t[i-1][j-3])+(t[i-2][j]-t[i-2][j-3])
        ans[p]+=1
for i in ans:
    print(i)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w,n = map(int, input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())
    a[i] -= 1; b[i] -= 1
    
## 左上のマスを(0,0)とする
## 正方形の左上のマスを(j,i)とする
sq = [[0]*(w-2) for i in range(h-2)] 

for x in range(n):
    for k in range(3):
        for l in range(3):
            i = a[x]-k ; j = b[x]-l
            if i<0 or i+3>h or j<0 or j+3>w:
                continue
            sq[i][j] += 1

sq = np.array(sq)

for j in range(10):
    print(np.count_nonzero(sq == j))

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)
ans = 0
tmp = 0
inf = 10 ** 20
INF = float("INF")
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
ddn9 = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

h, w, n = wi()
c = mip(n)

d = collections.defaultdict(int)

for i in range(n):
    for dx, dy in ddn9:
        nx = c[i][1] + dx;
        ny = c[i][0] + dy
        if 0 < nx < w - 1 and 0 < ny < h - 1:
            d[str(ny) + str(nx)] += 1

ansli = [0] * 10
for i in d:
    ansli[d[i]] += 1

ansli[0] = (h - 2) * (w - 2) - sum(ansli)
for i in ansli:
    print(i)

Submission status: Runtime Error

Solution code:
H, W, N = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]

from itertools import product

S = [set() for _ in range(10)]
# S[i]: set(黒いマスをi個こ含む3*3マスの中心セル)

for a,b in AB:
  for x,y in product([-1,0,1], repeat=2):
    X = a+x-1
    Y = b+y-1
    if X<=0 or H-1<=X or Y<=0 or W-1<=Y:
      continue
    for i in range(10):
      if (X, Y) in S[i]:
        S[i].remove((X, Y))
        S[i+1].add((X, Y))
        N[i] -=1
        N[i+1] +=1
        break
    else:
      S[1].add((X, Y))
      N[1] +=1
      N[0] -=1

L = [len(s) for s in S[1:]]
print((H-2)*(W-2) - sum(L))

for l in L:
  print(l)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
H,W,N = [int(n) for n in input().split()]
# N = int(input())
dxy = [[0,0],[1,0],[0,1],
[-1,0],[0,-1],[1,1],
[-1,-1], [1,-1], [-1,1]]

effdic = defaultdict(int)
for i in range(N):
    a,b = [int(n)-1 for n in input().split()]
    for d in dxy:
        ta, tb = a+d[0], b+d[1]
        if(1 <= ta < H-1 and 1 <= tb < W-1):
            s = str(ta) + str(tb)
            effdic[s] += 1
ans = {0:(H-2)*(W-2), 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0}
for k in effdic.keys():
    ans[effdic[k]]+=1
    ans[0]-=1
for k in ans.keys():
    print(ans[k])

Submission status: Runtime Error

Solution code:
from sys import exit
H,W,N = [int(n) for n in input().split()]
# N = int(input())
dxy = [[0,0],[1,0],[0,1],
[-1,0],[0,-1],[1,1],
[-1,-1], [1,-1], [-1,1]]

effdic = {}
for i in range(N):
    a,b = [int(n)-1 for n in input().split()]
    for d in dxy:
        ta, tb = a+d[0], b+d[1]
        if(1 <= ta < H-1 and 1 <= tb < W-1):
            s = str(ta) + str(tb)
            if(s in effdic):
                effdic[s] += 1
            else:
                effdic[s] = 1

ans = {0:(H-2)*(W-2), 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0}
for k in effdic.keys():
    ans[effdic[k]]+=1
    ans[0]-=1
for k in ans.keys():
    print(ans[k])
# S = str(input())
# L = len(S)
# T = str(input())
# exit()

Submission status: Runtime Error

Solution code:
from sys import exit
H,W,N = [int(n) for n in input().split()]
dxy = [[1,0],[0,1],[-1,0],[0,-1],[1,-1],[-1,1],[1,1],[-1,-1],[0,0]]
# ansdic = {0:(H-2)*(W-2),1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
ansdic = {}
# memo = [[0 for _ in range(W-1)] for __ in range(H-1)]
# print(memo)

for i in range(N):
    ab = [int(n) for n in input().split()]
    ab[0]-=1
    ab[1]-=1
    for d in dxy:
        per = [ab[0] + d[0],ab[1] + d[1]]
        if(1 <= per[0] <= H-2 and 1 <= per[1] <= W-2):
            rep = "".join([str(per[0]),str(per[1])])

            if not rep in ansdic:
                ansdic[rep] = 1
            else:
                ansdic[rep] +=1
            # ansdic[memo[per[0]][per[1]]]-=1
            # memo[per[0]][per[1]]+=1
            # ansdic[memo[per[0]][per[1]]]+=1
ans = {0:(H-2)*(W-2),1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0}
for k in ansdic.keys():
    ans[ansdic[k]]+=1
    ans[0]-=1
for k in ans.keys():
    print(ans[k])
# S = str(input())
# L = len(S)
# T = str(input())
exit()

Submission status: Runtime Error

Solution code:
h,w,n = map(int,input().split())
coord = [list(map(int,input().split())) for i in range(n)]

num = {}

for i in range(n):
  for j,k in [[0,0],[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]]:
    if not(2<=coord[i][0]+j<=h-1) or not(2<=coord[i][1]+k<=w-1):
      continue
    if not coord[i][0]+j in num:
      num[coord[i][0]+j] = {}
    if not coord[i][1]+k in num[coord[i][0]+j]:
      num[coord[i][0]+j][coord[i][1]+k] = 1
    else:
      num[coord[i][0]+j][coord[i][1]+k] += 1

ans = [0]*9
for i in num:
  for value in num[i].values():
    ans[value] +=1

print((h-2)*(w-2)-sum(ans))
for i in range(1,9):
  print(ans[i])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef pair<int, int> P;

int main(){
    int h, w, n; cin >> h >> w >> n;
    map<P, int> mp;
    int dx[3] = {-1, 0, 1};
    int dy[3] = {-1, 0, 1};
    rep(i, n){
        int a, b; cin >> a >> b;
        rep(j, 3)rep(k, 3){
            int nx = a + dx[j]; int ny = b + dy[k];
            if(1<nx && nx<h && 1<ny && ny<w) mp[P(nx, ny)]++;
        }
    }
    long cnt[10]; rep(i, 10) cnt[i] = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) cnt[itr->second]++;
    cnt[0] = (h-2) * (w-2);
    For(i, 1, 10) cnt[0] -= cnt[i];
    rep(i, 10) cout << cnt[i] << endl;
}

Submission status: Runtime Error

Solution code:
from collections import defaultdict 
import numpy as np
d=defaultdict(dict)
h,w,n=map(int,input().split())
for s in range(1,11):
  d[s]=0
A=np.zeros((h,w))
for s in range(n):
  a,b=map(int,input().split())
  A[a-1][b-1]=1
for s in range(h-2):
  for t in range(w-2):
    d[int(np.sum(A[s:s+3,t:t+3]))]+=1
for k,v in d.items():
  print(v)