#P7009. Magical GCD

    ID: 20216 Type: Default 1000ms 256MiB

Magical GCD

Magical GCD

The Magical GCD of a nonempty sequence of positive integers is defined as the product of its length and the greatest common divisor (GCD) of all its elements. Formally, for a sequence S with |S| elements:

$\text{Magical GCD}(S)= |S| \times \gcd(S)$

Given a sequence \( (a_1, a_2, \ldots, a_n) \), your task is to find the largest possible Magical GCD among all of its connected (contiguous) subsequences.

inputFormat

The first line contains a single integer \( n \) representing the length of the sequence.

The second line contains \( n \) positive integers \( a_1, a_2, \ldots, a_n \) separated by spaces.

You may assume that \( 1 \leq n \leq 10^5 \) and \( 1 \leq a_i \leq 10^9 \) for all \( i \).

outputFormat

Output a single integer, the maximum Magical GCD among all connected subsequences of the sequence.

sample

3
5 10 20
20