QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#1001. Sealing

Statistics

Given two strings $s$ and $t$ consisting only of lowercase letters $a$ and $b$, answer $q$ queries. Each query asks for the length of the longest common substring between $s[l \dots r]$ and $t$.

Input

The input consists of $q+3$ lines.

The first line contains a string $s$.

The second line contains a string $t$.

The third line contains an integer $q$.

The next $q$ lines each contain two integers $l_i, r_i$ ($1 \le l_i \le r_i \le |s|$), representing a query.

Output

The output consists of $q$ lines.

The $i$-th line represents the length of the longest common substring between $s[l_i \dots r_i]$ and $t$.

Examples

Input 1

aaba
aaaabbbaa
3
1 4
1 3
2 4

Output 1

3
3
2

Subtasks

Test Case ID $ s , t \le$ $q \le$
$1$ $50$ $50$
$2, 3$ $2 \times 10^3$ $2 \times 10^3$
$4, 5$ $2 \times 10^5$ $10$
$6 \sim 10$ $2 \times 10^5$ $2 \times 10^5$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.