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.*;
import java.util.*;
public class Sol{
	public static int dp[][] = new int[501][501];
	public static int s[];
	public static int n;
    public static void main(String[] args) throws IOException{
    	FastScanner sc = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    	n = sc.nextInt();
    	s = new int[n];
    	String str = sc.nextToken();
    	for(int i = 0; i<n; i++) {
    		s[i] = str.charAt(i)-'a';
    	}
    	for(int i=0; i<501; i++) {
    		Arrays.fill(dp[i],-1);
    	}
    	out.println(go(0,n-1));
    	out.close();
    }
    public static int go(int left, int right) {
    	if(dp[left][right]!=-1)return dp[left][right];
    	if(left>right)return dp[left][right]=0;
    	if(left==right)return dp[left][right]=1;
    	int min = 1+go(left+1,right);
    	for(int i=left+1; i<=right; i++) {
    		if(s[left]==s[i]) {
    			min = Math.min(min, go(left+1,i-1) + go(i,right));
    		}
    	}
    	return dp[left][right] = min;
    }
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

		String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

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

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

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