stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<n; i++)

#define PI 3.14159265359

#define INF 1000100100

#define all(x) (x).begin(),(x).end()

typedef long long ll;

#define P pair<int, int>

using namespace std;



int main(){

    int n; cin >> n;

    vector<int> a(n);

    rep(i,n) cin >> a[i];

    vector<P> prime2;

    vector<P> prime1;

    

    int now=a[0]; int p1l=0;

    for(int i=2; i<=(int)sqrt(a[0])+1; i++){

        if(now%i==0){

            prime1.push_back(P(i,1));

            now/=i;

            p1l++;

        }

        while(now%i==0){

            prime1[p1l-1].second++;

            now/=i;

        }

    }

    if(now!=1) prime1.push_back(P(now,1));



    now=a[1]; int p2l=0;

    for(int i=2; i<=(int)sqrt(a[1])+1; i++){

        if(now%i==0){

            prime2.push_back(P(i,1));

            now/=i;

            p2l++;

        }

        while(now%i==0){

            prime2[p2l-1].second++;

            now/=i;

        }

    }

    if(now!=1) prime1.push_back(P(now,1));



    int pl=prime1.size();

    rep(i,prime2.size()){

        bool ex=false;

        rep(j,pl){

            if(prime2[i].first==prime1[j].first){

                prime1[j].second=max(prime1[j].second,prime2[i].second);

                ex=true;

                break;

            }

        }

        if(ex==false) prime1.push_back(prime2[i]);

    }



    vector<int> primes;

    rep(i,prime1.size()){

        rep(j,prime1[i].second) primes.push_back(prime1[i].first);

    }

    sort(all(primes));

    int prl=primes.size();

   //rep(i,prl) cout << primes[i] << endl;

    vector<int> check(prl,-1);

    rep(i,n){

        rep(j,prl){

            if(a[i]%primes[j]==0) a[i]/=primes[j];

            else if(check[j]==-1) check[j]=i;

            else check[j]=-2;

        }

    }



    int ans=1;

    rep(i,check.size()){

        if(check[i]==-1) ans*=primes[i];

    }

    int fac=1;

    rep(j,n){

        int tmp=1;

  	    rep(i,check.size()){

            if(check[i]==j) tmp*=primes[i];

        }

        fac=max(fac,tmp);

    }



    cout << fac*ans << endl;

    return 0;

}



//rate1379

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<n; i++)

#define PI 3.14159265359

#define INF 1000100100

#define all(x) (x).begin(),(x).end()

typedef long long ll;

#define P pair<int, int>

using namespace std;



int gcd(int a,int b){

    if(a<b) swap(a,b);

    int r=a%b;

    while(r!=0){

        a=b;

        b=r;

        r=a%b;

    }

    return b;

}



int main(){

    int n; cin >> n;

    vector<int> a(n);

    rep(i,n) cin >> a[i];

    vector<int> l(n),r(n);

    l[0]=a[0];

    for(int i=1; i<n; i++) l[i]=gcd(l[i-1],a[i]);

    r[n-1]=a[n-1];

    for(int i=n-2; i>=0; i--) r[i]=gcd(r[i+1],a[i]);

    int ans=0;

    rep(i,n){

        if(i==0) ans=max(ans,r[1]);

        else if(i==n-1) ans=max(ans,l[n-2]);

        else ans=max(ans,gcd(l[i-1],r[i+1]));

    }

    cout << ans << endl;

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// C - GCD on Blackboard

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

#define MAX 100000



int N;

vi A(MAX+1), L(MAX+1), R(MAX+1), M(MAX+1);



int gcd(int a, int b){

	if(a<b) swap(a,b);

	while(b){ int r = a%b; a = b; b = r; }

	return a;

}



int main(){

	cin>>N;

	for(int n=1; n<=N; ++n) cin>>A[n];

	for(int n=0; n<N; ++n) L[n+1] = gcd(L[n], A[n]);

	for(int n=N; n>=0; --n) R[n] = gcd(R[n+1], A[n]);

	for(int n=1; n<=N; ++n) M[n] = gcd(L[n], R[n+1]);

	int maxi = 0;

	for(int n=1; n<=N; ++n) maxi = max(maxi,M[n]);

	cout<< maxi <<endl;

}

// Optimized solution to the same problem (faster):
// C - GCD on Blackboard

#include <bits/stdc++.h>

using namespace std;



int gcd(int a, int b){

	if(a<b) swap(a,b);

	while(b){int r =a%b; a=b; b=r;}

	return a;

}



int main(){

	int N; cin>>N;

	vector<int> A(N), L(N), R(N), M(N);



	for(int n=0; n<N; ++n) cin>>A[n];

	for(int n=0; n<=N-1-1; ++n) L[n+1] = gcd(L[n], A[n]);

	for(int n=N-1-1; n>=0; --n) R[n] = gcd(R[n+1], A[n+1]);

	for(int n=0; n<N; ++n) M[n] = gcd(L[n], R[n]);



	int maxi = 0;

	for(int n=0; n<N; ++n) maxi = max(maxi,M[n]);

	cout<< maxi <<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define rep(i, m, n) for(int i = m; i < n; i++)

#define repM(i, m, n) for(int i = n-1; i>=m; i--)

#define all(x) (x).begin(),(x).end()

typedef long long ll; using namespace std;

//typedef pair<int,int> pii;

// d = distance(lower_bound(all(x)), upper_bound(all(x)));

int INF = 1e9;

int m = 1e9+7;

#include <iostream>

#include <vector>

#include <cmath>

#include <algorithm>

#include <queue>



int main(){

  int N; cin >> N; int a[N]; rep(i, 0, N) cin >> a[i];

  sort(a, a+N);

  //rep(i, 0, N) a[i] = (i==0) ? a[i] : a[i] - a[i-1];

  //sort(a, a+N);

  vector<int> r[2];

  rep(i, 0, 2) {

    for(int j=1; j*j <= a[i]; j++) {

      if (a[i] % j == 0) {r[i].push_back(j); r[i].push_back(a[i]/j);}

    }

    //cout << r[i].size() << endl;

  }

  int an=1;

  rep(i, 0, 2) {

    for (int k:r[i]){

      int dm=0; //cout << k << " ";

      rep(j, 0, N) {

        if (a[j] % k) dm++;

        if (dm==2) break;

      }

      if (dm<=1) an = max(an, k);

    }

  }

  cout << an << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

using namespace std;



int gcd(int x, int y) {if (y == 0) return x; return gcd(y,x%y);}



int main(){

  int n; cin>>n;

  int a[n]; for(int i=0;i<n;i++) cin>>a[i];

  int b[n]; b[0] = a[0];

  int c[n]; c[n-1] = a[n-1];

  for(int i=1;i<n;i++) {

    b[i] = gcd(b[i-1], a[i]);

  }

  for(int i=n-2;i>=0;i--) {

    c[i] = gcd(c[i+1], a[i]);

  }

  int an = max(c[1], b[n-2]);

  for(int i=0;i<n;i++) {

    an = max(an, gcd(b[i-1], c[i+1]));

  }

  cout<<an<<endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream> 

using namespace std;

const int maxn = 100005;

int GCD(int a, int b){ return b ? GCD(b, a % b) : a; }

int A[maxn],l[maxn], r[maxn];

int main(){

	int N; cin >> N;

	for(int i = 0; i < N; ++i) cin >> A[i];

	for(int i = 0; i < N; ++i) {

		l[i+1] = GCD(l[i], A[i]);

	}

	for(int i = N-1; i >= 0; --i){

		r[i] = GCD(r[i+1], A[i]);

	}

 

	int max = 0;

	for(int i = 0; i < N; ++i){

		int ll = l[i], rr = r[i+1];

		int g = GCD(ll, rr);

		if(max < g) max = g;

	}

	cout << max << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<algorithm>

using namespace std;

int n,a[1000005],ans=1;

int main()

{

    scanf("%d",&n);

    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    sort(a+1,a+n+1);

    for(int i=a[2];i>=2;i--)

    {

        int t=0;

        for(int j=1;j<=n;j++)

        {

            if(a[j]%i!=0) t++;

            if(t>=2) break;

        }

        if(t<=1)

        {

            ans=i;

            break;

        }

    }

    printf("%d",ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <cmath>

#include <queue>

#include <list>

#include <string>

using namespace std;

 

typedef long long ll;

typedef pair<int, int> P;

const int MOD = 998244353;

 

int gcd(int a, int b){

  if(b == 0) return a;

  return gcd(b, a%b);

}

 

int main()

{

  int N,keep,count;

  bool finish = false;

  ll A[100000],i,k,secmin,min;

  cin >> N;

  cin >> A[0] >> A[1];

  min = std::min(A[0],A[1]);

  secmin = max(A[0],A[1]);

  vector<int> minl;

  vector<int> minsl;

  for(int i=2;i<N;i++){

    cin >> A[i];

    if(A[i] < min) {

      secmin = min;

      min = A[i];

    }else if(A[i] < secmin){

      secmin = A[i];

    }

  }

  for(i=1;i<=sqrt(min);i++){

    if(min % i == 0){

      minl.push_back(i);

      minl.push_back(min/i);

    }

  }

  for(i=1;i<=sqrt(secmin);i++){

    if(secmin % i == 0){

      minsl.push_back(i);

      minsl.push_back(secmin/i);

    }

  }

  sort(minl.begin(),minl.end());

  sort(minsl.begin(),minsl.end());

  for(i=minl.size()-1;i>=0;i--){

      count = 0;

      for(int j=0;j<N;j++){

        if(A[j]%minl[i] == 0) count++;

      }

      if(count >= N-1){

        i = minl[i];

          break;

      }

    }

  for(k=minsl.size()-1;k>=0;k--){

    count = 0;

    for(int j=0;j<N;j++){

      if(A[j]%minsl[k] == 0) count++;

    }

    if(count >= N-1){

      k = minsl[k];

      break;

    }

  }

  cout << max(k,i);

}


// Optimized solution to the same problem (faster):
#pragma region template

#include "bits/stdc++.h"

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const long long MOD = 1e9 + 7, MAX = LLONG_MAX, larg = 1e5, INF = -1e9;

long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;

typedef long long ll;

typedef pair<ll, ll> Pa;



ll gcd(ll a, ll b) {

	if (b == 0) return a;

	return gcd(b, a % b);

}



ll arr[100000];

ll _left[100000];

ll _right[100000];

int main() {

	cin >> N;

	rep(i, N) {

		cin >> arr[i];

	}

	_left[0] = arr[0];

	_right[N - 1] = arr[N - 1];

	rep(i, N - 1) {

		_left[i + 1] = gcd(_left[i], arr[i + 1]);

		_right[N - i - 2] = gcd(_right[N - i - 1], arr[N - i - 2]);

	}

	ll maxv = _right[1];

	rep(i, N - 2) {

		maxv = max(maxv, gcd(_left[i], _right[i + 2]));

	}

	maxv = max(maxv, _left[N - 2]);

	cout << maxv;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;



typedef long long ll;



ll gcd(ll x, ll y) {

    if (y == 0) return x;

    return gcd(y, x % y);

}



int main() {

    int N;

    cin >> N;

    vector<int> A(N);

    map<int, int> mp;

    rep(i, N) cin >> A[i];

    rep(i, 2) {

        for (int j = 1; j * j <= A[i]; j++) {

            if (A[i] % j == 0) {

                mp[j]++;

                mp[A[i] / j]++;

            }

        }

    }

    //for (auto i : mp) cout << i.first << " " << i.second << endl;

    for (int i = 2; i < N; i++) {

        for (auto j : mp) {

            if (A[i] % j.first == 0) {

                mp[j.first]++;

            }

        }

    }

    int ans = 1, b = 1;

    for (auto i : mp) {

        if (i.second == N) ans = max(ans, i.first);

        if (i.second == N - 1) ans = max(ans, i.first);

    }

    cout << ans << endl;

    //for (auto i : mp) cout << i.first << " " << i.second << endl;

}

// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;



using ll = long long;



ll gcd(ll x, ll y) {

    if (y == 0) return x;

    return gcd(y, x % y);

}



int main() {

    int N;

    cin >> N;

    vector<ll> A(N), l(N), r(N);

    rep(i, N) cin >> A[i];

    l[0] = A[0];

    rep(i, N - 1) l[i + 1] = gcd(l[i], A[i + 1]);

    r[0] = A[N - 1];

    rep(i, N - 1) r[i + 1] = gcd(r[i], A[N - 2 - i]);

    ll ans = max(l[N - 2], r[N - 2]);

    rep(i, N - 2) {

        ans = max(ans, gcd(l[i], r[N - 3 - i]));

    }

    cout << ans << "\n";

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=(0);i<(n);i++)



using namespace std;



typedef long long ll;



int max_N = 100005;





int gcd(int a, int b){

	if(b == 0) return a;

	return gcd(b, a % b);

}



void addDivs(set<int> &st, int t){

	for(int i = 1; i * i <= t; i++){

		if(t % i == 0){

			st.insert(i);

			st.insert(t / i);

		}

	}

}



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);



	int N;

	cin >> N;



	vector<int> A(N, 0);

	rep(i, N) cin >> A[i];



	set<int> st;

	addDivs(st, A[0]);

	addDivs(st, A[1]);



	int ans = 1;



	for(int x : st){

		int cnt = 1;

		bool chk = true;

		for(int i = 0; i < N; i++){

			if(A[i] % x != 0){

				if(cnt == 1){

					cnt--;

				}else{

					chk = false;

					break;

				}

			}

		}



		if(chk){

			ans = max(ans, x);

		}

	}



	cout << ans << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=(0);i<(n);i++)



using namespace std;



typedef long long ll;



ll mygcd(ll a, ll b){

    if(b == 0) return a;

    return mygcd(b, a % b);

}



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);



    ll n;

    cin >> n;



    vector<ll> a(n);

    rep(i, n) cin >> a[i];



    vector<ll> lg(n);

    lg[0] = a[0];

    for(int i = 1; i < n; i++){

        lg[i] = mygcd(a[i], lg[i-1]);

    }



    vector<ll> rg(n);

    rg[n-1] = a[n-1];

    for(int i = n - 2; i >= 0; i--){

        rg[i] = mygcd(a[i], rg[i+1]);

    }



    ll ans = max(rg[1], lg[n-2]);



    for(int i = 1; i <= n-2; i++){

        ans = max(ans, mygcd(lg[i-1], rg[i+1]));

    }



    cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<math.h>

#include<stdlib.h>

#include<string>

#include<vector>

#include<map>



using namespace std;



#define INF (1<<30)



int n;

int a[100001];



vector<int> enum_div(int n)//nの約数を列挙

{

	vector<int> ret;

	for(int i=1 ; i*i<=n ; ++i)

	{

			if(n%i == 0)

			{

				ret.push_back(i);

				ret.push_back(n/i);

			}

	}

	return ret;

}



int main(){

	cin >> n;

	for(int i = 0;i < n;i++){

		cin >> a[i];

	}

	vector<int> list = enum_div(a[0]);

	int ans = 0;

	for(int i = 0;i < list.size();i++){

		int target = list[i];

		int amount = 0;

		for(int j = 0;j < n;j++){

			if(a[j]%target==0)amount++;

		}

		// cout << amount << endl;

		if(amount == n || amount == n-1)ans = max(ans,target);

	}

	list = enum_div(a[1]);

	for(int i = 0;i < list.size();i++){

		int target = list[i];

		int amount = 0;

		for(int j = 0;j < n;j++){

			if(a[j]%target==0)amount++;

		}

		if(amount == n || amount == n-1)ans = max(ans,target);

	}

    cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<math.h>

#include<stdlib.h>

#include<string>

#include<vector>

#include<map>

#include<algorithm>



using namespace std;



#define INF (1<<30)



int n;

int a[100001];

int gcdl[100001];

int gcdr[100001];



int main(){

	cin >> n;

	for(int i = 0;i < n;i++){

		cin >> a[i];

	}

	gcdl[0] = 0;

	gcdr[0] = 0;

	for(int i = 1; i<n; i++){

		gcdl[i] = __gcd(gcdl[i-1],a[i-1]);

		gcdr[i] = __gcd(gcdr[i-1],a[n-i]);

	}

	int ans = 1;

	for(int i = 0;i < n;i++){

		int now = __gcd(gcdl[i],gcdr[n-i-1]);

		ans = max(ans, now);

	}

	cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<math.h>

#include<stdlib.h>

#include<string>

#include<vector>

#include<map>

#include<algorithm>



using namespace std;



#define INF (1<<30)



int n;

int a[100001];

int dp[100001][2];



int dpsolve(){

	random_shuffle(a, a+n);

	fill_n(*dp,100001*2,-1);

	for(int d = n-1;d != -1;d--){

		for(int skip = 0;skip < 2;skip++){

			if(d == n-1){

				// if(skip==0){//まだ何も飛ばしてない

				// 	return a[d];

				// }else{

				// 	return a[d];

				// }

				dp[d][skip] = a[d];

				continue;

			}

			int ans = 0;

			ans = max(ans, __gcd(dp[d+1][skip], a[d]));//選ぶ

			if(skip == 0){

				ans = max(ans, dp[d+1][1]);//スキップする

			}

			dp[d][skip] = ans;

		}

	}

	return dp[0][0];

}



int main(){

	cin >> n;

	for(int i = 0;i < n;i++){

		cin >> a[i];

	}

	int ans = 0;

	for(int i = 0;i < 5;i++){

		ans = max(ans, dpsolve());

	}

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<math.h>

#include<stdlib.h>

#include<string>

#include<vector>

#include<map>

#include<algorithm>



using namespace std;



#define INF (1<<30)



int n;

int a[100001];

int gcdl[100001];

int gcdr[100001];



int main(){

	cin >> n;

	for(int i = 0;i < n;i++){

		cin >> a[i];

	}

	gcdl[0] = 0;

	gcdr[0] = 0;

	for(int i = 1; i<n; i++){

		gcdl[i] = __gcd(gcdl[i-1],a[i-1]);

		gcdr[i] = __gcd(gcdr[i-1],a[n-i]);

	}

	int ans = 1;

	for(int i = 0;i < n;i++){

		int now = __gcd(gcdl[i],gcdr[n-i-1]);

		ans = max(ans, now);

	}

	cout << ans << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define P pair<ll,ll>

#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)

#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)

#define TO(x,t,f) ((x)?(t):(f))

#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9

#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted

#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted

#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted

#define REV(x) (reverse(x.begin(),x.end())) //reverse

ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}

ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu

#define NEXTP(x) next_permutation(x.begin(),x.end())

const ll INF=1e18+7;

const ll MOD=1e9+7;



vector<ll> enum_div(int n){

	vector<ll> ret;

	for(ll i=1 ; i*i<=n ; ++i){

			if(n%i == 0){

				ret.push_back(i);

				ret.push_back(n/i);

			}

	}

	return ret;

}





int main(){

	ll N,ans=0;

	cin >> N;

	vector<ll> a(N);

	FOR(i,0,N)cin>>a[i];

	SORT(a);

	FOR(i,0,2){

		for(auto y:enum_div(a[i])){

			ll k = 0;

			FOR(j,0,N){

				if(a[j]%y==0)k++;

			}

			if(k>=N-1){

				ans = max(ans,y);

			}

		}

	}

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}



class Seg_Tree{//gcd

public:

	vector<int> dat;

	int n;

	void initsize(int n0){

		int k=1;

		while(1){

			if(n0<=k){

				n=k;

				dat.resize(2*n-1);

				for(int i=0;i<2*n-1;i++)dat[i]=1;

				break;

			}

			k*=2;

		}

	}



	//to sg[i]  x

	void update(int i,int x){

		i += n-1;

		dat[i] = x;

		while(i>0){

			i = (i-1) / 2;

			dat[i] = gcd(dat[i*2+1],dat[i*2+2]);

		}

	}



	//gcd[a,b)

	int query0(int a,int b,int k,int l,int r){

		if(r<=a || b<=l)return dat[a+n-1];

		if(a<=l && r<=b)return dat[k];

		else{

			int vl = query0(a,b,k*2+1,l,(l+r)/2);

			int vr = query0(a,b,k*2+2,(l+r)/2,r);

			return gcd(vl,vr);

		}

	}



	//return gcd [a,b)

	int query(int a,int b){

		return query0(a,b,0,0,n);

	}

};



int main(){

	int N;

	cin >> N;

	Seg_Tree sg;

	sg.initsize(N);

	for(int i=0;i<N;i++){

		int k;

		cin >> k;

		sg.update(i,k);

	}



	int ans = max(sg.query(1,N),sg.query(0,N-1));

	for(int i=1;i<N-1;i++){

		int p = gcd(sg.query(0,i),sg.query(i+1,N));

		ans = max(ans,p);

	}



	cout << ans << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



const int N = 1e5 + 5, mod = 1e9 + 7;



int a[N], dp[N][2], n;



int solve(int i, int taken)

{

    if (i == n - 1)

    {

        if (taken)

            return a[i];

        return 0;

    }

    if (dp[i][taken] != -1)

        return dp[i][taken];

    int ans = 0;

    if (taken)

        ans = __gcd(solve(i + 1, 1), a[i]);

    else

        ans = max(__gcd(solve(i + 1, 0), a[i]), solve(i + 1, 1));

    return dp[i][taken] = ans;

}



int main()

{

    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);

    cin >> n;

    for (int i = 0; i < n; i++)

        cin >> a[i];

    memset(dp, -1, sizeof dp);

    cout << solve(0, 0);

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n;

int a[100005]; 

int gcd1[100005];

int gcd2[100005];

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;++i)

	   scanf("%d",&a[i]);

	

	gcd1[1]=a[1];

	gcd2[n]=a[n];

	for(int i=2;i<=n;++i)

	    gcd1[i]=__gcd(gcd1[i-1],a[i]);//cout<<gcd1[i]<<" ";

	//cout<<endl;

	for(int i=n-1;i>=1;--i)

	    gcd2[i]=__gcd(gcd2[i+1],a[i]);//cout<<gcd2[i]<<" ";

	//cout<<endl;

	gcd1[0]=gcd2[2];

	gcd2[n+1]=gcd1[n-1];

	int ans=0;

	for(int i=1;i<=n;++i)

		ans=max(ans,__gcd(gcd1[i-1],gcd2[i+1]));

	printf("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    int t,a,p,c=0;

    vector<int>v,v1;

    cin>>t;

    for(int i=1; i<=t; i++)

    {

        cin>>a;

        v.push_back(a);

    }

    sort(v.begin(),v.end());

    p=sqrt(v[0]);

    for(int i=p; i>=1; i--)

    {

        if(v[0]%i==0)

        {

            v1.push_back(i);

            v1.push_back(v[0]/i);

        }

    }

    p=sqrt(v[t-1]);

    for(int i=p; i>=1; i--)

    {

        if(v[t-1]%i==0)

        {

            v1.push_back(i);

            v1.push_back(v[t-1]/i);

        }

    }

    sort(v1.begin(),v1.end());

    reverse(v1.begin(),v1.end());

    for(int i=0; i<v1.size(); i++)

    {

        c=0;

        for(int j=0; j<t; j++)

        {

            if(v[j]%v1[i]!=0)

            {

                c++;

                if(c==2)

                    break;

            }

        }

        if(c==1 || c==0)

        {

            cout<<v1[i]<<endl;

            break;

        }

    }

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

int n;

int a[100005]; 

int gcd1[100005];

int gcd2[100005];

int main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;++i)

	   scanf("%d",&a[i]);

	

	gcd1[1]=a[1];

	gcd2[n]=a[n];

	for(int i=2;i<=n;++i)

	    gcd1[i]=__gcd(gcd1[i-1],a[i]);//cout<<gcd1[i]<<" ";

	//cout<<endl;

	for(int i=n-1;i>=1;--i)

	    gcd2[i]=__gcd(gcd2[i+1],a[i]);//cout<<gcd2[i]<<" ";

	//cout<<endl;

	gcd1[0]=gcd2[2];

	gcd2[n+1]=gcd1[n-1];

	int ans=0;

	for(int i=1;i<=n;++i)

		ans=max(ans,__gcd(gcd1[i-1],gcd2[i+1]));

	printf("%d\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

using ll = int64_t;

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順



int main() {

    int N;

    cin >> N;

    vector<ll> A(N);

    ll prev;

    bool same = true;

    rep(i,N) {

        cin >> A.at(i);

        if (i == 0) prev = A[0];

        else if (prev != A[i]) {

            same = false;

        }

        prev = A[i];

    }

    if (same) {

        cout << A[0] << endl;

        return 0;

    }

    ll a = A[0];

    ll b = A[1];

    set<ll> div;

    for (int i = 1; i < (int)sqrt(max(a,b)) + 1; i++) {

        if (a % i == 0) {div.insert(i); if (a / i != i) div.insert(a/i);}

        if (b % i == 0) {div.insert(i); if (b / i != i) div.insert(b/i);}

    }

    set<ll> res; 

    for (auto x : div) {

        int cnt = 0;

        rep(i, N) if (A[i] % x == 0)  cnt++;

        if (cnt > N - 2) res.insert(x);

    }

    cout << *rbegin(res) << endl;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;

using ll = int64_t;

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順



ll gcd(ll a, ll b) {

    if (a == 0) return b;

    else if (b == 0) return a;

    return gcd(b, a % b);

}



int main() {

    int N;

    cin >> N;

    vector<ll> A(N+1, 0);

    ll prev;

    bool same = true;

    for (int i = 1; i <= N; i++) {

        cin >> A.at(i);

        if (i == 1) prev = A[1];

        else if (prev != A[i]) {

            same = false;

        }

        prev = A[i];

    }

    /*

    if (same) {

        cout << A[1] << endl;

        return 0;

    }

    */

    vector<ll> LEFT(N+1,0);

    vector<ll> RIGHT(N+2,0);

    for (int i = 1; i <= N; i++) LEFT[i] = gcd(LEFT[i - 1], A[i]);

    for (int i = N; i >= 1; i--) RIGHT[i] = gcd(A[i], RIGHT[i+1]);

    ll ma = 0;

    for (int i = 1; i <= N; i++) {

       ma = max(ma, gcd(LEFT[i-1], RIGHT[i+1])); 

    }

    cout << ma << endl;

}

// Fastest known solution for this problem: