1714. Vera and Banquet

时间限制 2000 ms   内存限制 512 MB

Vera knows 26 recipes, each represented by a lowercase letter from a to z. She is preparing a banquet consisting of N dishes arranged around a circular table. Since Vera is lazy, each dish is independently and uniformly randomly chosen from one of her 26 recipes. The banquet can be represented as a string S of length N where Si is the recipe of dish i (1 ≤ i ≤ N). Dish j is clockwise to dish j − 1 for 2 ≤ j ≤ N and dish 1 is clockwise to dish N. 

A sample is the sequence of recipes in a consecutive section of dishes in either clockwise or counterclockwise direction. 

Vera wonders how many different samples there are. Two samples are the same if they have the same length and the same recipe at every position. 

输入数据

Line 1 contains integer N (2 ≤ N ≤ 50000). 

Line 2 contains string S of N lowercase letters. It is guaranteed that S represents a banquet created by the described process. 

输出数据

Print one line with one integer, the number of different samples. 

样例输入

复制
3
aba \n
   \n

样例输出

复制
8 \n

样例说明

For the example, the eight different samples are a, b, aa, ab, ba, aba, aab, baa. 

For input:

6

ondrej

The output should be:

66

For this example, rejo, drejon are clockwise samples and nojer, dnojer are counter-clockwise samples.

And for input:

8

abcdefgg

the output should be:

128


提交

请先 登录

© 2025 FAQs Contact About