#include<bits/stdc++.h>
#include <chrono>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define PI 3.14159265
#define INF 1000000000000000000
#define pll pair<ll,ll>
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vll vector<ll>
#define all(a) a.begin(),a.end()
#define forl(i,n) for(ll i=0;i<n;i++)
#define fore(i,n) for(ll i=1;i<=n;i++)
ll max(ll a,ll b)
{
    if(a>b)
    return a;
    return b;
}

ll min(ll a,ll b)
{
    return a+b-max(a,b);
}
ll mulmod(ll a, ll b, ll mod)
{
    /*ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0)
    {
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod; */
    return ((a%MOD)*(b%MOD)%MOD);
}
ll mod(ll a,ll b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;

}
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
int bits(ll n)
{
    ll ctr=0;
    while(n)
    {
        n/=10;
        ctr++;
    }
    return ctr;
}
// bool cmp(pll p1,pll p2)
// {
//     if(p1.f<p2.f)
//     return true;
//     if(p1.f==p2.f)
//     return p1.s>p2.s;
//     return false;
// }
vll bits1(ll n)
{
    vll res;
    while(n)
    {
        res.pb(n%10);
        n/=10;
    }
    reverse(all(res));
    return res;
}

void solve()
{
    ll n;
    cin>>n;
    vll vec(n);
    cin>>vec;
    vll alls[1000005];
    forl(i,n)
    alls[vec[i]].pb(i);
    map<pll,ll> m1;
    vll v1,v2;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            if(m1[{vec[i],vec[j]}])
            continue;
            m1[{vec[i],vec[j]}]=1;
            v1 = alls[vec[i]];
            v2 = alls[vec[j]];
            ll c1 = 0;
            ll c2 = 0;
            ll st1 = -1;
            ll st2 = -1;
            ll ctr = 0;
            while(c1<v1.size() || c2<v2.size())
            {
                if(ctr%2 == 0)
                {
                    if(c1<v1.size())
                    {
                        if(v1[c1]>st2)
                        {
                            st1 = v1[c1];
                            c1++;
                            ctr++;
                        }
                        else
                        c1++;
                    }
                    else
                    break;
                }
                else
                {
                    if(c2<v2.size())
                    {
                        if(v2[c2]>st1)
                        {
                            st2 = v2[c2];
                            c2++;
                            ctr++;
                        }
                        else
                        c2++;
                    }
                    else
                    break;
                }
            }
            ans = max(ans,ctr);

        }
    }
    cout<<ans;

}
int main()
{
    fastio;
    ll t;
    t=1;

    //prep();
    while(t--)
    {
        solve();

    }

}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

vector<int> adj[N];

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		adj[a[i]].push_back(i);
	}
	vector<vector<int>> v;
	int sol = 0;
	for(int i = 0; i < N; i++)
	{
		if(adj[i].size())
		{
			sol = max(sol, (int)adj[i].size());
			v.push_back(adj[i]);
		}
	}
	for(int i = 0; i < v.size(); i++)
	{
		for(int j = i + 1; j < v.size(); j++)
		{
			int l = 0;
			int r = 0;
			bool can = false;
			while(r < v[j].size() and v[j][r] < v[i][l])
			{
				r++;
				can = true;
			}
			int cnt = 2;
			sol = max(sol, cnt);
			// cout << v[i][0] << " " << v[j][0] << " " << v[i][l] << " " << v[j][r] << " " << sol << " ";
			while(l < v[i].size() and r < v[j].size())
			{
				while(l < v[i].size() and v[i][l] < v[j][r])
				{
					l++;
				}
				if(l == v[i].size())
					break;
				if(l < v[i].size())
					cnt++;
				while(r < v[j].size() and v[j][r] < v[i][l])
				{
					r++;
				}
				if(r < v[j].size() and l < v[i].size())
					cnt++;
				sol = max(sol, cnt);
			}
			// cout << sol << "\n";
		}
	}
	cout << sol;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

string vv[] = {"popStack", "popQueue", "popFront"};

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int sol = min(2, n);
	int cnt = min(2, n);
	for(int i = 2; i < n; i++)
	{
		if(a[i] == a[i - 2])
		{
			cnt++;
		}
		else
		{
			cnt = 2;
		}
		sol = max(sol, cnt);
	}
	sol = max(sol, cnt);
	cout << sol;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

vector<int> adj[N];

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		adj[a[i]].push_back(i);
	}
	vector<vector<int>> v;
	int sol = 0;
	for(int i = 0; i < N; i++)
	{
		if(adj[i].size())
		{
			sol = max(sol, (int)adj[i].size());
			v.push_back(adj[i]);
		}
	}
	for(int i = 0; i < v.size(); i++)
	{
		for(int j = i + 1; j < v.size(); j++)
		{
			int l = 0;
			int r = 0;
			bool can = false;
			while(r < v[j].size() and v[j][r] < v[i][l])
			{
				r++;
				can = true;
			}
			int cnt = 2;
			sol = max(sol, cnt);
			// cout << v[i][0] << " " << v[j][0] << " " << v[i][l] << " " << v[j][r] << " " << sol << " ";
			while(l < v[i].size() and r < v[j].size())
			{
				while(l < v[i].size() and v[i][l] < v[j][r])
				{
					l++;
				}
				if(l >= v[i].size())
					break;
				while(r < v[j].size() and v[j][r] < v[i][l])
				{
					r++;
				}
				if(r < v[j].size() and l < v[i].size())
					cnt++;
				sol = max(sol, cnt);
			}
			// cout << sol << "\n";
		}
	}
	cout << sol;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

vector<int> adj[N];

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		adj[a[i]].push_back(i);
	}
	vector<vector<int>> v;
	int sol = 0;
	for(int i = 0; i < N; i++)
	{
		if(adj[i].size())
		{
			sol = max(sol, (int)adj[i].size());
			v.push_back(adj[i]);
		}
	}
	for(int i = 0; i < v.size(); i++)
	{
		for(int j = i + 1; j < v.size(); j++)
		{
			int l = 0;
			int r = 0;
			bool can = false;
			while(r < v[j].size() and v[j][r] < v[i][l])
			{
				r++;
				can = true;
			}
			int cnt = 2;
			sol = max(sol, cnt);
			// cout << v[i][0] << " " << v[j][0] << " " << v[i][l] << " " << v[j][r] << " " << sol << " ";
			while(l < v[i].size() and r < v[j].size())
			{
				while(l < v[i].size() and v[i][l] < v[j][r])
				{
					l++;
				}
				if(l < v[i].size())
					cnt++;
				while(r < v[j].size() and v[j][r] < v[i][l])
				{
					r++;
				}
				if(r < v[j].size() and l < v[i].size())
					cnt++;
				sol = max(sol, cnt);
			}
			// cout << sol << "\n";
		}
	}
	cout << sol;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

vector<int> adj[N];

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		adj[a[i]].push_back(i);
	}
	vector<vector<int>> v;
	int sol = 0;
	for(int i = 0; i < N; i++)
	{
		if(adj[i].size())
		{
			sol = max(sol, (int)adj[i].size());
			v.push_back(adj[i]);
		}
	}
	for(int i = 0; i < v.size(); i++)
	{
		for(int j = i + 1; j < v.size(); j++)
		{
			int l = 0;
			int r = 0;
			bool can = false;
			while(v[j][r] < v[j].size() and v[j][r] < v[i][l])
			{
				r++;
				can = true;
			}
			int cnt = 2;
			sol = max(sol, cnt);
			while(l < v[i].size() and r < v[j].size())
			{
				while(l < v[i].size() and v[i][l] < v[j][r])
				{
					l++;
				}
				if(l < v[i].size())
					cnt++;
				while(r < v[j].size() and v[j][r] < v[i][l])
				{
					r++;
				}
				if(r < v[j].size() and l < v[i].size())
					cnt++;
				sol = max(sol, cnt);
			}
		}
	}
	cout << sol;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 10;

vector<int> adj[N];

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		adj[a[i]].push_back(i);
	}
	vector<vector<int>> v;
	int sol = 0;
	for(int i = 0; i < N; i++)
	{
		if(adj[i].size())
		{
			sol = max(sol, (int)adj[i].size());
			v.push_back(adj[i]);
		}
	}
	for(int i = 0; i < v.size(); i++)
	{
		for(int j = i + 1; j < v.size(); j++)
		{
			int l = 0;
			int r = 0;
			bool can = false;
			while(r < v[j].size() and v[j][r] < v[i][l])
			{
				r++;
				can = true;
			}
			int cnt = 2;
			if(can and r < v[j].size())
				cnt++;
			sol = max(sol, cnt);
			// cout << v[i][0] << " " << v[j][0] << " " << v[i][l] << " " << v[j][r] << " " << sol << " ";
			while(l < v[i].size() and r < v[j].size())
			{
				while(l < v[i].size() and v[i][l] < v[j][r])
				{
					l++;
				}
				if(l == v[i].size())
					break;
				if(l < v[i].size())
					cnt++;
				while(r < v[j].size() and v[j][r] < v[i][l])
				{
					r++;
				}
				if(r < v[j].size() and l < v[i].size())
					cnt++;
				sol = max(sol, cnt);
			}
			// cout << sol << "\n";
		}
	}
	cout << sol;

	return 0;
}


#include <bits/stdc++.h>
#include <bitset>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define mod 1000000007

using namespace std;

int n;
int arr[4004];
int mem[4004][4004][2], Next[4004];
bool visited[1000001];

int solve(int i, int other, bool e5tart)
{
    if(i==n)return 0;
    if(mem[i][other][e5tart]!=-1) return mem[i][other][e5tart];
    int ret, nextt;
    int u=Next[other];
    while(1)
    {
        if(u>i)
            {nextt=u; break;}
        u=Next[u];
    }
    ret = solve(nextt, i, 1)+1 ;
    if(!e5tart)
    {
        ret = max( ret, solve(i+1,other,0) );
    }
    return  mem[i][other][e5tart] = ret;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
    {
        bool b=0;
        for(int j=i+1;j<n;j++){
            if(arr[j]==arr[i])
                {Next[i]=j;b=1;break;}
        }
        if(!b)Next[i]=n;
    }
    for(int i=0;i<n;i++)
    {
       if(visited[arr[i]])continue;
       visited[arr[i]]=1;
        ans=max(ans,solve(i+1,i,0)+1);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
 //   ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++;
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
         // else if(p<pos[b].size() && p)
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++;
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(min(freq[*it],freq[*it2])+2<ans)continue;
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    int ans=1;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++,ans=max(ans,freq[v[i]]);
    vector<pair<int,int> > r;
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)r.push_back({it->second,it->first});
    sort(r.rbegin(),r.rend());
    vector<int>vv;
    for(int i=0 ; i<r.size();i++)vv.push_back(r[i].second);
    for(int it=0;it<vv.size();it++)
    {
      for(int it2=it+1 ;it2<vv.size();it2++)
      {
        if(min(freq[vv[it]],freq[vv[it2]])*2+1<=ans)continue;
        //if(it==it2)continue;
        int a=vv[it],b=vv[it2],cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
   // for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    for(int i=0;i<n;i++)cin>>v[i],se.insert(v[i]),pos[v[i]].push_back(i);
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    cout<<ans;
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++;
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(min(freq[*it],freq[*it2])*2+1<ans)continue;
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int arr[4004], n;
int mem[4004][4004];

int solve(int i,int pre)
{
  if(i==n)return 0;
  if(mem[i][pre]!=-1)return mem[i][pre];
  ll ret=solve(i+1,pre);
  int u=1e9,q=1e9;
  if(pre!=4001){
   u=arr[pre];
   if((i+1)%2==0)q=arr[i]-u;
   else q=u-arr[i];
  }
  if(arr[i]==u+q || !i)
  {
     ret=max((ll)ret,(ll)solve(i+1,i)+1);
  }
  return mem[i][pre]=ret;
}

int main ()
{
     memset(mem,-1,sizeof mem);
     cin>>n;
     for(int i=0;i<n;i++)cin>>arr[i];
     int ans=solve(0,4001);
     cout<<solve(0,4001);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    int ans=1;
    map<int,int>freq;
    for(int i=0;i<n;i++)cin>>v[i],se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++,ans=max(ans,freq[v[i]]);
    vector<pair<int,int> > r;
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)r.push_back({it->second,it->first});
    sort(r.rbegin(),r.rend());
    vector<int>vv;
    for(int i=0 ; i<r.size();i++)vv.push_back(r[i].second);
    for(int it=0;it<vv.size();it++)
    {
      if(freq[vv[it]]*2+1<=ans)continue;
      for(int it2=it+1 ;it2<vv.size();it2++)
      {
      //  if(min(freq[vv[it]],freq[vv[it2]])*2+1<=ans)continue;
        //if(it==it2)continue;
        int a=vv[it],b=vv[it2],cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
   // for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
   cout<<ans;
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++;
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(min(freq[*it],freq[*it2])*2+1<=ans)continue;
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++;
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    int ans=1;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++,ans=max(ans,freq[v[i]]);
    vector<pair<int,int> > r;
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)r.push_back({it->second,it->first});
    sort(r.rbegin(),r.rend());
    vector<int>vv;
    for(int i=0 ; i<r.size();i++)vv.push_back(r[i].second);
    for(int it=0;it<vv.size();it++)
    {
      if(freq[vv[it]]*2+1<=ans)continue;
      for(int it2=it+1 ;it2<vv.size();it2++)
      {
        if(min(freq[vv[it]],freq[vv[it2]])*2+1<=ans)continue;
        //if(it==it2)continue;
        int a=vv[it],b=vv[it2],cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
   // for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
   printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#include <bitset>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define mod 1000000007

using namespace std;

int n;
int arr[4004];
int mem[4004][4004][2], Next[4004];

int solve(int i, int other, bool e5tart)
{
    if(i==n)return 0;
    if(mem[i][other][e5tart]!=-1) return mem[i][other][e5tart];
    int ret, nextt;
    int u=Next[other];
    while(1)
    {
        if(u>i)
            {nextt=u; break;}
        u=Next[u];
    }
    ret = solve(nextt, i, 1)+1 ;
    if(!e5tart)
    {
        ret = max( ret, solve(i+1,other,0) );
    }
    return  mem[i][other][e5tart] = ret;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
    {
        bool b=0;
        for(int j=i+1;j<n;j++){
            if(arr[j]==arr[i])
                {Next[i]=j;b=1;break;}
        }
        if(!b)Next[i]=n;
    }
    for(int i=0;i<n;i++)
        ans=max(ans,solve(i+1,i,0)+1);
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    int ans=1;
    map<int,int>freq;
    for(int i=0;i<n;i++)cin>>v[i],se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++,ans=max(ans,freq[v[i]]);
    vector<pair<int,int> > r;
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)r.push_back({it->second,it->first});
    sort(r.rbegin(),r.rend());
    vector<int>vv;
    for(int i=0 ; i<r.size();i++)vv.push_back(r[i].second);
    for(int it=0;it<vv.size();it++)
    {
      for(int it2=it+1 ;it2<vv.size();it2++)
      {
        if(min(freq[vv[it]],freq[vv[it2]])*2+1<=ans)continue;
        //if(it==it2)continue;
        int a=vv[it],b=vv[it2],cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
   // for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
   cout<<ans;
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    scanf("%d",&n);
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    int ans=1;
    map<int,int>freq;
    for(int i=0;i<n;i++)scanf("%d",&v[i]),se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++,ans=max(ans,freq[v[i]]);
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(min(freq[*it],freq[*it2])*2+1<=ans)continue;
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p<pos[b].size() && p==pre && pos[b][pos[b].size()-1]==p){cnt++;break;}
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
   // for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    printf("%d",ans);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int arr[4004], n;
int mem[4004][4004];

int solve(int i,int pre)
{
  if(i==n)return 0;
  if(mem[i][pre]!=-1)return mem[i][pre];
  ll ret=solve(i+1,pre);
  int u=1e9,q=1e9;
  if(pre!=4001){
   u=arr[pre];
   if((i+1)%2==0)q=arr[i]-u;
   else q=u-arr[i];
  }
  if(arr[i]==u+q || pre==4001)
  {
     ret=max((ll)ret,(ll)solve(i+1,i)+1);
  }
  return mem[i][pre]=ret;
}

int main ()
{
     memset(mem,-1,sizeof mem);
     cin>>n;
     for(int i=0;i<n;i++)cin>>arr[i];
     //int ans=solve(0,4001);
     cout<<solve(0,4001);
       return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double

using namespace std;

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int>v(n);
    set<int>se;
    map<int,vector<int> >pos;
    map<int,int>freq;
    for(int i=0;i<n;i++)cin>>v[i],se.insert(v[i]),pos[v[i]].push_back(i),freq[v[i]]++;
    int ans=1;
    for(set<int>::iterator it=se.begin();it!=se.end();it++)
    {
      for(set<int>::iterator it2=it ;it2!=se.end();it2++)
      {
        if(it==it2)continue;
        int a=*it,b=*it2,cnt=0,pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
        swap(a,b); cnt=0;pre=-1;
        for(int i=0;i<pos[a].size();i++)
        {
          int p=upper_bound(pos[b].begin(),pos[b].end(),pos[a][i])-pos[b].begin();
          if(p<pos[b].size() && p!=pre)cnt+=2,pre=p;
          else if(p>=pos[b].size()){cnt++;break;}
        }
        ans=max(ans,cnt);
      }
    }
    for(map<int,int>::iterator it=freq.begin();it!=freq.end();it++)ans=max(ans,it->second);
    cout<<ans;
       return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	map<ii, int> mp[n];
	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			mp[i][ii(arr[i], arr[j])] = max(mp[i][ii(arr[i], arr[j])], (mp[j][ii(arr[j], arr[i])] ? 1 : 2) + mp[j][ii(arr[j], arr[i])]);
			ans = max(mp[i][ii(arr[i], arr[j])], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

unordered_map<int, int> mp[4000];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			int test = mp[j][arr[i]];
			mp[i][arr[j]] = max(mp[i][arr[j]], ((test ? 1 : 2) + test));
			ans = max(mp[i][arr[j]], ans);
			// cout << i << ' ' << j << ' ' << mp[i][arr[j]] << endl;
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

unordered_map<int, unordered_map<int, int>> mp[4001];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			mp[i][arr[i]][arr[j]] = max(mp[i][arr[i]][arr[j]], (mp[j][arr[j]][arr[i]] ? 1 : 2) + mp[j][arr[j]][arr[i]]);
			ans = max(mp[i][arr[i]][arr[j]], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int mp[4000][4000];
map<int, int> ch;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	int p = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		if (!ch[arr[i]]) {
			ch[arr[i]] = p++;
		}
		arr[i] = ch[arr[i]];
	}

	memset(mp, 0, sizeof mp);

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			int test = mp[j][arr[i]];
			mp[i][arr[j]] = max(mp[i][arr[j]], ((test ? 1 : 2) + test));
			ans = max(mp[i][arr[j]], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

unordered_map<int, map<int, int>> mp[4001];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			mp[i][arr[i]][arr[j]] = max(mp[i][arr[i]][arr[j]], (mp[j][arr[j]][arr[i]] ? 1 : 2) + mp[j][arr[j]][arr[i]]);
			ans = max(mp[i][arr[i]][arr[j]], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int mp[4000][4001];
map<int, int> ch;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	int p = 1;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		if (ch[arr[i]] == 0) {
			ch[arr[i]] = p++;
		}
		arr[i] = ch[arr[i]];
	}

	memset(mp, 0, sizeof mp);

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			int test = mp[j][arr[i]];
			mp[i][arr[j]] = max(mp[i][arr[j]], ((test ? 1 : 2) + test));
			ans = max(mp[i][arr[j]], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

map<int, map<int, int>> mp[4001];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			int test = mp[j][arr[j]][arr[i]];
			mp[i][arr[i]][arr[j]] = max(mp[i][arr[i]][arr[j]], (test ? 1 : 2) + test);
			ans = max(mp[i][arr[i]][arr[j]], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

map<int, map<int, int>> mp[4001];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			mp[i][arr[i]][arr[j]] = max(mp[i][arr[i]][arr[j]], (mp[j][arr[j]][arr[i]] ? 1 : 2) + mp[j][arr[j]][arr[i]]);
			ans = max(mp[i][arr[i]][arr[j]], ans);
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

map<int, int> mp[4000];

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int ans = 1;
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j >= 0; j--) {
			int test = mp[j][arr[i]];
			mp[i][arr[j]] = max(mp[i][arr[j]], ((test ? 1 : 2) + test));
			ans = max(mp[i][arr[j]], ans);
			// cout << i << ' ' << j << ' ' << mp[i][arr[j]] << endl;
		}
	}
	cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
int v[4010];
map<int,int>mapa;
int dp[5000][5000];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> v[i];

	int ans = 1;
	for(int i = 1; i <= n; i++ )
	{
		for(int j = i+1 ; j <= n; j++)
		{
			if(mapa.count(v[j]))
				dp[i][j] += dp[ mapa[v[j]] ][i] + 1;
			else
				dp[i][j] = 2;

			ans = max(ans,dp[i][j]);
		}
		mapa[v[i]] = i;
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int v[4010];
map<int,int>mapa;
int dp[5000][5000];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> v[i];

	int ans = 0;
	for(int i = 1; i <= n; i++ )
	{
		for(int j = i+1 ; j <= n; j++)
		{
			if(mapa.count(v[j]))
				dp[i][j] += dp[ mapa[v[j]] ][i] + 1;
			else
				dp[i][j] = 2;

			ans = max(ans,dp[i][j]);
		}
		mapa[v[i]] = i;
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int v[n];
	for(int i = 0; i < n; i++)
		scanf("%d",&v[i]);
	int ans = 1;

	for(int i = 0; i < n; i++)
	{
		int fix = v[i];
		int cont = 1;
		for(int j = i+1; j < n && v[j] == fix; j++)
			cont++;
		ans = max(ans,cont);
	}

	for(int i = 0; i < n; i++)
	{
		int fix = v[i];
		int aux = v[i+1];
		int cont = 2;
		int t = 1;
		for(int j = i+2; j < n; j++)
		{
			if(t && v[j] == fix)
			{
				cont++;
				t = 1 - t;
			}
			else if(!t && v[j] == aux)
			{
				cont++;
				t = 1 - t;
			}
		}
		ans = max(ans,cont);
	}
	printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
unordered_map<int,vector<int> >mapa;
int dp[4005][4005];
int v[4005];
int solve(int i, int j)
{
	if(dp[i][j] != -1)
		return dp[i][j];
	vector<int>::iterator it = lower_bound(mapa[v[i]].begin(),mapa[v[i]].end(),j+1);
	int aux;
	if(it == mapa[v[i]].end())
		aux = -1;
	else
		aux = (*it);

	if(aux == -1)
		dp[i][j] = 2;
	else
		dp[i][j] = solve(j,aux)+1;
	return dp[i][j];
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d",&v[i]);
		mapa[v[i]].push_back(i);
	}
	memset(dp,-1,sizeof(dp));
	int ans = 0;
	if(n == 1)
	{
		puts("1");
		return 0;
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = i+1; j < n; j++)
		{
			ans = max(ans,solve(i,j));
		}
	}
	printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int v[n];
	for(int i = 0; i < n; i++)
		scanf("%d",&v[i]);
	int ans = 0;

	for(int i = 0; i < n; i++)
	{
		int fix = v[i];
		int cont = 1;
		for(int j = i+1; j < n && v[j] == fix; j++)
			cont++;
		ans = max(ans,cont);
	}

	for(int i = 0; i < n-1; i++)
	{
		int fix = v[i];
		int aux = v[i+1];
		int cont = 2;
		int t = 1;
		for(int j = i+2; j < n; j++)
		{
			if(t && v[j] == fix)
			{
				cont++;
				t = 1 - t;
			}
			else if(!t && v[j] == aux)
			{
				cont++;
				t = 1 - t;
			}
		}
		ans = max(ans,cont);
	}
	printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int v[4010];
map<int,int>mapa;
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	if(n <= 2)
	{
		if(n == 2)
		{
			if(v[0] != v[1])
				cout << "2\n";
			else
				cout << "1\n";
		}
		else
			cout << "1\n";
		return 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int cont = 0;
		mapa[v[i]]++;
	}
	for(auto it  = mapa.begin(); it != mapa.end(); it++)
		ans = max(ans,it->second);
	for(int i = 0; i < n-2; i++)
	{
		int a = v[i];
		int b = v[i+1];
		bool c = 0;
		int aux = 2;
		for(int j = i+2 ; j < n; j++)
		{
			if(c == 0 && v[j] == a)
			{
				aux++;
				c ^= 1;
			}
			else if(c == 1 && v[j] == b)
			{
				aux++;
				c ^= 1;
			}
		}
		ans = max(ans,aux);
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int v[4010];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	if(n <= 2)
	{
		if(n == 2)
		{
			if(v[0] != v[1])
				cout << "2\n";
			else
				cout << "1\n";
		}
		else
			cout << "1\n";
		return 0;
	}
	int ans = 1;
	for(int i = 0; i < n-2; i++)
	{
		int a = v[i];
		int b = v[i+1];
		bool c = 0;
		int aux = 2;
		for(int j = i+2 ; j < n; j++)
		{
			if(c == 0)
			{
				if(v[j] == a)
					aux++;
			}
			else
			{
				if(v[j] == b)
					aux++;
			}
		}
		ans = max(ans,aux);
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int v[4010];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	if(n <= 2)
	{
		if(n == 2)
		{
			if(v[0] != v[1])
				cout << "2\n";
			else
				cout << "1\n";
		}
		else
			cout << "1\n";
		return 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int cont = 0;
		for(int j = i+1; j < n && v[j] == v[i]; j++)
			cont++;
		ans = (cont,ans);
	}
	for(int i = 0; i < n-2; i++)
	{
		int a = v[i];
		int b = v[i+1];
		bool c = 0;
		int aux = 2;
		for(int j = i+2 ; j < n; j++)
		{
			if(c == 0 && v[j] == a)
			{
				aux++;
				c ^= 1;
			}
			else if(c == 1 && v[j] == b)
			{
					aux++;

				c ^= 1;
			}
		}
		ans = max(ans,aux);
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int v[4010];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> v[i];
	if(n <= 2)
	{
		if(n == 2)
		{
			if(v[0] != v[1])
				cout << "2\n";
			else
				cout << "1\n";
		}
		else
			cout << "1\n";
		return 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int cont = 0;
		for(int j = i+1; j < n && v[j] == v[i]; j++)
			cont++;
		ans = (cont,ans);
	}
	for(int i = 0; i < n-2; i++)
	{
		int a = v[i];
		int b = v[i+1];
		bool c = 0;
		int aux = 2;
		for(int j = i+2 ; j < n; j++)
		{
			if(c == 0 && v[j] == a)
			{
				aux++;
				c ^= 1;
			}
			else if(c == 1 && v[j] == b)
			{
				aux++;
				c ^= 1;
			}
			else
				break;
		}
		ans = max(ans,aux);
	}
	cout << ans << '\n';
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

#include <string>

using namespace std;

int main()
{
	int n;
	cin >> n;

	string s;
	cin >> s;

	int x[300];
	for (int i = 0; i < 300; ++i)
		x[i] = 0;

	for (int i = 0; i < s.size(); ++i)
		x[s[i]]++;

	int num[2] = {0, 0};
	int c = 0;

	vector<int> even;
	vector<int> odd;

	for (int i = 0; i < 300; ++i)
	{
		if (x[i] == 0)
			continue;

		num[x[i] & 1]++;
		++c;

		if (x[i] & 1)
			odd.push_back(i);
		else
			even.push_back(i);
	}

	for (int ii = 1; ii <= n; ++ii)
	{
		if (n % ii != 0)
			continue;

		int len = n / ii;
		int groups = ii;

		if (len & 1)
		{
			if (num[1] > groups)
				continue;

			cout << groups << endl;

			for (int i = 0; i < groups; ++i)
			{
				string s(len, '0');

				if (odd.size() == 0)
				{
					int t = even.back();
					even.pop_back();
					--x[t];
					odd.push_back(t);

					s[len / 2] = (char)(t);
				}
				else
				{
					int t = odd.back();
					--x[t];
					s[len / 2] = (char)(t);

					odd.pop_back();
					if (x[t] != 0)
						even.push_back(t);
				}

				for (int j = 0; j < len / 2; ++j)
				{
					while (x[even.back()] == 0)
						even.pop_back();
					s[j] = (char)(even.back());
					s[len - 1 - j] = (char)(even.back());
				}

				cout << s << " ";
			}
			system("pause");
			return 0;
		}
		else
		{
			if (num[0] != c)
				continue;

			cout << groups << endl;

			int it = 0;
			int cur = 0;
			for (int i = 0; i < groups; ++i)
			{
				string s(len, '0');
				int r = 0;
				for (int j = 0; j < len / 2; ++j)
				{
					if (cur == x[it])
					{
						cur = 0;
						++it;
						while (x[it] == 0)
							++it;
					}

					s[r] = (char)(it);
					s[len - r - 1] = (char)(it);
					++r;
					cur += 2;
				}

				cout << s << " ";
			}
			system("pause");
			return 0;
		}
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int n;
string s;
map<char, int> mp;
vector<string> ans;

void print_ans(int cnt_group) {
	cout << cnt_group << "\n";
	if (cnt_group == n) {
		for (int i = 0; i < n; i++)
			cout << s[i] << " ";
		return;
	}
	int len = n / cnt_group;
	map<char, int>::iterator i = mp.begin();
	for (int x = 0; x < cnt_group; x++) {
		string new_s = "";
		int cnt = 0;
		while (i != mp.end() && cnt < len / 2) {
			if (i->second >= 2) {
				new_s += i->first;
				i->second -= 2;
				cnt++;
			}
			else
				i++;
		}
		ans.push_back(new_s);
	}
	int uk = 0;
	int sz = (int)ans.size();
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++) {
		int cnt = i->second;
		while (uk < sz && cnt > 0) {
			string new_s = ans[uk];
			ans[uk] += i->first;
			reverse(new_s.begin(), new_s.end());
			ans[uk] += new_s;
			uk++;
			cnt--;
		}
	}
	for (int i = 0; i < sz; i++)
		cout << ans[i] << " ";
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		mp[s[i]]++;
	int cnt_odd = 0;
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
		if (i->second % 2 != 0)
			cnt_odd++;

	if (cnt_odd == 0) {
		string new_s = "";
		for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
			for (int j = 0; j < i->second / 2; j++)
				new_s += i->first;
		cout << new_s;
		reverse(new_s.begin(), new_s.end());
		cout << new_s;
		return 0;
	}

	for (int i = cnt_odd; i <= n; i++)
		if (n % i == 0 && (n / i) % 2 != 0 && (i - cnt_odd) % 2 == 0) {
			print_ans(i);
			break;
		}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1000000000;
const int MAX_N = 50000;
string s;
vector <string> ans;
map<char,int> x;
map<char, int> p;
int f(int k,int size)
{
	ans.clear();
	string t;
	p = x;
	for (int i = 0; i < 26; i++)
	{
		if (p['a'+i] % 2 == 1)
		{
			p['a' + i]--;
			t.clear();
			t.push_back('a' + i);
			ans.push_back(t);
		}
		if (p['A' + i] % 2 == 1)
		{
			p['A' + i]--;
			t.clear();
			t.push_back('A' + i);
			ans.push_back(t);
		}
	}
	for (int i = 0; i < 10; i++)
	{
		if (p['0' + i] % 2 == 1)
		{
			p['0' + i]--;
			t.clear();
			t.push_back('0' + i);
			ans.push_back(t);
		}
	}
	while (ans.size()<k)
	{
		for (int i = 0; i < 26; i++)
		{
			if (p['a' + i]>=2)
			{
				p['a' + i]-=2;
				t.clear();
				t.push_back('a' + i);
				ans.push_back(t);
				ans.push_back(t);
			}
			if (p['A' + i] >= 2)
			{
				p['A' + i]-=2;
				t.clear();
				t.push_back('A' + i);
				ans.push_back(t);
				ans.push_back(t);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			if (p['0' + i] >= 2)
			{
				p['0' + i]-=2;
				t.clear();
				t.push_back('0' + i);
				ans.push_back(t);
				ans.push_back(t);
			}
		}
	}
	for (int q = 0; q < ans.size();q++)
	{
		t = ans[q];
		deque <char> temp;
		for (int j = 0; j < t.size(); j++)
			temp.push_back(t[j]);
		while (temp.size()<size)
		{
			for (int i = 0; i < 26; i++)
			{
				while (p['a'+i] >= 2 && temp.size()<size)
				{
					p['a'+i] -= 2;
					temp.push_back('a' + i);
					temp.push_front('a' + i);
				}
				while (p['A' + i] >= 2 && temp.size()<size)
				{
					p['A' + i] -= 2;
					temp.push_back('A' + i);
					temp.push_front('A' + i);
				}
				if (temp.size() >= size)
					break;
			}
			for (int i = 0; i < 10; i++)
			{
				while (p['0' + i] >= 2 && temp.size()<size)
				{
					p['0' + i] -= 2;
					temp.push_back('0' + i);
					temp.push_front('0' + i);
				}
				if (temp.size() >= size)
					break;
			}
		}
		t.clear();
		for (int j = 0; j < temp.size(); j++)
			t.push_back(temp[j]);
		ans[q] = t;
	}
	int sum = 0;
	for (int i = 0; i < 26; i++)
		sum += p[i];
	if (ans.size() == k&&sum == 0)
		return 1;
	return 0;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		x[s[i]]++;
	int y = 0;
	for (int i = 0; i < 26; i++)
	{
		if (x['a'+i] % 2 == 1)
			y++;
		if (x['A' + i] % 2 == 1)
			y++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (x['0' + i] % 2 == 1)
			y++;
	}
	if (y == 0)
	{
		deque <char> t;
		for (int i = 0; i < 26; i++)
		{
			while (x['a'+i] > 0)
			{
				x['a' + i] -= 2;
				t.push_back('a' + i);
				t.push_front('a' + i);
			}
			while (x['A' + i] > 0)
			{
				x['A' + i] -= 2;
				t.push_back('A' + i);
				t.push_front('A' + i);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			while (x['0' + i] > 0)
			{
				x['0' + i] -= 2;
				t.push_back('0' + i);
				t.push_front('0' + i);
			}
		}
		cout << 1 << endl;
		for (int j = 0; j < t.size(); j++)
			printf("%c",t[j]);
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (n%i == 0&&y<=i&&(i-y)%2==0&&(n/i)%2==1)
		{
			if (f(i,n/i) == 1)
			{
				cout << i << endl;
				for (int j = 0; j < i; j++)
				{
					cout << ans[j] << " ";
				}
				return 0;
			}
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int n;
string s;
map<char, int> mp;

void print_ans(int cnt_group) {
	cout << cnt_group << "\n";
	if (cnt_group == n) {
		for (int i = 0; i < n; i++)
			cout << s[i] << " ";
		return;
	}
	vector<char> v_odd;
	int uk = 0;
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
		if (i->second % 2 != 0)
			v_odd.push_back(i->first);

	int len = n / cnt_group;
	map<char, int>::iterator i = mp.begin();
	for (int x = 0; x < cnt_group; x++) {
		int cnt = 0;
		string new_s = "";
		while (i != mp.end() && cnt < (len / 2)) {
			if (i->second >= 2) {
				new_s += i->first;
				cnt++;
				i->second -= 2;
			}
			if (i->second == 1) {
				i->second = 0;
			}
			if (i->second == 0)
				i++;
		}
		string ans = new_s;
		if (len % 2 != 0)
			ans += v_odd[uk++];
		reverse(new_s.begin(), new_s.end());
		ans += new_s;
		cout << ans << " ";
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		mp[s[i]]++;
	int cnt_odd = 0;
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
		if (i->second % 2 != 0)
			cnt_odd++;

	if (cnt_odd == 0) {
		if (n % 2 == 0)
			print_ans(1);
		else
			print_ans(n);
	}
	else {
		if (n % cnt_odd == 0 && (n / cnt_odd) % 2 != 0)
			print_ans(cnt_odd);
		else
			print_ans(n);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int n;
string s;
map<char, int> mp;
vector<string> ans;

void print_ans(int cnt_group) {
	cout << cnt_group << "\n";
	if (cnt_group == n) {
		for (int i = 0; i < n; i++)
			cout << s[i] << " ";
		return;
	}
	int len = n / cnt_group;
	map<char, int>::iterator i = mp.begin();
	for (int x = 0; x < cnt_group; x++) {
		string new_s = "";
		int cnt = 0;
		while (i != mp.end() && cnt < len / 2) {
			if (i->second >= 2) {
				new_s += i->first;
				i->second -= 2;
				cnt++;
			}
			else
				i++;
		}
		ans.push_back(new_s);
	}
	int uk = 0;
	int sz = (int)ans.size();
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++) {
		int cnt = i->second;
		while (uk < sz && cnt > 0) {
			string new_s = ans[uk];
			ans[uk] += i->first;
			reverse(new_s.begin(), new_s.end());
			ans[uk] += new_s;
			uk++;
			cnt--;
		}
	}
	for (int i = 0; i < sz; i++)
		cout << ans[i] << " ";
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		mp[s[i]]++;
	int cnt_odd = 0;
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
		if (i->second % 2 != 0)
			cnt_odd++;

	if (cnt_odd == 0) {
		cout << "1\n";
		string new_s = "";
		for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
			for (int j = 0; j < i->second / 2; j++)
				new_s += i->first;
		cout << new_s;
		reverse(new_s.begin(), new_s.end());
		cout << new_s;
		return 0;
	}

	for (int i = cnt_odd; i <= n; i++)
		if (n % i == 0 && (n / i) % 2 != 0 && (i - cnt_odd) % 2 == 0) {
			print_ans(i);
			break;
		}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int n;
string s;
map<char, int> mp;

void print_ans(int cnt_group) {
	cout << cnt_group << "\n";
	if (cnt_group == n) {
		for (int i = 0; i < n; i++)
			cout << s[i] << " ";
		return;
	}
	vector<char> v_odd;
	int uk = 0;
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
		if (i->second % 2 != 0)
			v_odd.push_back(i->first);

	int len = n / cnt_group;
	map<char, int>::iterator i = mp.begin();
	for (int x = 0; x < cnt_group; x++) {
		int cnt = 0;
		string new_s = "";
		while (i != mp.end() && cnt < (len / 2)) {
			if (i->second >= 2) {
				new_s += i->first;
				cnt++;
				i->second -= 2;
			}
			if (i->second == 1) {
				i->second = 0;
			}
			if (i->second == 0)
				i++;
		}
		string ans = new_s;
		if (len % 2 != 0)
			ans += v_odd[uk++];
		reverse(new_s.begin(), new_s.end());
		ans += new_s;
		cout << ans << " ";
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		mp[s[i]]++;
	int cnt_odd = 0;
	for (map<char, int>::iterator i = mp.begin(); i != mp.end(); i++)
		if (i->second % 2 != 0)
			cnt_odd++;

	if (cnt_odd == 0) {
		if (n % 2 == 0)
			print_ans(1);
		else
			print_ans(n);
	}
	else {
		if (n % cnt_odd == 0)
			print_ans(cnt_odd);
		else
			print_ans(n);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1000000000;
const int MAX_N = 50000;
string s;
string ans[MAX_N];
vector <char> ans1;
int xa[26];
int xA[26];
int x0[26];
int pa[26];
int pA[26];
int p0[26];
int f(int k,int size)
{
	string t,qw;
	for (int i = 0; i < 26; i++)
	{
		pa[i] = xa[i];
		pA[i] = xA[i];
		if (pa[i] % 2 == 1)
		{
			pa[i]--;
			ans1.push_back('a' + i);
		}
		if (pA[i] % 2 == 1)
		{
			pA[i]--;
			ans1.push_back('A' + i);
		}
	}
	for (int i = 0; i < 10; i++)
	{
		p0[i] = x0[i];
		if (p0[i] % 2 == 1)
		{
			p0[i]--;
			ans1.push_back('0' + i);
		}
	}
	while (ans1.size()<k)
	{
		for (int i = 0; i < 26; i++)
		{
			if (pa[i]>=2)
			{
				pa[i]-=2;
				ans1.push_back('a' + i);
				ans1.push_back('a' + i);
			}
			if (pA[i] >= 2)
			{
				pA[i]-=2;
				ans1.push_back('A' + i);
				ans1.push_back('A' + i);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			if (p0[i] >= 2)
			{
				p0[i]-=2;
				ans1.push_back('0' + i);
				ans1.push_back('0' + i);
			}
		}
	}
	for (int q = 0; q < ans1.size();q++)
	{
		t.clear();
		while (t.size()<size/2)
		{
			for (int i = 0; i < 26; i++)
			{
				while (pa[i] >= 2 && t.size()<size / 2)
				{
					pa[i] -= 2;
					t.push_back('a' + i);
				}
				while (pA[i] >= 2 && t.size()<size / 2)
				{
					pA[i] -= 2;
					t.push_back('A' + i);
				}
				if (t.size() >= t.size()<size / 2)
					break;
			}
			for (int i = 0; i < 10; i++)
			{
				while (p0[i] >= 2 && t.size()<size / 2)
				{
					p0[i] -= 2;
					t.push_back('0' + i);
				}
				if (t.size()>=size / 2)
					break;
			}
		}
		qw = t;
		reverse(qw.begin(),qw.end());
		t = t + ans1[q] +qw;
		ans[q] = t;
	}
	return 1;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		if (s[i] >= 'a'&&s[i] <= 'z')
			xa[s[i]-'a']++;
		if (s[i] >= 'A'&&s[i] <= 'Z')
			xA[s[i] - 'A']++;
		if (s[i] >= '0'&&s[i] <= '9')
			x0[s[i] - '0']++;
	}
	int y = 0;
	for (int i = 0; i < 26; i++)
	{
		if (xa[i] % 2 == 1)
			y++;
		if (xA[i] % 2 == 1)
			y++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (x0[i] % 2 == 1)
			y++;
	}
	if (y == 0)
	{
		deque <char> t;
		for (int i = 0; i < 26; i++)
		{
			while (xa[i] > 0)
			{
				xa[i] -= 2;
				t.push_back('a' + i);
				t.push_front('a' + i);
			}
			while (xA[i] > 0)
			{
				xA[i] -= 2;
				t.push_back('A' + i);
				t.push_front('A' + i);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			while (x0[i] > 0)
			{
				x0[i] -= 2;
				t.push_back('0' + i);
				t.push_front('0' + i);
			}
		}
		cout << 1 << endl;
		for (int j = 0; j < t.size(); j++)
			printf("%c",t[j]);
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (n%i == 0&&y<=i&&(i-y)%2==0&&(n/i)%2==1)
		{
			f(i, n / i);
			cout << i << endl;
			for (int j = 0; j < i; j++)
			{
				cout << ans[j] << " ";
			}
			return 0;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1000000000;
const int MAX_N = 301000;
int s[MAX_N];
int t[4*MAX_N];
int p[4 * MAX_N];
void insert(int v,int l,int r,int L,int R)
{
	if (l == L&&r == R)
	{
		p[v] = 1;
		t[v] = 1;
		return ;
	}
	if (p[v] == 1)
	{
		p[2 * v] = t[2 * v + 1] = 1;
		t[2 * v] = t[2 * v + 1] = 1;
		p[v] = 0;
	}
	int mid = (l+r) / 2;
	if (L <= mid)
		insert(2*v,l,mid,L,min(mid,R));
	if (R > mid)
		insert(2*v+1,mid+1,r,max(mid+1,L),R);
	t[v] = t[2 * v] + t[2 * v + 1];
}
int ans(int v, int l, int r, int d)
{
	if (l == r)
		return t[v];
	int mid = (l + r) / 2,answer=0;
	if (p[v] == 1)
	{
		p[2 * v] = t[2 * v + 1] = 1;
		t[2 * v] = t[2 * v + 1] = 1;
		p[v] = 0;
	}
	if (d <= mid)
		answer+=ans(2 * v, l, mid, d);
	if (d > mid)
		answer += ans(2 * v + 1, mid + 1, r, d);
	t[v] = t[2 * v] + t[2 * v + 1];
	return answer;
}
int f(int d,int n,int k)
{
	for (int i = 0; i < 4 * MAX_N; i++)
		t[i] = 0;
	int l, r,mid,lx,rx;
	l = r = -1;
	for (int i = k - 1; i < n; i++)
	{
		if (s[i] - s[0] <= d)
		{
			if (l == -1)
				l = r = i;
			l = min(l,i);
			r = max(r,i);
		}
	}
	if (l == -1)
		return 0;
	insert(1,0,MAX_N-1,l,r);
	for (int i = 1; i < n; i++)
	{
		if (i + k <= n)
		{
			if (ans(1, 0, MAX_N - 1, i - 1)>0)
			{
				l = i + k - 1;
				r = n - 1;
				lx = rx = -1;
				for (int j = 0; j < 25; j++)
				{
					mid = (l + r) / 2;
					if (s[mid] - s[i] <= d)
						l = mid;
					else
						r = mid - 1;
				}
				for (int j = min(n-1,l + 5); j >= 0; j--)
				{
					if (s[j] - s[i] <= d)
					{
						rx = j;
						break;
					}
					if (j < i + k - 1)
						break;
				}
				if (rx != -1)
					insert(1, 0, MAX_N - 1, i + k - 1, rx);
			}
		}
	}
	if (ans(1, 0, MAX_N - 1, n - 1) >0)
		return 1;
	return 0;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k,l,r,mid;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	sort(s,s+n);
	l = 0;
	r = INF+20;
	for (int i = 0; i < 32; i++)
	{
		mid = (l+r) / 2;
		if (f(mid, n, k) == 1)
			r = mid;
		else
			l = mid +1;
	}
	for (int i = max(0,l-5); i <=INF+20; i++)
	{
		if (f(i, n, k) == 1)
		{
			cout << i;
			return 0;
		}
	}
	cout << 0;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1000000000;
const int MAX_N = 50000;
string s;
vector <string> ans;
map<char,int> x;
map<char, int> p;
int f(int k,int size)
{
	ans.clear();
	string t;
	p = x;
	for (int i = 0; i < 26; i++)
	{
		if (p['a'+i] % 2 == 1)
		{
			p['a' + i]--;
			t.clear();
			t.push_back('a' + i);
			ans.push_back(t);
		}
		if (p['A' + i] % 2 == 1)
		{
			p['A' + i]--;
			t.clear();
			t.push_back('A' + i);
			ans.push_back(t);
		}
	}
	for (int i = 0; i < 10; i++)
	{
		if (p['0' + i] % 2 == 1)
		{
			p['0' + i]--;
			t.clear();
			t.push_back('0' + i);
			ans.push_back(t);
		}
	}
	while (ans.size()<k)
	{
		for (int i = 0; i < 26; i++)
		{
			if (p['a' + i]>=2)
			{
				p['a' + i]-=2;
				t.clear();
				t.push_back('a' + i);
				ans.push_back(t);
				ans.push_back(t);
			}
			if (p['A' + i] >= 2)
			{
				p['A' + i]-=2;
				t.clear();
				t.push_back('A' + i);
				ans.push_back(t);
				ans.push_back(t);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			if (p['0' + i] >= 2)
			{
				p['0' + i]-=2;
				t.clear();
				t.push_back('0' + i);
				ans.push_back(t);
				ans.push_back(t);
			}
		}
	}
	for (int i = 0; i < ans.size(); i++)
	{
		t = ans[i];
		deque <char> temp;
		for (int j = 0; j < t.size(); j++)
			temp.push_back(t[j]);
		while (temp.size()<size)
		{
			for (int i = 0; i < 26; i++)
			{
				while (p['a'+i] >= 2 && temp.size()<size)
				{
					p['a'+i] -= 2;
					temp.push_back('a' + i);
					temp.push_front('a' + i);
				}
				while (p['A' + i] >= 2 && temp.size()<size)
				{
					p['A' + i] -= 2;
					temp.push_back('A' + i);
					temp.push_front('A' + i);
				}
				if (temp.size() >= size)
					break;
			}
			for (int i = 0; i < 10; i++)
			{
				while (p['0' + i] >= 2 && temp.size()<size)
				{
					p['0' + i] -= 2;
					temp.push_back('0' + i);
					temp.push_front('0' + i);
				}
				if (temp.size() >= size)
					break;
			}
		}
		t.clear();
		for (int j = 0; j < temp.size(); j++)
			t.push_back(temp[j]);
		ans[i] = t;
	}
	int sum = 0;
	for (int i = 0; i < 26; i++)
		sum += p[i];
	if (ans.size() == k&&sum == 0)
		return 1;
	return 0;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		x[s[i]]++;
	int y = 0;
	for (int i = 0; i < 26; i++)
	{
		if (x['a'+i] % 2 == 1)
			y++;
		if (x['A' + i] % 2 == 1)
			y++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (x['0' + i] % 2 == 1)
			y++;
	}
	if (y == 0)
	{
		deque <char> t;
		for (int i = 0; i < 26; i++)
		{
			while (x['a'+i] > 0)
			{
				x['a' + i] -= 2;
				t.push_back('a' + i);
				t.push_front('a' + i);
			}
			while (x['A' + i] > 0)
			{
				x['A' + i] -= 2;
				t.push_back('A' + i);
				t.push_front('A' + i);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			while (x['0' + i] > 0)
			{
				x['0' + i] -= 2;
				t.push_back('0' + i);
				t.push_front('0' + i);
			}
		}
		cout << 1 << endl;
		for (int j = 0; j < t.size(); j++)
			cout << t[j] ;
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (n%i == 0&&y<=i&&(i-y)%2==0)
		{
			if (f(i,n/i) == 1)
			{
				cout << i << endl;
				for (int j = 0; j < i; j++)
				{
					cout << ans[j] << " ";
				}
				return 0;
			}
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1000000000;
const int MAX_N = 50000;
string s;
vector <string> ans;
vector <char> ans1;
map<char,int> x;
map<char, int> p;
int f(int k,int size)
{
	ans.clear();
	string t,qw;
	p = x;
	for (int i = 0; i < 26; i++)
	{
		if (p['a'+i] % 2 == 1)
		{
			p['a' + i]--;
			ans1.push_back('a' + i);
		}
		if (p['A' + i] % 2 == 1)
		{
			p['A' + i]--;
			ans1.push_back('A' + i);
		}
	}
	for (int i = 0; i < 10; i++)
	{
		if (p['0' + i] % 2 == 1)
		{
			p['0' + i]--;
			ans1.push_back('0' + i);
		}
	}
	while (ans1.size()<k)
	{
		for (int i = 0; i < 26; i++)
		{
			if (p['a' + i]>=2)
			{
				p['a' + i]-=2;
				ans1.push_back('a' + i);
				ans1.push_back('a' + i);
			}
			if (p['A' + i] >= 2)
			{
				p['A' + i]-=2;
				ans1.push_back('A' + i);
				ans1.push_back('A' + i);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			if (p['0' + i] >= 2)
			{
				p['0' + i]-=2;
				ans1.push_back('0' + i);
				ans1.push_back('0' + i);
			}
		}
	}
	for (int q = 0; q < ans1.size();q++)
	{
		t.clear();
		while (t.size()<size/2)
		{
			for (int i = 0; i < 26; i++)
			{
				while (p['a' + i] >= 2 && t.size()<size / 2)
				{
					p['a'+i] -= 2;
					t.push_back('a' + i);
				}
				while (p['A' + i] >= 2 && t.size()<size / 2)
				{
					p['A' + i] -= 2;
					t.push_back('A' + i);
				}
				if (t.size() >= t.size()<size / 2)
					break;
			}
			for (int i = 0; i < 10; i++)
			{
				while (p['0' + i] >= 2 && t.size()<size / 2)
				{
					p['0' + i] -= 2;
					t.push_back('0' + i);
				}
				if (t.size()>=size / 2)
					break;
			}
		}
		qw = t;
		reverse(qw.begin(),qw.end());
		t = t + ans1[q] +qw;
		ans.push_back(t);
	}
	return 1;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++)
		x[s[i]]++;
	int y = 0;
	for (int i = 0; i < 26; i++)
	{
		if (x['a'+i] % 2 == 1)
			y++;
		if (x['A' + i] % 2 == 1)
			y++;
	}
	for (int i = 0; i < 10; i++)
	{
		if (x['0' + i] % 2 == 1)
			y++;
	}
	if (y == 0)
	{
		deque <char> t;
		for (int i = 0; i < 26; i++)
		{
			while (x['a'+i] > 0)
			{
				x['a' + i] -= 2;
				t.push_back('a' + i);
				t.push_front('a' + i);
			}
			while (x['A' + i] > 0)
			{
				x['A' + i] -= 2;
				t.push_back('A' + i);
				t.push_front('A' + i);
			}
		}
		for (int i = 0; i < 10; i++)
		{
			while (x['0' + i] > 0)
			{
				x['0' + i] -= 2;
				t.push_back('0' + i);
				t.push_front('0' + i);
			}
		}
		cout << 1 << endl;
		for (int j = 0; j < t.size(); j++)
			printf("%c",t[j]);
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		if (n%i == 0&&y<=i&&(i-y)%2==0&&(n/i)%2==1)
		{
			f(i, n / i);
			cout << i << endl;
			for (int j = 0; j < i; j++)
			{
				cout << ans[j] << " ";
			}
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>

#define REP(i,n) for ((i)=0; (i) < (n); (i)++ )
#define REPS(i,s,n) for ((i)=(s); (i) < (n); (i)++ )
#define MAX(A,B) (((A)>(B))?(A):(B))
#define MIN(A,B) (((A)<(B))?(A):(B))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int SMALL_LOOKUP_TABLE = 1000;
const int BIG_LOOKUP_TABLE = 1000000;
const int BIG_INT = (1 << 31) - 1;
const int SMALL_INT = BIG_INT + 1;
const ll BIG_LL = ((ll)1 << (ll)63) - 1;
const ll SMALL_LL = BIG_LL + 1;

using namespace std;

int freq[62] = { 0 };

char cget(int i) {
	if (i < 26) {
		return (char)('a' + i);
	}
	else if (i < 52) {
		return (char)('A' + i - 26);
	}
	else {
		return (char)('0' + i - 52);
	}
}

int iget(char c) {
	if (c >= 'a' && c <= 'z') {
		return (c - 'a');
	}
	else if (c >= 'A' && c <= 'Z') {
		return (c - 'A' + 26);
	}
	else {
		return (c - '0' + 52);
	}
}

int main() {
	int i, j, n;
	string word;
	cin >> n;
	cin >> word;
	REP(i, 62) freq[i] = 0;
	REP(i, n) freq[iget(word[i])]++;

	vector<int> divisors;
	divisors.reserve((int)ceil(sqrt((ld)n)) * 2);

	for (i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			divisors.push_back(i);
			divisors.push_back(n / i);
		}
	}

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

	int p = 0;
	REP(i, 62) {
		p += (freq[i] % 2);
	}

	int groupsize;
	if (p == 0) {
		groupsize = n;
	}
	else {
		REP(i, divisors.size()) {
			if (p <= divisors[i] && (n / divisors[i]) % 2 == 1) {
				groupsize = n / divisors[i];
				break;
			}
		}
	}
	cout << n / groupsize << "\n";
	char *palindrome = new char[groupsize + 1];
	palindrome[groupsize] = '\0';
	int palindrome_size = 0;
	while (n > 0) {
		if (palindrome_size == 0 && groupsize % 2 == 1) {
			//try grabbing from an odd pile.
			int big_j = 0;
			REP(j, 62) {
				if (palindrome_size == 0 && groupsize % 2 == 1) {
					if (freq[j] % 2 == 1) {
						palindrome[groupsize / 2] = (char)cget(j);
						n--;
						freq[j]--;
						palindrome_size++;
						break;
					}
				}
				if (freq[j] > freq[big_j]) {
					big_j = j;
				}
			}
			//no odd piles, grab from biggest pile
			if (palindrome_size == 0) {
				palindrome[groupsize / 2] = (char)cget(big_j);
				n--;
				freq[big_j]--;
				palindrome_size++;
			}
		}
		else {
			//grab from any pile with enough elements.
			REP(j, 62) {
				if (freq[j] >= 2) {
					freq[j] -= 2;
					palindrome[((groupsize - 1) / 2) - (palindrome_size + 1) / 2] = cget(j); // 0 1 2       (3-1)/2 = 1;    (3+1)/2 = 2
					palindrome[((groupsize) / 2) + (palindrome_size + 1) / 2] = cget(j); //
					n -= 2;
					palindrome_size += 2;
					break;
				}
			}
		}

		if (palindrome_size == groupsize) {
			cout << palindrome << " ";
			palindrome_size = 0;
		}
	}
	delete[] palindrome;
	return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>

#define REP(i,n) for ((i)=0; (i) < (n); (i)++ )
#define REPS(i,s,n) for ((i)=(s); (i) < (n); (i)++ )
#define MAX(A,B) (((A)>(B))?(A):(B))
#define MIN(A,B) (((A)<(B))?(A):(B))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int SMALL_LOOKUP_TABLE = 1000;
const int BIG_LOOKUP_TABLE = 1000000;
const int BIG_INT = (1 << 31) - 1;
const int SMALL_INT = BIG_INT + 1;
const ll BIG_LL = ((ll)1 << (ll)63) - 1;
const ll SMALL_LL = BIG_LL + 1;

using namespace std;

int freq[256] = { 0 };

int main() {
	int i, j, n;
	string word;
	cin >> n;
	cin >> word;
	REP(i, 256) freq[i] = 0;
	REP(i, n) freq[word[i]]++;

	vector<int> divisors;
	divisors.push_back(1);
	divisors.push_back(n);

	for (i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			divisors.push_back(i);
			divisors.push_back(n / i);
		}
	}

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

	int p = 0;
	REP(i, 256) {
		p += (freq[i] % 2);
	}

	int groupsize;
	if (p == 0) {
		groupsize = n;
	}
	else {
		REP(i, divisors.size()) {
			if (p <= divisors[i] && (n / divisors[i]) % 2 == 1) {
				groupsize = n / divisors[i];
				break;
			}
		}
	}
	cout << n / groupsize << endl;
	string palindrome = "";
	while (n > 0) {
		REP(j, 256) {
			if (palindrome.size() == 0 && groupsize % 2 == 1) {
				if (freq[j] % 2 == 1) {
					palindrome += (char)j;
					n--;
					freq[j]--;
				}
			}
			else {
				if (freq[j] >= 2) {
					freq[j] -= 2;
					palindrome = (char)j + palindrome + (char)j;
					n -= 2;
				}
			}
		}

		if (palindrome.size() == groupsize) {
			cout << palindrome << " ";
			palindrome = "";
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>

#define REP(i,n) for ((i)=0; (i) < (n); (i)++ )
#define REPS(i,s,n) for ((i)=(s); (i) < (n); (i)++ )
#define MAX(A,B) (((A)>(B))?(A):(B))
#define MIN(A,B) (((A)<(B))?(A):(B))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int SMALL_LOOKUP_TABLE = 1000;
const int BIG_LOOKUP_TABLE = 1000000;
const int BIG_INT = (1 << 31) - 1;
const int SMALL_INT = BIG_INT + 1;
const ll BIG_LL = ((ll)1 << (ll)63) - 1;
const ll SMALL_LL = BIG_LL + 1;

using namespace std;

int freq[256] = { 0 };

int main() {
	int i, j, n;
	string word;
	cin >> n;
	cin >> word;
	REP(i, 256) freq[i] = 0;
	REP(i, n) freq[word[i]]++;

	vector<int> divisors;
	divisors.push_back(1);
	divisors.push_back(n);

	for (i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			divisors.push_back(i);
			divisors.push_back(n / i);
		}
	}

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

	int p = 0;
	REP(i, 256) {
		p += (freq[i] % 2);
	}

	int groupsize;
	if (p == 0) {
		groupsize = n;
	}
	else {
		REP(i, divisors.size()) {
			if (p <= divisors[i] && (n / divisors[i]) % 2 == 1) {
				groupsize = n / divisors[i];
				break;
			}
		}
	}
	cout << n / groupsize << endl;
	string palindrome = "";
	while (n > 0) {
		if (palindrome.size() == 0 && groupsize % 2 == 1) {
			//try grabbing from an odd pile.
			int big_j = 0;
			REP(j, 256) {
				if (palindrome.size() == 0 && groupsize % 2 == 1) {
					if (freq[j] % 2 == 1) {
						palindrome += (char)j;
						n--;
						freq[j]--;
						break;
					}
				}
				if (freq[j] > freq[big_j]) {
					big_j = j;
				}
			}
			//no odd piles, grab from biggest pile
			if (palindrome.size() == 0) {
				palindrome += (char)big_j;
				n--;
				freq[big_j]--;
			}
		}
		else {
			//grab from any pile with enough elements.
			REP(j, 256) {
				if (freq[j] >= 2) {
					freq[j] -= 2;
					palindrome = (char)j + palindrome + (char)j;
					n -= 2;
					break;
				}
			}
		}

		if (palindrome.size() == groupsize) {
			cout << palindrome << " ";
			palindrome = "";
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>

#define REP(i,n) for ((i)=0; (i) < (n); (i)++ )
#define REPS(i,s,n) for ((i)=(s); (i) < (n); (i)++ )
#define MAX(A,B) (((A)>(B))?(A):(B))
#define MIN(A,B) (((A)<(B))?(A):(B))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int SMALL_LOOKUP_TABLE = 1000;
const int BIG_LOOKUP_TABLE = 1000000;
const int BIG_INT = (1 << 31) - 1;
const int SMALL_INT = BIG_INT + 1;
const ll BIG_LL = ((ll)1 << (ll)63) - 1;
const ll SMALL_LL = BIG_LL + 1;

using namespace std;

int freq[62] = { 0 };

char cget(int i) {
	if (i < 26) {
		return (char)('a' + i);
	}
	else if (i < 52) {
		return (char)('A' + i - 26);
	}
	else {
		return (char)('0' + i - 52);
	}
}

int iget(char c) {
	if (c >= 'a' && c <= 'z') {
		return (c - 'a');
	}
	else if (c >= 'A' && c <= 'Z') {
		return (c - 'A' + 26);
	}
	else {
		return (c - '0' + 52);
	}
}

int main() {
	int i, j, n;
	string word;
	cin >> n;
	cin >> word;
	REP(i, 62) freq[i] = 0;
	REP(i, n) freq[iget(word[i])]++;

	vector<int> divisors;
	divisors.push_back(1);
	divisors.push_back(n);

	for (i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			divisors.push_back(i);
			divisors.push_back(n / i);
		}
	}

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

	int p = 0;
	REP(i, 62) {
		p += (freq[i] % 2);
	}

	int groupsize;
	if (p == 0) {
		groupsize = n;
	}
	else {
		REP(i, divisors.size()) {
			if (p <= divisors[i] && (n / divisors[i]) % 2 == 1) {
				groupsize = n / divisors[i];
				break;
			}
		}
	}
	cout << n / groupsize << endl;
	string palindrome = "";
	while (n > 0) {
		if (palindrome.size() == 0 && groupsize % 2 == 1) {
			//try grabbing from an odd pile.
			int big_j = 0;
			REP(j, 62) {
				if (palindrome.size() == 0 && groupsize % 2 == 1) {
					if (freq[j] % 2 == 1) {
						palindrome += (char)cget(j);
						n--;
						freq[j]--;
						break;
					}
				}
				if (freq[j] > freq[big_j]) {
					big_j = j;
				}
			}
			//no odd piles, grab from biggest pile
			if (palindrome.size() == 0) {
				palindrome += (char)cget(big_j);
				n--;
				freq[big_j]--;
			}
		}
		else {
			//grab from any pile with enough elements.
			REP(j, 62) {
				if (freq[j] >= 2) {
					freq[j] -= 2;
					palindrome = (char)cget(j) + palindrome + (char)cget(j);
					n -= 2;
					break;
				}
			}
		}

		if (palindrome.size() == groupsize) {
			cout << palindrome << " ";
			palindrome = "";
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>

#define REP(i,n) for ((i)=0; (i) < (n); (i)++ )
#define REPS(i,s,n) for ((i)=(s); (i) < (n); (i)++ )
#define MAX(A,B) (((A)>(B))?(A):(B))
#define MIN(A,B) (((A)<(B))?(A):(B))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int SMALL_LOOKUP_TABLE = 1000;
const int BIG_LOOKUP_TABLE = 1000000;
const int BIG_INT = (1 << 31) - 1;
const int SMALL_INT = BIG_INT + 1;
const ll BIG_LL = ((ll)1 << (ll)63) - 1;
const ll SMALL_LL = BIG_LL + 1;

using namespace std;

int freq[62] = { 0 };

char cget(int i) {
	if (i < 26) {
		return (char)('a' + i);
	}
	else if (i < 52) {
		return (char)('A' + i - 26);
	}
	else {
		return (char)('0' + i - 52);
	}
}

int iget(char c) {
	if (c >= 'a' && c <= 'z') {
		return (c - 'a');
	}
	else if (c >= 'A' && c <= 'Z') {
		return (c - 'A' + 26);
	}
	else {
		return (c - '0' + 52);
	}
}

int main() {
	int i, j, n;
	string word;
	cin >> n;
	cin >> word;
	REP(i, 62) freq[i] = 0;
	REP(i, n) freq[iget(word[i])]++;

	vector<int> divisors;
	divisors.reserve(ceil(sqrt(n)) * 2);

	for (i = 1; i*i <= n; i++) {
		if (n % i == 0) {
			divisors.push_back(i);
			divisors.push_back(n / i);
		}
	}

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

	int p = 0;
	REP(i, 62) {
		p += (freq[i] % 2);
	}

	int groupsize;
	if (p == 0) {
		groupsize = n;
	}
	else {
		REP(i, divisors.size()) {
			if (p <= divisors[i] && (n / divisors[i]) % 2 == 1) {
				groupsize = n / divisors[i];
				break;
			}
		}
	}
	cout << n / groupsize << "\n";
	char *palindrome = new char[groupsize + 1];
	palindrome[groupsize] = '\0';
	int palindrome_size = 0;
	while (n > 0) {
		if (palindrome_size == 0 && groupsize % 2 == 1) {
			//try grabbing from an odd pile.
			int big_j = 0;
			REP(j, 62) {
				if (palindrome_size == 0 && groupsize % 2 == 1) {
					if (freq[j] % 2 == 1) {
						palindrome[groupsize / 2] = (char)cget(j);
						n--;
						freq[j]--;
						palindrome_size++;
						break;
					}
				}
				if (freq[j] > freq[big_j]) {
					big_j = j;
				}
			}
			//no odd piles, grab from biggest pile
			if (palindrome_size == 0) {
				palindrome[groupsize / 2] = (char)cget(big_j);
				n--;
				freq[big_j]--;
				palindrome_size++;
			}
		}
		else {
			//grab from any pile with enough elements.
			REP(j, 62) {
				if (freq[j] >= 2) {
					freq[j] -= 2;
					palindrome[((groupsize - 1) / 2) - (palindrome_size + 1) / 2] = cget(j); // 0 1 2       (3-1)/2 = 1;    (3+1)/2 = 2
					palindrome[((groupsize) / 2) + (palindrome_size + 1) / 2] = cget(j); //
					n -= 2;
					palindrome_size += 2;
					break;
				}
			}
		}

		if (palindrome_size == groupsize) {
			cout << palindrome << " ";
			palindrome_size = 0;
		}
	}
	delete[] palindrome;
	return 0;
}


/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
/*####*/
int cnt[128],n;
char s[444444],a[444444];int la;
int main(){
	scanf("%d%s",&n,s);
	for(int i=0; i<n; i++)
		cnt[s[i]]++;
	int mid = 0;
	for(int i=32; i<128; i++)
		if(cnt[i] % 2 == 1)
			mid ++;
	if(mid == 0){
		puts("1");
		int l = n/2;
		la=0;
		while(l--){
			int d;
			for(d = 32; cnt[d] < 2; d++);
			a[la++] = d;
			cnt[d] -=2;
		}
		for(int i=0; i<la; i++)printf("%c",a[i]);
		for(int i=la-1; i>=0; i--)printf("%c",a[i]);
		puts("");
		return 0;
	}
	while(n%mid!=0 || n/mid%2==0)mid++;
	printf("%d\n",mid);
	int len = n/mid;
	for(int run=0; run<mid; run++){
		int c = 32;
		while(c < 128 && cnt[c] % 2 == 0)c++;
		if(c == 128){
			c = 32;
			while(cnt[c] == 0)c++;
		}
		cnt[c] --;
		int l = n/mid/2;
		la=0;
		while(l--){
			int d;
			for(d = 32; cnt[d] < 2; d++);
			a[la++] = d;
			cnt[d] -= 2;
		}
		for(int i=0; i<la; i++)printf("%c",a[i]);printf("%c",c);
		for(int i=la-1; i>=0; i--)printf("%c",a[i]);
		if(run<mid-1)printf(" ");else
			printf("\n");
	}
	return 0;
}


/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
/*####*/
int cnt[128],n;
char s[444444],a[444444];int la;
int main(){
	scanf("%d%s",&n,s);
//	n = 399989;
//	for(int i=0;i<n-2;i++) s[i]='z';
//	s[n-2] = 'y'; s[n-1]='x';
	for(int i=0; i<n; i++)
		cnt[s[i]]++;
	int mid = 0;
	for(int i=32; i<128; i++)
		if(cnt[i] % 2 == 1)
			mid ++;
	if(mid == 0){
		puts("1");
		int l = n/2;
		la=0;
		while(l--){
			int d;
			for(d = 32; d<128 && cnt[d] < 2; d++);
			a[la++] = d;
			cnt[d] -=2;
		}
		for(int i=0; i<la; i++)printf("%c",a[i]);
		for(int i=la-1; i>=0; i--)printf("%c",a[i]);
		puts("");
		return 0;
	}
	while(n%mid!=0 || n/mid%2==0)mid++;
	printf("%d\n",mid);
	int len = n/mid;
	for(int run=0; run<mid; run++){
		int c = 32;
		while(c < 128 && cnt[c] % 2 == 0)c++;
		if(c == 128){
			c = 32;
			while(cnt[c] == 0)c++;
		}
		cnt[c] --;
		int l = n/mid/2;
		la=0;
		while(l--){
			int d;
			for(d = 32; d<128 && cnt[d] < 2; d++);
			a[la++] = d;
			cnt[d] -= 2;
		}
		for(int i=0; i<la; i++)printf("%c",a[i]);printf("%c",c);
		for(int i=la-1; i>=0; i--)printf("%c",a[i]);
		if(run<mid-1)printf(" ");else
			printf("\n");
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<deque>
#include<math.h>
#include<cstring>
#include <bitset>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>

#define all(v) v.begin(),v.end()
#define mpair make_pair

using namespace std;
typedef long double ld;
const ld epsilon = 1e-9;
typedef long long ll;

vector<int> getLetterCounts(const string& str) {
	vector<int> toRet(26 + 26 + 10);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			toRet[str[i] - 'a']++;
		}
		if (str[i] >= 'A' && str[i] <= 'Z') {
			toRet[str[i] - 'A' + 26]++;
		}
		if (str[i] >= '0' && str[i] <= '9') {
			toRet[str[i] - '0' + 52]++;
		}
	}
	return toRet;
}
char decodeLetter(int n) {
	if (n < 26) return 'a' + n;
	if (n < 52) return 'A' + n - 26;
	return '0' + n - 52;
}

string decode(const vector<int>& cnts) {
	vector<int> counts(cnts);
	string res;
	for (int i = 0; i < counts.size(); i++) {
		if (counts[i] % 2) {
			res = decodeLetter(i);
			counts[i]--;
			break;
		}
	}
	for (int i = 0; i < counts.size(); i++) {
		char c = decodeLetter(i);
		while(counts[i] > 0) {
			res = c + res + c;
			counts[i] -= 2;
		}
	}
	return res;
}

int main()
{
	//freopen("bobi.in", "r", stdin);
	int n;
	string str;
	cin >> n >> str;
	vector<int> counts = getLetterCounts(str);
	int numOdd = 0;
	for (int i = 0; i < counts.size(); i++) {
		numOdd += (counts[i] % 2);
	}
	vector<int> toProcess;

	for (int i = 1; i * i < n; i++) {
		if (n % i == 0) {
			toProcess.push_back(i);
		}
	}
	toProcess.push_back(n);
	for (int t = 0; t < toProcess.size(); t++) {
		int i = toProcess[t];
		if (n % i == 0) {
			if (i < numOdd) {
				continue;
			}
			int num = i;
			int per_each = n / i;
			if (per_each % 2 == 0 && numOdd > 0) {
				continue;
			}
			vector<vector<int> > splits(num);
			for (int j = 0; j < num; j++) {
				splits[j].resize(counts.size());
			}
			vector<int> sums(num);
			int k = 0;
			for (int j = 0; j < counts.size(); j++) {
				if (counts[j] % 2 == 1) {
					splits[k][j]++;
					sums[k]++;
					k++;
					counts[j]--;
				}
			}
			if (numOdd % 2 == 1) {
				while (k < num) {
					for (int j = 0; j < counts.size(); j++) {
						if (counts[j] > 0) {
							counts[j]--;
							sums[k]++;
							splits[k][j]++;
							k++;
							break;
						}
					}
				}
			}
			k = 0;
			for (int j = 0; j < num; j++) {
				while (sums[j] < per_each) {
					while (counts[k] == 0) {
						k++;
					}
					sums[j]++;
					counts[k]--;
					splits[j][k]++;
				}
			}
			cout << num << endl;
			bool first = true;
			for (int j = 0; j < num; j++) {
				if (!first) cout << " ";
				first = false;
				cout << decode(splits[j]);
			}
			cout << endl;
			return 0;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<deque>
#include<math.h>
#include<cstring>
#include <bitset>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>

#define all(v) v.begin(),v.end()
#define mpair make_pair

using namespace std;
typedef long double ld;
const ld epsilon = 1e-9;
typedef long long ll;

vector<int> getLetterCounts(const string& str) {
	vector<int> toRet(26 + 26 + 10);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			toRet[str[i] - 'a']++;
		}
		if (str[i] >= 'A' && str[i] <= 'Z') {
			toRet[str[i] - 'A' + 26]++;
		}
		if (str[i] >= '0' && str[i] <= '9') {
			toRet[str[i] - '0' + 52]++;
		}
	}
	return toRet;
}
char decodeLetter(int n) {
	if (n < 26) return 'a' + n;
	if (n < 52) return 'A' + n - 26;
	return '0' + n - 52;
}
char tmp[1 << 19];
string decode(const vector<int>& cnts) {
	vector<int> counts(cnts);
	int k = 0;
	bool isOdd = false;
	for (int i = 0; i < counts.size(); i++) {
		if (counts[i] % 2) {
			tmp[k++] = decodeLetter(i);
			counts[i]--;
			isOdd = true;
			break;
		}
	}
	for (int i = 0; i < counts.size(); i++) {
		char c = decodeLetter(i);
		while(counts[i] > 0) {
			tmp[k++] = c;
			counts[i] -= 2;
		}
	}
	reverse(tmp, tmp + k);
	int j = k - 1;
	if (isOdd) j--;
	while (j >= 0) {
		tmp[k++] = tmp[j];
		j--;
	}
	tmp[k] = '\0';
	string res = tmp;
	return res;
}

int main()
{
	//freopen("bobi.in", "r", stdin);
	int n;
	string str;
	cin >> n >> str;
	vector<int> counts = getLetterCounts(str);
	int numOdd = 0;
	for (int i = 0; i < counts.size(); i++) {
		numOdd += (counts[i] % 2);
	}
	vector<int> toProcess;

	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			toProcess.push_back(i);
			toProcess.push_back(n / i);
		}
	}
	sort(toProcess.begin(), toProcess.end());
	for (int t = 0; t < toProcess.size(); t++) {
		int i = toProcess[t];
		if (n % i == 0) {
			if (i < numOdd) {
				continue;
			}
			int num = i;
			int per_each = n / i;
			if (per_each % 2 == 0 && numOdd > 0) {
				continue;
			}
			vector<vector<int> > splits(num);
			for (int j = 0; j < num; j++) {
				splits[j].resize(counts.size());
			}
			vector<int> sums(num);
			int k = 0;
			for (int j = 0; j < counts.size(); j++) {
				if (counts[j] % 2 == 1) {
					splits[k][j]++;
					sums[k]++;
					k++;
					counts[j]--;
				}
			}
			if (numOdd % 2 == 1) {
				while (k < num) {
					for (int j = 0; j < counts.size(); j++) {
						if (counts[j] > 0) {
							counts[j]--;
							sums[k]++;
							splits[k][j]++;
							k++;
							break;
						}
					}
				}
			}
			k = 0;
			for (int j = 0; j < num; j++) {
				while (sums[j] < per_each) {
					while (counts[k] == 0) {
						k++;
					}
					sums[j]++;
					counts[k]--;
					splits[j][k]++;
				}
			}
			cout << num << endl;
			bool first = true;
			for (int j = 0; j < num; j++) {
				if (!first) cout << " ";
				first = false;
				cout << decode(splits[j]);
			}
			cout << endl;
			return 0;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<deque>
#include<math.h>
#include<cstring>
#include <bitset>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>

#define all(v) v.begin(),v.end()
#define mpair make_pair

using namespace std;
typedef long double ld;
const ld epsilon = 1e-9;
typedef long long ll;

vector<int> getLetterCounts(const string& str) {
	vector<int> toRet(26 + 26 + 10);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			toRet[str[i] - 'a']++;
		}
		if (str[i] >= 'A' && str[i] <= 'Z') {
			toRet[str[i] - 'A' + 26]++;
		}
		if (str[i] >= '0' && str[i] <= '9') {
			toRet[str[i] - '0' + 52]++;
		}
	}
	return toRet;
}
char decodeLetter(int n) {
	if (n < 26) return 'a' + n;
	if (n < 52) return 'A' + n - 26;
	return '0' + n - 52;
}

string decode(const vector<int>& cnts) {
	vector<int> counts(cnts);
	string res;
	for (int i = 0; i < counts.size(); i++) {
		if (counts[i] % 2) {
			res = decodeLetter(i);
			counts[i]--;
			break;
		}
	}
	for (int i = 0; i < counts.size(); i++) {
		char c = decodeLetter(i);
		while(counts[i] > 0) {
			res = c + res + c;
			counts[i] -= 2;
		}
	}
	return res;
}

int main()
{
	//freopen("bobi.in", "r", stdin);
	int n;
	string str;
	cin >> n >> str;
	vector<int> counts = getLetterCounts(str);
	int numOdd = 0;
	for (int i = 0; i < counts.size(); i++) {
		numOdd += (counts[i] % 2);
	}
	vector<int> toProcess;

	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			toProcess.push_back(i);
			toProcess.push_back(n / i);
		}
	}
	sort(toProcess.begin(), toProcess.end());
	for (int t = 0; t < toProcess.size(); t++) {
		int i = toProcess[t];
		if (n % i == 0) {
			if (i < numOdd) {
				continue;
			}
			int num = i;
			int per_each = n / i;
			if (per_each % 2 == 0 && numOdd > 0) {
				continue;
			}
			vector<vector<int> > splits(num);
			for (int j = 0; j < num; j++) {
				splits[j].resize(counts.size());
			}
			vector<int> sums(num);
			int k = 0;
			for (int j = 0; j < counts.size(); j++) {
				if (counts[j] % 2 == 1) {
					splits[k][j]++;
					sums[k]++;
					k++;
					counts[j]--;
				}
			}
			if (numOdd % 2 == 1) {
				while (k < num) {
					for (int j = 0; j < counts.size(); j++) {
						if (counts[j] > 0) {
							counts[j]--;
							sums[k]++;
							splits[k][j]++;
							k++;
							break;
						}
					}
				}
			}
			k = 0;
			for (int j = 0; j < num; j++) {
				while (sums[j] < per_each) {
					while (counts[k] == 0) {
						k++;
					}
					sums[j]++;
					counts[k]--;
					splits[j][k]++;
				}
			}
			cout << num << endl;
			bool first = true;
			for (int j = 0; j < num; j++) {
				if (!first) cout << " ";
				first = false;
				cout << decode(splits[j]);
			}
			cout << endl;
			return 0;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<sstream>
#include<deque>
#include<math.h>
#include<cstring>
#include <bitset>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>

#define all(v) v.begin(),v.end()
#define mpair make_pair

using namespace std;
typedef long double ld;
const ld epsilon = 1e-9;
typedef long long ll;

vector<int> getLetterCounts(const string& str) {
	vector<int> toRet(26 + 26 + 10);
	for (int i = 0; i < str.size(); i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			toRet[str[i] - 'a']++;
		}
		if (str[i] >= 'A' && str[i] <= 'Z') {
			toRet[str[i] - 'A' + 26]++;
		}
		if (str[i] >= '0' && str[i] <= '9') {
			toRet[str[i] - '0' + 52]++;
		}
	}
	return toRet;
}
char decodeLetter(int n) {
	if (n < 26) return 'a' + n;
	if (n < 52) return 'A' + n - 26;
	return '0' + n - 52;
}

string decode(const vector<int>& cnts) {
	vector<int> counts(cnts);
	string res;
	for (int i = 0; i < counts.size(); i++) {
		if (counts[i] % 2) {
			res = decodeLetter(i);
			counts[i]--;
			break;
		}
	}
	for (int i = 0; i < counts.size(); i++) {
		char c = decodeLetter(i);
		while(counts[i] > 0) {
			res = c + res + c;
			counts[i] -= 2;
		}
	}
	return res;
}

int main()
{
	//freopen("bobi.in", "r", stdin);
	int n;
	string str;
	cin >> n >> str;
	vector<int> counts = getLetterCounts(str);
	int numOdd = 0;
	for (int i = 0; i < counts.size(); i++) {
		numOdd += (counts[i] % 2);
	}
	vector<int> toProcess;

	for (int i = 1; i * i < n; i++) {
		if (n % i == 0) {
			toProcess.push_back(i);
			toProcess.push_back(n / i);
		}
	}
	sort(toProcess.begin(), toProcess.end());
	for (int t = 0; t < toProcess.size(); t++) {
		int i = toProcess[t];
		if (n % i == 0) {
			if (i < numOdd) {
				continue;
			}
			int num = i;
			int per_each = n / i;
			if (per_each % 2 == 0 && numOdd > 0) {
				continue;
			}
			vector<vector<int> > splits(num);
			for (int j = 0; j < num; j++) {
				splits[j].resize(counts.size());
			}
			vector<int> sums(num);
			int k = 0;
			for (int j = 0; j < counts.size(); j++) {
				if (counts[j] % 2 == 1) {
					splits[k][j]++;
					sums[k]++;
					k++;
					counts[j]--;
				}
			}
			if (numOdd % 2 == 1) {
				while (k < num) {
					for (int j = 0; j < counts.size(); j++) {
						if (counts[j] > 0) {
							counts[j]--;
							sums[k]++;
							splits[k][j]++;
							k++;
							break;
						}
					}
				}
			}
			k = 0;
			for (int j = 0; j < num; j++) {
				while (sums[j] < per_each) {
					while (counts[k] == 0) {
						k++;
					}
					sums[j]++;
					counts[k]--;
					splits[j][k]++;
				}
			}
			cout << num << endl;
			bool first = true;
			for (int j = 0; j < num; j++) {
				if (!first) cout << " ";
				first = false;
				cout << decode(splits[j]);
			}
			cout << endl;
			return 0;
		}
	}
	return 0;
}


n = int(input())
s = input()
d = {}
for c in s:
    if c not in d:
        d[c] = 0
    d[c] += 1
odd = []
sum = 0
for key in d:
    if d[key] % 2 == 1:
        odd.append(key)
        d[key] -= 1
    sum += d[key]

if sum // 2 < len(odd):
    print(len(s))
    for c in s:
        print(c+' ', end='')
    exit(0)
while True:
    if len(odd) == 0 or (sum // 2) % len(odd) == 0:
        break
    sum -= 2
    if sum // 2 < len(odd):
        print(len(s))
        for c in s:
            print(c + ' ', end='')
        exit(0)
    for key in d:
        odd.append(key)
        odd.append(key)
        d[key] -= 2
        if d[key] == 0:
            d.pop(key, None)
        break
if len(odd) == 0:
    odd.append('')
even = []
for key in d:
    even += [key] * (d[key] // 2)
l = (sum // 2) // len(odd)
print(len(odd))
for i in range(len(odd)):
    s = odd[i]
    for j in range(i * l, (i + 1) * l):
        s = even[j] + s + even[j]
    print(s + ' ', end='')


n = int(input())
s = input()
d = {}
for c in s:
    if c not in d:
        d[c] = 0
    d[c] += 1
odd = []
sum = 0
for key in d:
    if d[key] % 2 == 1:
        odd.append(key)
        d[key] -= 1
    sum += d[key]
while True:
    if len(odd) == 0 or (sum // 2) % len(odd) == 0:
        break
    sum -= 2
    for key in d:
        odd.append(key)
        odd.append(key)
        d[key] -= 2
        if d[key] == 0:
            d.pop(key, None)
        break
if len(odd) == 0:
    odd.append('')
even = []
for key in d:
    even += [key] * (d[key] // 2)
l = (sum // 2) // len(odd)
print(len(odd))
for i in range(len(odd)):
    s = odd[i]
    for j in range(i * l, (i + 1) * l):
        s = even[j] + s + even[j]
    print(s + ' ', end='')


n = int(input())
s = list(input())
d = {}
for char in s:
    if char not in d.keys():
        d[char] = 1
    else:
        d[char] += 1

odd = []
even = []
for char in d.keys():
    for i in range(d[char] // 2):
        even.append(char)
        even.append(char)
    for i in range(d[char] % 2):
        odd.append(char)

if len(odd) <= 1:
    x = ''.join([even[i] for i in range(1,len(even),2)])
    y = ''.join(odd)
    print(1)
    print(x+y+x[::-1])
elif (len(even)//len(odd)) % 2 == 0 and (len(even)//len(odd)) > 0:
    print(len(odd))
    x = []
    ratio = len(even)//len(odd)
    indx = 0
    for i in range(len(odd)):
        tail = ''
        while len(tail) < ratio//2:
            tail += even[indx]
            indx += 2
        x.append(tail+odd[i]+tail[::-1])
    print(' '.join(x))
else:
    print(len(even) + len(odd))
    print((' '.join(even)+' '+ ' '.join(odd)).strip())


n = int(input())
s = list(input())
d = {}
for char in s:
    if char not in d.keys():
        d[char] = 1
    else:
        d[char] += 1

odd = []
even = []
for char in d.keys():
    for i in range(d[char] // 2):
        even.append(char)
        even.append(char)
    for i in range(d[char] % 2):
        odd.append(char)

if len(odd) <= 1:
    x = ''.join([even[i] for i in range(1, len(even), 2)])
    y = ''.join(odd)
    print(1)
    print(x + y + x[::-1])

else:
    ratio = len(even)//len(odd)
    max_length = 1
    for i in range(1,ratio+2,2):
        if n % i == 0 and max_length < i:
            max_length = i
    parts = n//max_length
    print(parts)
    x = []
    indx = 0
    for i in range(len(odd)):
        tail = ''
        while len(tail) < max_length // 2:
            tail += even[indx]
            indx += 2
        x.append(tail + odd[i] + tail[::-1])
    middle = []
    for i in range(parts - len(odd)):
        middle.append(even.pop())
    for i in range(len(middle)):
        tail = ''
        while len(tail) < max_length // 2:
            tail += even[indx]
            indx += 2
        x.append(tail + middle[i] + tail[::-1])
    print(' '.join(x))


n = int(input())
s = list(input())
d = {}
for char in s:
    if char not in d.keys():
        d[char] = 1
    else:
        d[char] += 1

odd = []
even = []
for char in d.keys():
    for i in range(d[char] // 2):
        even.append(char)
        even.append(char)
    for i in range(d[char] % 2):
        odd.append(char)

if len(odd) <= 1:
    x = ''.join([even[i] for i in range(1,len(even),2)])
    y = ''.join(odd)
    print(1)
    print(x+y+x[::-1])
elif 2*len(odd) == len(even):
    print(len(odd))
    x = []
    for i in range(len(odd)):
        x.append(even[i*2]+odd[i]+even[i*2])
    print(' '.join(x))
elif len(even) != 2*len(odd):
    print(len(even) + len(odd))
    print((' '.join(even)+' '+ ' '.join(odd)).strip())


n = int(input())
s = list(input())
d = {}
for char in s:
    if char not in d.keys():
        d[char] = 1
    else:
        d[char] += 1

odd = []
even = []
for char in d.keys():
    for i in range(d[char] // 2):
        even.append(char)
    for i in range(d[char] % 2):
        odd.append(char)

if len(odd) <= 1:
    x = ''.join(even)
    y = ''.join(odd)
    print(1)
    print(x+y+x[::-1])
elif len(odd) == len(even):
    print(len(odd))
    for i in range(len(odd)):
        print(even[i]+odd[i]+even[i])
elif len(even) != len(odd):
    print(len(even) + len(odd))
    print(' '.join(even), ' '.join(odd))


n = int(input())
s = list(input())[:n]
d = {}
for char in s:
    if char not in d.keys():
        d[char] = 1
    else:
        d[char] += 1

odd = []
even = []
for char in d.keys():
    for i in range(d[char] // 2):
        even.append(char)
        even.append(char)
    for i in range(d[char] % 2):
        odd.append(char)

if len(odd) <= 1:
    x = ''.join([even[i] for i in range(1,len(even),2)])
    y = ''.join(odd)
    print(1)
    print(x+y+x[::-1])
elif (len(even)//len(odd)) % 2 == 0 and (len(even)//len(odd)) > 0:
    print(len(odd))
    x = []
    ratio = len(even)//len(odd)
    indx = 0
    for i in range(len(odd)):
        tail = ''
        while len(tail) < ratio//2:
            tail += even[indx]
            indx += 2
        x.append(tail+odd[i]+tail[::-1])
    print(' '.join(x))
else:
    print(len(even)//2 + len(odd))
    print((' '.join(even)+' '+ ' '.join(odd)).strip())