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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Remoting.Contexts;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray(int n)
        {
            var array = Array();
            var result = new int[n];
            for (int i = 0; i < n; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }


        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        public uint NextUint()
        {
            return uint.Parse(Next());
        }
    }

    struct SS
    {
        public string A, B;
    }

    class Program
    {
        private Scanner Sc;
        private int N;
        private string S;
        private Dictionary<SS, long> LL, RR;
        public void Solve()
        {
            Sc = new Scanner();
            N = Sc.NextInt();
            S = Sc.Next();
            string left = S.Substring(0, N);
            string right = S.Substring(N, N);
            LL = new Dictionary<SS, long>();
            RR = new Dictionary<SS, long>();
            int loop = 1 << N;
            for (int i = 0; i < loop; i++)
            {
                int cp = i;
                string la = "", lb = "", ra = "", rb = "";
                for (int j = 0; j < N; j++)
                {
                    if (cp % 2 == 0)
                    {
                        la += left[j];
                        ra = right[j] + ra;
                    }
                    else
                    {
                        lb += left[j];
                        rb = right[j] + rb;
                    }

                    cp /= 2;
                }
                var l = new SS()
                {
                    A = la,
                    B = lb
                };
                var r = new SS()
                {
                    A = ra,
                    B = rb
                };
                long o;
                LL.TryGetValue(l, out o);
                LL[l] = o + 1;
                RR.TryGetValue(r, out o);
                RR[r] = o + 1;
            }

            long ans = 0;
            foreach (var l in LL)
            {
                long o;
                RR.TryGetValue(l.Key, out o);
                ans += l.Value * o;
            }
            Console.WriteLine(ans);
        }



        static void Main() => new Program().Solve();
    }
}