#include<bits/stdc++.h>
using namespace std;
int a[1005];
int b[1100][1100];
int c[1100];
void gmin(int x)
{
	for(int i=2;i<=x;i++)
	{
		if(x%i==0) b[x][++c[x]]=i;
	}
}
inline int read()
{
	char ch=getchar();
	int x=0,f=1;
	while(ch>'9'||ch<'0')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		//a[i]=read();
		scanf("%d",&a[i]);
	}
	int maxx=-1,maxd;
	for(int i=1;i<=n;i++)
	{
		gmin(a[i]);
		for(int k=1;k<=c[a[i]];k++)
	 {
	 	int cnt=0;
		for(int j=1;j<=n;j++)
		{
			if(a[j]%b[a[i]][k]==0) cnt++;
			if(cnt>maxx)
			{
				maxx=cnt;
				maxd=b[a[i]][k];
			}
		}
	 }
	}
	printf("%d",maxd);
	return 0;
}
#define _DEBUG
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back(a)
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int N=S.size();
	/*
	int rui[26][200001]={};
	rep(k,26){
		brep(i,N){
			rui[k][i]=rui[k][i+1]+(S[i]-'a'==k);
		}
	}*/
	/*vint rensoeji;
	for(int i=N-1;i>=1;--i){
		if(S[i-1]==S[i]){
			rensoeji.puba(i);
		}
	}*/
	int charnum[26]={};
	bool ren[200001]={};
	for(int i=N-1;i>=1;--i){
		if(S[i-1]==S[i]) ren[i]=1;
	}
	ll ans=0;
	brep(i,N){
		if(ren[i]){
			ans+=N-1-i-charnum[S[i]-'a'];
			rep(k,26){
				if(S[i]-'a'==k) charnum[k]=N-1-i;
				else charnum[k]=0;
			}
		}
		charnum[S[i]-'a']++;
	}
	prin(ans);
	return 0;
}
