import java.io.*;
import java.util.*;

public class semipal_av_nohash_faster {

	FastScanner in;
	PrintWriter out;

	final static int ALPH = 26;

	void solve() {
		int n = in.nextInt();
		String s = in.nextToken();

		int[][] firstAfter = new int[ALPH][n], firstBefore = new int[ALPH][n];
		for (int i = 0; i < ALPH; i++) {
			Arrays.fill(firstAfter[i], n);
			Arrays.fill(firstBefore[i], -1);
		}
		for (int i = 0; i < n; i++) {
			int c = s.charAt(i) - 'a';
			firstAfter[c][i] = firstBefore[c][i] = i;
		}
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < ALPH; j++) {
				if (firstBefore[j][i] == -1) {
					firstBefore[j][i] = firstBefore[j][i - 1];
				}
			}
		}
		for (int i = n - 2; i >= 0; i--) {
			for (int j = 0; j < ALPH; j++) {
				if (firstAfter[j][i] == n) {
					firstAfter[j][i] = firstAfter[j][i + 1];
				}
			}
		}
		
		byte[][] count = new byte[n][n];
		
		for (int i = 0; i < n; i++) {
			boolean[] have = new boolean[ALPH];
			byte cnt = 0;
			for (int j = i; j < n; j++) {
				int c = s.charAt(j) - 'a';
				if (!have[c]) {
					cnt++;
					have[c] = true;
				}
				count[i][j] = cnt;
			}
		}

		boolean[][] dp1 = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			dp1[i][i] = true;
		}
		for (int i = 0; i < n - 1; i++) {
			dp1[i][i + 1] = true;
		}

		for (int len = 3; len <= n; len++) {
			for (int i = 0, j = len - 1; j < n; i++, j++) {
				if (dp1[i + 1][j - 1] == false) {
					continue;
				}

				int middleL = i + (len - 1) / 2, middleR = j - (len - 1) / 2;

				int c1 = s.charAt(i) - 'a', c2 = s.charAt(j) - 'a';
				int posLeft = firstBefore[c1][middleL], posRight = firstAfter[c2][middleR];

				byte countLeft = count[posLeft][middleL], countRight = count[middleR][posRight];

				dp1[i][j] = (countLeft == countRight);
			}
		}

		boolean[][] dp2 = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			dp2[i][i] = true;
		}
		for (int i = 0; i < n - 1; i++) {
			dp2[i][i + 1] = true;
		}

		for (int len = 3; len <= n; len++) {
			for (int i = 0, j = len - 1; j < n; i++, j++) {
				
				int middleL = i + len / 2 - 1, middleR = j - len / 2 + 1;
				
				dp2[i][j] = dp1[i][j] && dp2[i][middleL] && dp2[middleR][j];
			}
		}
		
		int bestLen = 1, bestI = 0;
		for (int len = 2; len <= n; len++) {
			for (int i = 0; i + len <= n; i++) {
				if (dp2[i][i + len - 1]) {
					bestLen = len;
					bestI = i;
				}
			}
		}

		out.println(s.substring(bestI, bestI + bestLen));
	}

	void run() {
		try {
			in = new FastScanner("semipal.in");
			out = new PrintWriter("semipal.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String file) {
			try {
				br = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new semipal_av_nohash_faster().run();
	}
}
