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 = 505;
const int inf = 1e9 + 7;
int dp[N][N][30], min1[N][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, i, j, k;
  string s;
  cin >> n >> s;
  s = " " + s;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= 26; j++) {
      dp[i][i][j] = inf;
    }
    dp[i][i][(s[i] - 'a' + 1)] = 1;
    min1[i][i] = 1;
  }
  for (k = 1; k <= n - 1; k++) {
    for (i = 1; i <= n - k; i++) {
      for (j = 1; j <= 26; j++) {
        dp[i][i + k][j] = inf;
      }
      for (j = i + 1; j < i + k; j++) {
        dp[i][i + k][(s[j] - 'a' + 1)] =
            min(dp[i][i + k][s[j] - 'a' + 1],
                min1[i][j - 1] + min1[j + 1][i + k] + 1);
        dp[i][i + k][(s[j] - 'a' + 1)] =
            min(min1[i][j - 1] + dp[j + 1][i + k][(s[j] - 'a' + 1)],
                dp[i][i + k][(s[j] - 'a' + 1)]);
        dp[i][i + k][(s[j] - 'a' + 1)] =
            min(dp[i][i + k][(s[j] - 'a' + 1)],
                dp[i][j - 1][(s[j] - 'a' + 1)] + min1[j + 1][i + k]);
        dp[i][i + k][(s[j] - 'a' + 1)] =
            min(dp[i][i + k][(s[j] - 'a' + 1)],
                dp[i][j - 1][(s[j] - 'a' + 1)] +
                    dp[j + 1][i + k][(s[j] - 'a' + 1)] - 1);
      }
      dp[i][i + k][(s[i] - 'a' + 1)] =
          min(min1[i + 1][i + k] + 1, dp[i + 1][i + k][(s[i] - 'a' + 1)]);
      dp[i][i + k][(s[i + k] - 'a' + 1)] =
          min(min1[i][i + k - 1] + 1, dp[i][i + k - 1][(s[i + k] - 'a' + 1)]);
      min1[i][i + k] = inf;
      for (j = 1; j <= 26; j++) {
        min1[i][i + k] = min(min1[i][i + k], dp[i][i + k][j]);
      }
    }
  }
  int ans = inf;
  for (i = 1; i <= 26; i++) {
    ans = min(ans, dp[1][n][i]);
  }
  cout << ans;
}