Template

No attempts yetTime limit3sMemory limit128 MB

Problem

Byteasar wants to paint a rather long pattern on the wall of his house. To do this he first prepares a suitable template with some letters cut out of it. He paints the pattern by placing the template at a chosen spot on the wall and painting over it: this way he "prints" all the letters on the template at once (it is not possible to print only some of them). A wall cell may be painted several times by different placements of the template, so the template may be stamped at many overlapping positions. The letters on the template are adjacent (there are no gaps between them).

Of course he could make a single template holding the whole pattern, but Byteasar wants to keep the cost down, so he wants the template to be as short as possible.

Write a program that:

  • reads the pattern Byteasar wants to paint on his wall from standard input,
  • determines the minimal length of a template needed to produce it,
  • writes the result to standard output.

Formally, given a string SS, find the smallest length T|T| of a string TT such that copies of TT can be stamped at several positions of SS to reproduce SS exactly, where:

  • every stamp lies entirely within SS and its letters match the corresponding letters of SS (so every stamped position is an occurrence of TT in SS), and
  • the stamps may overlap, but together they must cover every position of SS.

Input

The first and only line of standard input contains one word: the pattern Byteasar wants painted on his wall. It consists only of lower-case letters of the English alphabet, and its length is between 1 and 500,000 inclusive.

Output

The first and only line of standard output should contain a single integer: the minimal number of letters in the template (its minimal length).

Hint