Rikka with New Year's Party
Time limit5sMemory limit512 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
Rikka is now organizing a new year's party for the algorithm association. She has invited actors from 26 different groups, represented by lowercase letters. Rikka wants to select some actors among them for the opening show.
Now, the actors are in a row. The -th actor is from the -th group. Rikka decides to choose a non-empty range () and lets all actors in this range join the opening show.
The show proceeds as follows.
- The actors play in order. The -th actor plays first, and the -th actor plays last.
- When the -th actor is about to play, they decide their action as follows. If an actor who played before them is from the same group , the -th actor chooses the same action as actor . Otherwise, they choose the action with the smallest index that no one has chosen before.
For example, if the 5 actors are from groups abacb, they choose actions in that order.
Rikka found that different ranges can produce the same show. For example, if there are 6 actors from groups abacbc, the ranges and produce the same show.
Two shows are different if they have different numbers of actions, or if some index has different -th actions. A show is possible if some range of produces it. Given , count the number of different possible shows.
Input
The first line contains a single integer (), the number of actors.
The second line contains a lowercase string of length . is the group of the -th actor.
Output
Output a single integer on one line, the number of different possible shows.
Hint
For the first sample, there are 7 different possible shows:
- Action , corresponding to ranges , , , , .
- Actions , corresponding to ranges , , , .
- Actions , corresponding to ranges , .
- Actions , corresponding to range .
- Actions , corresponding to range .
- Actions , corresponding to range .
- Actions , corresponding to range .