Problem:
Score : 300 points

Problem Statement

Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:

For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.

There is a string s consisting of lowercase English letters.
Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same.
Find the minimum necessary number of operations.

Constraints

1 ≤ |s| ≤ 100

s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

s

Output

Print the minimum necessary number of operations to achieve the objective.

Sample Input 1

serval

Sample Output 1

3

One solution is: serval → srvvl → svvv → vvv.

Sample Input 2

jackal

Sample Output 2

2

One solution is: jackal → aacaa → aaaa.

Sample Input 3

zzz

Sample Output 3

0

All the characters in s are the same from the beginning.

Sample Input 4

whbrjpjyhsrywlqjxdbrbaomnw

Sample Output 4

8

In 8 operations, he can change s to rrrrrrrrrrrrrrrrrr.

Solution in Scala (2.11.7) (judge verdict: Wrong Answer)

object Main extends App {
	val S = scala.io.StdIn.readLine

	var a = new Array[Int](26)

	def test1(x: List[Char]): Unit = {
		x match {
			case t::rest => {
				a(t.toInt - 97) = a(t.toInt - 97) + 1
				test1(rest)
			}
			case Nil => 
		}
	}

	def test2: Boolean = {
		var temp = 0
		for(i <- 0 to 25){
			if(a(i) != 0) temp = temp + 1
		}

		if(temp == 1){
			return true;
		}else{
			return false;
		}
	}

	def init() = for(i<-0 to 25) a(i) = 0



	var i = 0
	init()
	var read = S.toList
	test1(read)

	while(! test2){
		val size = read.size - 1
		var write: List[Char] = List()

		if(a.max == 1){
			for(j <- 0 until size){
				if(read(j).toInt < read(j+1).toInt){
					write = write :+ read(j+1)
				}else{
					write = write :+ read(j)
				}
			}

		}else{

			for(j <- 0 until size){
				if(a(read(j).toInt - 97) < a(read(j+1).toInt - 97)){
					write = write :+ read(j+1)
				}else if(a(read(j).toInt - 97) > a(read(j+1).toInt - 97)){
					write = write :+ read(j)
				}else{
					if(read(j).toInt <= read(j+1).toInt){
					write = write :+ read(j+1)
					}else{
						write = write :+ read(j)
					}
				}
			}
		}

		read = write
		i = i + 1
		init()
		test1(read)
	}

	println(i)



}