QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 192 MB Total points: 10

#11184. Quasi-template [A]

الإحصائيات

A template of a word $ v $ is such a word $ s $ that all occurrences of $ s $ within $ v $ cover the whole word $ v $ (i.e. each letter of the word $ v $ appears within some fragment of consecutive letters of $ v $ equal to $ s $). By quasi-template of a word $ v $ we mean such a word $ s $ that $ s $ is a substring (i.e. a fragment of consecutive letters) of $ v $ and $ s $ is a template of some superstring of $ v $. The figure below shows why the word aabaa is a quasi-template of the word aaaabaabaaaba:

aabaa
aabaa
aabaa
aabaa
---------------------
  aaaabaabaaaba

For a given word $ v $ we would like to compute the number of its quasi-templates and the shortest one of them.

Input Format

The only line of the standard input contains a non-empty word $ v $ that is not longer than 200 000 letters. It consists of small letters of English alphabet.

Output Format

The first line of the standard output should contain the number of quasi-templates of word $ v $. The second line should contain the shortest word being a quasi-template of word $ v $. If there is more than one such shortest word, output the lexicographically smallest from the shortest quasi-templates.

Example

Input

aaaabaabaaaba

Output

10
aabaa

Notes

The word from the sample input has 10 quasi-templates: aaaabaabaaab, aaaabaabaaaba, aaabaaba, aaabaabaa, aaabaabaaa, aaabaabaaaba, aabaa, aabaabaa, aabaabaaa, and abaabaaa.

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.