Polish version    English version  
  History of OI -> XII OI 2004/2005 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
Schedule
Problems
Stage III - results
Stage II - results
Stage I - results
Stage II
Stage III
Regulations
For contestants
Helpful resources
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN

Task: Template


Byteasar wants to put a rather long pattern on his house. In order to do this, he has to prepare an appropriate template with letters cut off first. He is going to put the pattern on the wall by putting the pattern on the wall in the appropriate place and painting over it. This way he can "print" all the letters that are on the template at one time (it is not possible to "print" only some of them). It is, however, possible, to paint some letters on the wall several times, as a result of different applications of the template. The letters on the template are adjacent (there are no spaces on it). Of couse, it is possible to prepare a template with the whole pattern on it. But Bytesar would like to minimize the cost, so he wants to make a template as short as possible.

Task

Write a programme that:

  • reads from the standard input the pattern Byteasar wants to put on his house,
  • determines the minimal length of the template needed to do it,
  • writes the result to the standard output.

Input

In the first and only line of the standard input there is one word. It is the pattern Byteasar wants painted on his house. It consists of no more than 500 000 and no less than 1 lower-case (non-capital) letters of the English alphabet.

Output

In the first and only line of the standard output one integer should be written - the minimal number of letters in the template.

Example

For the following input data:
ababbababbabababbabababbababbaba
the correct answer is:
8



Print friendly version