#BS0000012. Giúp Fill Bates (Helping Fill Bates)
Giúp Fill Bates (Helping Fill Bates)
Helping Fill Bates
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a string containing only A..Z and a..z. Its characters are indexed from .
For each query string , determine whether is a subsequence of . Equivalently, there must exist indices
such that for every . If a match exists, print the first and last selected positions for the match with the smallest starting position; break any remaining tie by the smallest ending position.
Input
The first line contains .
The second line contains .
The next lines contain query strings.
Output
For each query, print Matched l r if it can be matched; otherwise print Not matched.
Subtasks
- Subtask 1 — 20%: , .
- Subtask 2 — 30%: , .
- Subtask 3 — 50%: , , .
Examples
Input
aaaaaaaaaaaaaabbbbbbbbbdddddddddddccccccccccccc
3
aaaaaaaaaaaaaaaaaaa
aaaaaaaaaaabbbbbbbbbbbc
abccc
Output
Not matched
Not matched
Matched 0 36
Explanation
For abccc, one valid matching starts at position and ends at position ; this pair also satisfies the required tie-breaking rule.