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 long long MAXN = 5e2 + 69, INF = 1e9;
long long n;
string t;
vector<long long> s = {0};
long long dp[MAXN][MAXN], dp2[MAXN][MAXN];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t;
  s.push_back(t[0]);
  for (long long i = 1; i < t.length(); i++)
    if (t[i] != t[i - 1]) s.push_back(t[i]);
  n = s.size() - 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = i; j <= n; j++)
      dp[i][j] = dp2[i][j] = (j == i ? 1 : INF);
  for (long long len = 2; len <= n; len++) {
    for (long long l = 1; l + len - 1 <= n; l++) {
      long long r = l + len - 1;
      if (s[l] == s[r]) dp[l][r] = dp[l + 1][r - 1] + 1;
      for (long long mid = l; mid < r; mid++) {
        dp[l][r] = min(dp[l][r], dp[l][mid] + dp[mid + 1][r]);
      }
      dp2[l][r] = dp[l][r];
      if (s[l] == s[r]) {
        dp2[l][r]--;
        for (long long mid = l + 1; mid < r; mid++) {
          if (s[mid] == s[l]) {
            dp2[l][r] = min(dp2[l][r], dp2[l][mid] + dp2[mid][r]);
          }
        }
        dp[l][r] = min(dp[l][r], dp2[l][r] + 1);
      }
    }
  }
  cout << dp[1][n];
}