Task Magic (English) : Remarks: A Substring Is A Part of A Given String, Which Contains
Task Magic (English) : Remarks: A Substring Is A Part of A Given String, Which Contains
Task
Write a program magic which counts the number of magical
substrings in a given sequence of N English letters. Substrings which are
the same but on different positions are counted as different
Input
From the first line of the standard input, your program has to read
one integer N – the number of characters in the sequence written by Mr.
Daskalov. From the next line your program has to read a string of N English
letters. The letters can be lower- and uppercase. Note that the lower- and
uppercase forms of the same letter are considered to be different
characters (A and a are different characters).
Output
The program must print to the standard output the number of
magical substrings in the given string. Since this number may be quite
large, you are required to print its remainder when divided by
1 000 000 007.
Constraints
2 ≤ N ≤ 100 000
Subtasks
Subtas
Points N Further constraints
k
1 10 ≤ 100 There are no further constraints.
2 20 ≤ 2000 There are no further constraints.
≤ 100 There are only two kinds of characters in
3 30
000 the given string (K=2).
≤ 100 There are no further constraints.
4 40
000
Examples
Sample Input Sample Explanation
Output
8 4 The magical substrings are
abccbabc abc, cba, abc and abccba.
Note that for example the
substring ab is not magical
because the letter c is
not in it.
7 1 Only the substring abcABC
abcABCC is magical (the letters a and
A are different because a is
a lowercase letter and A is
an uppercase letter).
20 22 The number of magical
SwSSSwwwwSwSwwSww substrings is 22 and one of
wwS them is SwSwwS.