#C7756. Minimum Flips to Convert Binary String to Alternating Pattern

    ID: 51662 Type: Default 1000ms 256MiB

Minimum Flips to Convert Binary String to Alternating Pattern

Minimum Flips to Convert Binary String to Alternating Pattern

Given a binary string s consisting of characters '0' and '1', your task is to determine the minimum number of flips needed to transform s into an alternating string.

An alternating string is one in which no two adjacent characters are the same. There are two possible alternating patterns for any given length n:

\( pattern1 = 0101\ldots \) (starting with '0') and \( pattern2 = 1010\ldots \) (starting with '1').

You need to compare the number of mismatches of the given string with both these patterns and output the minimum of these two counts.

The formula can be represented as:

\( result = \min(\text{mismatches with }pattern1,\; \text{mismatches with }pattern2) \)

inputFormat

The input consists of a single line containing the binary string s.

Note: The input is provided via standard input (stdin).

outputFormat

Output an integer representing the minimum number of flips required to transform the binary string into an alternating pattern. The output should be printed to standard output (stdout).

## sample
010101
0