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 condition that 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 ≤ N ≤ 18, length of S is 2N, and S consists of lowercase English letters. Input is given as N and S. Output the number of ways to paint the string that satisfy the condition. For example, given input "4" and "cabaacba", the output is "4".

# Buggy version:
from collections import defaultdict
N = int(input())
S = input()
countp = defaultdict(int)
counts = defaultdict(int)
prefix = S[:N]
suffix = S[2*N-1:N-1:-1]
for i in range(1 << (N - 1)):
    p1 = ''
    s1 = ''
    p2 = ''
    s2 = ''
    for j in range(N):
        if (1 << j) & i:
            p1 += prefix[j]
            s1 += suffix[j]
        else:
            p2 += prefix[j]
            s2 += suffix[j]
    countp[(p1, p2)] += 1
    countp[(p2, p1)] += 1
    counts[(s1, s2)] += 1
    counts[(s2, s1)] += 1
    

print(countp, counts)

ans = 0
for k, v in countp.items():
    ans += v * counts[k]

print(ans)

# Fixed version:
from collections import defaultdict
N = int(input())
S = input()
countp = defaultdict(int)
counts = defaultdict(int)
prefix = S[:N]
suffix = S[2*N-1:N-1:-1]
for i in range(1 << (N - 1)):
    p1 = ''
    s1 = ''
    p2 = ''
    s2 = ''
    for j in range(N):
        if (1 << j) & i:
            p1 += prefix[j]
            s1 += suffix[j]
        else:
            p2 += prefix[j]
            s2 += suffix[j]
    countp[(p1, p2)] += 1
    countp[(p2, p1)] += 1
    counts[(s1, s2)] += 1
    counts[(s2, s1)] += 1
    

# print(countp, counts)

ans = 0
for k, v in countp.items():
    ans += v * counts[k]

print(ans)

# Buggy version:
from collections import defaultdict
n=int(input())
s=input()
a=s[:n]
b=s[n:][::-1]
def coloring(x):
    N=1<<n
    dc=defaultdict(int)
    for i in range(N):
        r=''
        b=''
        for j in range(n):
            if i>>j&1:
                r+=x[j]
            else:
                b+=x[j]
        dc[r+'-'+b]+=1
    return dc    

fd=coloring(a)
ld=coloring(b)

for i,j in fd.items():
    ans+=ld[i]*j

print(ans)

# Fixed version:
ans=0

from collections import defaultdict
n=int(input())
s=input()
a=s[:n]
b=s[n:][::-1]
def coloring(x):
    N=1<<n
    dc=defaultdict(int)
    for i in range(N):
        r=''
        b=''
        for j in range(n):
            if i>>j&1:
                r+=x[j]
            else:
                b+=x[j]
        dc[r+'-'+b]+=1
    return dc    

fd=coloring(a)
ld=coloring(b)

for i,j in fd.items():
    ans+=ld[i]*j

print(ans)

# Buggy version:

from collections import defaultdict


N = int(input())
S = input()

X = S[:N]
Y = S[N:]
Y = Y[::-1]

dx = defaultdict(int)
dy = defaultdict(int)

for bit in range(1 << N):
    red = ""
    blue = ""
    for i in range(N):
        if bit & (1 << i):
            red += X[i]
        else:
            blue += X[i]

    dx[(red, blue)] += 1

for bit in range(1 << N):
    red = ""
    blue = ""
    for i in range(N):
        if bit & (1 << i):
            red += Y[i]
        else:
            blue += Y[i]

    dy[(red, blue)] += 1

# 前後が同じになる組がいくつできるか。
ans = 0
for k,v in dx.items():
    ans += dy[k] * v

print(ans)

# Fixed version:

from collections import defaultdict


def main():
        
    N = int(input())
    S = input()

    X = S[:N]
    Y = S[N:]
    Y = Y[::-1]

    dx = defaultdict(int)
    dy = defaultdict(int)

    for bit in range(1 << N):
        red = ""
        blue = ""
        for i in range(N):
            if bit & (1 << i):
                red += X[i]
            else:
                blue += X[i]

        dx[(red, blue)] += 1

    for bit in range(1 << N):
        red = ""
        blue = ""
        for i in range(N):
            if bit & (1 << i):
                red += Y[i]
            else:
                blue += Y[i]

        dy[(red, blue)] += 1

    # 前後が同じになる組がいくつできるか。
    ans = 0
    for k,v in dx.items():
        ans += dy[k] * v

    print(ans)


if __name__ == "__main__":
    main()

# Buggy version:
# encoding:utf-8

import itertools
from collections import defaultdict


def main():
	n = int(input())
	s = input()

	left = s[:n]
	right = s[n:]
	right = right[::-1]

	ans = 0
	#print(left, right)
	for n_r in range(n+1):
		d_left = defaultdict(lambda: 0)
		d_right = defaultdict(lambda: 0)
		#print([1 if x >= n_r else 0 for x in range(n)])
		pts = itertools.combinations(list(range(n)), r = n_r)
		
		for pt in pts:
			#print(pt)
			b_l = "".join([left[i] for i in range(n) if i in pt])
			r_l = "".join([left[i] for i in range(n) if i not in pt])

			d_left[(b_l, r_l)] += 1

			b_r = "".join([right[i] for i in range(n) if i in pt])
			r_r = "".join([right[i] for i in range(n) if i not in pt])

			d_right[(b_r, r_r)] += 1

		for key in d_left:
#			print(n_r, key, d_left[key], d_right[key])
			ans += d_left[key] * d_right[key]

	print(ans)

if __name__ == '__main__':
	main()


# Fixed version:
# encoding:utf-8

import itertools
from collections import defaultdict


def main():
	n = int(input())
	s = input()

	left = s[:n]
	right = s[n:]
	right = right[::-1]

	ans = 0
	#print(left, right)
	for n_r in range(n+1):
		d_left = defaultdict(lambda: 0)
		d_right = defaultdict(lambda: 0)
		#print([1 if x >= n_r else 0 for x in range(n)])
		pts = itertools.combinations(list(range(n)), r = n_r)
		
		for pt in pts:
			#print(pt)
			b_l = ""
			r_l = ""
			b_r = ""
			r_r = ""
			for i in range(n):
				if i in pt:
					b_l += left[i]
					b_r += right[i]
				else:
					r_l += left[i]
					r_r += right[i]

			d_left[(b_l, r_l)] += 1
			d_right[(b_r, r_r)] += 1

		for key in d_left:
#			print(n_r, key, d_left[key], d_right[key])
			ans += d_left[key] * d_right[key]

	print(ans)

	

if __name__ == '__main__':
	main()

# Buggy version:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())
s=input().strip()

memo={}
def getans(a,b,c):
    while a and c and a[0]==c[-1]:
        a=a[1:]
        c=c[:-1]
    if b=="":
        if a=="" and c=="": return 1
        else: return 0
    key=a+"/"+b+"/"+c
    if key in memo: return memo[key]
    # select first letter
    ans=0
    for i in range(1,len(b)):
        if b[0]==b[i]:
            ans+=getans(a,b[1:i],b[i+1:]+c)
    # don't select first letter
    ans+=getans(a+b[0],b[1:],c)
    memo[key]=ans
    #print(key,ans)
    return ans

print(getans("",s,"")*2)

print(len(memo))

# Fixed version:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())
s=input().strip()

memo={}
def getans(a,b,c):
    while a and c and a[0]==c[-1]:
        a=a[1:]
        c=c[:-1]
    if b=="":
        if a=="" and c=="": return 1
        else: return 0
    key=a+"/"+b+"/"+c
    if key in memo: return memo[key]
    # select first letter
    ans=0
    for i in range(1,len(b)):
        if b[0]==b[i]:
            ans+=getans(a,b[1:i],b[i+1:]+c)
    # don't select first letter
    ans+=getans(a+b[0],b[1:],c)
    memo[key]=ans
    #print(key,ans)
    return ans

print(getans("",s,"")*2)

#print(len(memo))