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

public class Main {
    public static final int[][] dir = {
            {-1, 0},
            {1, 0},
            {0, 1},
            {0, -1}
    };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int[][] memo = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                memo[i][j] = -1;
            }
        }
        dp(s, memo, 0, n - 1);
        System.out.println(memo[0][n - 1]);
    }

    private static int dp(String s, int[][] memo, int left, int right) {
        if (left > right) {
            return 0;
        }
        if (memo[left][right] != -1) {
            return memo[left][right];
        }
        if (left == right) {
            return memo[left][right] = 1;
        }
        int res = 1 + dp(s, memo, left + 1, right);
        for (int i = left+1; i <= right; i++) {
            if (s.charAt(i) == s.charAt(left)) {
                res = Math.min(res, dp(s, memo, left+1, i - 1) + dp(s, memo, i, right));
            }
        }
        return memo[left][right] = res;
    }

}