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.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class F {

    private static StringTokenizer st;
    private static BufferedReader br;
    private static PrintWriter pw;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        int n = nextInt();
        String s = next();
        int[][][]dp = new int[26][n][n];

        int INF = (int)1e9;
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < n; j++) {
                Arrays.fill(dp[i][j], INF);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 26; j++) {
//                if (j == s.charAt(i) - 'a') {
//                    dp[j][i][i] = 0;
//                } else {
//                    dp[j][i][i] = 1;
//                }
            }
            dp[s.charAt(i) - 'a'][i][i] = 0;
        }


        for (int leng = 2; leng <= n; leng++) {
            for (int i = 0; i <= n - leng; i++) {
                int j = i + leng - 1;
                int ii = s.charAt(i) - 'a';
                int jj = s.charAt(j) - 'a';
                for (int k = i; k < j; k++) {
                    if (ii == jj) {
                        dp[ii][i][j] = Math.min(dp[ii][i][j], dp[ii][i][k] + dp[jj][k+1][j]);
                    } else {
                        dp[ii][i][j] = Math.min(dp[ii][i][j], dp[ii][i][k] + dp[jj][k + 1][j] + 1);
                        dp[jj][i][j] = Math.min(dp[jj][i][j], dp[ii][i][k] + dp[jj][k + 1][j] + 1);
                    }
                }
                if (ii == jj) {
                    if (i+1 <= j-1) {
                        for (int k = 0; k < 26; k++) {
                            if (k == ii) {
                                dp[ii][i][j] = Math.min(dp[ii][i][j], dp[k][i + 1][j - 1]);
                            } else {
                                dp[ii][i][j] = Math.min(dp[ii][i][j], dp[k][i + 1][j - 1] + 1);
                            }
                        }
                    } else {
                        dp[ii][i][j] = 0;
                    }
                }

            }
        }

        int ans = Math.min(dp[s.charAt(0)-'a'][0][n-1], dp[s.charAt(n-1)-'a'][0][n-1]) + 1;

        System.out.println(ans);
        pw.close();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    private static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    private static String next() throws IOException {
        while (st==null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

}