let rec pow acc n m =
  if m = 0 then acc else pow (acc * n) n (m - 1)

let pow = pow 1

let solve n s =
  let base = ref ((pow 2 n) - 1) in
  for i = 0 to n - 1 do
    let c = String.get s i in
    for j = (i + 1) to n - 1 do
      if c = (String.get s j) then 
        let left, right = i, (n - 1) - j in
        base := !base - (pow 2 (left + right))
    done;
  done;
  !base

let _ =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  print_int @@ solve n s