AtCoder Regular Contest 107
E
Mex Mat
AtCoder
⌀ 2604
原题
← DF →
翻译中…

Problem Statement

翻译中…

Consider an $N \times N$ matrix. Let us denote by $a_{i, j}$ the entry in the $i$-th row and $j$-th column. For $a_{i, 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:

翻译中…
  • $a_{i,j} = \mathrm{mex}(a_{i-1,j}, a_{i,j-1}) (2 \leq i, j \leq N)$ where $\mathrm{mex}(x, y)$ is defined by the following table:
翻译中…
$\mathrm{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

翻译中…
  • $1 \leq N \leq 500{,}000$
  • $a_{i,j}$'s given in input are one of $0$, $1$ and $2$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
a_{1, 1} a_{1, 1} ... a_{1, N}
a_{2, 1}
:
a_{N, 1}

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
4
1 2 0 2
0
0
0
Output #1
7 4 5
The matrix is as follows:
题目信息
题号
arc107_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。