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()

a=[]
b=[]

for i in range(len(s)):
  if i%2==0:
    a.append(0)
    b.append(1)
  else:
    a.append(1)
    b.append(0)
ans1=0
ans2=0
for i in range(len(s)):
  if a[i]==int(s[i]):
    ans1+=1

for i in range(len(s)):
  if b[i]==int(s[i]):
    ans2+=1    
    

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
alt = '0'
n = 0
for c in S:
  if c == alt:
    n += 1
  if alt == '0':
    alt = '1'
  else:
    alt = '0'

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

Submission status: Accepted

Solution code:
a= input()

ans, res = 0,0
#white
for i in range(len(a)):
	if i % 2:
		if a[i] == '1':
			ans += 1
	else:
		if a[i] == '0':
			ans += 1
	
#black
for i in range(len(a)):
	if i % 2:
		if a[i] == '0':
			res += 1
	else:
		if a[i] == '1':
			res += 1

print(min(ans,res))

Submission status: Accepted

Solution code:
s = str(input())
odd = s[1::2]
even = s[0::2]
a = odd.count("0") + even.count("1")
b = odd.count("1") + even.count("0")
print(min(a,b))

Submission status: Accepted

Solution code:
S=input()
l,len01,len10=2,0,0
for i in range(len(S)):
	if (l%2==0)&(S[i]=='1'):
		len10+=1
	elif (l%2==0)&(S[i]=='0'):
		len01+=1
	if (l%2==1)&(S[i]=='1'):
		len01+=1
	elif (l%2==1)&(S[i]=='0'):
		len10+=1
	l+=1
print(min(len01,len10))

Submission status: Accepted

Solution code:
s=input()
odd,even=s[1::2],s[0::2]
print(min(odd.count('1')+even.count('0'),odd.count('0')+even.count('1')))

Submission status: Accepted

Solution code:
def subtract_lst (lst1, lst2):
    ans = 0
    for i in range(len(lst1)):
        e1 = lst1[i]
        e2 = lst2[i]
        if e1 != e2:
            ans += 1
    return ans

if __name__ == '__main__':
    s = input()
    lenS = len(s)
    a = ""
    b = ""
    for i in range(lenS // 2):
      a = a + "10"
      b = b + "01"
    if lenS % 2 == 1:
        a = a + "1"
        b = b + "0"
    aAns = subtract_lst (a, s)
    bAns = subtract_lst (b, s)
    print (min(aAns, bAns))

Submission status: Accepted

Solution code:
s=list(input())
odd,even=s[1::2],s[0::2]
print(min(even.count('0') + odd.count('1'), even.count('1') + odd.count('0')))

Submission status: Accepted

Solution code:
s = input()

a = "01"*int(len(s)/2) + "0"*int(len(s)%2)
b = "10"*int(len(s)/2) + "1"*int(len(s)%2)

a_count = 0
b_count = 0
for i, j, k in zip(a, b, s):
    if i != k:
        a_count += 1
    if j != k:
        b_count += 1

print(min(a_count, b_count))

Submission status: Accepted

Solution code:
#入力
S = list(input())

N = len(S)
count_1010 = 0
count_0101 = 0
#処理 初めの数字について場合分け
#1始まり 1010...
for i in range(N):
    #奇数文字目 (1になる)
    if i % 2 == 0:
        if S[i] != "1":
            count_1010 += 1
    #偶数文字目 (0になる)
    else:
        if S[i] != "0":
            count_1010 += 1

#0始まり 0101...
for j in range(N):
    #奇数文字目 (0になる)
    if j % 2 == 0:
        if S[j] != "0":
            count_0101 += 1
    #偶数文字目 (1になる)
    else:
        if S[j] != "1":
            count_0101 += 1

#出力
print(min(count_0101, count_1010))

Submission status: Accepted

Solution code:
S = input()
a = [1 if i%2==0 else 0 for i in range(len(S))]
cnt = 0
for c in list(zip(S,a)):
    if int(c[0]) == c[1]: cnt += 1
print(min(cnt,len(S)-cnt))

Submission status: Accepted

Solution code:
#abc124bc

s=[int(s) for s in raw_input()]
s0=[x%2 for x in xrange(len(s))]
s1=[(x^1)%2 for x in xrange(len(s))]
t0,t1=[],[]
for i in xrange(len(s)):
 t0.append(s[i]^s0[i])
 t1.append(s[i]^s1[i])
print min(sum(t0),sum(t1))

Submission status: Accepted

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


def solve(S: int):
    first0 = 0
    first1 = 0
    for i in range(len(S)):
        c = S[i]
        if i % 2 == 0:
            if c == '0':
                first0 += 1
            else:
                first1 += 1
        else:
            if c == '0':
                first1 += 1
            else:
                first0 += 1
    print(min(first0, first1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: int
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
s=input()
count =0
isSuccession = True #True:1 False:0
for i in range(len(s) -1):
    if s[i] != s[i+1]:
        if isSuccession == False:
            count +=1
    else:
        isSuccession = (isSuccession+1)%2
        if isSuccession == False:
            count +=1
print(min(count, len(s) - count))

Submission status: Accepted

Solution code:
l = list(input())

ans1 = 0
ans2 = 0

for i in range(len(l)):
  if i % 2 == 0:
    if l[i] == "0":
      ans1 += 1
    if l[i] == "1":
      ans2 += 1  
  else:
    if l[i] == "1":
      ans1 += 1
    if l[i] == "0":
      ans2 += 1
    
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import numpy

s = list(input())
N = len(s)
count_A = 0
count_B = 0

for i in range(N):
    s[i] = int(str(s[i]))

A = numpy.empty(N)
B = numpy.empty(N)

for j in range(N):
    if j % 2 == 0 :
        A[j] = 1
        B[j] = 0
    else:
        A[j] = 0
        B[j] = 1

for k in range(N):
    A[k]=s[k]-A[k]
    B[k]=s[k]-B[k]
    if A[k] != 0:
        count_A = count_A + 1
    if B[k] != 0:
        count_B = count_B + 1

if count_A > count_B :
    print(count_B)
else :
    print(count_A)

Submission status: Accepted

Solution code:
N = str(input())
N_list = [int(x) for x in list(N)]
counter = 0
mae = N_list[0]
for i in range(len(N_list)-1):
    if N_list[i+1]==mae:
        counter +=1
        if mae == 0:
            N_list[i+1]=1
        else:
            N_list[i+1]=0

    mae=N_list[i+1]

print(counter)

Submission status: Accepted

Solution code:
s = input()
count_0 = 0
count_1 = 0
for i, si in enumerate(s):
    if i % 2 == 0 and si == '1':
        count_0 += 1
    elif i % 2 == 1 and si == '0':
        count_0 += 1

for i, si in enumerate(s):
    if i % 2 == 0 and si == '0':
        count_1 += 1
    elif i % 2 == 1 and si == '1':
        count_1 += 1

print(min(count_0, count_1))

Submission status: Accepted

Solution code:
S = input()

ans1 = 0
ans0 = 0

for s in S:
    if s == "0":
        ans1 += 1
    elif s == "1":
        ans0 += 1
    ans1, ans0 = ans0, ans1

print(min(ans1, ans0))

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


s = IS()
P(min(s[::2].count('1')+s[1::2].count('0'), s[::2].count('0')+s[1::2].count('1')))

Submission status: Accepted

Solution code:
S=input()
a,b=list(map(int,S[::2])),list(map(int,S[1::2]))
p,q=sum(a),sum(b)
r,s=len(a)-sum(a),len(b)-sum(b)
print(min(p+s,q+r))

Submission status: Accepted

Solution code:
S = input()
S = list(S)
b_num =0
w_num = 0
for i in range(0,len(S),2):
    if S[i] == '0':
        b_num +=1
    else:
        w_num += 1
for i in range(1,len(S),2):
    if S[i] == '0':
        w_num +=1
    else:
        b_num += 1

ans = min([b_num , w_num])
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float('inf')
MOD = 10**9+7
dy = [0,1,0,-1]
dx = [1,0,-1,0]
ddy = [0,1,1,1,0,-1,-1,-1]
ddx = [1,1,0,-1,-1,-1,0,1]

S = input()
res1 = S[::2].count('1')+S[1::2].count('0')
res2 = S[1::2].count('1')+S[::2].count('0')
print(min(res1,res2))

Submission status: Accepted

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

# 01010... か 10101...の二択

# 0...
err1 = 0
for i in range(n):
    if i % 2 == 0 and s[i] == "1":
        err1 += 1
    elif i % 2 == 1 and s[i] == "0":
        err1 += 1

# 1...
err2 = 0
for i in range(n):
    if i % 2 == 0 and s[i] == "0":
        err2 += 1
    elif i % 2 == 1 and s[i] == "1":
        err2 += 1

print(min(err1, err2))

Submission status: Accepted

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

    import itertools
    x = sum(map(lambda t: t[0]==t[1], zip(s,itertools.cycle("01"))))
    y = sum(map(lambda t: t[0]==t[1], zip(s,itertools.cycle("10"))))
    print(min(x,y))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    x = "01" * (len(s)//2+1)
    y = "10" * (len(s)//2+1)

    x = sum(map(lambda t: t[0]==t[1], zip(s,x)))
    y = sum(map(lambda t: t[0]==t[1], zip(s,y)))
    print(min(x,y))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

cnt1 = 0
cnt2 = 0
for i, char in enumerate(s):
    if i % 2 == 0:
        if char == '1':
            cnt1 += 1
        else:
            cnt2 += 1
    else:
        if char == '1':
            cnt2 += 1
        else:
            cnt1 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()

ans1 = 0
for i in range(len(s)):
    if i % 2 == 0 and s[i] == '0':
        ans1 += 1
    elif i % 2 == 1 and s[i] == '1':
        ans1 += 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(ans1, ans2))

Submission status: Accepted

Solution code:
S=list(input())
N=len(S)
S_int_1=list(S)
S_int_2=list(S)
for i in range(N):
    S_int_1[i]=int(S[i])
    S_int_2[i]=int(S[i])
cnt_1=0
cnt_2=0
for i in range(N):
    if i%2==0 and S_int_1[i]==0:
        S_int_1[i]=1
        cnt_1+=1
    elif i%2==1 and S_int_1[i]==1:
        S_int_1[i]=0
        cnt_1+=1
for i in range(N):
    if i%2==0 and S_int_2[i]==1:
        S_int_2[i]=0
        cnt_2+=1
    elif i%2==1 and S_int_2[i]==0:
        S_int_2[i]=1
        cnt_2+=1
print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
S = input()

answer1 = '10' * (len(S) // 2) + '1' * (len(S) % 2)
answer2 = '01' * (len(S) // 2) + '0' * (len(S) % 2)
count1 = bin(int(answer1, 2) ^ int(S, 2))[2:].count('1')
count2 = bin(int(answer2, 2) ^ int(S, 2))[2:].count('1')
print(min(count1, count2))

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i,j in enumerate(s):
  if i % 2 == 0:
    if j == "0":
      ans += 1
  else:
    if j == "1":
      ans += 1
print(min(ans,len(s)-ans))

Submission status: Accepted

Solution code:
S = input()
cnt = [[0,0],[0,0]]
for i, s in enumerate(S):
    x = int(i) % 2
    y = int(s)
    cnt[x][y] += 1
print(min(cnt[0][1] + cnt[1][0], cnt[0][0] + cnt[1][1]))

Submission status: Accepted

Solution code:
Tiles=input()

N_len=len(Tiles)
type1 = sum( 1 if int(Tiles[i]) == (i%2) else 0 for i in range(N_len))
type2 = sum( 0 if int(Tiles[i]) == (i%2) else 1 for i in range(N_len))
print(min(type1,type2))

Submission status: Accepted

Solution code:
Tiles=input()

N_len=len(Tiles)
type1 = sum( 1 if Tiles[i] == str(i%2) else 0 for i in range(N_len))
type2 = sum( 0 if Tiles[i] == str(i%2) else 1 for i in range(N_len))
print(min(type1,type2))

Submission status: Accepted

Solution code:
Tiles=input()

N_len=len(Tiles)

type1 = 0

# １スタート
for i in range(N_len):
    if Tiles[i] == str(i%2):
        type1 += 1
        
# 0スタート
type2=0
for i in range(N_len):
    if Tiles[i] != str(i%2):
        type2 += 1
        
print(min(type1,type2))

Submission status: Accepted

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

cost=0
for i in range(0,N,2):
	if S[i]=='1':
		cost+=1
	if i!=N-1:
		if S[i+1]=='0':
			cost+=1
print(min(cost,N-cost))

Submission status: Accepted

Solution code:
S = input()
ans = 0
if S[0] == '0':
    for i, x in enumerate(S):
        if i % 2 == 0 and x == '1':
            ans += 1
        elif i % 2 == 1 and x == '0':
            ans += 1
elif S[0] == '1':
    for i, x in enumerate(S):
        if i % 2 == 0 and x == '0':
            ans += 1
        elif i % 2 == 1 and x == '1':
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
ans1 = s[::2].count('0') + s[1::2].count('1')
ans2 = s[::2].count('1') + s[1::2].count('0')
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
#C 
S =input()
s0=0
s1=0
for i in range(len(S)):
    if i%2==0 and S[i]=="0":
        s1+=1
    elif i%2==0:
        s0+=1
    elif i%2!=0 and S[i]=="0":
        s0+=1
    elif i%2!=0:
        s1+=1
print(min(s0,s1))

Submission status: Accepted

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

pre = a[0]
chenge = 0
for i in range(1,len(a)):
    if pre == "0" and a[i] == "0":
        a = a[:i] + "1" + a[i+1:]
        chenge += 1
    elif pre == "1" and a[i] == "1":
        a = a[:i] + "0" + a[i+1:]
        chenge += 1
    else:
        pass
    pre = a[i]

print(chenge)

Submission status: Accepted

Solution code:
def c_coloring_colorfully(S):
    ans1 = S[::2].count('0') + S[1::2].count('1')  # 1010...と一致しない数字の数
    ans2 = S[::2].count('1') + S[1::2].count('0')  # 0101...と一致しない数字の数
    return min(ans1, ans2)

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

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
if S[0] == "1":
	for i in range(len(S)):
		if i % 2 == 0 and S[i] == "0":
			ans += 1
		if i % 2 == 1 and S[i] == "1":
			ans += 1
else:
	for i in range(len(S)):
		if i % 2 == 0 and S[i] == "1":
			ans += 1
		if i % 2 == 1 and S[i] == "0":
			ans += 1
print(ans)

Submission status: Accepted

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

count = 0
tmp = S[0]
for ii in S:
    if ii != tmp:
        count += 1
    tmp = abs(tmp-1)

print(count)

Submission status: Accepted

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

count = 0
tmp = S[0]
for ii in S:
    if ii != tmp:
        count += 1
    if tmp == 1:
        tmp = 0
    else:
        tmp = 1


print(count)

Submission status: Accepted

Solution code:
import numpy as np
S = list(map(int, input()))

tmp = [0]*len(S)
if S[0] == 1:
    for ii in range(0,len(S),2):
        tmp[ii] = 1
else:
    for ii in range(1,len(S),2):
        tmp[ii] = 1

A = []
for ii in range(len(tmp)):
    A.append(S[ii]-tmp[ii])
    
count = np.count_nonzero(A)

print(count)

Submission status: Accepted

Solution code:
S = input().strip()
ansB = 0
ansW = 0
for i,c in enumerate(S):
	if (i % 2 == 0):
		if (c == '0'):
			ansW += 1
		else:
			ansB += 1
	else:
		if (c == '1'):
			ansW += 1
		else:
			ansB += 1
ans = min(ansW, ansB)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
p = 0 #1010
q = 0 #0101
n = len(s)
for i in range(n):
    if i % 2 == 0:
        if s[i] == "1":
            p += 1
        else:
            q += 1
    else:
        if s[i] == "1":
            q += 1
        else:
            p += 1

print(n - max(p,q))

Submission status: Accepted

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

count = 0
for ii in range(1,len(S)):
    if S[ii-1] == S[ii]:
        if S[ii] == 1:
            S[ii] = 0
        else:
            S[ii] = 1
        count += 1

print(count)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
even_white = 0
odd_white = 0
for i in range(N):
    if i % 2 == 0:
        if S[i] == '1':
            even_white += 1
    else:
        if S[i] == '1':
            odd_white += 1
even_black = (N + 1) // 2 - even_white
odd_black = N // 2 - odd_white
# cost to change S into '0101..'
cost01 = even_white + odd_black
# cost to change S into '1010..'
cost10 = even_black + odd_white
cost = min(cost01, cost10)
print(cost)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
count=0
if s[0]=='0':
    for i in range(1,n):
        if i%2==1 and s[i]=='0':
            count+=1
        elif i%2==0 and s[i]=='1':
            count+=1
else:
    for i in range(1,n):
        if i%2==1 and s[i]=='1':
            count+=1
        elif i%2==0 and s[i]=='0':
            count+=1
print(count)

Submission status: Accepted

Solution code:
s = input()
s_len = len(s)
s = int(s)
s_1 = '1'
s_0 = '0'

for i in range(0,s_len-1):
    if i%2==0:
        s_1 = s_1 + '0'
    else:
        s_1 = s_1 + '1'

for i in range(0,s_len-1):
    if i%2==0:
        s_0 = s_0 + '1'
    else:
        s_0 = s_0 + '0'

s_1 = int(s_1)
s_0 = int(s_0)

s_1_1 = str(s+s_1)
s_0_1 = str(s+s_0)

count_1=0
count_0=0
for i in s_1_1:
    if int(i)==1:
        count_1+=1
for i in s_0_1:
    if int(i)==1:
        count_0+=1
 
print(min(count_0,count_1))

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
s10 = ['1' if i%2==0 else '0' for i in range(N)]
s01 = ['0' if i%2==0 else '1' for i in range(N)]
ans10, ans01 = 0, 0
for i in range(N):
    if S[i] != s10[i]:
        ans10 += 1
    elif S[i] != s01[i]:
        ans01 += 1
print(min(ans10, ans01))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
one_zero_list = ['0' if i%2==0 else '1' for i in range(len(s))]
zero_one_list = ['1' if i%2==0 else '0' for i in range(len(s))]

count_one_zero = len([0 for i in range(len(s)) if s[i]!=one_zero_list[i]])
count_zero_one = len([0 for i in range(len(s)) if s[i]!=zero_one_list[i]])

print(min(count_one_zero,count_zero_one))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
#入力
S = input()
#入力値を取り出す
A = np.array([int(S[i]) for i in range(len(S))])
C = np.zeros(len(S), dtype='int')
C[1:len(S):2] = 1
D = np.zeros(len(S), dtype='int')
D[0:len(S):2] = 1
print(np.min([np.sum(A!=C), np.sum(A!=D)]))

Submission status: Accepted

Solution code:
n=input()
li=list(n)
if len(n)==1:
  print(0)
elif len(n)%2==0:
  counta=0 
  countb=0
  a=list("10"*int((int(len(n))/2)))
  b=list("01"*int((int(len(n))/2)))
  for i in range(len(n)):
    counta+= abs(int(li[i])-int(a[i]))
    countb+=abs(int(li[i])-int(b[i]))
  print(min(counta,countb))

elif len(n)%2==1 and len(n) != 1:
  countaa=0 
  countbb=0
  aa=list("10"*int(((int(len(n))-1)/2))+"1")
  bb=list("01"*int(((int(len(n))-1)/2))+"0")
  for i in range(len(n)):
    countaa+=abs(int(li[i])-int(aa[i]))
    countbb+=abs(int(li[i])-int(bb[i]))
  print(min(countaa,countbb))

Submission status: Accepted

Solution code:
S = str(input())

err1, err2 = 0, 0

for i in range(len(S)):
    if S[i] != str(int(bool(int(i%2)))):
        err1 += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
odd = s[::2]
even = s[1::2]
pred1 = len(even) - even.count("1") + (len(odd) - odd.count("0"))
pred2 = len(even) - even.count("0") + (len(odd) - odd.count("1"))
print(min(pred1, pred2))

Submission status: Accepted

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

for i in range(2):
  cnt = 0
  for j in range(len(S)):
    if j % 2 == 0 and S[j] != str(i):
      cnt += 1
    if j % 2 == 1 and S[j] == str(i):
      cnt += 1
  ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = 0
flag ='0'
for x in S:
    if flag != x:
        ans += 1
    if flag == '1':
        flag = '0'
    else:
        flag = '1'
print(min(ans,len(S)-ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s = list(map(int, s))
ans = len(s)
for i in range(2):
    cnt = 0
    for j, ss in enumerate(s):
        if (j + i) % 2 != ss: cnt += 1
    ans = min(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
raw = input()
s = bin(int(raw, 2))
n = len(raw)
m = bin(int(''.join([str(i%2) for i in range(n)]),2))
 
a = bin((int(s,2))^int(m,2)).count("1")
b = n-a
 
print(a if a < b else b)

Submission status: Accepted

Solution code:
s = input()
count_odd = 0
for i in range(len(s)): #010101のようにする
    if s[i] != str(i % 2):
        count_odd += 1
count_even = 0
for i in range(len(s)):
    if s[i] == str(i % 2):
        count_even += 1

print(min(count_odd, count_even))

Submission status: Accepted

Solution code:
S = input()
A = ''.join([str(i % 2) for i in range(len(S))])
B = ''.join([str((i + 1) % 2)  for i in range(len(S))])

ans1 = ans2 = 0

for s, a, b, in zip(S, A, B):
    if s != a:
        ans1 += 1
    if s != b:
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = list(input())
cnt = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        if S[i] == '0':
            S[i] = '1'
        else:
            S[i] = '0'
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
S = str(input())
N = len(S)

s0 = ''
s1 = ''

def count_diff(s):
    count = 0
    for i in range(N):
        if s[i] != S[i]:
            count += 1
    return(count)

for i in range(N):
    if i % 2 == 0:
        s0 = s0 + '0'
        s1 = s1 + '1'
    else:
        s0 = s0 + '1'
        s1 = s1 + '0'

print(min(count_diff(s0), count_diff(s1)))

Submission status: Accepted

Solution code:
s = input()
count = 0

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

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

Submission status: Accepted

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

ans = 99999999
for i in range(2):
    cnt = 0
    for j, s_j in enumerate(S):
        if (j % 2 == 0) ^ (s_j != i):
            cnt += 1
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
S = input()
c1 = Counter(S[::2])
c2 = Counter(S[1::2])
print(min(c1["0"] + c2["1"], c1["1"] + c2["0"]))

Submission status: Accepted

Solution code:
t = list(input())
 
ans = min(t[::2].count('0') + t[1::2].count('1'),t[::2].count('1') + t[1::2].count('0'))
     
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=str(input())
S=[]

for i in s:
    S.append(i)

if len(S)==1:
    print(0)
elif S[0]=='1':
    T=[0 for i in range(len(S)) if (i%2==0 and S[i]=='0') or (i%2==1 and S[i]=='1')]
    print(len(T))
elif S[0]=='0':
    T=[0 for i in range(len(S)) if (i%2==0 and S[i]=='1') or (i%2==1 and S[i]=='0')]
    print(len(T))

Submission status: Accepted

Solution code:
S = list(input())

def way1():
    ans = 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] == "1":
            ans += 1
        elif i % 2 == 1 and S[i] == "0":
            ans += 1
    return ans

def way2():
    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
    return ans


print(min(way1(), way2()))

Submission status: Accepted

Solution code:
s=input()
cnt1=0
cnt2=0
for i,c in enumerate(s):
    cnt1+=int(c)!=i%2
    cnt2+=int(c)!=(i+1)%2
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
number=list(input())

paturn1=list("10"*(10**5))
paturn2=list("01"*(10**5))
convert1=[int(x)^int(y) for x,y in zip(number,paturn1)]
convert2=[int(x)^int(y) for x,y in zip(number,paturn2)]

print(min([convert1.count(1),convert2.count(1)]))

Submission status: Accepted

Solution code:
S = [int(x) for x in list(input())]

min_0 = 0 # min_0 = 01010...
min_1 = 0 # min_1 = 10101...

for i in range(len(S)):
    if i % 2 ==0:
        if not (S[i] == 0):
            min_0 += 1
        else:
            min_1 += 1
    if i % 2 ==1:
        if not (S[i] == 1):
            min_0 += 1
        else:
            min_1 += 1
                
times = min([min_0, min_1])
print(times)

Submission status: Accepted

Solution code:
s=input()
Z=0
W=0
for i in range(len(s)):
  if int(s[i]) == i % 2:
    Z += 1
  else:
    W += 1
print(min(Z,W))

Submission status: Accepted

Solution code:
S = [int(x) for x in list(input())]

min_0 = 0
min_1 = 0

for i in range(len(S)):
    if i % 2 ==0:
        if not (S[i] == 0):
            min_0 += 1
        elif not (S[i] == 1):
            min_1 += 1
    if i % 2 ==1:
        if not (S[i] == 1):
            min_0 += 1
        elif not (S[i] == 0):
            min_1 += 1
                
times = min([min_0, min_1])
print(times)

Submission status: Accepted

Solution code:
S = input()
even = S[0::2]
odd = S[1::2]
N = len(S)

tmp_e = N - (even.count("1")+odd.count("0"))
tmp_o = N - (even.count("0")+odd.count("1"))

print(min(tmp_e, tmp_o))

Submission status: Accepted

Solution code:
s=list(input())
l = len(s)
zero = [i % 2 for i in range(0, l)]
one = [(i+1) % 2 for i in range(0, l)]
strs_zero = [str(num) for num in zero]
strs_one = [str(num) for num in one]
import numpy as np
s_np = np.array(s)
zero_np = np.array(strs_zero)
one_np = np.array(strs_one)
count_zero = l - np.sum(s_np == zero_np)
count_one = l - np.sum(s_np == one_np)
if count_zero < count_one:
    print(count_zero)
else:
    print(count_one)

Submission status: Accepted

Solution code:
import numpy as np
S=np.array([int(s) for s in input()])
N=len(S)

goal1=np.array([(i%2) for i in range(N)])
goal2=np.array([1-(i%2) for i in range(N)])

print(min(np.sum(np.logical_xor(S,goal1)),np.sum(np.logical_xor(S,goal2))))

Submission status: Accepted

Solution code:
S = list(map(int, input()))
ans = [0, 0]

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

print(min(ans))

Submission status: Accepted

Solution code:
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#import math
#n=int(input())
#li=input().split()
#n=int(input())
#lis=list(map(int,input().split()))

S=input()
l=len(S)

a,b=0,0
#01010...という文字列との比較
for i in range(l):
    if i%2==1 and S[i]=="0":
        a+=1
    elif i%2==0 and S[i]=="1":
        a+=1

#10101...という文字列との比較
for i in range(l):
    if i%2==1 and S[i]=="1":
        b+=1
    elif i%2==0 and S[i]=="0":
        b+=1
c=max(a,b)

ans=l-c

print(ans)

Submission status: Accepted

Solution code:
S = input()
ans = [0, 0]

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

    
print(min(ans))

Submission status: Accepted

Solution code:
S = list(input())

a0 = 0
a1 = 0
b0 = 0
b1 = 0

f = True
for s in S:
    if f:
        if s == '0':
            a0 += 1
        else:
            a1 += 1
        f = False
    else:
        if s == '0':
            b0 += 1
        else:
            b1 += 1
        f = True

ans = min(a0 + b1, a1 + b0)
print(ans)

Submission status: Accepted

Solution code:
x = input()
point1 = 0
for i in range(len(x)):
    if i % 2 == 0 and x[i] == '0':
        point1 += 1
    elif i % 2 == 1 and x[i] == '1':
        point1 += 1

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

print(min(point1,point2))

Submission status: Accepted

Solution code:
s = input()
N = len(s)
t_01 = '01' * (N // 2) + ('0' if N % 2 == 1 else '')
t_10 = '10' * (N // 2) + ('1' if N % 2 == 1 else '')

# print(s)
# print(t_01)
# print(t_10)

s_n = int(s, 2)
t_01_n = int(t_01, 2)
t_10_n = int(t_10, 2)

# print(s_n)
# print(t_01_n)
# print(t_10_n)

ans = N
for x in s_n ^ t_01_n, s_n ^ t_10_n:
    ans = min(ans, bin(x)[2:].count('1'))

print(ans)

Submission status: Accepted

Solution code:
S = input()
c = 0
zo = 0 # zero-one
oz = 0 # one-zero
for i in range(0, len(S)//2 * 2, 2):
    if S[i] == '0':
        oz += 1
    else:
        zo += 1
    if S[i+1] == '0':
        zo += 1
    else:
        oz += 1
if len(S) & 1:
    if S[-1] == '0':
        oz += 1
    else:
        zo += 1
print(min(oz, zo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans = [0, 0]

for i in range(len(S)):
    if (i % 2 == 0 and S[i] != '1') or (i % 2 == 1 and S[i] != '0'):
        ans[0] += 1
    if (i % 2 == 0 and S[i] != '0') or (i % 2 == 1 and S[i] != '1'):
        ans[1] += 1
    
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(map(int,input()))
s2=list(reversed(s))

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

res2 = 0
for i in range(len(s2)-1):
	if s2[i] == s2[i+1]:
		if s2[i+1] == 0:
			s2[i+1]=1
		else:
			s2[i+1]=0
		res2 = res2 + 1

print(min(res,res2))