Ssari and Bird's Pyramid
Time limit1sMemory limit256 MB
Count how many times a given letter appears in a requested pyramid row filled by repeating a word in alternating directions.
- Level
Medium5 of 10
- Topics
- Math, Prefix sum
- Solved
- No attempts yet
Problem
Ssari and Bird had nothing at all to do, so they built a pyramid of height in the back yard and decided to write their favorite word on it. Row from the top has cells.
The word goes in one letter per cell, in a zigzag. Row 1 fills from left to right, row 2 from right to left, row 3 from left to right again, and so on. Once the word is written out, it starts over from its first letter.
For and the word JANJETINA the pyramid comes out like this.
J
N A
J E T
J A N I
A N J E T
N A J A N I
Bird picks a row number and an uppercase letter , then asks "how many times does appear in row ?". Answer Bird's questions and help Ssari out.
Input
The first line contains the height of the pyramid, ().
The second line contains a word made only of uppercase letters. The word is at most letters long.
The third line contains the number of rows Bird picked, ().
Each of the next lines contains and separated by a space (, and is an uppercase letter).
Output
Print lines. Line holds the number of times appears in row of the pyramid.