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;
int table[500][500][26] = {};
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n;
  cin >> s;
  int j = 0;
  while (j < (int)s.size()) {
    if (j > 0 && s[j] == s[j - 1])
      s.erase(s.begin() + j);
    else
      j++;
  }
  n = (int)s.size();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 26; j++)
      table[i][i][j] = (j == (int)s[i] - 'a' ? 0 : 1);
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      for (int k = 0; k < 26; k++) table[j][j + i][k] = 1000;
      for (int k = j; k <= j + i; k++) {
        if (k != j && k != i + j)
          table[j][j + i][(int)s[k] - 'a'] =
              min(table[j][j + i][(int)s[k] - 'a'],
                  table[j][k - 1][(int)s[k] - 'a'] +
                      table[k + 1][j + i][(int)s[k] - 'a']);
        else if (k == j)
          table[j][j + i][(int)s[k] - 'a'] =
              min(table[j][j + i][(int)s[k] - 'a'],
                  table[k + 1][j + i][(int)s[k] - 'a']);
        else
          table[j][j + i][(int)s[k] - 'a'] =
              min(table[j][j + i][(int)s[k] - 'a'],
                  table[j][k - 1][(int)s[k] - 'a']);
      }
      int legK = 1000;
      for (int k = 0; k < 26; k++) legK = min(legK, table[j][j + i][k]);
      for (int k = 0; k < 26; k++)
        table[j][j + i][k] = min(table[j][j + i][k], legK + 1);
    }
  }
  int meg = 1000;
  for (int i = 0; i < 26; i++) meg = min(meg, table[0][n - 1][i] + 1);
  cout << meg << "\n";
  return 0;
}