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: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lb lower_bound
#define maxn 100005
#define lowbit(x) (x)&(-x)
#define forup(i,a,b) for(int i=(a);i<=(b);i++)
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)
#define int long long
typedef long long  ll;
typedef unsigned long long ull;
template<class T> inline
void read(T &num)
{num=0; bool f=true; char ch=getchar();
 while(ch<'0'||ch>'9') {if(ch=='-')  f=false;  ch=getchar();}
 while(ch>='0'&&ch<='9') {num=num*10+ch-'0';ch=getchar();}
 num=f?num:-num;
}
int out[100];
template<class T> inline
void  write(T x,char ch)
{if(x==0) {putchar('0');putchar(ch);return;}
 if(x<0) {putchar('-'); x=-x;}
 int num=0;
 while(x){out[num++]=(x%10);x=x/10;}
 fordown(i,num-1,0) putchar(out[i]+'0');
 putchar(ch);
}
string s;
int n;
struct P
{string A,B;
 bool operator <(const P &y) const
  {if(A<y.A) return 1;
   if(A==y.A) return B<y.B; 
  } 
};
map<P,ll> mp;
int ans=0ll; 
int a[20];
void dfs1(int x)
{if(x>n) 
{string A="",B="";
 forup(i,1,n) if(a[i]==1){A=A+s[i-1];}else B=s[i-1]+B;
 P tmp; tmp.A=A;tmp.B=B;
 mp[tmp]=mp[tmp]+1; 
 return;
}
 a[x]=0;
 dfs1(x+1);
 a[x]=1;
 dfs1(x+1); 
}
void dfs2(int x)
{if(x>n)
 {string A="",B="";
  forup(i,1,n) if(a[i]==1) A=A+s[n+i-1]; else B=s[n+i-1]+B; 
  P tmp; tmp.A=B;tmp.B=A; 
  if(mp.find(tmp)!=mp.end())ans+=mp[tmp];	
  return;
 }
  a[x]=0;
  dfs2(x+1);
  a[x]=1;
  dfs2(x+1);	
}
signed main()
{ cin>>n;
  cin>>s;
  dfs1(1);
  
  dfs2(1);	
  cout<<ans<<endl;
return 0;
 }