Problem: You are given a string s of length n consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.

Calculate the minimum number of operations to delete the whole string s.

Input

The first line contains one integer n (1 ≤ n ≤ 500) — the length of string s.

The second line contains the string s (|s| = n) consisting of lowercase Latin letters.

Output

Output a single integer — the minimal number of operation to delete string s.

Examples

Input


5
abaca


Output


3

Input


8
abcddcba


Output


4

Solution (in JAVA):

Solution:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.List;

public class Main {

	private static final String NO = "No";
	private static final String YES = "Yes";
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long MOD = (long) (1e9 + 7);

	void solve() {
		int T = 1;// ni();
		for (int i = 0; i < T; i++)
			solve(i);
	}

	void solve(int nth) {
		int N = ni();
		char[] a = ns().toCharArray();
//		tr(a);
		N = a.length;
		int dp[][] = new int[N][N];
		for (int i = 0; i < N; i++) {
//			Arrays.fill(dp[i], N);
			dp[i][i] = 1;
		}
		for (int len = 2; len <= N; len++) {
			for (int i = 0; i <= N - len; i++) {
				int j = i + len - 1;
				dp[i][j] = dp[i + 1][j] + 1;
				for (int k = i + 1; k <= j; k++) {
					if (a[i] == a[k])
						dp[i][j] = Math.min(dp[i][j], dp[i + 1][k - 1] + dp[k][j]);
				}
//				tr(len, i, j, dp[i]);
			}
		}
		out.println(dp[0][N - 1]);
	}

	// a^b
	long power(long a, long b) {
		long x = 1, y = a;
		while (b > 0) {
			if (b % 2 != 0) {
				x = (x * y) % MOD;
			}
			y = (y * y) % MOD;
			b /= 2;
		}
		return x % MOD;
	}

	private long gcd(long a, long b) {
		while (a != 0) {
			long tmp = b % a;
			b = a;
			a = tmp;
		}
		return b;
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private char[] nc(int n) {
		char[] ret = new char[n];
		for (int i = 0; i < n; i++)
			ret[i] = nc();
		return ret;
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
									// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n) {
			if (!(isSpaceChar(b)))
				buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private Integer[] na2(int n) {
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int[][] na(int n, int m) {
		int[][] a = new int[n][];
		for (int i = 0; i < n; i++)
			a[i] = na(m);
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private Long[] nl2(int n) {
		Long[] a = new Long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private long[] nl(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private long[][] nl(int n, int m) {
		long[][] a = new long[n][];
		for (int i = 0; i < n; i++)
			a[i] = nl(m);
		return a;
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	public static class IterablePermutation implements Iterable<int[]>, Iterator<int[]> {
		int[] a;
		boolean first = true;

		public IterablePermutation(int n) {
			assert n >= 1;
			a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = i;
		}

		public IterablePermutation(int... a) {
			this.a = Arrays.copyOf(a, a.length);
		}

		@Override
		public boolean hasNext() {
			if (first)
				return true;
			int n = a.length;
			int i;
			for (i = n - 2; i >= 0 && a[i] >= a[i + 1]; i--)
				;
			return i != -1;
		}

		@Override
		public int[] next() {
			if (first) {
				first = false;
				return a;
			}
			int n = a.length;
			int i;
			for (i = n - 2; i >= 0 && a[i] >= a[i + 1]; i--)
				;
			assert i != -1;
			int j;
			for (j = i + 1; j < n && a[i] < a[j]; j++)
				;
			int d = a[i];
			a[i] = a[j - 1];
			a[j - 1] = d;
			for (int p = i + 1, q = n - 1; p < q; p++, q--) {
				d = a[p];
				a[p] = a[q];
				a[q] = d;
			}
			return a;
		}

		@Override
		public Iterator<int[]> iterator() {
			return this;
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}