module M = Map.Make (struct
  type t = char list * char list
  let compare = compare
end)

let () = Scanf.scanf "%d\n%s\n" @@ fun n s ->
  let m =
    Array.fold_left (fun m rb ->
      M.add rb (1 + try M.find rb m with Not_found -> 0) m) M.empty @@
    Array.init (1 lsl n) @@ fun i ->
      Array.fold_left (fun (r, b) j ->
        if i land (1 lsl j) = 0
        then (s.[j + n] :: r, b)
        else (r, s.[j + n] :: b)) ([], []) @@
      Array.init n @@ fun j -> j in
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.init (1 lsl n) @@ fun i ->
    let (r, b) =
      Array.fold_left (fun (r, b) j ->
        if i land (1 lsl j) = 0
        then (s.[j] :: r, b)
        else (r, s.[j] :: b)) ([], []) @@
      Array.init n @@ fun j -> j in
    try M.find (List.rev b, List.rev r) m with Not_found -> 0
