#P11753. [COCI 2024/2025 #5] 塔楼 / Tornjevi

[COCI 2024/2025 #5] 塔楼 / Tornjevi

Description

On a certain street, there are n n towers, numbered consecutively from 11 to nn. Each tower has its own height hih_i, expressed in meters.

For a consecutive subsequence of towers numbered l,l+1,,rl, l + 1, \ldots, r, we say that the tower with number ii (lirl ≤ i ≤ r) is good in that subsequence if it holds that hi=gcd(hl,hl+1,,hr)h_i = \gcd (h_l, h_{l+1}, \ldots , h_r), where gcd(a1,a2,,ak)\gcd (a_1, a_2, \ldots , a_k) denotes the greatest common divisor of the set of positive integers a1,a2,,aka_1, a_2, \ldots , a_k.

Your task is to determine, for each i=1,2,,ni = 1, 2, \ldots , n, the size of the largest consecutive subsequence in which the tower with number ii is good, where the size of a consecutive subsequence is defined as the number of towers in that subsequence.

Input Format

In the first line, there is an integer nn (1n1061 ≤ n ≤ 10^6), the number of towers.

In the second line, there are nn integers, in order, h1,h2,,hnh_1, h_2, \ldots, h_n (1hi1061 ≤ h_i ≤ 10^6).

Output Format

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

6
3 6 6 6 1 3
4 3 3 3 6 1
5
10 2 10 15 5
1 3 1 1 3

Hint

Clarification of the first example:

In the first four towers, tower number 11 is good. Towers with numbers 2,32, 3, and 44 are good in the subsequence they form themselves. Tower 55 will be good in any arbitrary subsequence that contains it, so the answer will be 6 (the entire sequence).

Scoring

Subtask Points Constraints
11 77 n100n ≤ 100
22 1111 n5000 n ≤ 5000
33 1717 n50000 n ≤ 50000
44 2929 hi100 h_i ≤ 100
55 2626 No additional constraints.