Substring

Time Limit: 1000ms
Memory Limit: 65536KB
This problem will be judged on HDU. Original ID: 5769
64-bit integer IO format: %I64d      Java class name: Main

Description

?? is practicing his program skill, and now he is given a string, he has to calculate the total number of its distinct substrings.
But ?? thinks that is too easy, he wants to make this problem more interesting.
?? likes a character X very much, so he wants to know the number of distinct substrings which contains at least one X.
However, ?? is unable to solve it, please help him.

Input

The first line of the input gives the number of test cases T;T test cases follow.
Each test case is consist of 2 lines:
First line is a character X, and second line is a string S.
X is a lowercase letter, and S contains lowercase letters(‘a’-‘z’) only.

T<=30
1<=|S|<=10^5
The sum of |S| in all the test cases is no more than 700,000.

Output

For each test case, output one line containing “Case #x: y”(without quotes), where x is the test case number(starting from 1) and y is the answer you get for that case.

Sample Input

2 
a 
abc 
b 
bbb

Sample Output

Case #1: 3 
Case #2: 3

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .