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.*;
import java.util.*;

public class C {
    static MyScanner sc;
    static PrintWriter pw;

    public static void main(String[] args) throws Throwable {
        sc = new MyScanner();
        pw = new PrintWriter(System.out);

        n = sc.nextInt();
        s = sc.next().toCharArray();
        mem = new Integer[n][n];
        pw.println(dp(0, n - 1));
        pw.flush();
        pw.close();
    }

    static int n;
    static char[] s;
    static Integer[][] mem;

    static int dp(int i, int j) {
        if (i > j)
            return 0;
        if (mem[i][j] != null)
            return mem[i][j];
        int ans = 1 + dp(i + 1, j);
        for (int k = i + 1; k <= j; k++)
            if (s[k] == s[i])
                ans = Math.min(ans, dp(i + 1, k - 1) + dp(k, j));

        return mem[i][j] = ans;
    }

    static void shuffle(int[] a) {
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int x = r.nextInt(a.length);
            int y = r.nextInt(a.length);
            int tmp = a[x];
            a[x] = a[y];
            a[y] = tmp;
        }
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}