From the prefix function to the z-function#8248

From the prefix function to the z-function

ثانية
64 ميغابايت
سهل جدًا

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.

المدخلات

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 a single line containing non-negative integers, which represent the z-function.

أمثلة

مثال 1

Loading
Loading