#C4635. Minimum Operations to Create a Valid String

    ID: 48195 Type: Default 1000ms 256MiB

Minimum Operations to Create a Valid String

Minimum Operations to Create a Valid String

You are given a string s consisting only of digits. Your task is to determine the minimum number of operations required to transform s into a valid string in which no two consecutive characters are identical. In one operation, you can change any single digit to any other digit.

More formally, for a given string \( s \) of length \( n \), you need to compute the minimal number \( k \) such that by performing \( k \) operations, the resulting string \( s' \) satisfies:

[ \forall i \in {1,2,\dots,n-1},\quad s'i \neq s'{i+1} ]

For example, if \( s = \texttt{1221} \), one optimal solution is to change the second '2' to '3', resulting in \( s' = \texttt{1231} \), which is valid. Therefore, the answer is 1.

inputFormat

The input consists of a single line containing a non-empty string composed only of digits.

Constraints:

  • The length of the string is at least 1 and can be up to \(10^5\) characters.

outputFormat

Output a single integer, the minimum number of operations required to ensure that no two adjacent characters in the string are the same.

## sample
1234567890
0