let fn1: string -> int =
  Seq.distinct >> Seq.length

let fn2: string -> int =
  fun s ->
    [0..(s.Length - 1)]
    |> Seq.fold (fun m i ->
      match Map.tryFind s.[i] m with
      | Some _ -> m
      | _ -> m.Add (s.[i], s.[(i + 1)..] |> fn1)
    ) Map.empty
    |> Seq.sumBy (fun x -> x.Value)

let fn3: string -> int =
  fun s ->
    [0..(s.Length - 1)]
    |> Seq.fold (fun m i ->
      match Map.tryFind s.[i] m with
      | Some _ -> m
      | _ -> m.Add (s.[i], s.[(i + 1)..] |> fn2)
    ) Map.empty
    |> Seq.sumBy (fun x -> x.Value)

stdin.ReadLine()
|> ignore
|> fun () -> stdin.ReadLine()
|> fn3
|> printfn "%d"
