#include<bits/stdc++.h>usingnamespacestd;constintinf=1e6;intsolve(string&str){intn=str.size();// dp[i][j] represents the minimum operations to reduce substring str[i..j]
// to an empty string.
vector<vector<int>>dp(n,vector<int>(n,inf));for(inti=n-1;i>=0;i--){for(intj=i;j<n;j++){// Single element : Only 1 move needed.
if(i==j){dp[i][j]=1;continue;}// We have 2 choices:
// 1. The first element of the substring is deleted alone.
intdelete_alone=1+dp[i+1][j];// 2. The first element of the substring is merged with another
// element at index k.
intmerge=inf;for(intk=i+1;k<=j;k++){if(str[i]==str[k]){// Notice that the left contribution would be initialised
// with 0 and not infinity. Consider "aab".
intleft_contribution=0;if(k-1>=i+1){left_contribution=dp[i+1][k-1];}intright_contribution=dp[k][j];merge=min(merge,left_contribution+right_contribution);}}dp[i][j]=min(delete_alone,merge);}}returndp[0][n-1];}intmain(){intn;cin>>n;stringstr;cin>>str;intres=solve(str);cout<<res<<endl;}