From the prefix function to the z-function#8248

From the prefix function to the z-function

1 second
64 megabytes
Very easy (≈850)

The author intended to create a legend for this problem, but the calculus colloquium demanded more of their attention.

You are provided with the correct prefix function of a specific string. Your task is to compute the z-function for this same string.

Input

The first line of the input contains the integer (1 \leq N \leq 10^6). The following line contains non-negative integers, which represent the prefix function.

Output

Output a single line containing non-negative integers, which represent the z-function.

Examples

Example 1

Loading
Loading