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 Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(s: Vec<char>) -> u64 {
    use std::collections::HashMap;

    let n = s.len() / 2;
    let ls = s.iter().take(n).cloned().collect::<Vec<char>>();
    let rs = s.iter().rev().take(n).cloned().collect::<Vec<char>>();

    let mut map: HashMap<(String, String), (u64, u64)> = HashMap::new();

    for i in 0..(1 << n) {
        let mut red = Vec::new();
        let mut blue = Vec::new();

        for j in 0..n {
            if (i >> j) & 1 == 1 {
                red.push(ls[j]);
            } else {
                blue.push(ls[j]);
            }
        }
        let key = (red.into_iter().collect::<String>(),
                   blue.into_iter().collect::<String>());

        if map.contains_key(&key) {
            let (v1, v2) = map[&key];
            map.insert(key, (v1+1, v2));
        } else {
            map.insert(key, (1, 0));
        }
    }

    for i in 0..(1 << n) {
        let mut red = Vec::new();
        let mut blue = Vec::new();

        for j in 0..n {
            if (i >> j) & 1 == 1 {
                red.push(rs[j]);
            } else {
                blue.push(rs[j]);
            }
        }
        let key = (red.into_iter().collect::<String>(),
                   blue.into_iter().collect::<String>());

        if map.contains_key(&key) {
            let (v1, v2) = map[&key];
            map.insert(key, (v1, v2+1));
        }
    }

    let mut ret = 0;
    for &(v1, v2) in map.values() {
        ret += v1 * v2;
    }

    ret
}

fn main() {
    read_line!();

    let s = read_line!();

    println!("{}", solve(s.chars().collect()));
}

#[test]
fn solve_test() {
    assert_eq!(solve("cabaacba".chars().collect()), 4);
    assert_eq!(solve("mippiisssisssiipsspiim".chars().collect()), 504);
    assert_eq!(solve("abcdefgh".chars().collect()), 0);
    assert_eq!(solve("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".chars().collect()), 9075135300);
}