#dwacon5thprelimsc. [dwacon5th_prelims_c]k-DMC
[dwacon5th_prelims_c]k-DMC
Problem Statement
In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short.
The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string.
Given a string of length and an integer , he defines the -DMC number of as the number of triples of integers that satisfy the following conditions:
- S\[a\] =
D
- S\[b\] =
M
- S\[c\] =
C
Here S\[a\] is the -th character of the string . Indexing is zero-based, that is, holds.
For a string and integers , calculate the -DMC number of for each .
Constraints
- consists of uppercase English letters
- All numbers given in input are integers
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the -DMC number of the string .
Sample Input 1
18
DWANGOMEDIACLUSTER
1
18
Sample Output 1
1
satisfies the conditions.
Strangely, Dwango Media Cluster does not have so much DMC-ness by his definition.
Sample Input 2
18
DDDDDDMMMMMCCCCCCC
1
18
Sample Output 2
210
The number of triples can be calculated as .
Sample Input 3
54
DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED
3
20 30 40
Sample Output 3
0
1
2
satisfy the conditions except the last one, namely, .
By the way, DWANGO is an acronym for "Dial-up Wide Area Network Gaming Operation".
Sample Output 4
30
DMCDMCDMCDMCDMCDMCDMCDMCDMCDMC
4
5 10 15 20
Sample Output 4
10
52
110
140