National Olympiad in Informatics, China, 2014
Recently, the zookeeper noticed that number of all-eat and no-work animals have been increasing. Take penguins for example – they only care about getting food from the zoo's visitors by showing off their cuteness alone. To fix the bad vibe around the zoo and to ensure that animals only get food via exhibiting their true talents, the zookeeper has decided to set up an algorithms class to teach algorithms to the animals.
One day, the zookeeper decided to lecture the KMP algorithm to the animals.
Zookeeper: "For a given string
Panda: "Within the first
Zookeeper: "Very good! Can you give an example?"
Panda: "If abcababc
, then abcab
, and ab
is both its prefix and suffix, and a
longer substring with this property does not exist. Likewise, we can
find that
The zookeeper commended Panda's studiousness. Then, he carefully
explained how
Before dismissing the class, the zookeeper posed a problem: "The KMP
algorithm can only generate the array aaaaa
, then aaaa
, substrings a
and
aa
each satisfy the conditions of 'being both a prefix and suffix,' as
well as guaranteeing that the prefix and suffix do not overlap. Although
substring aaa
does satisfy the condition of 'being both a prefix and
suffix,' we cannot count it because as simultaneously a prefix and
suffix of aaaa
, it overlaps with itself. By the same reasoning, we can
see that
Finally, the zookeeper designated a prize. The first student to solve
this will be rewarded a box of chocolates. After hearing this, Penguin,
who has been sleeping for the entire class, has immediately awoken! But
Penguin doesn't have a clue how to solve this problem. So, he has
scoured the entire zoo to find you for help. Can you help Penguin write
a program to compute the
Specifically, to avoid huge amounts of output, you do not have to output
each value of
Input Specification
The first line of input contains a single integer
For the next
The input will not contain extra or trailing spaces.
Output Specification
The output should contain
Sample Input
3
aaaaa
ab
abcababc
Sample Output
36
1
32
Constraints
The constraints of all the test cases are outlined below.
Test Case | Constraints |
---|---|
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 |
Problem translated to English by .
Comments