Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

s1 = s[:n]
s2 = s[n:]

d1 = dict()
for i in range(1 << n):
    rd = ''
    bl = ''
    for j in range(n):
        if (i >> j) & 1:
            rd = rd + s1[j]
        else:
            bl = s1[j] + bl
    tpl = (rd, bl)
    d1[tpl] = d1.get(tpl, 0) + 1

d2 = dict()
for i in range(1 << n):
    rd = ''
    bl = ''
    for j in range(n):
        if (i >> j) & 1:
            rd = rd + s2[j]
        else:
            bl = s2[j] + bl
    tpl = (bl, rd)
    d2[tpl] = d2.get(tpl, 0) + 1

ans = 0
for k1, v1 in d1.items():
    ans += v1 * d2.get(k1, 0)
print(ans)

Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
'''
参考: https://beta.atcoder.jp/contests/agc026/submissions/2849460
'''

n = int(input())
s = input()

s_left = s[:n]
s_right = s[n:]
m = dict()

for i in range(1 << n):
    s_red, s_blue = '', ''
    for j in range(n):
        if i & (1 << j):
            s_red = s_red  + s_left[j]
        else:
            s_blue = s_left[j] + s_blue
    tpl = (s_red, s_blue)
    if tpl in m:
        m[tpl] += 1
    else:
        m[tpl] = 1

ans = 0
for i in range(1 << n):
    s_red, s_blue = '', ''
    for j in range(n):
        if i & (1 << j):
            s_red = s_right[j] + s_red
        else:
            s_blue = s_blue + s_right[j]
        tpl = (s_red, s_blue)
    if tpl in m:
        ans += m[tpl]
print(ans)


Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
'''
参考: https://beta.atcoder.jp/contests/agc026/submissions/2849460
'''

n = int(input())
s = input()

s_left = s[:n]
s_right = s[n:]
m = dict()

for i in range(1 << n):
    s_red = s_blue = ''
    for j in range(n):
        if i & (1 << j):
            s_red = s_red  + s_left[j]
        else:
            s_blue = s_left[j] + s_blue
    if (s_red, s_blue) in m:
        m[(s_red, s_blue)] += 1
    else:
        m[(s_red, s_blue)] = 1

ans = 0
for i in range(1 << n):
    s_red = s_blue = ''
    for j in range(n):
        if i & (1 << j):
            s_red = s_right[j] + s_red
        else:
            s_blue = s_blue + s_right[j]
   
    if (s_red, s_blue) in m:
        ans += m[(s_red, s_blue)]
print(ans)


Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
'''
参考: https://beta.atcoder.jp/contests/agc026/submissions/2849460
'''

n = int(input())
s = input()

s_left = s[:n]
s_right = s[n:]
m = dict()

for i in range(1 << n):
    s_red, s_blue = '', ''
    for j in range(n):
        if i & (1 << j):
            s_red = s_red  + s_left[j]
        else:
            s_blue = s_left[j] + s_blue
    if (s_red, s_blue) in m:
        m[(s_red, s_blue)] += 1
    else:
        m[(s_red, s_blue)] = 1

ans = 0
for i in range(1 << n):
    s_red, s_blue = '', ''
    for j in range(n):
        if i & (1 << j):
            s_red = s_right[j] + s_red
        else:
            s_blue = s_blue + s_right[j]
   
    if (s_red, s_blue) in m:
        ans += m[(s_red, s_blue)]
print(ans)


Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
'''
参考: https://beta.atcoder.jp/contests/agc026/submissions/2849460
'''

if __name__ == '__main__':
    n = int(input())
    s = input()

    s_left = s[:n]
    s_right = s[n:]
    m = dict()

    '''
    1 << n　は　2 ** n
    '''
    
    for i in range(2 ** n):
        s_red, s_blue = '', ''
        for j in range(n):
            if i & (2 ** j):
                s_red = s_red  + s_left[j]
            else:
                s_blue = s_left[j] + s_blue
        if (s_red, s_blue) in m:
            m[(s_red, s_blue)] += 1
        else:
            m[(s_red, s_blue)] = 1

    ans = 0
    for i in range(2 ** n):
        s_red, s_blue = '', ''
        for j in range(n):
            if i & (2 ** j):
                s_red = s_right[j] + s_red
            else:
                s_blue = s_blue + s_right[j]
       
        if (s_red, s_blue) in m:
            ans += m[(s_red, s_blue)]
    print(ans)

Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
'''
参考: https://beta.atcoder.jp/contests/agc026/submissions/2849460
'''

if __name__ == '__main__':
    n = int(input())
    s = input()

    s_left = s[:n]
    s_right = s[n:]
    m = dict()

    '''
    1 << n　は　2 ** n
    '''
    
    for i in range(2 ** n):
        s_red, s_blue = '', ''
        for j in range(n):
            if i & (2 ** j):
                s_red += s_left[j]
            else:
                s_blue += s_left[j]
        if (s_red, s_blue) in m:
            m[(s_red, s_blue)] += 1
        else:
            m[(s_red, s_blue)] = 1

    ans = 0
    for i in range(2 ** n):
        s_red, s_blue = '', ''
        for j in range(n):
            if i & (2 ** j):
                s_red += s_right[j]
            else:
                s_blue += s_right[j]

        s_red = s_red[::-1]
        s_blue = s_blue[::-1]
        
        if (s_red, s_blue) in m:
            ans += m[(s_red, s_blue)]
    print(ans)

Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
'''
参考: https://beta.atcoder.jp/contests/agc026/submissions/2849460
'''

if __name__ == '__main__':
    n = int(input())
    s = input()

    s_left = s[:n]
    s_right = s[n:]
    m = dict()

    Bs = [bin(x)[2:].zfill(n) for x in range(2 ** n)]
    intBs = [list(map(int, list(x))) for x in Bs]

    for b in intBs:
        s_red, s_blue = '', ''
        for i in range(n):
            if b[i] == 0:
                s_red += s_left[i]
            else:
                s_blue += s_left[i]
        if (s_red, s_blue) in m:
            m[(s_red, s_blue)] += 1
        else:
            m[(s_red, s_blue)] = 1

    ans = 0
    for b in intBs:
        s_red, s_blue = '', ''
        for i in range(n):
            if b[i] == 0:
                s_red += s_right[i]
            else:
                s_blue += s_right[i]

        s_red = s_red[::-1]
        s_blue = s_blue[::-1]
        
        if (s_red, s_blue) in m:
            ans += m[(s_red, s_blue)]
    print(ans)

Fixed submission:
def main():
    from collections import defaultdict

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

    L, R = S[:N], S[N * 2 - 1:N - 1:-1]

    def make_counter(s: str) -> defaultdict(int):
        ret = defaultdict(int)
        for bit in range(1 << N):
            red, blue = '', ''
            for j in range(N):
                if (bit >> j) & 1:
                    red += s[j]
                else:
                    blue += s[j]

            ret[red + '_' + blue] += 1
        return ret

    ld = make_counter(L)
    rd = make_counter(R)

    print(sum(ld[key] * rd[key] for key in ld))


if __name__ == '__main__':
    main()