QOJ.ac

QOJ

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

#21648. Runs

Statistics

A run in a string $S$ is defined as a periodic substring that cannot be extended to the left or right, and whose period appears at least twice.

Formally, a run is a triple $(i, j, p)$ such that $p$ is the smallest period of $S[i..j]$, $j-i+1 \ge 2p$, and the following two conditions are satisfied:

  • Either $i=1$, or $S[i-1] \ne S[i-1+p]$;
  • Either $j=n$, or $S[j+1] \ne S[j+1-p]$.

Given a string $S$, find all its runs.

Input

A single line containing the string $S$, which is guaranteed to consist only of lowercase letters.

Output

The first line contains an integer $m$, representing the number of runs.

The next $m$ lines each contain three integers $i, j, p$ describing a run.

You should sort all runs primarily by the starting position $i$ and secondarily by the ending position $j$.

Examples

Input 1

aababaababb

Output 1

7
1 2 1
1 10 5
2 6 2
4 9 3
6 7 1
7 10 2
10 11 1

Subtasks

For $60\%$ of the data, $|S| \le 2 \times 10^5$.

For $100\%$ of the data, $|S| \le 10^6$.

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.