Problem:
Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.

Solution in Rust (1.15.1) (judge verdict: Time Limit Exceeded)

use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>(stdin: &mut StdinLock) -> T {
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn parse<T: FromStr>(line: &str) -> Vec<T> {
    let split_whitespace = line.split_whitespace();
    split_whitespace
        .map(|elem| elem.parse().ok().expect("failed to parse token"))
        .collect()
}

fn euclid(a: u32, b: u32) -> u32 {
    let r = a % b;
    if r == 0 {
        return b;
    }
    euclid(b, r)
}

fn multi_euclid(a: &[u32]) -> Option<u32> {
    let n = a.len();

    if n==0{
        return None
    }
    if n == 1 {
        return Some(a[0])
    }
    let (a1, a2) = a.split_at(n / 2);
    let result1 = multi_euclid(a1).unwrap_or(0);
    let result2 = multi_euclid(a2).unwrap_or(0);
    Some(euclid(result1, result2))
}

fn leave_one_euclid(a: &[u32], leave: usize) -> u32 {
    if leave == 0 {
        let (_, a_rest) = a.split_first().unwrap();
        multi_euclid(a_rest).unwrap()
    } else if leave == a.len() - 1 {
        let (_, a_rest) = a.split_last().unwrap();
        multi_euclid(a_rest).unwrap()
    } else {
        let (a1, a2) = a.split_at(leave);
        euclid(multi_euclid(a1).unwrap(), leave_one_euclid(a2, 0))
    }
}

fn generate_leaveone_vec(a: &[u32]) -> Vec<u32> {
    let mut vec = Vec::with_capacity(a.len());
    for i in 0..a.len() {
        vec.push(leave_one_euclid(a, i));
    }
    vec
}

fn main() {
    let stdin = stdin();
    let mut stdin_lock = stdin.lock();
    let _: u32 = read(&mut stdin_lock);
    let mut buf = String::new();
    stdin_lock.read_line(&mut buf).expect("failed to read");
    let a = parse(&mut buf);
    let res = generate_leaveone_vec(&a);
    println!("{}", res.iter().max().unwrap());
}