#include <bits/stdc++.h>
// using namespace std;
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace edamat {
template <class T>
constexpr auto abs(T i) -> ::std::enable_if_t<::std::is_integral<T>{}(), T> {
    return i < T(0) ? -i : i;
}
template <class M, class N = M>
using common_int_t =
    ::std::enable_if_t<::std::is_integral<M>{}() and ::std::is_integral<N>{}(),
                       ::std::common_type_t<M, N>>;
template <class M, class N>
constexpr common_int_t<M, N> gcd(M m, N n) {
    return n == 0 ? abs(m) : gcd(n, abs(m) % abs(n));
}
template <class M, class N>
constexpr common_int_t<M, N> lcm(M m, N n) {
    return m == 0 or n == 0 ? 0 : (abs(m) / gcd(m, n)) * abs(n);
}
}  // namespace edamat

namespace edamat {
template <class T, class Op>
class aggregatable_deque {
   private:
    class node {
       public:
        T val, sum;
        node(const T &val, const T &sum) : val(val), sum(sum) {}
    };

    Op op;
    std::stack<node> front_stack, back_stack;
    std::stack<T> tmp_stack;

    void split_to_front() {
        assert(!empty());
        // backに残す分をいったんtmpに移す
        const int N = back_stack.size();
        while(tmp_stack.size() < N / 2) {
            T q = back_stack.top().val;
            back_stack.pop();
            tmp_stack.push(q);
        }
        // backの前半分をfrontに移す
        assert(!back_stack.empty());
        front_stack.emplace(back_stack.top().val, back_stack.top().val);
        back_stack.pop();
        while(!back_stack.empty()) {
            T s{op(back_stack.top().val, front_stack.top().sum)};
            front_stack.emplace(back_stack.top().val, s);
            back_stack.pop();
        }
        // いったん移しておいたtmpからbackに戻す
        if(tmp_stack.empty()) return;
        back_stack.emplace(tmp_stack.top(), tmp_stack.top());
        tmp_stack.pop();
        while(!tmp_stack.empty()) {
            T s{op(tmp_stack.top(), back_stack.top().sum)};
            back_stack.emplace(tmp_stack.top(), s);
            tmp_stack.pop();
        }
    }

    void split_to_back() {
        assert(!empty());
        // frontに残す分をいったんtmpに移す
        const int N = front_stack.size();
        while(tmp_stack.size() < N / 2) {
            T q = front_stack.top().val;
            front_stack.pop();
            tmp_stack.push(q);
        }
        // frontの後半分をbackに移す
        assert(!front_stack.empty());
        back_stack.emplace(front_stack.top().val, front_stack.top().val);
        front_stack.pop();
        while(!front_stack.empty()) {
            T s{op(front_stack.top().val, back_stack.top().sum)};
            back_stack.emplace(front_stack.top().val, s);
            front_stack.pop();
        }
        // いったん移しておいたtmpからfrontに戻す
        if(tmp_stack.empty()) return;
        front_stack.emplace(tmp_stack.top(), tmp_stack.top());
        tmp_stack.pop();
        while(!tmp_stack.empty()) {
            T s{op(tmp_stack.top(), front_stack.top().sum)};
            front_stack.emplace(tmp_stack.top(), s);
            tmp_stack.pop();
        }
    }

   public:
    aggregatable_deque(const Op &op = Op())
        : op(op), front_stack(), back_stack() {}

    bool empty() const { return front_stack.empty() && back_stack.empty(); }

    std::size_t size() const { return front_stack.size() + back_stack.size(); }

    T fold_all() const {
        assert(!empty());
        if(front_stack.empty()) {
            return back_stack.top().sum;
        } else if(back_stack.empty()) {
            return front_stack.top().sum;
        } else {
            return op(front_stack.top().sum, back_stack.top().sum);
        }
    }

    void push_back(const T &x) {
        if(back_stack.empty()) {
            back_stack.emplace(x, x);
        } else {
            T s{op(back_stack.top().sum, x)};
            back_stack.emplace(x, s);
        }
    }

    void push_front(const T &x) {
        if(front_stack.empty()) {
            front_stack.emplace(x, x);
        } else {
            T s{op(front_stack.top().sum, x)};
            front_stack.emplace(x, s);
        }
    }

    void pop_front() {
        assert(!empty());
        if(front_stack.empty()) {
            split_to_front();
        }
        front_stack.pop();
    }

    void pop_back() {
        assert(!empty());
        if(back_stack.empty()) {
            split_to_back();
        }
        back_stack.pop();
    }

    // todo:front()とback()の定義の計算量が壊れてる（たぶん）
    const T front() {
        assert(!empty());
        if(front_stack.empty()) {
            split_to_front();
        }
        return front_stack.top().val;
    }
    void back() {
        assert(!empty());
        if(back_stack.empty()) {
            split_to_back();
        }
        return back_stack.top().val;
    }
};
}  // namespace edamat

void ABC146_F() {
    /*
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    */
    int n, m;
    std::cin >> n >> m;
    std::string s;
    std::cin >> s;

    struct node {
        int step;
        int idx;
    };
    const auto f = [](const node &l, const node &r) {
        if(l.step == r.step)
            return l.idx < r.idx ? l : r;
        else
            return l.step < r.step ? l : r;
    };

    edamat::aggregatable_deque<node, decltype(f)> qa(f);
    std::vector<int> next(n + 1);
    qa.push_back({0, n});
    constexpr int Inf = std::numeric_limits<int>::max() / 2;
    int ans;
    for(int i = n - 1; i >= 0; i--) {
        if(qa.size() > m) {
            qa.pop_front();
        }
        const node t = qa.fold_all();
        // std::cout << t.step << " " << t.idx << std::endl;
        next[i] = t.idx;
        if(i == 0) {
            ans = t.step + 1;
        }
        if(s[i] == '0') {
            qa.push_back({t.step + 1, i});
        } else {
            qa.push_back({Inf, i});
        }
    }
    if(ans >= Inf) {
        std::cout << "-1" << std::endl;
        return;
    }
    int p = 0;
    while(p != n) {
        // std::cout << next[p] << " ";
        std::cout << next[p] - p << ' ';
        p = next[p];
    }
    std::cout << std::endl;
}

void AOJ_DSL_3D() {
    int n, l;
    scanf("%d%d", &n, &l);
    std::vector<int> a(n);
    const auto f = [](const int a, const int b) { return std::min(a, b); };
    edamat::aggregatable_deque<int, decltype(f)> q(f);
    rep(i, n) scanf("%d", &a[i]);
    std::vector<int> ans;
    rep(i, n) {
        if(q.size() == l) q.pop_front();
        q.push_back(a[i]);
        if(q.size() == l) {
            const int x = q.fold_all();
            ans.emplace_back(x);
        }
    }
    rep(i, n - l + 1) {
        if(i == n - l)
            printf("%d\n", ans[i]);
        else
            printf("%d ", ans[i]);
    }
}

void ABC125_C() {
    int n;
    scanf("%d", &n);
    std::vector<int> a(n);
    rep(i, n) scanf("%d", &a[i]);
    const auto f = [](const int a, const int b) { return edamat::gcd(a, b); };
    edamat::aggregatable_deque<int, decltype(f)> lq(f), rq(f);
    repeat(i, 1, n) rq.push_back(a[i]);
    int ans = 0;

    // ! 左が空のときfold_allが壊れる
    int r = rq.fold_all();
    repeat(i, 0, n - 1) {
        lq.push_back(a[i]);
        rq.pop_front();
        if(!lq.empty() and !rq.empty())
            ans = std::max(ans, edamat::gcd(lq.fold_all(), rq.fold_all()));
    }
    // ! 右が空のときfold_allが壊れる
    int l = lq.fold_all();
    printf("%d\n", std::max({l, ans, r}));
}

int main() {
    // ABC146_F();
    // AOJ_DSL_3D();
    ABC125_C();
    return 0;
}

Measured memory_bytes: 1536