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;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    int n;
    string s;
    cin >> n >> s;
    string f, b;
    f = s.substr(0, n);
    b = s.substr(n);
    reverse(b.begin(), b.end());
    map< pair<string, string>, ll> left, right;
    set< pair<string, string> > st;

    rep(k, 1 << n) {
        bitset<20> bs(k);
        string red, blue;

        rep(i, n) {
            if (bs[i]) red.push_back(f[i]);
            else blue.push_back(f[i]);
        }
        left[MP(red, blue)]++;
        st.insert(MP(red, blue));
    }

    rep(k, 1 << n) {
        bitset<20> bs(k);
        string red, blue;

        rep(i, n) {
            if (bs[i]) red.push_back(b[i]);
            else blue.push_back(b[i]);
        }
        right[MP(red, blue)]++;
        st.insert(MP(red, blue));
    }

    ll ans = 0;
    for (auto itr = st.begin(); itr != st.end(); itr++) {
        ans += left[*itr] * right[*itr];
    }
    cout << ans << endl;
    return 0;
}