Skwishinese 
Difficulty: Hard

The language Skwishinese has its own elegant, albeit complicated, measure for the beauty of a word.

Before we can start describing how to measure it, we must first define a subsequence. Discovered by and named after the famous Skwishinese doctor, Aaron J. Subsequence, a _subsequence_ of a word is another word that can be formed by removing one or more (possibly none) of the letters of that word. For example, `loooo` is a subsequence of `troolooloo`, but `trooooll` and `banana` are not.

Moreover, the _reverse_ of a word is obtained simply by reversing the order of the letters. For example, the reverse of `troolooloo` is `oolooloort`. We denote the reverse of $U$ by $U^R$.

Let $U$ be a Skwishinese word. We can form a nonsensical word, $UU^R$, by _concatenating_ $U$ and its reverse. For example, if $U$ is `loooo`, then $UU^R$ will be `looooooool`.

Now, the _beauty_ of a Skwishinese word $V$ is the length of the shortest word $U$ that is a subsequence of $V$ and such that $V$ is a subsequence of $UU^R$ (the concatenation of $U$ and its reverse).

For example, the beauty of the word `troolooloo` is 6, because 6 is the length of the shortest word $U$ satisfying the above conditions (in this case, $U$ is `troolo`).

**Input Format**  
The input consists of exactly two lines.  

The first line contains $N$, a positive integer giving the length of the word $V$.  

The second line contains $V$ a word in Skwishinese. It is a string consisting only of lowercase letters from the English alphabet.

**Output Format**  
Output the beauty of the Skwishinese word $V$.

**Constraints**  
$1 \le N \le 400$  
$V$ consists only of lowercase letters

**Sample Input**  

    6
    oleleo

**Sample Output**  

    4

**Explanation**  
One such possible $U$ is `oele` (because `oele` is a subsequence of `oleleo`, and `oleleo` is a subsequence of $UU^R$ = `oeleeleo`). Another is `olel`.

It can be shown that this is the shortest possible, so the answer is 4.

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
```cpp
#include <cstring>
#include <string>
#include <cstdio>
#include <cctype>
#include <cassert>

using namespace std;

char s[402];
int dp[2][402][402];

void better(int &x,int y) {
    if ((x < 0) || (x > y)) {
        x = y;
    }
}

int main() {
    memset(dp,0xff,sizeof(dp));
    dp[0][0][0] = 0;
    int n;
    scanf("%d%s",&n,s);
    assert((n >= 1) && (n <= 400));
    assert(strlen(s) == n);
    int  answer = n, last = 0;
    for (int i = 1; i <= n; ++i) {
        assert(islower(s[i - 1]));
        int now = i & 1;
        memcpy(dp[now], dp[last],sizeof(dp[0]));
        for (int j = 0; j < i; ++j) {
            for (int k = 0; (k < i) && (j + k < n); ++k) {
                if (dp[last][j][k] >= 0) {
                    int jj = (s[i - 1] == s[j])?(j + 1):j;
                    int kk = (s[i - 1] == s[n - k - 1])?(k + 1):k;
                    better(dp[now][jj][kk], dp[last][j][k] + 1);
                    if (jj + kk >= n) {
                        answer = min(answer, dp[now][jj][kk]);
                    }
                }
            }
        }
        last = now;;
    }

    printf("%d\n",answer);
    return 0;
}
```