Problem:


Score : 300 points

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Sample Input 1

000

Sample Output 1

1

The condition can be satisfied by repainting the middle tile white.

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

Solution code:
S = input()
s01 = 0
s10 = 1
c01 = 0
c10 = 0

for s in S:
    if s01 != int(s):
        c01 += 1
    if s10 != int(s):
        c10 += 1
    s01 = (s01 + 1) % 2
    s10 = (s10 + 1) % 2

print(min(c01, c10))

Submission status: Accepted

Solution code:
S = str(input())
N = len(S)
ans = 0
count = 0
S = list(S)#pythonではlistに渡すと文字列を分割できる

odd = [0]*N
for i in range(N//2):
  odd[2*i+1] = 1
  
even = [0]*N
for i in range((N+1)//2):
  even[2*i] = 1

for i in range(N):
  if int(odd[i]) != int(S[i]):
    count += 1

ans = count
count = 0

for i in range(N):
  if int(even[i]) != int(S[i]):
    count += 1
ans = min(ans,count)   

print(ans)

Submission status: Accepted

Solution code:
S = input()

length = len(S)
pattern1 = ""
for i in range(length):
    pattern1 += "0" if i % 2 == 0 else "1"
# print(pattern1)

count1 = 0
count2 = 0

for i in range(length):
    if pattern1[i] == S[i]:
        count2 += 1
    else:
        count1 += 1

print(min(count1, count2))

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    s = list(sys.stdin.readline().rstrip())
    ans = 0
    for i in range(len(s)):
        if i%2 == 0 and s[i] == "0":
            ans +=1
        elif i%2 == 1 and s[i] == "1":
            ans +=1
    
    ans2 = 0
    for i in range(len(s)):
        if i%2 ==0 and s[i] == "1":
            ans2 +=1
        elif i%2 ==1 and s[i] == "0":
            ans2 +=1
    print(min(ans,ans2))

Submission status: Accepted

Solution code:
Narray = [n for n in str(input())]

counter = 0
if len(Narray) > 1:
    for n in range(1,len(Narray)):
        if Narray[n] == Narray[n-1]:
            counter+=1
            if  Narray[n] == '1':
                Narray[n] = '0'
            else:
                Narray[n] = '1'

print(counter)

Submission status: Accepted

Solution code:
s = input()
_s = int(s, 2)
n = len(s)

mask_1 = int(('01' * (n//2+1))[:n], 2)
mask_2 = int(('10' * (n//2+1))[:n], 2)

ans = min(bin(_s ^ mask_1).count('1'), bin(_s ^ mask_2).count('1'))

print(ans)

Submission status: Accepted

Solution code:
N = list(map(int,input()))

count = 0
for i in range(-(-(len(N))//2)):
	if N[2*i] == 1:
		count += 1

for i in range(len(N)//2):
	if N[2*i+1] == 0:
		count += 1

print(min(count,len(N)-count))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
ans=0
for i in range(1,n):
  if s[i] == s[i-1]:
    if s[i] == "0":
      s[i] = "1"
    elif s[i] == "1":
      s[i] = "0"
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
Ss = input()

c1 = 0
c2 = 0
for i in range(0, len(Ss)):
    if i & 1:
        if Ss[i] == '0':
            c1 += 1
        else:
            c2 += 1
    else:
        if Ss[i] == '1':
            c1 += 1
        else:
            c2 += 1
print(min([c1, c2]))

Submission status: Accepted

Solution code:
#ABC124 C
S = input()
ans = 10000000000000
gl = ["",""]
for i in range(2):
    for j in range(len(S)):
        if j % 2 == i:
            gl[i] += "0"
        else:
             gl[i] += "1"

for i in range(2):
    tmp = 0
    for j in range(len(S)):
        if S[j] != gl[i][j]:
            tmp += 1
    ans = min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
a = input()
a = [bool(int(a[i])) for i in range(len(a))]
b = True
c = 0
d = 0
for i in range(len(a)):
    if b is a[i]:
        c += 1
    if b is not a[i]:
        d += 1
    b = not b
print(min(c, d))

Submission status: Accepted

Solution code:
color = str(input())

ans1 = 0
ans2 = 0

for i in range(len(color)):
    if (i%2==0 and color[i:i+1]=='0') or (i%2==1 and color[i:i+1]=='1'):
        ans1+=1
    else:
        ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
#124

S = str(input())

N = len(S)
count_tmp1 = 0
count_tmp2 = 0

#101010...
for j in range(0,N):
    if j % 2 == 0 and S[j] == '0':
        count_tmp1 += 1
    elif j % 2 == 1 and S[j] == '1':
        count_tmp1 += 1

#0101010...
for j in range(0,N):
    if j % 2 == 0 and S[j] == '1':
        count_tmp2 += 1
    elif j % 2 == 1 and S[j] == '0':
        count_tmp2 += 1

if count_tmp1 >= count_tmp2:
    print(count_tmp2)

else:
    print(count_tmp1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC124 C

s = list(map(int,list(input())))
n = len(s)
ans1 = 0
ans2 = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] != 1:
            ans1 += 1
    else:
        if s[i] != 0:
            ans1 += 1
for i in range(n):
    if i % 2 == 0:
        if s[i] != 0:
            ans2 += 1
    else:
        if s[i] != 1:
            ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
zero = ""
one = ""
for i in range(n):
  if i%2 == 0:
    zero += "0"
    one += "1"
  else:
    zero += "1"
    one += "0"
z = 0
o = 0
for i in range(n):
  tmp = s[i]
  if tmp != zero[i]:
    z += 1
  if tmp != one[i]:
    o += 1
if z < o:
  print(z)
else:
  print(o)

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
n = len(s)
s1 = [abs(s[i]-i%2) for i in range(n)]
s2 = [abs(s[i]-(i+1)%2) for i in range(n)]
print(min(sum(s1),sum(s2)))

Submission status: Accepted

Solution code:
s = input()
n = len(s)

end = ""

for i in range(n):
    if i % 2 == 0:
        end += "0"
    else:
        end += "1"

cnt = 0

for i in range(n):
    if s[i] == end[i]:
        cnt += 1

print(min(cnt, n-cnt))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S=input()
N=len(S)
count1=0
count2=0
for i in range(N):
    if i%2==0:
        if S[i]=="1":
            count1=count1+1
    else:
        if S[i]=="0":
            count1=count1+1

for i in range(N):
    if i%2==0:
        if S[i]=="0":
            count2=count2+1
    else:
        if S[i]=="1":
            count2=count2+1
            
print(min(count1,count2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = [int(i) for i in input()]

    ans = list()
    ans.append([i % 2 for i in range(len(n))])
    ans.append([i % 2 for i in range(1, len(n) + 1)])

    a = list()
    for i in ans:
        count = 0
        for j in range(len(n)):
            if i[j] == n[j]:
                count += 1

        a.append(count)

    print(min(a))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
elements = ["0", "1"]
black_start = [elements[x % 2] for x in range(len(s))]
white_start = [elements[(x+1) % 2] for x in range(len(s))]

ans_white = 0
ans_black = 0
for i in range(len(s)):
    if black_start[i] != s[i]:
        ans_black += 1
    if white_start[i] != s[i]:
        ans_white += 1
print(min(ans_black, ans_white))

Submission status: Accepted

Solution code:
s = list(map(int, input()))
sod = [s[i] for i in range(len(s)) if i % 2 == 0]
sev = [s[i] for i in range(len(s)) if i % 2 == 1]
sodb = sod.count(0)
sodw = sod.count(1)
sevb = sev.count(0)
sevw = sev.count(1)
print(min([sodb+sevw, sodw+sevb]))

Submission status: Accepted

Solution code:
s = input()

oddFirst = 0
evenFirst = 0

for i in range(len(s)):
    if i % 2 == 0:
        if int(s[i]) % 2 == 0:
            oddFirst += 1
        else:
            evenFirst += 1
    else:
        if int(s[i]) % 2 == 0:
            evenFirst += 1
        else:
            oddFirst += 1

print(min(oddFirst, evenFirst))

Submission status: Accepted

Solution code:
s = input()

li = ["0" if i % 2 == 0 else "1" for i in range(len(s))]


count1 = 0
count2 = 0
ans = 0
for i in range(len(s)):
    if s[i] == li[i]:
        count1 += 1
    else:
        count2+= 1

print(min(count1, count2))

Submission status: Accepted

Solution code:
s = input()
s_odd = s[0::2]
s_even = s[1::2]
ans = min(s_odd.count("0")+s_even.count("1"),s_odd.count("1")+s_even.count("0"))
print(ans)

Submission status: Accepted

Solution code:
s =input()

ol=[]
lo=[]
for i in range(len(s)):
  if i%2==0:
    ol.append('0')
    lo.append('1')
  else:
    ol.append('1')
    lo.append('0')

dif_ol=0
dif_lo=0
for i in range(len(s)):
  if ol[i]!=s[i]:
    dif_ol+=1
  if lo[i]!=s[i]:
    dif_lo+=1

print(min(dif_ol,dif_lo))

Submission status: Accepted

Solution code:
S = input()
len_S = len(S)
n = len_S // 2
A = "01" * n
if len_S % 2 == 1:
    A += "0"
an, bn = 0, 0
for s, a in zip(S, A):
    if s == a:
        bn += 1
    else:
        an += 1
print(min(an, bn))

Submission status: Accepted

Solution code:
S = input()
len_S = len(S)
n = len_S // 2
A = "01" * n
B = "10" * n
if len_S % 2 == 1:
    A += "0"
    B += "1"
an, bn = 0, 0
for s, a, b in zip(S, A, B):
    if s == a:
        bn += 1
    else:
        an += 1
print(min(an, bn))

Submission status: Accepted

Solution code:
s=list(input())
count1=0
count2=0
for i in range(0,len(s),2):
    if s[i]==str(0):
        count1+=1
    if s[i]==str(1):
        count2+=1
for i in range(1,len(s),2):
    if s[i]==str(1):
        count1+=1
    if s[i]==str(0):
        count2+=1
print(min(count1,count2))

Submission status: Accepted

Solution code:
inf = float('inf')

s = input()

ans = inf
for start_color in '01':
    cost = 0
    for i, ss in enumerate(s):
        if i % 2 == 0:
            if ss != start_color:
                cost += 1
        else:
            if ss == start_color:
                cost += 1
    ans = min(ans, cost)
print(ans)

Submission status: Accepted

Solution code:
moji_arr = input()

change=0
now_moji = moji_arr[0]

for v in moji_arr[1:]:
    if v==now_moji:
        change += 1
        if v=='0':
            now_moji = '1'
        elif v=='1':
            now_moji = '0'
    else:
        now_moji = v

print(change)

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def change_color(t):
    if t == '0':
        return '1'
    return '0'


def solve(inputs):
    tiles = list(inputs[0])
    tiles = [x == "1" for x in tiles]

    diff_num_1 = 0
    diff_num_2 = 0
    state_1 = True
    state_2 = False

    for t in tiles:
        if t != state_1:
            diff_num_1 += 1
        if t != state_2:
            diff_num_2 += 1

        state_1 = not state_1
        state_2 = not state_2
    return min(diff_num_1, diff_num_2)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
def main():
    S = input()

    odd_tile_dict = {"0": 0, "1": 0}
    even_tile_dict = {"0": 0, "1": 0}
    for s in S[1::2]:
        odd_tile_dict[s] += 1

    for s in S[::2]:
        even_tile_dict[s] += 1

    res = min(odd_tile_dict["0"] + even_tile_dict["1"], odd_tile_dict["1"] + even_tile_dict["0"])
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(map(int, input()))
a = 0
b = 0
for i, v in enumerate(s):
    a += v ^ (i & 1)
    b += v ^ ((i + 1) & 1)

print(min(a, b))

Submission status: Accepted

Solution code:
s = list(map(int, input()))
a = 0
b = 0
for i in range(len(s)):
    a += s[i] ^ (i % 2)
    b += s[i] ^ ((i + 1) % 2)

print(min(a, b))

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))

last = S[0]
n_change = 0
for idx, current in enumerate(S):
    if idx == 0:
        continue
    if current == last:
        current = 0 if current == 1 else 1
        S[idx] = current
        n_change += 1
    last = current

print(n_change)

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y:
		return x
	return y

S = input()
dp0 = []
dp1 = []
if S[0] == '0':
	dp0.append(0)
	dp1.append(1)
else:
	dp0.append(1)
	dp1.append(0)
for i in range(1, len(S)):
	newdp0 = dp1[-1]
	newdp1 = dp0[-1] + 1
	if S[i] == '1':
		newdp0 = dp1[-1] + 1
		newdp1 = dp0[-1]
	dp0.append(newdp0)
	dp1.append(newdp1)
print(smaller(dp0[-1], dp1[-1]))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = list(input())
s_len = len(s)
ctr = 0

for i in range(s_len - 1):
    if s[i] == s[i + 1]:
        if s[i] == '0':
            s[i + 1] = '1'
        else:
            s[i + 1] = '0'
        ctr += 1
print(ctr)

Submission status: Accepted

Solution code:
s = input()
ans = 0
if len(s) > 1:
    k = s[1]
    if s[0] == '0' and s[1] == '0':
        k ='1'
    elif s[0] == '1' and s[1] == '1':
        k = '0'
for i in range(1,len(s)):
    if i%2 == 0 and s[i] != s[0]:
        ans+=1
    elif i%2 != 0 and s[i] != k:
        ans+=1

print (ans)

Submission status: Accepted

Solution code:
s = list(input())
even = s[1::2]
odd = s[::2]
a = even.count('0')
b = even.count('1')
c = odd.count('0')
d = odd.count('1')
if a+d <= b+c:
	print(a+d)
else:
	print(b+c)

Submission status: Accepted

Solution code:
count1 = 0
count2 = 0
num = input()
le = len(num)

for n in range(le):
    if n%2 == 0:
        if num[n] == "0":
            count1 += 1
    else:
        if num[n] == "1":
            count1 += 1
for n in range(le):
    if n%2 == 0:
        if num[n] == "1":
            count2 += 1
    else:
        if num[n] == "0":
            count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
S = input()

len_s = len(S)
if len_s == 1:
  print(0)
else:
  temp = len_s//2

  a = '10' * (temp)
  b = '01' * (temp)

  if len_s%2 != 0:
    a = a + '1'
    b = b + '0'

  cnt_a = 0
  cnt_b = 0
  for i in range(len_s):
    if a[i] != S[i]:
      cnt_a += 1
    if b[i] != S[i]:
      cnt_b += 1
  print(min(cnt_a, cnt_b))

Submission status: Accepted

Solution code:
s = input()
l = len(s)
left = ""
right = ""
l_ans = 0
r_ans = 0
if l % 2 == 0:
    left = "10" * (l // 2)
    right = "01" * (l // 2)
else:
    left = "10" * (l // 2) + "1"
    right = "01" * (l // 2) + "0"
for i in range(l):
        if s[i] != left[i]:
            l_ans += 1
        if s[i] != right[i]:
            r_ans += 1
print(min(l_ans, r_ans))

Submission status: Accepted

Solution code:
s=input()
count1=0
count2=0
for i,j in enumerate(s):
    if i%2==0:
        if j=='0':
            count1+=1
    else:
        if j=='1':
            count1+=1
    
for i,j in enumerate(s):
    if i%2==0:
        if j=='1':
            count2+=1
    else:
        if j=='0':
            count2+=1
print(min(count1,count2))

Submission status: Accepted

Solution code:
S = input()


def solve(color):
    ret = 0

    for s in S:
        if s != color:
            ret += 1
        color = '0' if color == '1' else '1'

    return ret


print(min(solve('0'), solve('1')))

Submission status: Accepted

Solution code:
s=list(input())
s1=[]
s2=[]

for i in range(len(s)):
    if i%2==0:
        s1.append('0')
        s2.append('1')
    else:
        s1.append('1')
        s2.append('0')
    
count1=0
count2=0
for i in range(len(s)):
    if s[i]!=s1[i]:
        count1+=1
    if s[i]!=s2[i]:
        count2+=1
        
print(min(count1,count2))

Submission status: Accepted

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    S = i2s()
    a = 0
    b = 0
    t = ['0', '1']
    for i, s in enumerate(S):
        if s == t[i & 1]:
            a += 1
        else:
            b += 1
    n = min(a, b)
    print(n)

main()

Submission status: Accepted

Solution code:


s = input()
ls = len(s)
zero_one = "01" * (ls//2) + "0" * (ls%2)
one_zero = "10" * (ls//2) + "1" * (ls%2)


a, b = 0, 0
for i in range(ls):
    if s[i] != zero_one[i]:
        a += 1
    if s[i] != one_zero[i]:
        b += 1

print(min(a,b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

S = list(map(int, list(input())))

length = len(S)
diff = [abs(s - i % 2) for (i, s) in enumerate(S)]
diff_sum = sum(diff)
ans = min(diff_sum, length - diff_sum)

print(ans)

Submission status: Accepted

Solution code:
# using main() makes code faster from the point of view of "access to variables in global name-space"
# def main():

""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""

import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    # TODO: How should I do when n - r is negative?
    if n < 0 or r < 0:
        raise Exception('combinations_count(n, r) not defined when n or r is negative')
    if n - r < r: r = n - r
    if r < 0: return 0
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combinations_with_replacement_count(n, r):
    """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
    
    Args:
        n (long): number
        r (long): number
    
    Raises:
        Exception: not defined when n or r is negative
    
    Returns:
        long: number
    """
    if n < 0 or r < 0:
        raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
    elif n == 0:
        return 1
    else:
        return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from operator import itemgetter
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce
def chmin(x, y):
    """change minimum
    if x > y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current minimum value
        y (long): potential minimum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x > y:
        x = y
        return (x, True)
    else:
        return (x, False)
def chmax(x, y):
    """change maximum
    if x < y, x = y and return (x, True).
    convenient when solving problems of dp[i]
    
    Args:
        x (long): current maximum value
        y (long): potential maximum value
    
    Returns:
        (x, bool): (x, True) when updated, else (x, False)
    """
    if x < y:
        x = y
        return (x, True)
    else:
        return (x, False)

from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)

# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
    # evaluate reciprocal using Fermat's little theorem:
    # a**(p-1) is identical to 1 (mod p) when a and p is coprime
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    # fac_list = modfactorial_list(100)
    # print(modcomb(100, 5, modfactorial_list(100)))
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))

""" initialize variables and set inputs
# initialize variables
    # to initialize list, use [0] * n
    # to initialize two dimentional array, use [[0] * N for _ in range(N)]
# set inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
# preprocessing
    # transpose = [x for x in zip(*data)]
    # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
    # flat = [flatten for inner in data for flatten in inner]
    # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
    # output pattern
    # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""

# functions used
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
R = lambda: list(map(int, r().split()))
Rfloat = lambda: list(map(float, r().split()))
Rtuple = lambda: tuple(map(int, r().split()))
Rmap = lambda: map(int, r().split())

""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""


# ----------------------------------
# main
S = r()
count = 0
if len(S) == 1:
    print(0)
    exit()
for i in S[::2]:
    if i == "0":
        count += 1
for i in S[1::2]:
    if i == "1":
        count += 1
print(min(count, len(S)-count))
# end of main
# ----------------------------------

"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append / extend
Dic[x].append(y)
# for
for k, v in Dic.items():
"""

# if __name__ == '__main__':
#     main()

Submission status: Accepted

Solution code:
S = input()
A = [int(S[i]) for i in range(len(S))]
X = [0]
Y = [1]
for i in range(len(S)-1):
  if X[i] == 0:
    X.append(1)
  elif X[i] == 1:
    X.append(0)
for i in range(len(S)-1):
  if Y[i] == 0:
    Y.append(1)
  elif Y[i] == 1:
    Y.append(0)
B = 0
C = 0
for k in range(len(S)):
  if A[k] == X[k]:
    B += 0
  else:
    B += 1
for l in range(len(S)):
  if A[l] == Y[l]:
    C += 0
  else:
    C += 1
print(min(B,C))

Submission status: Accepted

Solution code:
def main():
    S = [int(s) for s in input()]

    cnt0 = 0  # starts with 0
    for i, s in enumerate(S):
        if i % 2 != s:
            cnt0 += 1
    print(min(cnt0, len(S)-cnt0))


main()

Submission status: Accepted

Solution code:
s = input()

if len(s) % 2:
  white_black = '10' * (len(s) // 2) + '1'
  black_white = '01' * (len(s) // 2) + '0'
else:
  white_black = '10' * (len(s) // 2)
  black_white = '01' * (len(s) // 2)

if s == white_black or s == black_white:
  count = 0
else:
  diff_wb = sum([len(x) for x, y in zip(s, white_black) if x != y])
  diff_bw = sum([len(x) for x, y in zip(s, black_white) if x != y])
  count = min(diff_wb, diff_bw)

print(count)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s1 = '1'
s0 = '0'
for x in range(n-1):
    if s1[x] == '1':
        s1 = s1 + '0'
        s0 = s0 + '1'
    else:
        s1 = s1 +'1'
        s0 = s0 +'0'
s11  =0
s00 = 0
for a in range(n):
    if s1[a] != s[a]:
        s11 += 1
    else:
        s00 += 1
print(min(s11,s00))

Submission status: Accepted

Solution code:
s = input()

ans1 = 0
ans2 = 0
for i,j in enumerate(s):
    if i % 2 == 0 and j == '0':
        ans1 += 1
    if i % 2 == 1 and j == '1':
        ans1 += 1
    if i % 2 == 0 and j == '1':
        ans2 += 1
    if i % 2 == 1 and j == '0':
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
a = input()
b = [bool(int(a[i])) for i in range(len(a))]
b.insert(0, True)
c = [bool(int(a[i])) for i in range(len(a))]
c.insert(0, False)
bc = 0
cc = 0

for i in range(1, len(b)):
    if b[i-1] == b[i]:
        b[i] = not b[i-1]
        bc += 1
    if c[i-1] == c[i]:
        c[i] = not c[i - 1]
        cc += 1

print(min(bc, cc))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=0
for i in range(n):
  m=i%2
  if s[i]==str(m):
    ans+=1
print(min(ans,n-ans))

Submission status: Accepted

Solution code:
import numpy as np
s = list(map(int, list(str(input()))))
s = np.array(s)

s1 = np.array([0 if i%2 == 0 else 1 for i in range(len(s))])
s2 =np.array([0 if i%2 == 1 else 1 for i in range(len(s))])

print(min(np.sum(np.abs(s-s1)), np.sum(np.abs(s-s2))))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
data = []
for i in range(n):
    data.append(int(s[i]))
for  i in range(n -1):
    if data[i] == data[i + 1]:
        data[i + 1] = (data[i + 1] + 1) % 2
        count += 1
print(count)

Submission status: Accepted

Solution code:
S = input()

# 最初が0のパターン
count = 0
for i in range(0, len(S), 2):
    if S[i] != "0":
        count += 1
for i in range(1, len(S), 2):
    if S[i] != "1":
        count += 1
ans = count
# 最初が1のパターン
count = 0
for i in range(0, len(S), 2):
    if S[i] != "1":
        count += 1
for i in range(1, len(S), 2):
    if S[i] != "0":
        count += 1
ans = min(ans, count)
print(ans)

Submission status: Accepted

Solution code:
S=input()

n1=0
istr=1
for i,s in enumerate(S):
    if i%2==0:
        if int(s)!= istr:
            n1+=1
    else:
        if int(s) == istr:
            n1+=1


n2=0
istr=0
for i,s in enumerate(S):
    if i%2==0:
        if int(s)!= istr:
            n2+=1
    else:
        if int(s) == istr:
            n2+=1

print(min(n1,n2))

Submission status: Accepted

Solution code:
s = list(input())

count1  = 0
count2 = 0

for i in range(len(s)):
    if i % 2 == 0 and s[i] == '1':
        count1 += 1
    elif i % 2 and s[i] == '0':
        count1 += 1

    if i % 2 == 0 and s[i] == '0':
        count2 += 1
    elif i % 2 and s[i] == '1':
        count2 += 1

print(min(count1, count2))

Submission status: Accepted

Solution code:
S = list(input())

n_operation = 0
for i, s_val in enumerate(S):
    if i == 0:
        continue
    last_val = S[i-1]
    if s_val == last_val:
        if s_val == '0':
            S[i] = '1'
        else:
            S[i] = '0'
        n_operation += 1

print(n_operation)

Submission status: Accepted

Solution code:
#塗り方としては"0101..."か"1010..."の2種類しかない。２つとの差分を求めて少ない方を出力すればok
S = input()
N = len(S)
cost1 = 0
cost2 = 0
for i in range(N):
    if i % 2 == 0:
        if S[i] == "0":
            cost1 += 1
        else:
            cost2 += 1
    else:
        if S[i] == "1":
            cost1 += 1
        else:
            cost2 += 1

if cost1 < cost2:
    print(cost1)
else:
    print(cost2)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
cost1 = 0
cost2 = 0
for i in range(N):
    if i % 2 == 0:
        if S[i] == "0":
            cost1 += 1
        else:
            cost2 += 1
    else:
        if S[i] == "1":
            cost1 += 1
        else:
            cost2 += 1

if cost1 < cost2:
    print(cost1)
else:
    print(cost2)

Submission status: Accepted

Solution code:
S = input()

a = "01"*(10**5)
b = "10"*(10**5)
acnt = 0
bcnt = 0
for i in range(len(S)):
  if a[i] != S[i]:
    acnt += 1
  if b[i] != S[i]:
    bcnt += 1
print(min(acnt, bcnt))

Submission status: Accepted

Solution code:
s = raw_input()
diff01 = 0
diff10 = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '1':
            diff01 += 1
        else:
            diff10 += 1
    else:
        if s[i] == "1":
            diff10 += 1
        else:
            diff01 += 1
print min(diff10, diff01)

Submission status: Accepted

Solution code:
s=input()
s_len = len(s)
l = '01' * (s_len//2) + '0' * (s_len%2)
s,l=int(s,2),int(l,2)
c= sum(list(map(int,format(s^l,'0b'))))
print(min(c,s_len-c))