The Only Mode

시간 제한2초메모리 제한1024 MB

문제

You are given an array of integers $A$ of size $N$ (indexed from $1$ to $N$) where $A_i$ is either $0$, $1$, $2$, or $3$.

A subarray $⟨l, r⟩$ of $A$ is defined as $[A_l , A_{l+1}, \cdots , A_r]$, and its size is $r - l + 1$.

A value $x$ is the only mode of a subarray $⟨l, r⟩$ if and only if $x$ appears strictly more often than other values in subarray $⟨l, r⟩$.

Your task in this problem is to find, for each $x ∈ \{0, 1, 2, 3\}$, the size of the longest subarray of $A$ such that $x$ is the only mode of that subarray, or determine if $x$ cannot be the only mode in any subarray.

입력

Input begins with an integer $N$ ($1 ≤ N ≤ 100\, 000$) representing the size of array $A$. The next line contains $N$ integers $A_i$ ($A_i ∈ \{0, 1, 2, 3\}$).

출력

Output four space-separated integers in a single line. Each integer represents the answer where $x$ is $0$, $1$, $2$, and $3$, respectively. For each value of $x$, if there exists a subarray such that $x$ is the only mode in that subarray, then output the size of the longest subarray; otherwise, output $0$.