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{
        TreeMap<Integer,TreeSet<Integer>> tm = new TreeMap<Integer,TreeSet<Integer>>();
        int[] tab;
        int[][] dp;
        int n;
        int[] c;
        Coloring(int n,int[] tab){
            this.tab = tab;
            buildColor(n);
            for(int i=0;i<this.n;i++){
                if(!tm.containsKey(c[i])) tm.put(c[i],new TreeSet<Integer>()); 
                tm.get(c[i]).add(i);
            }
            dp = new int[this.n][this.n];
            for(int i=0;i<this.n;i++) dp[i][i] = 1;
            for(int i=1;i<this.n;i++){
                for(int j=0;j<this.n-i;j++){
                    regle(dp,j,j+i);
                }
            }
        }
        void buildColor(int n){
            int[] d = new int[n];
            int l = 1;
            d[0] = tab[0];
            for(int i=1;i<n;i++){
                if(tab[i]==tab[i-1]) 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]);
            TreeSet<Integer> ts = tm.get(c[l]);
            int k = ts.last();
            int ind = l+1;
            while(ind<k){
                ind = ts.higher(ind);
                if(ind>=r) break;
                dp[l][r] = Math.min(dp[l][r],dp[l+1][ind]+dp[ind+1][r]);
            }
            ts = tm.get(c[r]);
            k = ts.last();
            ind = l;
            while(ind<k){
                ind = ts.higher(ind);
                if(ind>=r-1) break;
                dp[l][r] = Math.min(dp[l][r],dp[l][ind-1]+dp[ind][r-1]);
            }
        }
        int get(int l,int r){
            int a = l;
            int b = r-1;
            int cnt = 0;
            for(int i=1;i<r;i++){
                if(tab[i]==tab[i-1]) cnt++;
                if(i==l) a-=cnt;
            }
            b -= cnt;
            return dp[a][b]-1;
        }
    }

}