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;
long long const MAXN = 5e2 + 8;
long long const INF = 1e12 + 8;
long long const delta = 1000000007;
long long dp[MAXN][MAXN];
int main() {
  std::ios::sync_with_stdio(0);
  ;
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  s += 'a';
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) dp[i][j] = INF;
  }
  for (long long i = 0; i < n; i++) dp[i][i] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 0; j < n; j++) {
      if (j + i - 1 >= n) break;
      long long temp = INF;
      for (long long k = j; k <= j + i - 2; k++) {
        long long x = dp[j][k] + dp[k + 1][j + i - 1];
        if (s[j] == s[k + 1] || s[j] == s[j + i - 1] || s[k] == s[k + 1] ||
            s[k] == s[j + i - 1])
          x--;
        temp = min(temp, x);
      }
      dp[j][j + i - 1] = min(dp[j][j + i - 1], temp);
      long long l = j, r = j + i - 1;
      if (s[l] != s[r]) continue;
      while (s[l] == s[l + 1] && l + 1 <= j + i - 1) l++;
      while (s[r] == s[r - 1] && r - 1 >= l) r--;
      if (l == r)
        dp[j][j + i - 1] = 1;
      else
        dp[j][j + i - 1] = min(dp[j][j + i - 1], 1 + dp[l + 1][r - 1]);
    }
  }
  cout << dp[0][n - 1];
  return 0;
}