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 <stdio.h>
#define infinity 111111111
int min(int a, int b) {
    return a < b ? a : b;
}

char V[411];
int F[411][411][411];
int main() {
    int N;
    scanf("%d%s", &N, V);
    for (int i = N; i >= 0; i--) {
        // try on ones and zeroes
        for (int j = 0; j < N; j++) {
            for (int k = j ? j - 1 : 0; k < N; k++) {
                if (j > k) {// empty strjng
                    F[i][j][k] = 0;
                } else if (i >= N) {
                    F[i][j][k] = infinity;
                } else {
                    int X;
                    if (V[i] != V[j] and V[i] != V[k]) {
                        X = 1 + F[i+1][j][k];
                    } else if (V[i] != V[j] and V[i] == V[k]) {
                        X = 1 + F[i+1][j][k-1];
                    } else if (V[i] == V[j] and V[i] != V[k]) {
                        X = 1 + F[i+1][j+1][k];
                    } else if (V[i] == V[j] and V[i] == V[k]) {
                        X = 1 + F[i+1][j+1][k-1];
                    }
                    F[i][j][k] = min(F[i+1][j][k], X);
                }
            }
        }
    }
    printf("%d\n", F[0][0][N-1]);
}
```