P15767 [JAG 2025 Summer Camp #2] Broken Keyboard

Description

You have a keyboard with $25$ keys. Initially, key $i$ ($1 \leq i \leq 25$) is mapped to the $i$-th lowercase English letter, i.e., key $1$ to ‘a’, key $2$ to ‘b’, ..., and key $25$ to ‘y’. You also have an empty string $T$. You can perform the following two operations any number of times, in any order: 1. Choose an integer $i$ ($1 \leq i \leq 25$) and a lowercase English letter $c$, and change the mapping of key $i$ to $c$. This operation costs $1$. 2. Choose an integer $i$ ($1 \leq i \leq 25$), and append the letter currently mapped to key $i$ to the end of $T$. This operation costs $0$. You are given a string $S$ consisting of lowercase English letters. Find the minimum total cost required to make $T$ equal to $S$.

Input Format

The input consists of a single test case in the following format. $$S$$ The only line contains a string $S$ consisting of lowercase English letters. The length of $S$ is between $1$ and $500\,000$, inclusive.

Output Format

Print the minimum total cost as an integer.