Problem list
Log in
#coci00730 · COCI 2024/2025 Contest 5

Tornjevi

Unrated 2.0 s 512 MB

On a certain street, there are $n$ towers, numbered consecutively from 1 to $n$. Each tower has its own height $h_{i}$, expressed in meters. For a consecutive subsequence of towers numbered $l$, $l + 1$, . . ., $r$, we say that the tower with number $i$ ($l \le i \le r$) is good in that subsequence if it holds that $h_{i} = gc$d ($h_{l}$, h_{$l+1$}, . . . , $h_{r}$), where gcd ($a_{1}$, $a_{2}$, . . . , $a_{k}$) denotes the greatest common divisor of the set of positive integers $a_{1}$, $a_{2}$, . . . , $a_{k}$. Your task is to determine, for each $i = 1$, 2, . . . , n, the size of the largest consecutive subsequence in which the tower with number $i$ is good, where the size of a consecutive subsequence is defined as the number of towers in that subsequence.

Input

In the first line, there is an integer $n$ ($1 \le n \le 10^{6}$), the number of towers. In the second line, there are $n$ integers, in order, $h_{1}$, $h_{2}$, . . ., $h_{n}$ ($1 \le h_{i} \le 10^{6}$).

Output

In a single line, print the answer to the above-mentioned question for each $i = 1$, 2, . . . , n, in order.

Example 1

Input
6
3 6 6 6 1 3
Output
4 3 3 3 6 1

Example 2

Input
5
10 2 10 15 5
Output
1 3 1 1 3

Clarification of the first example: In the first four towers, tower number 1 is good. Towers with numbers 2, 3, and 4 are good in the subsequence they form themselves. Tower 5 will be good in any arbitrary subsequence that contains it, so the answer will be 6 (the entire sequence).

Source
COCI 2024/2025 Contest 5
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code