#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector> 
#include<cstring>
#include<string>

#define mp make_pair
#define scn second
#define frs first
#define pb push_back
#define NAME "semipal"
using namespace std;
const unsigned long long P = 239017, INF=100000000;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;

char s[3010];
ll hash[3100][3010], hash_reverse[3010][3010], p[3010];
int was[3010][3010], was1[3000];
vector<int> tmp;

ll get_hash(int l, int r) {
	return hash[l][r - l + 1];
}
ll get_hash_reverse(int l, int r) {
	return hash_reverse[r][r - l + 1];
}
void precalc() {
	p[0] = 1;
	int len = strlen(s);
	for (int i = 0; i < len; ++i)
		for (int j = 0; j < len; ++j)
			was[i][j] = -1;	
	for (int i = 1; i <= 1000; ++i)
		p[i] = p[i - 1] * P;
	for (int i = 0; i < len; ++i) {
		tmp.clear();
		for (int j = 'a'; j <= 'z'; ++j)
			was1[j] = 0;
		int cnt = 1;
		for (int j = i; j < len; ++j) {
			if (!was1[s[j]])
				was1[s[j]] = cnt++;
			tmp.pb(was1[s[j]]);	
		}
		for (int j = 0; j < tmp.size(); ++j) 
			hash[i][j + 1] = hash[i][j] * P + tmp[j];	
	}
	for (int i = len - 1; i >= 0; --i) {
		tmp.clear();
		for (int j = 'a'; j <= 'z'; ++j)
			was1[j] = 0;
		int cnt = 1;
		for (int j = i; j >= 0; --j) {
			if (!was1[s[j]])
				was1[s[j]] = cnt++;
			tmp.pb(was1[s[j]]);	
		}
		for (int j = 0; j < tmp.size(); ++j) 
			hash_reverse[i][j + 1] = hash_reverse[i][j] * P + tmp[j];	
	}
}

int palin(int l, int r) {
	if (l == r || r == l + 1)
		return 1;
	int len = r - l + 1;
	if (was[l][r] >= 0)
		return was[l][r];
	if (!palin(l, l + (len) / 2 - 1) || !palin(r - (len)/2 + 1, r))
		return was[l][r] = 0;	
	if (get_hash(l, l + (len) / 2 - 1) == get_hash_reverse(r - (len)/2 + 1, r))
		return was[l][r] = 1;
	return was[l][r] = 0;
}



int main(){
	freopen(NAME ".in", "r", stdin); 
	freopen(NAME ".out", "w", stdout);
	scanf("%*d%s", s); 
	precalc();
	int len = strlen(s), mx = 0; 
	for (int i = 0; i < len; ++i)
		for (int j = i; j < len; ++j) 
			mx = max(palin(i, j) * (j - i + 1), mx);
	
	for (int i = 0; i < len; ++i)
		for (int j = i; j < len; ++j) 
			if (palin(i, j) && j - i + 1 == mx) {
				for (int y = i; y <= j; ++y) 
					printf("%c", s[y]);
				return 0;		
			}	 
	return 0;
}