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

using namespace std;



#define int long long

#define pb push_back

#define f first

#define s second

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



#define fast ios::sync_with_stdio(0); cin.tie(0)



int32_t main(){



    fast;

    int n; cin >> n;

    int ar[n];



    int maxx_freq = -1 , element = -1;

    map<int,int> mp;



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

      cin >> ar[i];

      mp[ar[i]]++;

      if(mp[ar[i]]>maxx_freq){

        maxx_freq = mp[ar[i]];

        element = ar[i];

      }

    } 

    

    if(maxx_freq==1){

      for(auto p : mp) element = max(element,p.f);

    }

    // cout << "maxx " << element << '\n';



    vector<int> divisor;



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

      if(element%i==0){

        divisor.pb(i);

        if(i!=element/i) divisor.pb(element/i);

      }

    }



    int ans = -1;



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

      int gcd = 0;

      bool flag = false;

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

        if(ar[j]%divisor[i]!=0&&!flag){

          gcd = __gcd(divisor[i],gcd);

          flag = true;

        }

        else {

          gcd = __gcd(ar[j],gcd);

        }

      }

      ans = max(ans,gcd);

    }



    cout << ans << '\n';





    return 0;

} 

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

using namespace std;



#define int long long

#define pb push_back

#define f first

#define s second

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



#define fast ios::sync_with_stdio(0); cin.tie(0)



int32_t main(){

  

    fast;

    int n; cin >> n;

    int ar[n+1];



    for(int i=1;i<=n;i++) cin >> ar[i];



    int leftgcd[n+1] = {0};

    int rightgcd[n+2] = {0};



    leftgcd[0] = 0;

    rightgcd[n+1] = 0;



    for(int i=1;i<=n;i++) leftgcd[i] = __gcd(ar[i],leftgcd[i-1]);



    for(int i=n;i>=1;i--) rightgcd[i] = __gcd(ar[i],rightgcd[i+1]);

    

    int maxx = -1;

    

    for(int i=1;i<=n;i++) maxx = max(maxx,__gcd(leftgcd[i-1],rightgcd[i+1]));



    cout << maxx;

    

    return 0;

} 

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

#include <vector>

#include <algorithm>



using namespace std;



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

{

	std::vector<int> ret;

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

	{

		if(n%i == 0)

		{

			ret.push_back(i);

			if(i*i!=n)

			{

				ret.push_back(n/i);

			}

		}

	}

    sort(ret.begin(), ret.end(), greater<int>());

	return ret;

}



int main(){

    int N;

    cin >> N;



    vector <int> A(N);

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

        cin >> A[i];

    }



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

    

    int result0 = A[0];

    vector <int> EA0 = enum_div(A[0]);

    int j = 0;



    while(result0 > 0){

        int count = 0;

        result0 = EA0[j];

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

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

                count += 1;

            }

        }

        if (count <= 1) {

            break;

        }else{

            j += 1;

        }

    }



    int result1 = A[1];

    vector <int> EA = enum_div(A[1]);

    j = 0;

    while(result1 > 0){

        int count = 0;

        result1 = EA[j];

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

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

                count += 1;

            }

        }

        if (count <= 1) {

            break;

        }else{

            j += 1;

        }

    }



    if (result0 >= result1) {

        cout << result0 << endl;

    }else{

        cout << result1 << endl;

    }

    

    

    



    return 0;

}

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



using namespace std;

 

typedef long long ll;

typedef long double ld;

typedef pair<int, int> Pii;

typedef pair<int, ll> Pil;

typedef pair<ll, ll> Pll;

typedef pair<ll, int> Pli;



#define fi first

#define se second



const ll MOD = 1e9 + 7;

const ll MOD2 = 998244353;

const ll MOD3 = 1812447359;

const ll INF = 1ll << 62;

const double PI = 2 * asin(1);



void yes() {printf("yes\n");}

void no() {printf("no\n");}

void Yes() {printf("Yes\n");}

void No() {printf("No\n");}

void YES() {printf("YES\n");}

void NO() {printf("NO\n");}



ll GCD(ll A, ll B){

  if (A < B) swap(A, B);

  while (A % B != 0){

    A %= B; swap(A, B);

  }

  return B;

}



int N;

ll A[int(1e5+5)];

ll L[int(1e5+5)], R[int(1e5+5)];



int main(){

  cin >> N;

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



  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]);

  }



  ll ans = max(R[1], L[N - 2]);



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

    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):
#include <iostream>

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <cmath>

#include <cstring>

#include <iomanip>

#include <random>

#include <chrono>

#include <queue>

#include <ctime>

using namespace std;

typedef long long ll;

typedef pair<int, int> PII;

typedef pair<ll, ll> PLL;

#define fs first

#define sc second

#define INF 1000000000

#define MOD 1000000007

#define EPS 0.00000001



int main() {

    int N; cin >> N;

    vector<int> A(N);

    for(int &a:A)

        cin >> a;



    set<int> S;

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

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

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

                S.insert(j);

                S.insert(A[i]/j);

            }

        }

    }

    

    map<int, int> M;

    for(int s:S){

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

            if(A[j]%s==0) M[s]++;

        }

    }

    

    int ans = 0;

    for(auto m:M){

        if(m.sc >= N-1) ans = max(ans, m.fs);

    }

        

    cout << ans << endl;

    return 0;

}


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

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <cmath>

#include <cstring>

#include <iomanip>

#include <random>

#include <chrono>

#include <queue>

#include <ctime>

using namespace std;

typedef long long ll;

typedef pair<int, int> PII;

typedef pair<ll, ll> PLL;

#define fs first

#define sc second

#define INF 1000000000

#define MOD 1000000007

#define EPS 0.00000001





int gcd(int a, int b){

    if(b==0) return a;

    return gcd(b, a%b);

}



int main() {

    int N; cin >> N;

    vector<int> A(N);

    for(int &a:A)

        cin >> a;

    vector<vector<int>> dp(N+1, vector<int>(3));

    

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

        dp[i+1][0] = gcd(dp[i][0], A[i]);

        dp[i+1][1] = dp[i][0];

        dp[i+1][2] = max(gcd(dp[i][1], A[i]), gcd(dp[i][2], A[i]));

    }

    cout << max(dp[N][1], dp[N][2]) << endl;

    return 0;

}


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

using namespace std;

using ll = long long;

#define fi first

#define se second

vector<ll> finddivisor(ll x){//整数xの約数が入ったvectorを返すよ(xを含む)  

    vector<ll> divisor;

    for(ll i=1; (i*i)<=x ;i++)

    {

        if(x%i==0){

            divisor.push_back(i);

            if(i*i!=x){

                divisor.push_back(x/i);

            }//約数はペアを持つことを利用



        }

    }

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

    //divisor.push_back(x);

    return divisor;

}

int main(){

    ll n,ans=1;

    cin >> n;

    vector<ll> v(n),a,b;

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

    {

        cin >> v.at(i);

    }

    a=finddivisor(v.at(0));

    b=finddivisor(v.at(1));



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

    {

        ll cnt=0;

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

        {

            if(v.at(j)%a.at(i)!=0){

                cnt++;

            }

            if(cnt>=2){

                break;

            }

        }

        if(cnt<2){

            ans=max(ans,a.at(i));

        }

    }

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

    {

        ll cnt=0;

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

        {

            if(v.at(j)%b.at(i)!=0){

                cnt++;

            }

            if(cnt>=2){

                break;

            }

        }

        if(cnt<2){

            ans=max(ans,b.at(i));

        }

    }

    cout << ans << endl;

}

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

using namespace std;

using ll = long long;

#define fi first

#define se second



ll gcd(ll a,ll b){//最大公約数を求める関数

    if(a<b){

        swap(a,b);

    }



    if(a%b == 0){

        return b;

    }else{

    return gcd(b,a%b);

    }

}

/*問題文を言い換えると、A1からANのうち一つの数を除いた時の、

A1からAN(全部でN-1個）の最大公約数の最大値を求める

とりあえず一つずつ除いてみて、最大公約数を求め、最大値を出力すればよい



同じ部分のgcdを何度も計算したくない→累積gcd(先に計算しておいて後で利用）

同じ処理を何度もしたくない時は先に計算しておいて後で参照できるようにしておく*/



int main(){

    ll n,ans=0;

    cin >> n;

    vector<ll> v(n),g(n,0),c(n,0);//gは左からの,cは右からの累積テーブル

    for(int i=0;i < n;i++)//入力

    {

        cin >> v.at(i);

    }



    g.at(1)=v.at(0);

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

    {

        g.at(i)=gcd(g.at(i-1),v.at(i-1));

    }//g.at(i)はv.at(0)からv.at(i-1)のgcd



    c.at(n-2)=v.at(n-1);

    for(int i=n-3;0<=i;i--)

    {

        c.at(i)=gcd(c.at(i+1),v.at(i+1));

    }//c.at(i)はv.at(i+1)からv.at(n)のgcd



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

    {

        ans=max(ans,gcd(g.at(i),c.at(i)));

        //gcd(g.at(i),c.at(i)) はv.at(i)を除いたときの最大公約数

        //g.at(i)はv.at(0)からv.at(i-1)の最大公約数、同様に

        //c.at(i)はv.at(i+1)からv.at(n-1)の最大公約数

        //v.at(0)とv.at(n-1)を除くときは下で別の処理をしてる（それぞれ左側,右側のgcdがないので)

    }

    ans=max(ans,g.at(n-1));

    ans=max(ans,c.at(0));

    cout << ans << endl;

}

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

using namespace std;

const int maxn=1e5+5;

int a[maxn];

vector<int> fac[5];

void gf(int a,int num)

{

	fac[num].push_back(1);

	fac[num].push_back(a);

	int i;

	for(i=2;i*i<a;i++)

		if(a%i==0)

		{

			fac[num].push_back(i);

			fac[num].push_back(a/i);

		}

	if(i*i==a)

		fac[num].push_back(1);

	sort(fac[num].begin(),fac[num].end());

}

void fl()

{

	freopen(".in","r",stdin);

	freopen(".out","w",stdout);

}

int main()

{

//  fl();

	int n;

	scanf("%d",&n);

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

	{

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

	}

	gf(a[1],1);

	gf(a[2],2);

	int ans=-maxn;

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

	{

		for(int i=fac[t].size()-1;i>=0;i--)

		{

			int tmp=fac[t][i],num=0;

			bool sign=true;

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

			{

				if(a[j]%tmp!=0)

					num++;

				if(num>1)

				{

					sign=false;

					break;

				}

			}

			if(sign)

				ans=max(ans,tmp);

		}

	}

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

	return 0;

}


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

#include<string.h>

#include<math.h>

#include<iostream>

#include<string>

#include<sstream>

#include<algorithm>

#include<map>

#include<set>

#include<queue>

#include<stack>

#include<vector>

using namespace std;

typedef long long ll; 

typedef pair<int, int> P; 

const int mod = 1e9 + 7;

const int N = 2e6 + 5;

struct ed{

	int to, nxt;

}e[N << 1];

int head[N], tot = 1;

void add(int u, int v){

	e[tot].to = v, e[tot].nxt = head[u], head[u] = tot++;

}

ll gcd(ll a, ll b)

{

	return b == 0 ? a : gcd(b, a % b);

}

ll f[N], h[N], a[N], n, ans;

int  main()

{

	scanf("%lld", &n);

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

	{

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

		if (i)

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

		else

			f[i] = a[i];

	}

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

	{

		if (i == n - 1)

			h[i] = a[i];

		else

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

	}

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

	{

		if (i == 0)

			ans = max(ans, h[i + 1]);

		else if (i == n - 1)

			ans = max(ans, f[n - 2]);

		else

			ans = max(ans, gcd(f[i - 1], h[i + 1]));

	}

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

}

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

using namespace std;

const int maxn=1e5+5;

int a[maxn];

vector<int> fac[5];

void gf(int a,int num)

{

	fac[num].push_back(1);

	fac[num].push_back(a);

	int i;

	for(i=2;i*i<a;i++)

		if(a%i==0)

		{

			fac[num].push_back(i);

			fac[num].push_back(a/i);

		}

	if(i*i==a)

		fac[num].push_back(1);

	sort(fac[num].begin(),fac[num].end());

}

void fl()

{

	freopen(".in","r",stdin);

	freopen(".out","w",stdout);

}

int main()

{

//  fl();

	int n;

	scanf("%d",&n);

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

	{

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

	}

	gf(a[1],1);

	gf(a[2],2);

	int ans=-maxn;

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

	{

		for(int i=fac[t].size()-1;i>=0;i--)

		{

			int tmp=fac[t][i],num=0;

			bool sign=true;

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

			{

				if(a[j]%tmp!=0)

					num++;

				if(num>1)

				{

					sign=false;

					break;

				}

			}

			if(sign)

			{

				ans=max(ans,tmp);

				break;

			}

		}

	}

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

	return 0;

}


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

#include<string.h>

#include<math.h>

#include<iostream>

#include<string>

#include<sstream>

#include<algorithm>

#include<map>

#include<set>

#include<queue>

#include<stack>

#include<vector>

using namespace std;

typedef long long ll; 

typedef pair<int, int> P; 

const int mod = 1e9 + 7;

const int N = 2e6 + 5;

struct ed{

	int to, nxt;

}e[N << 1];

int head[N], tot = 1;

void add(int u, int v){

	e[tot].to = v, e[tot].nxt = head[u], head[u] = tot++;

}

ll gcd(ll a, ll b)

{

	return b == 0 ? a : gcd(b, a % b);

}

ll f[N], h[N], a[N], n, ans;

int  main()

{

	scanf("%lld", &n);

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

	{

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

		if (i)

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

		else

			f[i] = a[i];

	}

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

	{

		if (i == n - 1)

			h[i] = a[i];

		else

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

	}

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

	{

		if (i == 0)

			ans = max(ans, h[i + 1]);

		else if (i == n - 1)

			ans = max(ans, f[n - 2]);

		else

			ans = max(ans, gcd(f[i - 1], h[i + 1]));

	}

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

}

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

using namespace std;



int main() {

    int N;

    cin >> N;

    vector<int> A(N);

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

  

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

    int MIN1 = A[0];

    int MIN2 = A[1];

    //cout << MIN1 << " " << MIN2 << endl;

    int ans = 0;

    vector<int> yaku = {};

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

        if (MIN1 % i == 0) {

            yaku.push_back(i);

            yaku.push_back(MIN1 / i);

        }

    }



    //for (int i = 0; i < yaku.size(); i++) cout << yaku[i] << endl;

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

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

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

        int cnt = 0;

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

            if (A[j] % yaku[i] == 0) cnt++;

        }

        if (cnt >= N - 1) {

            ans = yaku[i];

            break;

        }

    }

  

    yaku = {};

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

        if (MIN2 % i == 0) {

            yaku.push_back(i);

            yaku.push_back(MIN2 / i);

        }

    }



    //for (int i = 0; i < yaku.size(); i++) cout << yaku[i] << endl;

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

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

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

        int cnt = 0;

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

            if (A[j] % yaku[i] == 0) cnt++;

        }

        if (cnt >= N - 1) {

            ans = max(ans, yaku[i]);

            break;

        }

    }

    cout << ans << endl;

}

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

using namespace std;



long long gcd(long long a, long long b) {

	if (b == 0) return a;

	return gcd(b, a % b);

}



int main() {

    int N;

    cin >> N;

    vector<long long> A(N);

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

  

    vector<long long> L(N + 1);

    vector<long long> R(N + 1);

    L[0] = 0;

    R[N] = 0;

    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]);



    long long ans = 0;

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

        if (ans < gcd(L[i], R[i + 1])) ans = gcd(L[i], R[i + 1]);

    }

    cout << ans << endl;

}

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

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

using namespace std;

typedef long long ll;

typedef pair<ll,ll> P;

const int MOD = 1000000007;



int main() {

  int n;

  cin >> n;

  map<int,int>mp;

  vector<int>a(n);

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

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

  rep(i,2){

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

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

        mp[j]++;

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

      }

    }

  }

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

    for(auto j:mp){

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

        mp[j.first]++;

      }

    }

  }

  int ans=1;

  for(auto p:mp){  

    if(p.second==n || p.second==n-1){

      if(ans<p.first)ans=p.first;

    }

  }

  

  cout << ans << endl;

  

}


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

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

using namespace std;

typedef unsigned long long ull;

typedef long long ll;

const ll INF=1e18;

const int MOD=1e9+7;

const double pi=acos(-1);

ll gcd(ll x, ll y){

  if(x%y==0)return y;

  else return gcd(y,x%y);

}

int main(){

  int n;

  cin >> n;

  vector<ll>a(n);

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

  vector<ll>lg(n);

  vector<ll>rg(n);

  lg[0]=a[0];

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

  rep(i,n-1){

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

    rg[i+1]=gcd(rg[i],a[n-1-(i+1)]);

  }

  ll ans=0;

  rep(i,n){

    if(i==0)ans=max(ans,rg[n-2]);

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

    else ans=max(ans,gcd(lg[i-1],rg[n-i-2]));

  }

  cout << ans << endl;

            

}


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

using namespace std;

using ll = long long;

int gcd(int a, int b)

{

    if(b == 0) return a;

    return gcd(b, a%b);

}



int main()

{

    int n;

    cin >> n;

    vector<int> a(n);

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

    {

        cin >> a[i];

    }

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

    int ans = 1;

    int m1 = a[n-1];

    int m2 = a[n-2];

    vector<int> m1p;

    vector<int> m2p;

    m1p.push_back(m1);

    m2p.push_back(m2);

    for(int i = 2; i * i <= m1; i++)

    {

        if(m1 % i == 0)

        {

            m1p.push_back(i);

            m1p.push_back(m1 / i);

        }

    }

    for(int i = 2; i * i <= m2; i++)

    {

        if(m2 % i == 0)

        {

            m2p.push_back(i);

            m2p.push_back(m2 / i);

        }

    }



    int i = m1;

    int cnt = 2;

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

    {

        int cand = m1p[i];

        int tmp = 0;

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

        {

            if(a[j] % cand != 0) tmp++;

        }

        if(tmp <= 1)

        {

            ans = max(ans, cand);

        }

    }

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

    {

        int cand = m2p[i];

        int tmp = 0;

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

        {

            if(a[j] % cand != 0) tmp++;

        }

        if(tmp <= 1)

        {

            ans = max(ans, cand);

        }

    }

    cout << ans << endl;

}




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

using namespace std;

int gcd(int a, int b)

{

    if(b == 0) return a;

    return gcd(b, a%b);

}

int main()

{

    int n;

    cin >> n;

    vector<int> a(n);

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

    {

        cin >> a[i];

    }

    vector<int> l(n+1);

    vector<int> r(n+1);

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

    {

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

    }

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

    {

        r[i+1] = gcd(r[i], a[n-i-1]);

    }



    int ans = 0;

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

    {

        int g = gcd(l[i], r[n-1-i]);

        ans = max(ans, g);

    }

    cout << ans << endl;

}






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

using namespace std;

int a[100010];

int res[100010];

int cnt[100010];

int main(){

	int n;

	cin>>n;

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

	sort(a,a+n);

	int x=a[0];

	int y=a[1];

	int c=0;

	int b=0;

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

		if(x%i==0){

			res[c]=i;

			c++;

			res[c]=x/i;

			c++;

		}

	}

	sort(res,res+c);

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

		if(y%i==0){

			cnt[b]=i;

			b++;

			cnt[b]=y/i;

			b++;

		}

	}

	sort(cnt,cnt+b);

	int ans=-1;

	int ans2=-1;

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

		int ans3=0;

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

			if(a[j]%res[i]!=0){

				ans3++;

			}

		}

		if(ans3==0||ans3==1){

			ans=res[i];

			break;

		}

	}

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

		int ans3=0;

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

			if(a[j]%cnt[i]!=0){

				ans3++;

			}

		}

		if(ans3==0||ans3==1){

			ans2=cnt[i];

			break;

		}

	}

	cout<<max(ans,ans2)<<endl;

	return 0;

}

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

using namespace std;

int a[100010];

int res[100010];

int cnt[100010];

int solve(int n){

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

		cin>>a[i];

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

	}

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

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

	}

	int ans=1;

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

		ans=max(ans,__gcd(res[i-1],cnt[i+1]));

	}

	return ans;

}

int main(){

	int n;

	cin>>n;

	cout<<solve(n)<<endl;

	return 0;

}

// Fastest known solution for this problem: