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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        String s;
        int[][] memo;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            s = in.next();
            memo = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    memo[i][j] = -1;
                }
            }
            out.println(calc(0, n - 1));
        }

        int calc(int l, int r) {
            if (memo[l][r] != -1) {
                return memo[l][r];
            }
            if (l == r) {
                return memo[l][r] = 1;
            }
            memo[l][r] = 1 + calc(l + 1, r);
            if (s.charAt(l) == s.charAt(l + 1)) {
                memo[l][r] = Math.min(memo[l][r], calc(l + 1, r));
            }
            for (int i = l + 2; i <= r; i++) {
                if (s.charAt(l) == s.charAt(i)) {
                    memo[l][r] = Math.min(memo[l][r], calc(l + 1, i - 1) + calc(i, r));
                }
            }
            return memo[l][r];
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}