QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#897. Basic Substring Dictionary

统计

For a non-empty string $S$ and $T$, if $T$ is both a prefix and a suffix of $S$, and $|T|<|S|$, then $T$ (or $|T|$) is called a border of $S$.

Given a string $S$ and $q$ queries, each query provides a substring of $S$. For each query, find the length of the shortest border, the length of the longest border, and the total number of borders for that substring.

Input

The first line contains a string $S$. The second line contains an integer $q$. The next $q$ lines each contain two integers $l$ and $r$, representing the query for the substring $S[l \cdots r]$ (0-indexed).

Output

For each query, output a single line. If there are no borders, output -1. Otherwise, output three integers representing the length of the shortest border, the length of the longest border, and the number of borders.

Examples

Input 1

abacaba
2
0 6
1 2

Output 1

1 3 2
-1

Input 2

aaaaaa
1
0 5

Output 2

1 5 5

Subtasks

$1 \le |S|, q \le 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.