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<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


main(){
    //制約的に半分全列挙が間に合う
    //前後半にわけて後半を反転そいつらを2つにわけることを考える
    //同じようにわけれればいい。
    int n;
    cin>>n;
    string s;
    cin>>s;
    string s1="",s2="";
    for(int i=0;i<n;i++){
        s1+=s[i];
        s2+=s[i+n];
    }
    reverse(ALL(s2));
    map<pair<string,string>,ll> m1,m2;
    for(int i=0;i<(1<<n);i++){
        string t11="",t12="",t21="",t22="";
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                t11+=s1[j];
                t21+=s2[j];
            }
            else{
                t12+=s1[j];
                t22+=s2[j];
            }
        }
        m1[make_pair(t11,t12)]++;
        m2[make_pair(t21,t22)]++;
    }
    ll ans=0;
    
    for(auto x:m1){
        /*
        前半部分について
        x.firstのペアのようにわけるのがx.secondある
        後半部分について
        x.firstのペアのようにわけるのがm2[x.first]個ある
        それらはすべて条件を満たすのでかけて加えてあげる
         */
        ans+=m2[x.first]*x.second;
    }
    cout<<ans<<endl;
    return 0;
}