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

public class Test {
	public static boolean isPrime(long num) {
		if (num == 2 || num == 3)
			return true;
		if (num % 2 == 0)
			return false;
		for (long i = 3; i * i <= num; i += 2) {
			if (num % i == 0)
				return false;
		}
		return true;
	}

	public static boolean isPalindromeNum(long num) {
		String s = Long.toString(num);
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - i - 1))
				return false;
		}
		return true;
	}

	public static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}
	
	public static void check(int[] a, int l, int r, int m) {
		if(l == r) {
    		System.out.println(l);
    		return;
		}
		int mid = (l + r) / 2;
		int curSum = 0, level = -1;
    	for(int j = 0; j < a.length; j++) {
    		if(j % mid == 0)level++; 
    		curSum += Math.max(0, a[j] - level);
    	}
    	if(curSum >= m) {
    		check(a, l, mid, m);
    	}
    	else {
    		check(a, l + 1, r, m);
    	}
	}
	
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] dp = new int[n][n];
        String s = scanner.next();
        for(int i = 0; i < n; i++)dp[i][i] = 1;
        for(int i = 0; i < n; i++) {
        	for(int j = i + 1; j < n; j++) dp[i][j] = n + 1;
        }
        for(int j = 1; j < n; j++) {
        	for(int i = 0; i < j; i++) {
        		if(s.charAt(j) == s.charAt(j - 1))dp[i][j] = Math.min(dp[i][j], dp[i][j - 1]);
        		else {
            		dp[i][j] = Math.min(dp[i][j], 1 + dp[i][j - 1]);
        			for(int k = i; k < j; k++) {
        				if(s.charAt(k) == s.charAt(j)) {
//        					System.out.println(k + " " + j + " " + dp[i][k] + " " + dp[k + 1][j - 1]); 
        					dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j - 1]);
        				}
        			}
        		}
        	}
        }
        System.out.println(dp[0][n - 1]);
    }
}