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:
#coding: utf-8
S = list(input())
zero, one = ["0"] * len(S), ["0"] * len(S)
for i in range(1, len(S)+1):
    if i % 2 == 0:
        zero[i-1] = "1"
    else:
        one[i-1] = "1"
c1, c2 = 0, 0
for i in range(len(S)):
    if S[i] != zero[i]:
        c1 += 1
    elif S[i] != one[i]:
        c2 += 1
print(min(c1, c2))

Submission status: Accepted

Solution code:
S = input()
c = S[::2].count('0') + S[1::2].count('1') 
print(min(c, len(S) - c))

Submission status: Accepted

Solution code:
s=input()
p=[0]*2
for a,i in enumerate(s):
    if a%2==0 and i=="0":
        p[0]+=1
    if a%2==1 and i=="1":
        p[0]+=1
    if a%2==0 and i=="1":
        p[1]+=1
    if a%2==1 and i=="0":
        p[1]+=1

print(min(p))

Submission status: Accepted

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

#スライスを用いて奇数番目s1と偶数番目s2に分ける
s1 = s[::2]
s2 = s[1::2]

zero = s1.count('0')
one = s2.count('1')

if zero + one < n/2:
  print(zero + one)
else:
  print(n - zero - one)

Submission status: Accepted

Solution code:
a=0
for i,s in enumerate(input()):a+=i%2^int(s)
print(min(a,i-a+1))

Submission status: Accepted

Solution code:
s = input()
odd = 0
even = 0
n = len(s)
# 奇数回目が1か偶数回目が1かで考える
for i in range(n):
    if s[i] == '1':
        if i%2 == 0:
            odd += 1
        else:
            even += 1
# sが偶数ならoddかevenの少ないほうをチェンジ
if n%2 == 0:
    n //= 2
    ans = n - max(odd,even) + min(odd,even)
    print(ans)
#　奇数だと一か所ずれる
else:
    n //= 2
    x = n+1 - odd + even
    y = n - even + odd
    ans = min(x,y)
    print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ev = S[0::2]
od = S[1::2]
A = N - (ev.count('0') + od.count('1'))
B = N - (ev.count('1') + od.count('0'))
print(min(A, B))

Submission status: Accepted

Solution code:
S = input()
sumi = 0
sumii = 0

for i in range(len(S)):
  if (i % 2) == 0:
    if S[i:i+1] == "1":
      sumi += 1
  if (i % 2) == 1:
    if S[i:i+1] == "0":
      sumi += 1

for i in range(len(S)):
  if (i % 2) == 0:
    if S[i:i+1] == "0":
      sumii += 1
  if (i % 2) == 1:
    if S[i:i+1] == "1":
      sumii += 1
        
if sumi > sumii:
  print(sumii)
else:
  print(sumi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

#01010..
ans = 10 ** 5
count = 0
for i in range(len(S)):
    if S[i] != "0" and i % 2 == 0:
        count += 1
    elif S[i] != "1" and i % 2 == 1:
        count += 1
ans = min(ans, count)

#10101...
count = 0
for i in range(len(S)):
    if S[i] != "1" and i % 2 == 0:
        count += 1
    elif S[i] != "0" and i % 2 == 1:
        count += 1
ans = min(ans, count)
print(ans)

Submission status: Accepted

Solution code:
S = input()

def solve(B):
    res = 0
    for i, s in enumerate(S):
        if s == B[i % 2]:
           res += 1 
    return res

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
S = stdin.readline()
L = len(S)
cnt = 0
cnt1 = 0
# 0101010101
for i, s in enumerate(S):
    if i & 1 == 1:
        incr = 1 if s == '1' else 0
        cnt += incr
    else:
        incr = 1 if s == '0' else 0
        cnt += incr
for i, s in enumerate(S):
    if i & 1 == 1:
        incr = 1 if s == '0' else 0
        cnt1 += incr
    else:
        incr = 1 if s == '1' else 0
        cnt1 += incr
print(min(cnt, cnt1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 21:45:12 2019

@author: sofugo
"""
import numpy as np
N = (input())
x=np.array(list(N),dtype=np.int)
count=0
count2=0

now=0
for n,i in enumerate(x):
    if i==now:
        if n%2==0:
            now=1
        else:
            now=0
    else:
        count+=1
        if n%2==0:
            now=1
        else:
            now=0
    
now=1
for n,i in enumerate(x):
    if i==now:
        if n%2==0:
            now=0
        else:
            now=1
    else:
        count2+=1
        if n%2==0:
            now=0
        else:
            now=1
if(count>count2):
    print(count2)
else:
    print(count)

Submission status: Accepted

Solution code:
def c_coloring_colorfully(S):
    s1 = '10' * (len(S) // 2) + ('1' if len(S) % 2 == 1 else '')
    s2 = '01' * (len(S) // 2) + ('0' if len(S) % 2 == 1 else '')
    ans1 = len([1 for k, s in enumerate(S) if s != s1[k]])
    ans2 = len([1 for k, s in enumerate(S) if s != s2[k]])
    return min(ans1, ans2)

S = input()
print(c_coloring_colorfully(S))

Submission status: Accepted

Solution code:
s=list(input())
dp=[[0,0] for i in range(len(s)+1)]
dp[0][1] = 1
for i in range( len(s)-1 ):
  if s[i] == s[i+1]:
    dp[i+1][0] = dp[i][1]
    dp[i+1][1] = dp[i][0]+1
  else:
    dp[i+1][0] = dp[i][0]
    dp[i+1][1] = dp[i][1]+1
print(min(dp[len(s)-1]))

Submission status: Accepted

Solution code:
s = input()
strlist = list(s)
ans = 0
for i in range(len(s)-1):
    if strlist[i] == strlist[i+1]:
        strlist[i+1] = str(abs(1-int(strlist[i])))
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
"""
C - Coloring Colorfully
https://atcoder.jp/contests/abc124/tasks/abc124_c
"""
if __name__ == '__main__':
    S = str(input())

    len_S = len(S)
    S_list = []
    answer_type_1 = []
    answer_type_2 = []
    for i in range(0, len_S):
        S_list.append(S[i])
        if i % 2 == 0:
            answer_type_1.append("0")
            answer_type_2.append("1")
        else:
            answer_type_1.append("1")
            answer_type_2.append("0")

    answer_1 = 0
    answer_2 = 0

    for i, Si in enumerate(S_list):
        if S_list[i] != answer_type_1[i]:
            answer_1 += 1
        if S_list[i] != answer_type_2[i]:
            answer_2 += 1

    answer = min(answer_1, answer_2)

    print(answer)

Submission status: Accepted

Solution code:
s = input()

#先頭が1の場合
count_1 = s[::2].count('0') + s[1::2].count('1')

#先頭が0の場合
count_0 = s[::2].count('1') + s[1::2].count('0')

print(min(count_1, count_0))

Submission status: Accepted

Solution code:
s = list(input())
count1 = 0
s_copy = s.copy()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count1 += 1
        if s[i+1] == '0':
            s[i+1] = '1'
        else:
            s[i+1] = '0'
print(count1)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
even = S[0::2]
odd = S[1::2]
ptn0 = N - (even.count('0') + odd.count('1'))
ptn1 = N - (even.count('1') + odd.count('0'))
print(min(ptn0, ptn1))

Submission status: Accepted

Solution code:
S = input()

B = []
W = []
for i in range (len(S)):
    if i % 2 == 0:
        B += ["0"]
        W += ["1"]
    else:
        B += ["1"]
        W += ["0"]
        
aB = 0
aW = 0

for i in range(len(S)):
    if B[i] != S[i]:
        aB += 1
    if W[i] != S[i]:
        aW += 1
print(min(aB, aW))

Submission status: Accepted

Solution code:
S = str(input())

S1 = list(S)

LEN = len(S1)


start0_CONT=0
for i in range(0,LEN):
    if int(i) % 2 == 0:
        if int(S1[i]) == 1:
            start0_CONT=start0_CONT+1
    elif int(i) % 2 == 1:
        if int(S1[i]) == 0:
            start0_CONT=start0_CONT+1
      

start1_CONT=0
for i in range(0,LEN):
    if int(i) % 2 == 0:
        if int(S1[i]) == 0:
            start1_CONT=start1_CONT+1
    elif int(i) % 2 == 1:
        if int(S1[i]) == 1:
            start1_CONT=start1_CONT+1


if start0_CONT > start1_CONT:
    print(start1_CONT)
else:
    print(start0_CONT)

Submission status: Accepted

Solution code:
numList = [int(c) for c in input()]

sum_a = 0
sum_b = 0

for index, num in enumerate(numList):
  a = index % 2
  b = (index + 1) % 2
  if(num - a != 0): 
  	sum_a += 1
  else:
    sum_b += 1

if(sum_a >= sum_b):
  print(sum_b)
else:
  print(sum_a)

Submission status: Accepted

Solution code:
S = str(input())

first0= 0
first1 = 0

nextStr = 1
for s in S:
    if int(s) != nextStr:
        first1 += 1 
        
    if nextStr == 1:
        nextStr = 0 
    else: nextStr = 1 

nextStr = 0
for s in S:
    if int(s) != nextStr:
        first0 += 1 
        
    if nextStr == 1:
        nextStr = 0 
    else:
        nextStr = 1 
    
print(min(first0, first1))

Submission status: Accepted

Solution code:
import itertools
S = input()

p1 = itertools.cycle('01')
p2 = itertools.cycle('10')

ans1=0
ans2=0
for s,P1,P2 in zip(S,p1,p2):
  if s == P1:
    ans1 += 1
  if s == P2:
    ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
*s,=map(int,input());a=0
for i in range(1,len(s)):a+=s[i]==s[i-1];s[i]=1-s[i-1]
print(a)

Submission status: Accepted

Solution code:
s=input()
a=[int(c) for c in s]
n=0
c=0
d=len(a)
while n<=d:
    b=n%2
    if a[n]==0 and b==1:
        c=c+1
    if a[n]==1 and b==0:
        c=c+1
    if n+1==d:
        break
    n=n+1
if c<= d/2:
    print(c)
else:
    print(d-c)

Submission status: Accepted

Solution code:
aj = input()
a1 = [str(i%2) for i in range(len(aj))]
a2 = [str((i+1)%2) for i in range(len(aj))]
cnt1=cnt2=0
for i in range(len(aj)):
  if aj[i]==a1[i]:
    cnt1+=1
  if aj[i]==a2[i]:
    cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
a = input()
n = len(a)
count0 = 0    #start from 0
count1 = 0    #start from 1
for i in range(n):
    if i % 2 == 0 and int(a[i]) ==1:
        count0 = count0 +1
    elif i % 2 == 0 and int(a[i]) ==0:
        count1 = count1 +1
    elif i % 2 == 1 and int(a[i]) ==1:
        count1 = count1 +1
    elif i % 2 == 1 and int(a[i]) ==0:
        count0 = count0 +1

print(min(count0, count1))

Submission status: Accepted

Solution code:
strS = input()
S0 = []
S1 = []
changeA = 0
changeB = 0
S = [int(s) for s in strS]
for i in range(len(strS)):
    if (i % 2 == 0):
        S0.append(0)
        S1.append(1)
    else:
        S0.append(1)
        S1.append(0)

for i in range(len(S)):
    if not S[i] == S0[i]:
        changeA += 1
    if not S[i] == S1[i]:
        changeB += 1
if changeA > changeB :
    print(changeB)
else :
    print(changeA)

Submission status: Accepted

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

def henkan(a):
    if a == "0":
        a = "1"
    else:
        a = "0"
    return a
    
ans = 0
a = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        a = henkan(S[i+1])
        ans += 1
        S[i+1] = a
print(ans)

Submission status: Accepted

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

for i, b1 in enumerate(S):
    if i < len(S)-1:
        b2 = S[i+1]
    else:
        break
    
    if b1 == b2:
        result += 1
        if b2 == 1:
            S[i+1] -= 1
        else:
            S[i+1] += 1

print(result)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
a=str(input())
odd0,even0=0,0
odd1,even1=0,0
for i in range(len(a)):
  if i%2==0:#奇数
    if a[i]=="0":
      odd0+=1
  else:
    if a[i]=="0":
      even0+=1
odd1=len(a)-int(len(a)/2)-odd0
even1=int(len(a)/2)-even0
print(min(odd1+even0,odd0+even1))

Submission status: Accepted

Solution code:
tiles = list(map(int, input()))
# inputs = "10010010"
# tiles = list(map(int, inputs))


def count_repaint_tiles(tiles):
    if len(tiles) == 0:
        return 0
    counts = 0
    color = tiles[0]
    for tile in tiles[1:]:
        if tile == color:
            counts = counts + 1
        color = 1 - color
    return counts


print(count_repaint_tiles(tiles))

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter
s = list(stdin.readline().rstrip())
odd = Counter(s[0::2])
even = Counter(s[1::2])
if odd['1'] > even['1']:
    print(odd['0']+even['1'])
elif odd['1'] < even['1']:
    print(odd['1']+even['0'])
else:
    if odd['0'] > even['0']:
        print(odd['1']+even['0'])
    elif odd['0'] < even['0']:
        print(odd['0']+even['1'])
    else:
        print(len(s)//2)

Submission status: Accepted

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

import re

a = input()

preans1 = 0
preans2 = 1000000
if(a[0] == "0"):
    for i in range(len(a)):
        if(i%2 == 0):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 1):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "1"):
        preans2 = 0
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "0"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "1"):
                    preans2 += 1
elif(a[0] == "1"):
    for i in range(len(a)):
        if(i%2 == 1):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 0):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "0"):
        preans2 = 0
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "1"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "0"):
                    preans2 += 1
print(min(preans1,preans2))

Submission status: Accepted

Solution code:
def main():
  S=input()
  char = list(S)
  char2= list(S)
  num =len(list(S))
  count=0
  
  
  if num ==1:
    print(0)
  
  else:
    for i in range(0,num,2):
      if(char[i]=='0'):
        char[i]='1'
        count=count+1
    for j in range(1,num,2):
      if(char[j]=='1'):
        char[j]='0'
        count=count+1
    count_even=count
  
    count=0
    for i in range(0,num,2):
      if(char2[i]=='1'):
        char2[i]='0'
        count=count+1
    for j in range(1,num,2):
      if(char2[j]=='0'):
        char2[j]='1'
        count=count+1
    count_odd=count

    print(min(count_even,count_odd))
  
main()

Submission status: Accepted

Solution code:
S = input()
count = 0
smae = ""

for i in range(len(S)) :
    if i == 0 :
        smae = S[i]
    elif smae == S[i] :
        smae = ("1" if S[i] == "0" else "0")
        count += 1
        continue
    smae = S[i]
    
print(count)

Submission status: Accepted

Solution code:
import numpy as np
tmp = str(input())

H = []
for i in range(len(tmp)):
    H.append(int(tmp[i]))

#print(H)
H = np.array(H, int)

#print(H)
x = []
y = []
for i in range(len(H)):
    x.append(i%2)
    y.append((i+1)%2)
#print(H == np.array(x))
#print(H == np.array(y))
a = sum(H == np.array(x))
b = sum(H == np.array(y))

if(a>=b):
    print(len(H)-a)
else:
    print(len(H)-b)

Submission status: Accepted

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

suuti=[]
for _ in s:
    suuti.append(int(_))

rei=[]
for _ in range(l):
    rei.append(_%2)

c=0
for _ in range(l):
    if rei[_]==suuti[_]:
        c+=1

print(min(c,l-c))

Submission status: Accepted

Solution code:
import collections
import math
S = [int(i) for i in input()]
guusuu = S[1::2]
kisuu = S[0::2]
if len(S)==1:
    print(0)
else:
    if len(S)%2==0:
        if guusuu.count(1)>=kisuu.count(1):
            print(len(guusuu)-guusuu.count(1)+len(kisuu)-kisuu.count(0))
        else:
            print(len(guusuu)-guusuu.count(0)+len(kisuu)-kisuu.count(1))
    else:
        if guusuu.count(1)>=kisuu.count(1):
            print(len(guusuu)-guusuu.count(1)+len(kisuu)-kisuu.count(0))
        else:
            print(len(guusuu)-guusuu.count(0)+len(kisuu)-kisuu.count(1))

Submission status: Accepted

Solution code:
s = input()

l = len(s)
a, b = '0', '1' 
res_a = res_b = 0 
for i in range(l):
    if s[i] != a:
        res_a += 1                                                                                             
    if s[i] != b:
        res_b += 1
    a, b = b, a

print(min(res_a, res_b))

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
# L = list(map(int, input().split()))
# A, B = map(int, input().split())
S = input()

l = len(S) - 1
leng = l // 2

check1 = "01" * leng
check2 = "10" * leng

if l % 2 != 0:
    check1 = "1" + check1
    check2 = "0" + check2

check1 = int(check1, 2)
check2 = int(check2, 2)
S = int(S, 2)

check1 ^= S
check2 ^= S

print(min(bin(check1).count('1'), bin(check2).count('1')))

Submission status: Accepted

Solution code:
S = raw_input()

value = int(S, 2)

eval = ''
length = len(S)
if length % 2 == 0: val = 1
else: val = 0
for i in xrange(length):
    if i % 2 == val: eval += '1'
    else: eval += '0'

count = bin(value ^ int(eval,2)).count('1')

if count <= 0.5 * length: print count
else: print (length - count)

Submission status: Accepted

Solution code:
s = str(input())

compare1 = "01"*int(len(s)/2)
compare2 = "10"*int(len(s)/2)
if len(compare1)!=len(s):
  compare1 = compare1 + "0"
  compare2 = compare2 + "1"

diff1=0
diff2=0
for i,j,k in zip(s,compare1,compare2):
  if i == j:
    diff1 = diff1 + 1
  if i == k:
    diff2 = diff2 + 1

print(min(diff1,diff2))

Submission status: Accepted

Solution code:
s = input()

odd = 0
even = 0
for i in range(len(s)):
    if(i%2==0):
        even = even + int(s[i])
    else:
        odd = odd + int(s[i])

e_c = int((len(s)+1)/2)
o_c = len(s)-e_c

e1 = e_c - even + odd
o1 = o_c - odd + even
if(e1 > o1):
    print(o1)
else:
    print(e1)

Submission status: Accepted

Solution code:
S=str(input())
a=0
b=0
c=0
d=0
for i in range(0,len(S),1):
  if i%2==1 and S[i]=="1": #奇数番目が1
    a+=1
  if i%2==0 and S[i]=="1": #偶数番目が1
    b+=1
  if i%2==1 and S[i]=="0": #奇数番目が0
    c+=1
  if i%2==0 and S[i]=="0": #偶数番目が0
    d+=1

A=a+d
C=b+c
if A>=C:
  print(len(S)-A)
elif A<C:
  print(len(S)-C)

Submission status: Accepted

Solution code:
s = [int(i) for i in input()]
n = len(s)

p1 = [i for i in map(lambda n: n%2, range(n))]
p2 = [i for i in map(lambda n: (n+1)%2, range(n))]

s1,s2 = 0,0

for i in range(n):
    if s[i] != p1[i]:
        s1 += 1
    if s[i] != p2[i]:
        s2 += 1

print(min(s1, s2))

Submission status: Accepted

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

if len(S) <= 1:
  print(0)
  exit()

zerone = ['0', '1']
a = 0
b = 0

def is_even(num):
  return 0  if num % 2 == 0 else 1

for i in range(len(S)):
  if S[i] != zerone[is_even(i)]:
    a += 1
  else:
    b += 1

print(a if a < b else b)

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:
# 入力
S = str(input())
# 配列に変換
S_list = list(S)

S_len  = len(S_list)
## B = 0, W = 1
##BWB
BWB_list = ["0"] * S_len
for i in range(S_len):
  if i % 2 != 0:
    BWB_list[i] = "1"
## print("BWB_list:"+str(BWB_list))

##WBW
WBW_list = ["1"] * S_len
for i in range(S_len):
  if i % 2 != 0:
    WBW_list[i] = "0"
## print("WBW_list:"+str(WBW_list))

    
## cost	の計算
##BWB
BWB_cost = 0
for (target, bwb) in zip(S_list, BWB_list):
  if target != bwb:
    BWB_cost += 1
## WBW
WBW_cost = 0
for (target, wbw) in zip(S_list, WBW_list):
  if target != wbw:
    WBW_cost += 1
    
## print("BWB_cost:"+str(BWB_cost))
## print("WBW_cost:"+str(WBW_cost))
print(str( min(BWB_cost,WBW_cost) ) )

Submission status: Accepted

Solution code:
S = list(input())
count1 = 0
count2 = 0

for i in range(int(len(S)/2)):
    if S[2*i] == "0" and S[2*i+1] == "1":
        count1 += 2
    elif S[2*i] == "1" and S[2*i+1] == "0":
        count2 += 2
    else:
        count1 += 1
        count2 += 1

if len(S)%2 == 0:
    if count1 >= count2:
        print(count2)
    else:
        print(count1)
else:
    if S[-1] == "0":
        count1 += 1
    else:
        count2 += 1
    
    if count1 >= count2:
        print(count2)
    else:
        print(count1)

Submission status: Accepted

Solution code:
s = raw_input()

s_str = list(str(s))
list_0 = []
list_1 = []
count_0 = 0
count_1 = 0

for i in range(0,len(s_str)):
 if i%2 == 0:
  list_0.extend(s_str[i])
 else:
  list_1.extend(s_str[i])

v0 = list_0.count("1")
v1 = list_1.count("1")

if v0 > v1:
 v = v1 + list_0.count("0")
else:
 v = v0 + list_1.count("0")

print v

Submission status: Accepted

Solution code:
s = input()
l = len(s)
a = 0
for i in range(l):
  if i&1 == 0:
    a <<= 2
    a += 1
b = ((2**l)-1) ^ a

S = int(s, 2)
A = bin(S^a).count('1')
B = bin(S^b).count('1')
print(min(A, B))

Submission status: Accepted

Solution code:
string = str(input())
lis = []

for s in string:
  lis.append(int(s))
  
ans = 0
itr = 0
j = 0
for i in lis:
  if len(lis) == 1:
    break
    
  if itr == 0:
    itr += 1
    j = i
    continue
    
  if  j == i:
    ans += 1
    if i == 1:
      j = 0
    else:
      j = 1
  else:
    j = i
    continue

print(ans)

Submission status: Accepted

Solution code:
import  numpy as np

s = input()
x = [int(str) for str in list(s)]
a0 = [0]
a1 = [1]

for i, v in enumerate(x):
    if i == 0:
        continue
    else:
        if a0[i-1] == 0:
            a0.append(1)
        else:
            a0.append(0)

        if a1[i-1] == 0:
            a1.append(1)
        else:
            a1.append(0)

x = np.array(x)
a0 = np.array(a0)
a1 = np.array(a1)

num_a0 = np.sum(x != a0)
num_a1 = np.sum(x != a1)

print(min(num_a0, num_a1))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
s0 = 0
s1 = 0

for i in range(n):
    if i % 2 == 0:
        if S[i] != "0":
            s0 += 1
        else :
            s1 += 1
    
    else:
        if S[i] != "1":
            s0 += 1
        else:
            s1 += 1

if s0 > s1:
    print(s1)
else:
    print(s0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 21:15:41 2019

@author: screamLab
"""

s = input()

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

Submission status: Accepted

Solution code:
S = input()

a = int("".join(["0" if i%2 == 0 else "1" for i in range(len(S))]), 2)
b = int("".join(["0" if i%2 == 1 else "1" for i in range(len(S))]), 2)


a_ = int(S, 2) ^ a
b_ = int(S, 2) ^ b

cnt1 = 0
cnt2 = 0

for c1 in bin(a_)[2:]:
    if c1 == "1":
        cnt1 += 1

for c2 in bin(b_)[2:]:
    if c2 == "1":
        cnt2 += 1

if cnt1 > cnt2:
    print(cnt2)
else:
    print(cnt1)

Submission status: Accepted

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

count1=0
count2=0

for i in range(0,length):
	if i%2==0:
		if s[i]=='0':
			count1+=1
		else:
			count2+=1
	if i%2==1:
		if s[i]=='0':
			count2+=1
		else:
			count1+=1

if count1>=count2:
	print(count2)
else:
	print(count1)

Submission status: Accepted

Solution code:
Tiles=input()
N_len=len(Tiles)
if N_len == 1:
    print("0")
    exit()
    
cur=Tiles[0]

change=0
for i in range(1, N_len):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change+=1

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

    #print("new cur={}".format(cur))

min_change = change


change_first=1
if Tiles[0] == "0":
    cur = "1"
else:
    cur = "0"

for i in range(1, N_len):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_first+=1
        if min_change <= change_first:
            break

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]
        
if min_change > change_first:
    min_change = change_first

        
change_reverse=0
cur=Tiles[N_len-1]
for i in reversed(range(0, N_len-1)):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_reverse+=1
        if min_change <= change_reverse:
            break


        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

    #print("new cur={}".format(cur))
    
if min_change > change_reverse:
    min_change = change_reverse


change_reverse_first=1
if Tiles[N_len-1] == "0":
    cur = "1"
else:
    cur = "0"

for i in reversed(range(0, N_len-1)):
    #print("i={}".format(i))
    #print("cur={}".format(cur))
    #print("next={}".format(Tiles[i]))
    if cur is Tiles[i]:
        change_reverse_first+=1
        if min_change <= change_reverse_first:
            break

        if Tiles[i] == "0":
            cur = "1"
        else:
            cur ="0"
    else:
        cur=Tiles[i]

if min_change > change_reverse_first:
    min_change = change_reverse_first

print(str(min_change))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

S0 = "0"
S1 = "1"

S00 = ""
SA = ""

for i in range(len(S)):

    S00 += str(abs(int(S0) - (i % 2)))

for i in range(len(S)):

    SA += str(int(S[i]) ^ int(S00[i]))

print(min(SA.count("0"), SA.count("1")))

Submission status: Accepted

Solution code:
S = input()

a=0
b=0
for i,s in enumerate(S):
    if  i% 2 == 0:
        if s =="0":
            a += 1
        else:
            b += 1
    else:
        if s=="0":
            b+=1
        else:
            a+=1
ans = min(a,b)
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
loop = len(S)//2
if len(S)%2 == 1:
    odd = 1
else:
    odd = 0
A = 0
B = 0
for x in range(loop):
    if S[x*2] == "0":
        A += 1
    if S[1+x*2] == "1":
        A += 1
for x in range(loop):
    if S[x*2] == "1":
        B += 1
    if S[1+x*2] == "0":
        B += 1
if odd == 1:
        if S[-1] == "0":
            A += 1 
        else:
            B += 1
if A < B:
    ans = A
else:
    ans = B
print(ans)

Submission status: Accepted

Solution code:
s = input()

num = len(s)
case1 = ''
case2 = ''
item1 = '1'
item2 = '0'
for item in range(len(s)):
    case1 += item1
    case2 += item2
    if item1 == '1':
        item1 = '0'
    else:
        item1 = '1'

    if item2 == '1':
        item2 = '0'
    else:
        item2 = '1'

count1 = 0
count2 = 0
for i in range(len(s)):
    if case1[i] != s[i]:
        count1 += 1
    if case2[i] != s[i]:
        count2 += 1
ret = min(count1, count2)
print(ret)

Submission status: Accepted

Solution code:
S = input()

N = len(S)

S = list(S)
count = 0
for i in range(1, N):
    if S[i] == S[i - 1]:
        S[i] = "1" if S[i - 1] == "0" else "0"
        count += 1

print(count)

Submission status: Accepted

Solution code:
S = input()
S = list(S)
for i in range(len(S)):
    S[i] = int(S[i])
dic = {0:1,1:0}

S1 = S[:]
S2 = S[:]

S2[0] = dic[S2[0]]
cnt1 = 0
cnt2 = 1


for i in range(len(S1)-1):
    if S1[i] == S1[i+1]:
        S1[i+1] = dic[S1[i+1]]
        cnt1 += 1



for i in range(len(S2)-1):
    if S2[i] == S2[i+1]:
        S2[i+1] = dic[S2[i+1]]
        cnt2 += 1


print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = tuple(input())
n = len(s)
count_0start = 0
count_1start = 0

for i in range(n)[::2]:
    if s[i] == '0':
        count_0start += 1
    else:
        count_1start += 1
    
for i in range(n)[1::2]:
    if s[i] == '1':
        count_0start +=1
    else:
        count_1start += 1

print(count_0start if count_0start < count_1start else count_1start)

Submission status: Accepted

Solution code:
a = input()
inp = [int(i) for i in a]

cnt = 0

#はじめに偶数枚目、奇数枚目に同じ番号が連続する値を探す

gu_0 = 0
gu_0_score = 0
gu_1 = 0
gu_1_score = 0
ki_0 = 0
ki_0_score = 0
ki_1 = 0
ki_1_score = 0

for index, i in enumerate(inp):
	if index % 2 == 0:
		if i == 0:
			gu_0 += 1
		else:
			gu_1 += 1
	else:
		if i == 0:
			gu_1 += 1
		else:
			gu_0 += 1

maxscore = max([gu_0,gu_1,ki_0,ki_1])
			
if gu_0 + ki_1 == len(inp) or gu_1 + ki_0 == len(inp):
	print(0)
else:
	for score in [gu_0,gu_1,ki_0,ki_1]:
		if maxscore > score and score != 0:
			maxscore = score
	print(maxscore)
#

Submission status: Accepted

Solution code:
s = list(input())

if len(s) == 1:
  print(0)
  exit()

ans = 0

for i in range(1, len(s)):
  if s[i-1] == s[i]:
    ans += 1
    if s[i] == '0':
      s[i] = '1'
    else:
      s[i] = '0'
  else:
    prev = s[i]

print(ans)

Submission status: Accepted

Solution code:
A = input()
A = list(A)
A = list(map(int,A))
B = [0 for _ in range(len(A))]
C = [1 for _ in range(len(A))]
for i in range(len(A)):
    if i%2==0:
        B[i] = 1
        C[i] = 0
count1 = 0
count2 = 0
for i in range(len(A)):
    if A[i]!=B[i]:
        count1 +=1
    if A[i]!= C[i]:
        count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:



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

def reverse(i):
    return (i+1)%2

ans1 = 0
expect = S[0]
for s in S:
    if s != expect:
        ans1 += 1
    expect = reverse(expect)

ans2 = 0
expect = reverse(S[0])
for s in S:
    if s != expect:
        ans2 += 1
    expect = reverse(expect)


print(min(ans1, ans2))

Submission status: Accepted

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

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator

S = input()
N = len(S)


s1 = S[0::2]
b1 = s1.count('0')
w1 = len(s1) - b1
s2 = S[1::2]
b2 = s2.count('0')
w2 = len(s2) - b2

print(min(b1 + w2, w1 + b2))

Submission status: Accepted

Solution code:
S = str(input())
cnt = 0
ch_flag = 0 

for i in range(len(S)):
  if(i + 1) >= len(S): 
    break
  if(ch_flag == 1):
    if(S[i] == '0'):
      tmp = '1'
    else:
      tmp = '0'
    ch_flag = 0
  else:
    tmp = S[i]
  if (tmp == S[i + 1]):
    ch_flag = 1
    cnt += 1
print(cnt)