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:
Ss = [int(x) for x in list(input())]

A = [abs(i%2-x) for i,x in enumerate(Ss) ]
B = [abs((i+1)%2-x) for i,x in enumerate(Ss) ]
print(min([sum(A), sum(B)]))

Submission status: Accepted

Solution code:
N = list(input())
A = []
B = []
for i in range(len(N)):
    if int(i) % 2 == 0:
        B.append(N[i])
    else:
        A.append(N[i])
C = A.count('0') + B.count('1')
D = B.count('0') + A.count('1')
print(min(C,D))

Submission status: Accepted

Solution code:
S = input()                                                                                                                                                  
N = len(S)                                                                                                                                                   
                                                                                                                                                             
C = 0                                                                                                                                                        
for i in range(0,N,2):                                                                                                                                       
    if S[i] != '0':                                                                                                                                          
        C = C+1                                                                                                                                              
                                                                                                                                                             
for i in range(1,N,2):                                                                                                                                       
    if S[i] != '1':                                                                                                                                          
        C = C+1                                                                                                                                              
                                                                                                                                                             
print(min(C,N-C))

Submission status: Accepted

Solution code:
a = input()
a = list(a)
k = 0
if a[0] == '1':
    for i in range(len(a)-1):
        if (i%2 == 0) & (a[i+1] == '1'):
            k += 1
        elif (i%2 == 1) & (a[i+1] == '0'):
            k += 1
else:
    for j in range(len(a)-1):
        if (j%2 == 0) & (a[j+1] == '0'):
            k += 1
        elif (j%2 == 1) & (a[j+1] == '1'):
            k += 1
print(k)

Submission status: Accepted

Solution code:
S = input()

ans = 0
numOperations = 0
# 先頭を1にする場合
for i in range(len(S)):
    if i%2 == 0 and S[i] == '0': numOperations += 1
    if i%2 == 1 and S[i] == '1': numOperations += 1
ans = numOperations    

numOperations = 0
# 先頭を0にする場合
for i in range(len(S)):
    if i%2 == 0 and S[i] == '1': numOperations += 1
    if i%2 == 1 and S[i] == '0': numOperations += 1
 
print( min(ans, numOperations) )

Submission status: Accepted

Solution code:
s = input()
a = ('01' * 10 ** 5)[:len(s)]
b = ('10' * 10 ** 5)[:len(s)]

n_a = 0
n_b = 0
for c, d in zip(s, a):
    n_a += 1 if c == d else 0

for c, d in zip(s, b):
    n_b += 1 if c == d else 0
print(min([n_a, n_b]))

Submission status: Accepted

Solution code:
S = input()

cnt = 0

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

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

print(min(cnt,cnt2))

Submission status: Accepted

Solution code:
#ABC124C/Coloring_Colorfully
def main():
    s = [int(x) for x in input()]
    cnt = 0
    if len(s) == 1:
        print("0")
        exit()
    for i in range(len(s)-1):
        if s[i] == 1:
            if s[i+1] == 1:
                s[i+1] = 0
                cnt+=1
        else:
            if s[i+1] == 0:
                s[i+1] = 1
                cnt+=1
    print(cnt)
main()

Submission status: Accepted

Solution code:
#ABC124C/Coloring_Colorfully_別解
def main():
    s = [int(x) for x in input()]
    odd = s[::2]
    even = s[1::2]
    cnt = 0

    if odd[0]:
        cnt = odd.count(0) + even.count(1)    
    else:
        cnt = odd.count(1) + even.count(0)
    print(cnt)
main()

Submission status: Accepted

Solution code:
#ABC124C/Coloring_Colorfully
def main():
    s = [int(x) for x in input()]
    cnt = 0
    if len(s) == 1:
        print("0")
        exit()
    for i in range(len(s)-1):   #タイルの枚数分ループ
        if s[i] == 1:   #もし,そのタイルが1で
            if s[i+1] == 1: #次のタイルが1だった場合
                s[i+1] = 0  #次のタイルを0にして
                cnt+=1  #cntに1を足す
        else:
            if s[i+1] == 0:
                s[i+1] = 1
                cnt+=1
    print(cnt)
main()

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)

odd = S[::2]
cnt1 = odd.count("1")

even = S[1::2]
cnt2 = even.count("0")

sum_num = cnt1 + cnt2
sum_num2 = N - cnt1 - cnt2

print(min(sum_num,sum_num2))

Submission status: Accepted

Solution code:
s = input()

str_list = list(s)
count =0

for i in range(1,len(s)):
    if str_list[i-1] == str_list[i] == '0':
        str_list[i] = '1'
        count += 1
    elif str_list[i-1] == str_list[i] == '1':
        str_list[i] = '0'
        count += 1

print(count)

Submission status: Accepted

Solution code:
S = input()
size = len(S)
A = ""
B = ""
countA = 0
countB = 0
if size%2 == 0:
    cnt = int(size/2)
    for _ in range(cnt):
        A = A+"01"
        B = B+"10"
else:
    cnt = int((size-1)/2)
    for _ in range(cnt):
        A = A +"01"
        B = B + "10"
    A = A + "0"
    B = B + "1"
for i in range(size):
    if S[i] != A[i]:
        countA += 1
    if S[i] != B[i]:
        countB += 1
print(min(countA,countB))

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)

#one = S.count("1")
#zero = S.count("0")

odd = S[::2]
cnt1 = odd.count("1")

even = S[1::2]
cnt2 = even.count("0")

sum1 = N - cnt1 - cnt2
sum2 = cnt1 + cnt2
print(min(sum1,sum2))

Submission status: Accepted

Solution code:
m = map(int, list(raw_input()))
ans = 0
for i in range(len(m) - 1):
  if m[i] == m[i + 1]:
    m[i + 1] = 1 - m[i + 1]
    ans = ans + 1
print ans

Submission status: Accepted

Solution code:
S = input()
test = int(S[0])
count = 0

for i in range(len(S)):
    if int(S[i]) == test:
        if test == 0:
            test += 1
        elif test == 1:
            test -= 1
    else:
        count += 1
        if test == 0:
            test += 1
        elif test == 1:
            test -= 1

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    S = "0b" + input()
    
    # 01010...のビット列とのXORをとってビットの数を数える
    # 0と1で少ないほうが最小値
    """
    # 桁揃えをしないと一桁減る場合がある
    0000
    0b0000 0b0101
    0b101
    1
    """
    base = "0b"
    for i in range(len(S)-2):
        if i % 2 == 0:
            base += "1"
        else:
            base += "0"
    # print(S, base)
    res = int(S, 0) ^ int(base, 0)

    b_format = "{:0" + str(len(S)-2) + "b}"
    bit = b_format.format(res)
    # print(bit)
    bit = list(map(int, list(bit)))
    count = sum(bit)
    
    if count >= len(bit) / 2:
        print(len(bit) - count)
    else:
        print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)

c1 = S[1::2].count('0')
c2 = S[0::2].count('1')

sum1 = N-c1-c2
sum2 = c1+c2

print(min(sum1,sum2))

Submission status: Accepted

Solution code:
s = list(input())
sl = len(s)
sample1 = ['0' if e % 2 == 0 else '1' for e in range(sl)]
c1, c2 = 0, 0
for i in range(sl):
    if sample1[i] != s[i]:
        c1 += 1
    else:
        c2 += 1
print(min(c1, c2))

Submission status: Accepted

Solution code:
s = input().strip()

t1 = ('01' * (len(s) // 2 + 1))[:len(s)]
t2 = ('10' * (len(s) // 2 + 1))[:len(s)]

d1, d2 = 0, 0
for i in range(len(s)):
    cs, ct1, ct2 = s[i], t1[i], t2[i]
    if cs != ct1:
        d1 += 1
    else:
        d2 += 1

print(min(d1, d2))

Submission status: Accepted

Solution code:
S=list(input())
if len(S)%2==0:
    A=['0','1']*(len(S)//2)
    B=['1','0']*(len(S)//2)
else:
    A=['0','1']*(len(S)//2)+['0']
    B=['1','0']*(len(S)//2)+['1']

a,b=0,0
for i in range(len(S)):
    if A[i]!=S[i]:
        a+=1
        continue
for k in range(len(S)):
    if B[k]!=S[k]:
        b+=1
        continue
print(min(a,b))

Submission status: Accepted

Solution code:
s = input()
to_0 = 0

for i in range(len(s)):
    if i % 2 != int(s[i]):
        to_0 += 1

print(min(to_0, len(s)-to_0))

Submission status: Accepted

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

n = len(a)
o_odd = 0
o_even = 0
for i in range(n):
    if i % 2 == 0 and a[i] == 1:
        o_odd += 1
    elif i % 2 == 1 and a[i] == 1:
        o_even += 1

z_even = int(n / 2 - o_even)
z_odd = round(n / 2 - o_odd + 0.1)

f_o = z_odd + o_even
f_z = z_even + o_odd

print(min(f_o, f_z))

Submission status: Accepted

Solution code:
def make01mask(start, len):
    mask = start
    for i in range(0, len - 1):
        if mask[i] == "0":
            mask += "1"
        else:
            mask += "0"
    return mask


# XOR演算して1の数を返す
def maskxor(bit, mask, digits):
    type = '0' + str(digits) + 'b'
    # print(format(int(bit, 2) ^ int(mask, 2), type))
    # print(str(format(int(bit, 2) ^ int(mask, 2), type)).count("1"))

    return (format(int(bit, 2) ^ int(mask, 2), type)).count("1")


#ビット列で入力される
bin_str = str(input())
bitdigits = len(bin_str)

#print(bin_str)
#print(make01mask("0", bitdigits))
#print(make01mask("1", bitdigits))

start0 = maskxor(bin_str, make01mask("0", bitdigits), bitdigits)
start1 = maskxor(bin_str, make01mask("1", bitdigits), bitdigits)

if start0 > start1:
    print(start1)
else:
    print(start0)

Submission status: Accepted

Solution code:
S = input()
N = [int(i) for i in S]

cnt = 0
for i in range(len(N)-1):
    if N[i] == 0:
        if N[i] == N[i+1]:
            N[i+1] = 1
            cnt += 1
    else:
        if N[i] == N[i+1]:
            N[i+1] = 0
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 13 09:24:23 2019

@author: avina
"""

s = input().strip()

k = s[0]
cnt_1 = 0;cnt_2 = 1
for i in range(1,len(s)):
    if k == s[i] and i%2 !=0:
        cnt_1+=1
    
    if i%2 ==0 and k != s[i]:
        cnt_1+=1
if k == '1':
    e = '0'
else :
    e = '1'

for i in range(1,len(s)):
    
    if e != s[i] and i%2 ==0:
        cnt_2 +=1
    
    if e == s[i] and i%2 != 0:
        cnt_2+=1

print(min(cnt_1, cnt_2))

Submission status: Accepted

Solution code:
a = input()
t1 = ""
t2 = ""

for i in range(len(a)):
  if (i % 2 == 0):
    t1 = t1 + "1"
    t2 = t2 + "0"
  else :
    t1 = t1 + "0"
    t2 = t2 + "1"
    
b1 = int(t1, 2) ^ int(a, 2)
b2 = int(t2, 2) ^ int(a, 2)
c1 = bin(b1).count("1")
c2 = bin(b2).count("1")

if(c1 < c2):
  print(c1)
else :
  print(c2)

Submission status: Accepted

Solution code:
S = str(input())
N = len(S)

left_b = 0
if N%2 == 0:
    for i in range(N//2):
        if S[2*i] == str(1): #もし奇数番目が白だったらひっくり返す
            left_b = left_b + 1
        if S[2*i+1] == str(0):
            left_b = left_b + 1
    mini = min(left_b,N - left_b)
        
else:
    for i in range(N//2):
        if S[2*i] == str(1): #もし奇数番目が白だったらひっくり返す
            left_b = left_b + 1
        if S[2*i+1] == str(0):
            left_b = left_b + 1
    if S[N-1] == str(1):
            left_b = left_b + 1
    mini = min(left_b,N - left_b)

print(mini)

Submission status: Accepted

Solution code:
s = input()

cnt_0 = 0
cnt_1 = 0
for i in range(0, len(s), 2):
  if s[i] == '0':
    cnt_0 += 1
  else:
    cnt_1 += 1

if cnt_0 > cnt_1:
  first = '0'
  second = '1'
elif cnt_0 == cnt_1:
  if s[len(s)-1] == '1':
    first = '0'
    second = '1'
  else:
    first = '1'
    second = '0'
else:
  first = '1'
  second = '0'

cnt = 0
for i in range(0, len(s)):
  if not i%2:
    if s[i] != first:
      cnt += 1
  else:
    if s[i] != second:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Coloring Colorfully
https://atcoder.jp/contests/abc124/tasks/abc124_c

"""
import sys


from itertools import cycle

def solve(S):
    c1 = cycle('10')
    ans1 = 0
    for s in S:
        if s != next(c1):
            ans1 += 1

    c2 = cycle('01')
    ans2 = 0
    for s in S:
        if s != next(c2):
            ans2 += 1
    return min(ans1, ans2)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    S = stdin.readline().rstrip()
    count = [0, 0]
    x = ['01', '10']
    for j in range(2):
        for i, c in enumerate(S):
            if c == x[j][i % 2]:
                count[j] += 1
    print(min(count))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)

bw = ''
wb = ''
for n in range(N):
    bw += str(n % 2)
    wb += str((n+1) % 2)

diff_bw = 0
diff_wb = 0
for n in range(N):
    if S[n] != bw[n]:
        diff_bw += 1
    if S[n] != wb[n]:
        diff_wb += 1

print(min(diff_bw, diff_wb))

Submission status: Accepted

Solution code:
S = input()

BW = "01" * (10**5)
WB = "10" * (10**5)

ans = 0
if S[0] == "0":
    for i in range(len(S)):
        if S[i] != BW[i]:
            ans += 1
else:
    for i in range(len(S)):
        if S[i] != WB[i]:
            ans += 1
            
print(ans)

Submission status: Accepted

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

res = 0
for i in range(1, len(S)):
    if S[i - 1] == S[i]:
        S[i] = 0 if S[i] == 1 else 1
        res += 1
print(res)

Submission status: Accepted

Solution code:
s = input()
ans = 0

for i in range(len(s)):
    if i % 2 == int(s[i]):
        ans += 1

print(min(ans, len(s)-ans))

Submission status: Accepted

Solution code:
S = input()

ans = len(S)
tmp = 0
for i in range(len(S)):
    if int(S[i]) == i%2:
        tmp += 1
ans = min(ans,tmp)

tmp=0
for i in range(len(S)):
    if int(S[i]) == (i+1)%2:
        tmp += 1
ans = min(ans,tmp)

print(ans)

Submission status: Accepted

Solution code:
#N = int(input())
L = list(map(int, input()))
L0 = 0
L1 = 0
for i, n in enumerate(L):
    if i % 2 == 0:
        if n == 1:
            L1 += 1
        else:
            L0 += 1
    else:
        if n == 0:
            L1 += 1
        else:
            L0 += 1
print(min(L1, L0))

Submission status: Accepted

Solution code:
s = list(map(int, input()))
ans = 0

for i in range(len(s)):
    if i % 2 == s[i]:
        ans += 1

print(min(ans, len(s)-ans))

Submission status: Accepted

Solution code:
S = input()
tmp1,tmp2 = 0,0
c1,c2 = 0,1
ans = 0
length = len(S)

for i in range(length):
	tmp1 += 1 if int(S[i]) == c1 else 0
	tmp2 += 1 if int(S[i]) == c2 else 0
	c1 = abs(c1 - 1)
	c2 = abs(c2 - 1)

ans = min(tmp1,tmp2)
print(ans)

Submission status: Accepted

Solution code:
'''input
0
'''

S=input()

da, db=0,0
A=[]
B=[]
# print(da,db)

for i in range(len(S)):
	A.append(i%2)
	B.append((i+1)%2)
	# print(S[i])
	da+=abs(A[i]-int(S[i]))
	db+=abs(B[i]-int(S[i]))

# print(A, B)
print(min(da, db))

Submission status: Accepted

Solution code:
S_array = [int(c) for c in list(input())]
count = 0

if len(S_array) == 1:
  print(count)
  exit()

for i in range(len(S_array) - 1):
  if S_array[i] != S_array[i + 1]:
    continue
  elif S_array[i] == 0:
    S_array[i + 1] = 1
  else:
    S_array[i + 1] = 0
  count = count + 1

print(count)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
num = float('inf')
tmp = 0
for k in range(N):
    if k % 2 == 0 and S[k] == '0':
        tmp += 1
    if k % 2 != 0 and S[k] == '1':
        tmp += 1

num = min(tmp, num)

tmp = 0
for k in range(N):
    if k % 2 == 1 and S[k] == '0':
        tmp += 1
    if k % 2 != 1 and S[k] == '1':
        tmp += 1

num = min(tmp, num)

print(num)

Submission status: Accepted

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

# 0始まり
# 01010101...
count_0 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s!= 0:
            count_0 += 1
    else:
        if s!= 1:
            count_0 += 1
# print(count_0)

# 1始まり
# 10101010...
count_1 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s!= 1:
            count_1 += 1
    else:
        if s!= 0:
            count_1 += 1
# print(count_1)
print(min(count_0, count_1))

Submission status: Accepted

Solution code:
import copy

S = [int(x) for x in input()]
N = len(S)

com = [0] * N
com_01 = copy.deepcopy(com)
com_10 = copy.deepcopy(com)

dif_01 = 0
dif_10 = 0
for n in range(N):
    
    if n % 2 == 0:
        com_10[n] = 1
    else:
        com_01[n] = 1

    dif_01 += abs(S[n] - com_01[n])
    dif_10 += abs(S[n] - com_10[n])

print(min(dif_01, dif_10))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = list(map(int,list(input())))
#1010...か、0101...の2パターンしかないので、塗替え回数の少ない方を選択
lnS = len(S)
pt1 = [0,1] * (lnS // 2)
if lnS % 2==1:
    pt1.append(0)

dif_S_pt1 = sum(list(map(lambda x,y:abs(x-y),S,pt1)))
print(min([dif_S_pt1,lnS - dif_S_pt1]))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
Sw = '01' * (N // 2)
if (N % 2):
  Sw += '0'
Sb = '10' * (N // 2)
if (N % 2):
  Sb += '1'
diffw = 0
for i in range(N):
  if (S[i] != Sw[i]):
    diffw += 1
diffb = 0
for i in range(N):
  if (S[i] != Sb[i]):
    diffb += 1
print(min(diffw, diffb))

Submission status: Accepted

Solution code:
#0が黒、1が白
s = input()
sirokuro = 0
kurosiro = 0
for i in range(len(s)):
    if i % 2 == 0:#奇数番目
        if s[i] == '0':#奇数番目が黒
            sirokuro += 1
        else:#奇数番目が白
            kurosiro += 1
    else:#偶数番目
        if s[i] == '0':#偶数番目が黒
            kurosiro += 1
        else:#偶数番目が白
            sirokuro += 1
print(min(sirokuro,kurosiro))

Submission status: Accepted

Solution code:
color = input().rstrip("\n")

l1 = [str(i % 2) for i in range(len(color))]
l2 = [str((i + 1) % 2) for i in range(len(color))]

s1 = s2 = 0
for c, n1, n2 in zip(color, l1, l2):
    s1 += (c != n1)
    s2 += (c != n2)

print(min(s1, s2))

Submission status: Accepted

Solution code:
def solve():
    S = raw_input()
    even0 = 0
    even1 = 0
    odd0 = 0
    odd1 = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == '0':
                even0 += 1
            else:
                even1 += 1
        else:
            if S[i] == '0':
                odd0 += 1
            else:
                odd1 += 1
    ret = min(even0 + odd1, even1 + odd0)
    print str(ret)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = input()


def eq(x, y):
    if x == y:
        return 1
    return 0


A = "01" * len(S)
B = "10" * len(S)

a = sum(map(eq, S, A))
b = sum(map(eq, S, B))

print(min(a, b))

Submission status: Accepted

Solution code:
s = input()
c = 0
 
for x in range(len(s)):
    c += s[x] != ('0' if x%2 else '1')
 
print(c if c < x+1-c else x+1-c)

Submission status: Accepted

Solution code:
s = input()
c = 0

for x in range(len(s)):
    c += 1 if s[x] != str(x%2) else 0

print(c if c < x+1-c else x+1-c)

Submission status: Accepted

Solution code:
s = input()
c = 0

for x in range(len(s)):
    c += 1 if s[x] != ('0' if x%2 else '1') else 0

print(c if c < x+1-c else x+1-c)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
cnt1,cnt2 = 0,0
for i in range(n):
    if (i%2==0 and S[i]=='1') or (i%2==1 and S[i]=='0'):
        cnt1 += 1
for i in range(n):
    if (i%2==1 and S[i]=='1') or (i%2==0 and S[i]=='0'):
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S = input()
c = S[::2].count('1')
c += S[1::2].count('0')
if c > len(S)/2:
    c = len(S)-c

print(c)

Submission status: Accepted

Solution code:
s = input()
c1,c2 = 0, 0

for x in range(len(s)):
    c1 += 1 if s[x] != ('0' if x%2 else '1') else 0
    c2 += 1 if s[x] != ('1' if x%2 else '0') else 0

print(min(c1,c2))

Submission status: Accepted

Solution code:
s = input()
a = list(s)
n = len(s)
ansa = 0
ansb = 0
for i in range(n):
    if i%2 == 0 and int(a[i]) == 0:
      ansa = ansa + 1

    if i%2 == 1 and int(a[i]) == 1:
      ansa = ansa + 1    
    
    if i%2 == 0 and int(a[i]) == 1:
      ansb = ansb + 1
        
    if i%2 == 1 and int(a[i]) == 0:
      ansb = ansb + 1
     
        
if ansa > ansb:
  print(ansb)
else :
  print(ansa)

Submission status: Accepted

Solution code:
n=list(map(int,list(input())))
a=[1 if i%2==0 else 0 for i in range(len(n))]
b=[1 if i%2==1 else 0 for i in range(len(n))]
num_a=0
num_b=0
for i in range(len(n)):
	if n[i] is a[i]:
		num_a+=1
	if n[i] is b[i]:
		num_b+=1

if num_a>=num_b:
	print(len(n)-num_a)
else:
	print(len(n)-num_b)

Submission status: Accepted

Solution code:
s = input()
ans1, ans2 = 0, 0
for i, e in enumerate(s):
  if i%2:
    if e=="0":
      ans1 += 1
    if e=="1":
      ans2 += 1
  else:
    if e=="1":
      ans1 += 1
    if e=="0":
      ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

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

def main(S):
    count=[0,0]
    for i in range(len(S)):
        if i%2==0:
            if S[i]=='0':
                count[0]+=1
            else :
                count[1]+=1
        else :
            if S[i]=='1':
                count[0]+=1
            else :
                count[1]+=1
    print(min(count))

if __name__ == '__main__':
    S = list(input())
    
    main(S)

Submission status: Accepted

Solution code:
li = [ int(it) for it in input() ]
N = len(li)

s1 = 0
flip = 0
for it in li:
  if it != flip:
    s1+=1
  flip=1-flip
s2 = 0
flip = 1
for it in li:
  if it != flip:
    s2+=1
  flip=1-flip
print ( min (s1,s2) )

Submission status: Accepted

Solution code:
S = input()
SL = [int(i) for i in S]
SL.append("A")
keepcount = "start"
count = 0
for i in SL:
        if keepcount == "start":
                keepcount = i
        elif keepcount == i:
                keepcount = i^1
                count += 1
        else:
                keepcount = i

print(count)

Submission status: Accepted

Solution code:
s=list(map(int,list(input())))
so=[]
se=[]
for i in range(len(s)):
    if i%2==0:
        so.append(s[i])
    if i%2!=0:
        se.append(s[i])

tso=sum(so)
tse=sum(se)

if tso>tse:
    print(-(-len(s)//2)-tso+tse)

else:
    print(len(s)//2+tso-tse)

Submission status: Accepted

Solution code:
s = list(map(int,input()))
e = []
o = []
for i in range(len(s)):
    if i%2==0:
        e.append(0)
    else:
        e.append(1)
for i in range(len(s)):
    if i%2==1:
        o.append(0)
    else:
        o.append(1)
x = 0
y = 0
for i in range(len(s)):
    if s[i]!=e[i]:
        x += 1
    if s[i]!=o[i]:
        y += 1
print(min(x,y))

Submission status: Accepted

Solution code:
S=str(input())
count=[0,0]
for i in range(len(S)):
  if i%2==0:
    if S[i]=='0':
      count[0]+=1
    else :
      count[1]+=1
  else :
    if S[i]=='1':
      count[0]+=1
    else :
      count[1]+=1
print(min(count))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()

res1 = 0
res2 = 0
f1 = "0"
f2 = "1"
for c in s:
    if f1!=c:
        res1 += 1
    if f2!=c:
        res2 += 1

    if f1=="0":
        f1 = "1"
    else:
        f1 = "0"
    if f2=="0":
        f2 = "1"
    else:
        f2 = "0"

print(min(res1,res2))

Submission status: Accepted

Solution code:
S = list(input())

target = '0'
cnt = 0
for i in range(len(S)):
  if i == 0:
    target = S[i]
    continue
  if target == S[i]:
    cnt += 1
    if S[i] == '0':
      target = '1'
    else:
      target = '0'
  else:
    target = S[i]
print(cnt)

Submission status: Accepted

Solution code:
s = input()
odd = s[0::2]
even = s[1::2]

odd0 = odd.count("0")
odd1 = odd.count("1")
even0 = even.count("0")
even1 = even.count("1")

print(min((odd0 + even1), (odd1 + even0)))

Submission status: Accepted

Solution code:
S = list(input())
ans1 = 0
ans2 = 0

tmp = S[0]
for i in range(1, len(S)):
    if tmp == S[i]:
        ans1 += 1
        tmp = "0" if tmp == "1" else "1"
    else:
        tmp = S[i]


tmp = S[-1]
for i in reversed(range(0, len(S)-1)):
    if tmp == S[i]:
        ans2 += 1
        tmp = "0" if tmp == "1" else "1"
    else:
        tmp = S[i]

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()
if len(s) == 1:
    print(0)
else:
    r = 0
    f = s[0]
    for i in s[1:]:
        if i == f:
            r += 1
            f = '1' if i == '0' else '0'
        else:
        	f = i
    print(r)

Submission status: Accepted

Solution code:
s = input()
b = 0
w = 0
bn = '0'
wn = '1'
for c in s:
    if c != bn:
        b += 1
    if c != wn:
        w += 1
    bn = str(1-int(bn))
    wn = str(1 - int(wn))
print(min(b,w))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
a = 0

for i in range(N):
	if S[i] == str(i%2):
		a += 1

print(min(a, N-a))

Submission status: Accepted

Solution code:
S = input()

if not S[:-1]:
    print(0)
else:

  out1 = out2 = 0
  for i, j in enumerate(S):
    xor = (j == '1') ^ (i % 2)
    out1 += xor

  print(out1 if out1 < (i + 1) - out1 else (i + 1) - out1)

Submission status: Accepted

Solution code:
S = input()

out1 = out2 = 0
for i, j in enumerate(S):
  xor = (j == '1') ^ (i % 2)
  out1 += xor

print(out1 if out1 < (i + 1) - out1 else (i + 1) - out1)

Submission status: Accepted

Solution code:
S = input()
l = len(S)

out1 = out2 = 0
for i, j in enumerate(S):
  xor = (j == '1') ^ (i % 2)
  out1 += xor

print(out1 if out1 < l - out1 else l - out1)

Submission status: Accepted

Solution code:
S = input()

out1 = out2 = 0
for i, j in enumerate(S):
  xor = (j == '1') ^ (i % 2)
  out1 += xor
  out2 += (1 - xor)

print(out1 if out1 < out2 else out2)

Submission status: Accepted

Solution code:
S = input()

out1, out2 = 0, 0
for i, j in enumerate(S):
  xor = int(j) ^ (i % 2)
  out1 += xor
  out2 += (1 - xor)
  
print(min(out1, out2))

Submission status: Accepted

Solution code:
S = input()
l = len(S)

seikai1 = [i % 2 for i in range(l)]
seikai2 = [1 ^ i for i in seikai1]

out = min(sum(i ^ int(j) for i, j in zip(seikai1, S)), \
          sum(i ^ int(j) for i, j in zip(seikai2, S)))
print(out)

Submission status: Accepted

Solution code:

# coding: utf-8

# In[20]:

import sys
#input = sys.stdin.readline
S = input()


# In[21]:

if len(S)%2==0:
    a = "01"*(len(S)//2)
    b = "10"*(len(S)//2)
else:
    a = "01"*(len(S)//2)+"0"
    b = "10"*(len(S)//2)+"1"


# In[22]:

ac = 0
bc = 0
for i in range(len(S)):
    if S[i] != a[i]:
        ac += 1
    if S[i] != b[i]:
        bc += 1
print(min(ac, bc))


# In[ ]:

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
count2 = 0
for i in range(n):
    if i % 2 == 0:
        x = "0"
    else:
        x = "1"
    if s[i] == x:
        count2 += 1
        #print(i, s[i], x, "OK")
    else:
        count += 1
        #print(i, s[i], x)
print(min(count,count2))

Submission status: Accepted

Solution code:
s =input()
n =len(s)
count=0
count2=0
for i in range(n):
	if i %2==0:
		x="0"
	else:
		x="1"
	if s[i]==x:
		count2+=1
		#print(i,s[i],x,"OK")
	else:
		count +=1
		#print(i,s[i],x)
print(min(count,count2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
count2 = 0
for i in range(n):
	if i % 2 == 0:
		x = "0"
	else:
		x = "1"
	if s[i] == x:
		count2 += 1 
		#print(i, s[i],x, "OK")
	else:
		count += 1
		#print(i, s[i], x)
print(min(count,count2))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
count=0
count2=0
for i in range(n):
	if i % 2 == 0:
		x="0"
	else:
		x="1"
	if s[i] == x:
		count2 += 1
		#print(i,s[i],x,"OK")
	else:
		count += 1
		#print(i,s[i],x)
print(min(count,count2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
count2 = 0
for i in range(n):
    if i % 2 == 0:
        x = "0"
    else:
        x = "1"
    if s[i] == x:
        count2 += 1
    else:
        count += 1
print(min(count,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
count2 = 0
for i in range(n):
	if i % 2 == 0:
		x = "0"
	else:
		x = "1"
	if s[i] == x:
		count2 += 1
	    #print(i, s[i], x, "OK")
	else:
		count += 1
		#print(i, s[i], x)
print(min(count,count2))

Submission status: Accepted

Solution code:
S = input()
n =len(S)
y = int()
c = int()
for i in range(n):
	if i % 2 ==0:
		x = "0"
	else:
		x ="1"
	if S[i] == x:
		c += 1
		#print(i, S[i],x,"OK")
	else:
		y += 1
		#print(i,S[i],x)

if c < y:
	print(c)
else:
	print(y)

Submission status: Accepted

Solution code:
S = list(input())
a, b = [], []
cnt_a, cnt_b = 0, 0

for i in range(len(S)):
    if i % 2 == 0:
        a.append('0')
        b.append('1')
    else:
        a.append('1')
        b.append('0')

for j in range(len(S)):
    if a[j] != S[j]:
        cnt_a += 1
    if b[j] != S[j]:
        cnt_b += 1

print(min(cnt_a, cnt_b))

Submission status: Accepted

Solution code:
S  = str(input())
p1 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            p1 += 1
    else:
        if S[i] == '1':
            p1 += 1
print(min(p1, len(S) - p1))

Submission status: Accepted

Solution code:
S  = str(input())
p1 = 0
p2 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            p1 += 1
        else:
            p2 += 1
    else:
        if S[i] == '0':
            p2 += 1
        else:
            p1 += 1
print(min(p1, p2))

Submission status: Accepted

Solution code:
s = [int(i) for i in input()]
odd = sum(s[::2])
even = sum(s[1::2])
if odd > even:
    print(even + abs(odd - len(s[::2])))
else:
    print(odd + abs(even - len(s[1::2])))

Submission status: Accepted

Solution code:
s = input()
x = [s[j] for j in range(0,len(s))]
x.insert(0,'2')
count = 0
for j in range(1,len(x)):
    if x[j] == '0' and x[j] == x[j-1]:
        x[j] = '1'
        count = count + 1
    elif x[j] == '1' and x[j] == x[j-1]:
        x[j] = '0' 
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
from itertools import zip_longest, islice

S = input()
ans = 0

for curr, next in islice(zip_longest(S, S[1:]), 0, None, 2):
  if curr == '0': ans += 1
  if next == '1': ans += 1

print(min(ans, len(S) - ans))