Transformation of String Functions: Inverse Problem#4907

Transformation of String Functions: Inverse Problem

1 second
64 megabytes
Medium

For a string , the -function is defined as follows: Z[i] = lcp(S, S[i..|S|]), where lcp(S_1, S_2) represents the length of the longest common prefix between the strings S_1 and S_2. For instance, if S = abacabaa, the -function is [8, 0, 1, 0, 3, 0, 1, 1].

Additionally, for a string , we define its prefix function as: pi[i] = \max\{k \mid 0 \le k < i, S[1..k] = S[i - k + 1..i]\}. For example, for S = abacabaa, the prefix function is [0, 0, 1, 0, 1, 2, 3, 1].

In this problem, the prefix function of a certain string is given, but the string itself is missing. Your task is to derive the -function from the provided prefix function.

Input

The first line of the input contains a natural number (1 \le N \le 200000), which represents the length of . The second line contains the prefix function of the string .

Output

Output numbers representing the desired -function.

Examples

Example 1

Loading
Loading