cswork / OAOpen practice workspace

IBMOA #18

Get Min Move

Estimated MediumJudge-ready

Topics (AI-labelled)HashingGreedy

In one operation you choose a character and delete the nearest identical character to its left and the nearest identical character to its right; if one side has none, delete only on the other side. The chosen character itself stays. Find the minimum number of operations needed to reach the shortest possible string.

Input

One line containing a non-empty lowercase string of length 1..100000.

Output

Output one integer, the answer.

Example 1

Input:

adabacaea

Output:

2

Example 2

Input:

aaaa

Output:

2

Example 3

Input:

abc

Output:

0

Example notes

The examples give 2, 2 and 0 respectively. The original example mixes up indices 8/4; choosing original index 4 deletes 2 and 6 and gives adbacea.

Editorial

Loading solution…