Under construction

Still being built. Things may change

Complexity

Interview

Time limit2sMemory limit256 MB

Summary
You delete the fewest letters so at most two distinct letters remain.
Level

Easy3 of 10

Topics
Hash map, Greedy
Solved
No attempts yet

Problem

The complexity of a string is the number of distinct letters in it. For example, string has complexity 6 and letter has complexity 4.

You like strings whose complexity is 1 or 2. A friend handed you a string and you want to turn it into a string you like. You have a magic eraser that deletes one letter from the string. Compute the minimum number of times you have to use the eraser to make the complexity of the string at most 2.

Input

The first line contains a string made up of lowercase ASCII letters ('a' to 'z'). The length of the string is between 1 and 100.

Output

Print the minimum number of eraser uses on a single line.

Examples7

  1. Example 1

    Input
    string
    
    Expected output
    4
    
  2. Example 2

    Input
    letter
    
    Expected output
    2
    
  3. Example 3

    Input
    aaaaaa
    
    Expected output
    0
    
  4. Example 4

    Input
    uncopyrightable
    
    Expected output
    13
    
  5. Example 5

    Input
    ambidextrously
    
    Expected output
    12
    
  6. Example 6

    Input
    assesses
    
    Expected output
    1
    
  7. Example 7

    Input
    assassins
    
    Expected output
    2