stores number of ones at odd and even position respectively
one_odd = 0 NEW_LINE one_even = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( s [ i ] == '1' ) : NEW_LINE INDENT if ( i % 2 ) : NEW_LINE INDENT one_odd += 1 NEW_LINE DEDENT else : NEW_LINE INDENT one_even += 1 NEW_LINE DEDENT DEDENT DEDENT return min ( N // 2 - one_odd , N // 2 - one_even ) NEW_LINE