Type: Default 1000ms 512MiB

E - Mex Mat

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Score : 800 points

Problem Statement

Consider an N×N matrix. Let us denote by ai,j the entry in the i-th row and j-th column. For ai,j where i=1 or j=1 holds, its value is one of 0, 1 and 2 and given in the input. The remaining entries are defined as follows:

  • ai,j=mex(ai1,j,ai,j1)(2i,jN) where mex(x,y) is defined by the following table:
mex(x,y) y=0 y=1 y=2
x=0 1 2 1
x=1 2 0 0
x=2 1 0 0

How many entries of the matrix are 0,1, and 2, respectively?

Constraints

  • 1N500,000
  • ai,j's given in input are one of 0, 1 and 2.

Input

Input is given from Standard Input in the following format:

N
a1,1 a1,1 ... a1,N
a2,1
:
aN,1

Output

Print the number of 0's, 1's, and 2's separated by whitespaces.


Sample Input 1

4
1 2 0 2
0
0
0

Sample Output 1

7 4 5

The matrix is as follows:

1 2 0 2
0 1 2 0
0 2 0 1
0 1 2 0

排位赛1

Not Attended
Status
Done
Rule
IOI
Problem
8
Start at
2023-7-11 8:00
End at
2023-7-11 12:00
Duration
4 hour(s)
Host
Partic.
21