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.*;
import java.io.*;
/*
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
Integer.parseInt(st.nextToken());
Long.parseLong(st.nextToken());
Scanner sc = new Scanner(System.in);


*/



public class answer{
    
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        String s = sc.next();
        int[] color = new int[n];
        color[0] = s.charAt(0) - 'a';
        int l = 1;
        int num;
        for(int i=1;i<n;i++){
            num = s.charAt(i) - 'a';
            if(num!=color[l-1]) {
                color[l] = num;
                l++;
            }
            
        }
        int[] col = new int[l];
        for(int i=0;i<l;i++) col[i] = color[i];
        n = l;
        int[][] dp = new int[n][n];
        int same,first,second;
        for(int i=n-1;i>=0;i--){
            for(int j=i;j<n;j++){
                if(i==j) dp[i][j] = 1;
                else if(i==j-1) {
                     dp[i][j] = 2;
                }
                else{
                    same = (col[i]==col[j]) ? dp[i+1][j-1] + 1 : dp[i+1][j-1]+2;
                    first = 1 + dp[i+1][j] ;
                    second = (col[i]==col[j]) ? dp[i][j-1] : 1 + dp[i][j-1];
                    
                   
                    for(int k=j-1;k>i;k--){
                        if(col[k]==col[j]) same = Math.min(dp[i][k-1]+dp[k][j-1],same);
                    }    
                    
                    dp[i][j] = Math.min(same,Math.min(first,second));
                    
                }
            }
        }
        
        System.out.println(dp[0][n-1]);
        
    }
}