Input
3 2 3 4 0 1 1 0 1 1 0 3 0 0 0 **_* 0 0 1 ___* 0 0 2 ___* 0 1 0 *__* 0 1 1 ___* 0 1 2 __** 1 0 0 **** 1 0 1 **** 1 0 2 *___ 1 1 0 **__ 1 1 1 *_** 1 1 2 **** 2 0 0 **** 2 0 1 **** 2 0 2 **** 2 1 0 **_* 2 1 1 __** 2 1 2 ****
Output
0 1 1 0 0 1 1 1 0 1 1 2 0 1 0 2 1 1 0 2 1 1 0 3