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.*;
public class code{
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int[] d = new int[n];
        for(int i=0;i<n;i++) d[i] = (int)c[i];
        Coloring col = new Coloring(n,d);
        int res = col.get(0,n)+1;
        System.out.println(res);
    }
    
    
    
    public static class Coloring{
        int[] tab;
        int[][] dp;
        int[] q;
        int n;
        int[] c;
        Coloring(int n,int[] tab){
            this.tab = tab;
            buildColor(n);
            n = this.n;
            dp = new int[n][n];
            for(int i=0;i<n;i++) dp[i][i] = 1;
            for(int i=1;i<n;i++){
                for(int j=0;j<n-i;j++){
                    regle(dp,j,j+i);
                }
            }
        }
        void buildColor(int n){
            int[] d = new int[n];
            q = new int[n];
            int cnt = 0;
            int l = 1;
            d[0] = tab[0];
            for(int i=1;i<n;i++){
                q[i] = i-cnt;
                if(tab[i]==tab[i-1]){
                    cnt++;
                    q[i]--;
                    continue;
                }
                d[l] = tab[i];
                l++;
            }
            this.n = l;
            c = new int[l];
            for(int i=0;i<l;i++) c[i] = d[i];
        }
        void regle(int[][] dp,int l,int r){
            dp[l][r] = Math.min(dp[l][r-1]+1,dp[l+1][r]+1);
            if(c[l]==c[l+1]||c[l]==c[r]) dp[l][r] = Math.min(dp[l][r],dp[l+1][r]);
            if(c[r]==c[r-1]||c[r]==c[l]) dp[l][r] = Math.min(dp[l][r],dp[l][r-1]);
            for(int i=l+2;i<r;i++){
                if(c[l]==c[i]){
                    dp[l][r] = Math.min(dp[l][r],dp[l+1][i]+dp[i+1][r]);
                }
            }
            for(int i=r-2;i>l;i--){
                if(c[r]==c[i]){
                    dp[l][r] = Math.min(dp[l][r],dp[l][i-1]+dp[i][r-1]);
                }
            }
        }
        int get(int l,int r){
            return dp[q[l]][q[r-1]]-1;
        }
    }

}