atcoder#AGC016A. [AGC016A] Shrinking

[AGC016A] Shrinking

Score : 300300 points

Problem Statement

Snuke can change a string tt of length NN into a string tt' of length N1N - 1 under the following rule:

  • For each ii (1iN11 \leq i \leq N - 1), the ii-th character of tt' must be either the ii-th or (i+1)(i + 1)-th character of tt.

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

Constraints

  • 1s1001 \leq |s| \leq 100
  • ss consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

ss

Output

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

serval
3

One solution is: servalsrvvlsvvvvvv.

jackal
2

One solution is: jackalaacaaaaaa.

zzz
0

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

whbrjpjyhsrywlqjxdbrbaomnw
8

In 88 operations, he can change ss to rrrrrrrrrrrrrrrrrr.