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.util.Arrays;
import java.util.Scanner;

public class clearthestring {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		a=scan.next().toCharArray();
		dp=new int[n][n];
		for(int[] d:dp) Arrays.fill(d,-1);
		System.out.println(go(0,n-1));
	}
	static int n;
	static int[][] dp;
	static char[] a;
	public static int go(int l, int r) {
		if(l>r) return 0;
		if(l==r) return 1;
		if(dp[l][r]!=-1) return dp[l][r];
		int res=Integer.MAX_VALUE/2;
		//eliminate duplicate letters at the ends
		if(a[l]==a[l+1]) res=Math.min(res,go(l+1,r));
		if(a[r]==a[r-1]) res=Math.min(res,go(l,r-1));
		//and at both ends since it is the same as eliminating everything in the middle
		if(a[l]==a[r]) res=Math.min(res,1+go(l+1,r-1));
		//they aren't the same so add +1 operation and move in
		res=Math.min(res,1+go(l+1,r));
		res=Math.min(res,1+go(l,r-1));
		
		//abaca
		//split to b and aca
		for(int i=l;i<r;i++) {
			if(a[i+1]==a[l]) res=Math.min(res,go(l+1,i)+go(i+1,r));
		}
		return dp[l][r]=res;
	}
}