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.io.DataInputStream;
import java.util.Arrays;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author xwchen
 */
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);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();
            int[][] dp = new int[n + 1][n + 1];
            for (int i = 0; i < n; ++i) {
                Arrays.fill(dp[i], 505);
                dp[i][i] = 1;
                if (i + 1 < n && s[i] == s[i + 1]) {
                    dp[i][i + 1] = 1;
                } else {
                    dp[i][i + 1] = 2;
                }
            }
            for (int len = 3; len <= n; ++len) {
                for (int st = 0; st < n; ++st) {
                    int i = st;
                    int j = st + len - 1;
                    if (j >= n) {
                        break;
                    }
                    for (int k = i; k <= j; ++k) {
//                    if (i <= k - 1) {
//                        dp[i][j] = Math.min(dp[i][j], dp[i][k - 1] + dp[k][j]);
//                        dp[i][j] = Math.min(dp[i][j], dp[i][k - 1] + 1 + dp[k][j]);
//                    }
//                    if (k + 1 <= j && s[k] == s[k + 1]) {
//                        dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j] - 1);
//                    } else {
//                        dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j]);
//                    }
                        if (s[i] == s[k]) {
                            int p1 = 0;
                            if (i + 1 <= k - 1) {
                                p1 = dp[i + 1][k - 1];
                            }
                            int p2 = 0;
                            if (k <= j) {
                                p2 = dp[k][j];
                            }
                            dp[i][j] = Math.min(dp[i][j], p1 + p2);
                        } else {
                            dp[i][j] = Math.min(dp[i][j], dp[i][k - 1] + dp[k][j]);
                        }
                    }
                }
            }
//        for (int i = 0; i < n; ++i) {
//            for (int j = 0; j < n; ++j) {
//                out.print(dp[i][j] + "\t");
//            }
//            out.println();
//        }

            out.println(dp[0][n - 1]);

        }

    }

    static class InputReader {
        final private int BUFFER_SIZE = 1 << 10;
        final private int LINE_SIZE = 1 << 20;
        private DataInputStream in;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public InputReader(InputStream inputStream) {
            this.in = new DataInputStream(inputStream);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String next() {
            byte[] buf = new byte[LINE_SIZE]; // line length
            int cnt = 0, c;
            c = read();
            while (c == ' ' || c == '\n' || c == '\r')
                c = read();
            do {
                if (c == ' ' || c == '\n' || c == '\r')
                    break;
                buf[cnt++] = (byte) c;
            } while ((c = read()) != -1);
            return new String(buf, 0, cnt);
        }

        public int nextInt() {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
                if (bytesRead == -1)
                    buffer[0] = -1;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

    }
}