#C6032. Maximum GCD After Removal

    ID: 49748 Type: Default 1000ms 256MiB

Maximum GCD After Removal

Maximum GCD After Removal

You are given a sequence of N positive integers. Your task is to remove exactly one element from the sequence such that the greatest common divisor (GCD) of the remaining N-1 numbers is maximized. In other words, if the remaining numbers after removal are denoted by \(a_1, a_2, \dots, a_{N-1}\), you need to maximize \(\gcd(a_1, a_2, \dots, a_{N-1})\).

Note: When \(N = 2\), after removing one number, only one element remains so the answer is the value of that element (i.e. the maximum among the two).

Input must be read from stdin and output should be written to stdout.

inputFormat

The first line contains an integer \(N\) — the number of elements in the sequence. The second line contains \(N\) space-separated positive integers.

For example:

5
12 15 18 24 30

outputFormat

Output a single integer representing the maximum possible GCD of the sequence after removing exactly one element.

For the sample input above, the output should be:

6
## sample
5
12 15 18 24 30
6