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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 5;
const int A = 27;
const long long inf = 1791791791;
const long long mod = 1e9 + 7;
int dp[N][N][50];
char str[N];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", str);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < A; k++) {
        dp[i][j][k] = N;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int k = 0; k < A; k++) {
      dp[i][i][k] = 2;
    }
    dp[i][i][str[i] - 'a'] = 1;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j + i <= n; j++) {
      int ed = j + i - 1;
      for (int k = j + 1; k <= ed; k++) {
        int l = str[k] - 'a';
        dp[j][ed][l] = min(dp[j][ed][l], dp[j][k - 1][l] + dp[k][ed][l] - 1);
      }
      int l = str[j] - 'a';
      dp[j][ed][l] = min(dp[j][ed][l], dp[j][j][l] + dp[j + 1][ed][l] - 1);
      int mn = N;
      for (int k = 0; k < A; k++) {
        mn = min(mn, dp[j][ed][k]);
      }
      for (int k = 0; k < A; k++) {
        dp[j][ed][k] = min(dp[j][ed][k], mn + 1);
      }
    }
  }
  int resp = N;
  for (int i = 0; i < A; i++) {
    resp = min(resp, dp[0][n - 1][i]);
  }
  printf("%d\n", resp);
  return 0;
}