#P6416. [COCI 2014/2015 #1] PIRAMIDA
[COCI 2014/2015 #1] PIRAMIDA
Description
So, they repeatedly write their favorite string JANJETINA on a pyramid from left to right and from top to bottom following a certain pattern.
This is what the pyramid looks like when it has only six layers:

Now they want to test you with a question: given a string and the number of layers of the pyramid, the string is written on the pyramid over and over again. Then there are queries. In the -th query, you are asked how many times the character appears in layer .
Input Format
The first line contains an integer .
The second line contains a string .
The third line contains an integer .
The next lines each contain an integer and a character .
Output Format
For each query, output one line with an integer representing the answer.
6
JANJETINA
5
1 J
1 A
6 N
6 I
5 E
1
0
2
1
1
5
A
5
1 A
2 A
3 A
4 A
5 B
1
2
3
4
0
3
AB
3
2 A
2 B
3 B
1
1
2
Hint
Explanation for Sample Input/Output 1
It corresponds to the example shown in the statement.
Constraints
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that .
- For of the testdata, it is guaranteed that , , , , and all characters in the input are uppercase letters.
Note
The total score for this problem is points.
This problem is translated from Task 3 PIRAMIDA of Croatian Open Competition in Informatics 2014/2015 Contest #1.
Translated by ChatGPT 5
京公网安备 11011102002149号