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)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;
fn main() {
    input!(
        n: i32,
        a: [i64; n],
    );
    let mut map: HashMap<i64, i32> = HashMap::new();
    let mut num2cds: HashMap<i64, Vec<i64>> = HashMap::new();
    for ai in a {
        let mut cds: Vec<i64> = Vec::new();
        if num2cds.contains_key(&ai) {
            cds = num2cds.get(&ai).unwrap().to_vec();
        } else {
            let upto = (ai/2) + 1;
            for divisor in 1..upto {
                if ai % divisor == 0 {
                    cds.push(divisor);
                }
            }
            cds.push(ai);
            num2cds.entry(ai).or_insert(cds.clone());
        }
        for cd in &cds {
            // println!("{}", cd);
            let counter = map.entry(*cd).or_insert(0);
            *counter += 1;
        }
    }
    let mut max: i64 = 1;
    let hoge: i32 = n - 1; // v==n-1 の n-1部分
    // println!("max:{}  hoge:{}", max,hoge);
    for (k, v) in &map {
        // println!("k:{}  v:{}", k,v);
        if (v >= &hoge) && (&max <= k) {
            max = k.clone();
        }
    }
    println!{"{}", max};
}