Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    memo = {}

    ans = 0
    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        r = blue[::-1]
        b = red[::-1]

        if sorted(s) != sorted(blue+red+b+r): continue
        if (r, b) in memo:
            ans += memo[(r,b)]
            continue

        dp = [[[0 for _ in xrange(len(b)+1)] for _ in xrange(len(r)+1)] for _ in xrange(n+1)]
        dp[0][0][0] = 1

        for i in xrange(n):
            si = s[n+i]
            for ri in xrange(max(0,len(r)-n+i), len(r)+1):
                for bi in xrange(max(0,len(b)-n+i),len(b)+1):
                    if ri < len(r) and r[ri] == si:
                        dp[i+1][ri+1][bi] += dp[i][ri][bi]
                    if bi < len(b) and b[bi] == si:
                        dp[i+1][ri][bi+1] += dp[i][ri][bi]

        memo[(r,b)] = dp[-1][-1][-1]
        ans += dp[-1][-1][-1]

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    cand1 = collections.defaultdict(int)
    cand2 = collections.defaultdict(int)

    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        cand1[(red,blue)] += 1

        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[2*n-i-1]
            else:
                blue += s[2*n-i-1]
        cand2[(red,blue)] += 1

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

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    memo = {}

    ans = 0
    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        r = blue[::-1]
        b = red[::-1]

        if sorted(s) != sorted(blue+red+b+r): continue
        if (r, b) in memo:
            ans += memo[(r,b)]
            continue

        dp = [[[0 for _ in xrange(len(b)+1)] for _ in xrange(len(r)+1)] for _ in xrange(n+1)]
        dp[0][0][0] = 1

        for i in xrange(n):
            si = s[n+i]
            for ri in xrange(len(r)+1):
                for bi in xrange(len(b)+1):
                    if ri < len(r) and r[ri] == si:
                        dp[i+1][ri+1][bi] += dp[i][ri][bi]
                    if bi < len(b) and b[bi] == si:
                        dp[i+1][ri][bi+1] += dp[i][ri][bi]

        memo[(r,b)] = dp[-1][-1][-1]
        ans += dp[-1][-1][-1]

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    cand1 = collections.defaultdict(int)
    cand2 = collections.defaultdict(int)

    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        cand1[(red,blue)] += 1

        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[2*n-i-1]
            else:
                blue += s[2*n-i-1]
        cand2[(red,blue)] += 1

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

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    d = collections.defaultdict(set)
    for i in xrange(2*n):
        d[s[i]].add(i)

    ans = 0
    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        r = blue[::-1]
        b = red[::-1]

        if sorted(s) != sorted(blue+red+b+r): continue

        dp = [[[0 for _ in xrange(len(b)+1)] for _ in xrange(len(r)+1)] for _ in xrange(n+1)]
        dp[0][0][0] = 1

        for i in xrange(n):
            si = s[n+i]
            for ri in xrange(len(r)+1):
                for bi in xrange(len(b)+1):
                    if ri < len(r) and r[ri] == si:
                        dp[i+1][ri+1][bi] += dp[i][ri][bi]
                    if bi < len(b) and b[bi] == si:
                        dp[i+1][ri][bi+1] += dp[i][ri][bi]

        ans += dp[-1][-1][-1]

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Fixed submission:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    cand1 = collections.defaultdict(int)
    cand2 = collections.defaultdict(int)

    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        cand1[(red,blue)] += 1

        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[2*n-i-1]
            else:
                blue += s[2*n-i-1]
        cand2[(red,blue)] += 1

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

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)