포럼
문제 COCI00314

Piramida

설명

Zoran and Tomislav don't really have anything important to do, so they spend their days doing various activities. Today, they built a pyramid of the height \(N\) in the back garden and wrote their favorite word on it, repeating it from line to line and changing direction, as shown in the picture.

 J
N A

J E T
J A N I
A N J E T
N A J A N I
Pyramid of the height 6 marked with the word JANJETINA

Tomislav has now chosen \(K\) lines of the pyramid, marked with \(a_i\), and has chosen a letter \(c_i\) for each line. Then he asked Zoran \(K\) tricky questions: "How many times does the letter \(c_i\) appear in the row \(a_i\)?"

You are Zoran's counselor. Write a programme that will, for the given pyramid height and their favorite word, answer Tomislav's questions.

제약

In test cases worth 50% of total points, \(N\) will not exceed \(1\,000\).
In test cases worth 70% of total points, length of the string will not exceed \(10^5\).

입력 형식

The first line of input contains the integer \(N\) \((1 \le N \le 10^{18})\).

The second line of input contains a word that consists of only uppercase letters of the English alphabet. The word's length will not exceed \(10^6\).

The third line of input contains the integer \(K\) \((1 \le K \le 50\,000)\), the number of lines Tomislav has chosen.

Each of the following \(K\) lines contains the pair \(a_i\), \(c_i\) (\(1 \le a_i \le N\), \(c_i\) uppercase letter of the English alphabet) which represent Tomislav's questions.

출력 형식

Output \(K\) lines. The \(i^{th}\) line of output must contain a single integer – the number of appearances of letter \(c_i\) in the row \(a_i\).

예제 1
입력
6
JANJETINA
5
1 J
1 A
6 N
6 I
5 E
출력
1
0
2
1
1
예제 2
입력
5
A
5
1 A
2 A
3 A
4 A
5 B
출력
1
2
3
4
0
예제 3
입력
3
AB
3
2 A
2 B
3 B
출력
1
1
2
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2014/2015 Contest 1

평가 및 의견

Piramida

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Piramida

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8