Mock CCC '22 2 S3 - Kaguya Wants to Analyze the Academy Anthem

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 5.0s
Memory limit: 1G

Problem type

Kaguya has heard that Miyuki has trouble singing the academy anthem. Upon deeper inspection, Kaguya suspects that the academy anthem has certain substrings that trip Miyuki up.

Given the academy anthem s and several query pairs (ti,ki), compute the kth 1-indexed position where the substring t appears in s.

Constraints

1ki|s|2105

1Q2105

|ti|2105

All strings only contain lowercase letters.

There are no subtasks in this problem. Each correct test case will award marks.

Input Specification

The first line contains the string s.

The next line contains an integer Q.

Each of the next Q lines contains a string ti and an integer ki, representing a query for the kth occurrence of t in s.

Output Specification

Output Q lines, the ith line containing the position of the kith occurrence of ti in s, or -1 if there are fewer than ki occurrences.

Sample Input 1

Copy
abacabadabacaba
4
a 7
e 3
bac 2
abada 1

Sample Output 1

Copy
13
-1
10
5

Comments

There are no comments at the moment.