Problem:
Score : 600 points

Problem Statement

You are given a string S of length 2N consisting of lowercase English letters.

There are 2^{2N} ways to color each character in S red or blue. Among these ways, how many satisfy the following condition?

The string obtained by reading the characters painted red from left to right is equal to the string obtained by reading the characters painted blue from right to left.

Constraints

1 \leq N \leq 18

The length of S is 2N.

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of ways to paint the string that satisfy the condition.

Sample Input 1

4
cabaacba

Sample Output 1

4

There are four ways to paint the string, as follows:

cabaacba

cabaacba

cabaacba

cabaacba

Sample Input 2

11
mippiisssisssiipsspiim

Sample Output 2

504

Sample Input 3

4
abcdefgh

Sample Output 3

0

Sample Input 4

18
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Sample Output 4

9075135300

The answer may not be representable as a 32-bit integer.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[20][20];

int main(void) {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	string ss = s;
	reverse(all(s));
	ll ans = 0;
	rep(i,0,1<<n){
		string s1;
		string s2;
		rep(j,0,n){
			if(((i>>j)&1)==1){
				s1+=s[j];
			}
			else{
				s2+=s[j];
			}
		}
		clr(dp,-1);
		dp[0][0] = 1;
		rep(j,0,n){
			rep(k,0,s1.sz){
				if(dp[j][k]==-1)continue;
				if(k<s1.sz&&ss[j]==s1[k]){
					if(dp[j+1][k+1]==-1){
						dp[j+1][k+1] = dp[j][k];
					}
					else{
						dp[j+1][k+1] += dp[j][k];
					}
				}
				if(j-k>=0&&j-k<s2.sz&&ss[j]==s2[j-k]){
					if(dp[j+1][k]==-1){
						dp[j+1][k] = dp[j][k];
					}
					else{
						dp[j+1][k] += dp[j][k];
					}
				}
			}
		}
		if(dp[n][s1.sz]!=-1){
			ans += dp[n][s1.sz];
		}
	}
	cout << ans*2 << endl;
	return 0;
}