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 Main {
    static class Pair {
        int l;
        int r;

        public Pair(int l, int r) {
            this.l = l;
            this.r = r;
        }

        @Override
        public int hashCode() {
            return l * 12345 + r;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null)
                return false;
            if (!(obj instanceof Pair))
                return false;
            Pair objPair = (Pair) obj;
            return objPair.l == this.l && objPair.r == this.r;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        Map<Pair, Integer> cache = new HashMap<>();
        System.out.println(stepsToDelete(str, 0, n - 1, cache));
    }

    public static int stepsToDelete(String s, int l, int r, Map<Pair, Integer> cache) {
        if (l > r)
            return 0;
        if (l == r)
            return 1;
        if (s.charAt(l) == s.charAt(l + 1))
            return stepsToDelete(s, l + 1, r, cache);

        // aababbca


        Pair pair = new Pair(l, r);
        if (cache.containsKey(pair))
            return cache.get(pair);

        int result = 1 + stepsToDelete(s, l + 1, r, cache);

        for (int i = l + 1; i <= r; i++) {
            if (s.charAt(l) == s.charAt(i))
                result = Math.min(result, stepsToDelete(s, l + 1, i - 1, cache) +
                        stepsToDelete(s, i, r, cache));
        }

        cache.put(pair, result);
        return result;
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public 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;
        }

    }
}