#P9970. MEX Subarray Selection

    ID: 23114 Type: Default 1000ms 256MiB

MEX Subarray Selection

MEX Subarray Selection

Given an integer sequence \(a_1, a_2, \dots, a_n\), we define the \(\operatorname{mex}\) of a set \(S\) as the smallest non-negative integer not present in \(S\). For every integer \(k\) with \(1 \le k \le n\), consider all contiguous subarrays of \(a\) of length \(k\). For each such subarray, compute the \(\operatorname{mex}\) of the set of elements in that subarray. Let \(b_k\) be the \(\operatorname{mex}\) of the set of all these subarray \(\operatorname{mex}\) values. Your task is to compute and output the sequence \(b = [b_1, b_2, \dots, b_n]\).

inputFormat

The first line contains an integer \(n\) (the number of elements). The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\).

outputFormat

Output \(n\) space-separated integers \(b_1, b_2, \dots, b_n\) in one line.

sample

3
0 1 2
2 1 0