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:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    N = len(S)

    s = ["", ""]
    for i in range(N):
        for j in range(2):
            s[j] += str((i + j)%2)

    cnt = [0, 0]
    for i in range(N):
        for j in range(2):
            if s[j][i] != S[i]: cnt[j] += 1

    print(cnt[0] if cnt[0] < cnt[1] else cnt[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n%2==0:
  m=n//2
  ans1=(4**m-1)//3
  ans2=2*ans1
else:
  m=(n-1)//2
  ans1=(4**(m+1)-1)//3
  ans2=2*(4**m-1)//3

  
s=int(s,2)
tmp1=bin(ans1^s).count('1')
tmp2=bin(ans2^s).count('1')
print(min(tmp1,tmp2))

Submission status: Accepted

Solution code:
S = input()
d = int(S[0])
T = []
U = []
for i in range(len(S)):
  T.append(d)
  d = (d + 1) % 2
  U.append(d)
count1 = 0
count2 = 0
for i in range(len(S)):
  if int(S[i]) != T[i]:
    count1 += 1
  if int(S[i]) != U[i]:
    count2 += 1
print(min(count1, count2))

Submission status: Accepted

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

evensum=0
oddsum=0
for i in range(n):
    evenflg=i%2
    if s[i]=="0":
        if evenflg==1:
            oddsum=oddsum+1
        else:
            evensum=evensum+1
    else:
        if evenflg==0:
            oddsum=oddsum+1
        else:
            evensum=evensum+1
if evensum<oddsum:
    print(evensum)
else:
    print(oddsum)

Submission status: Accepted

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

if (s[0] == '0'):
   x = '01' * int(m/2)
   if (m % 2 == 1):
      x += '0'
else:
   x = '10' * int(m/2)
   if (m % 2 == 1):
      x += '1'

ans = [0 if s[i] == x[i] else 1 for i in range(m)]
print(sum(ans))

Submission status: Accepted

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

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

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = list(input())
ctr = S[::2].count('0') + S[1::2].count('1')  #0101...
answer=min(ctr,len(S)-ctr)
print(answer)

Submission status: Accepted

Solution code:
S = list(input())
S_con = []
ctr = 1

for i in range(len(S)-1):
    if (S[i] != S[i + 1]):
        ctr += 1
    else:
        S_con.append(ctr)
        ctr = 1

if (ctr > 1):
    S_con.append(ctr)
else:
    S_con.append(1)

even = sum(S_con[0::2])
odd=sum(S_con[1::2])
answer = min(even, odd)
print(answer)

Submission status: Accepted

Solution code:
s = input()
# 0, 2, 4, ..., 2n 番目がeven_position
even_position_nums = s[::2]
len_even = len(even_position_nums)
odd_position_nums = s[1::2]
len_odd = len(odd_position_nums)

# 辞書のほうが計算量的に良い（毎度O(n)かかっている）
# evenを0、oddを1にする
tmp = len_even - even_position_nums.count('1')
tmp1 = len_odd - odd_position_nums.count('0')
first = tmp + tmp1
# evenを1、oddを0にする
tmp = len_even - even_position_nums.count('0')
tmp1 = len_odd - odd_position_nums.count('1')
second = tmp + tmp1
print(min(first, second))

Submission status: Accepted

Solution code:
s = [int(x) for x in list(map(str, input()))]

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
s = list(input())
cnt1 = 0
cnt2 = 0
val1 = 0
val2 = 1
for i in range(len(s)):
    if int(s[i]) == val1 % 2:
        cnt1 += 1
    val1 += 1
    if int(s[i]) == val2 % 2:
        cnt2 += 1
    val2 += 1
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
def solve(s):
    l = len(s)
    even_0 = len([s[i] for i in range(l) if i % 2 == 0 and s[i] == '0'])
    even_1 = len([s[i] for i in range(l) if i % 2 == 0 and s[i] == '1'])
    odd_0 = len([s[i] for i in range(l) if i % 2 == 1 and s[i] == '0'])
    odd_1 = len([s[i] for i in range(l) if i % 2 == 1 and s[i] == '1'])

    return even_0 + odd_1 if even_0 + odd_1 < even_1 + odd_0 else even_1 + odd_0


if __name__ == '__main__':
    s = input()
    print(solve(s))

Submission status: Accepted

Solution code:
s = list(input())

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

count01 = 0
count10 = 0
for i in range(len(s)):
    if s[i] != l01[i]:
        count01 += 1

for i in range(len(s)):
    if s[i] != l10[i]:
        count10 += 1

print(min(count01, count10))

Submission status: Accepted

Solution code:
S = list(input())
s1 = S[::2]
s2 = S[1::2]
res1 = s1.count("0") + s2.count("1")
res2 = s1.count("1") + s2.count("0")
print(min(res1, res2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = tuple(map(int, tuple(input())))

    ans = 10 ** 5
    for i in range(2):
        v = i
        a = 0
        for s in S:
            if s != v:
                a += 1
            v = 1 if v == 0 else 0
        ans = min(ans, a)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8')
f0 = S[::2].count('1') + S[1::2].count('0')
f1 = S[::2].count('0') + S[1::2].count('1')

print(min(f1, f0))

Submission status: Accepted

Solution code:
s = input()
count_2 = 0
count_1 = 0
sum_2 = 0
sum_1 = 0
for i in range(0,len(s),2):
    sum_2 += 1
    if s[i] == "0":
        count_2 += 1
for i in range(1, len(s), 2):
    sum_1 += 1
    if s[i] == "0":
        count_1 += 1
p1 = sum_1 - count_1 + count_2
p2 = sum_2 - count_2 + count_1
if p1 <= p2:
    print(p1)
else:
    print(p2)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

curr = S[0]
count = 0
for i in range(1, len(S)):
    if curr == S[i]:
        if curr == '0':
            S[i] = '1'
        else:
            S[i] = '0'
        count = count + 1
    curr = S[i]

print(count)

Submission status: Accepted

Solution code:
S = input()

c = int(S, 2)
a = int(''.join('0' if x % 2 == 0 else '1' for x in range(len(S))), 2) ^ c
b = int(''.join('1' if x % 2 == 0 else '0' for x in range(len(S))), 2) ^ c

ax = len([x for x in str(bin(a)) if x == '1'])
bx = len([x for x in str(bin(b)) if x == '1'])

print(min(ax, bx))

Submission status: Accepted

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

odd = even = 0
for i in range(len(S)):
    if i % 2 + S[i] == 1:
        even += 1
    if i % 2 + S[i] != 1:
        odd += 1
print(min(odd, even))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
dic={"0":"1","1":"0"}

temp=[]
temp.append(s[0])
ans=0
for i in range(1,n):
    temp.append(dic[temp[i-1]])

for i in range(n):
    if temp[i]!=s[i]:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = sum((i+int(c))%2 for i,c in enumerate(s))
print(min(n, len(s)-n))

Submission status: Accepted

Solution code:
S=list(input())
A=[]
B=[]
a=0
b=0
for i in range(len(S)):
    if i%2==0:
        A.append("0")
    else:
        A.append("1")
for i in range(len(S)):
    if A[i]!=S[i]:
        a+=1
for j in range(len(S)):
    if j%2==0:
        B.append("1")
    else:
        B.append("0")
for j in range(len(S)):
    if B[j]!=S[j]:
        b+=1
print(min(a, b))

Submission status: Accepted

Solution code:
s=input()
li=[]
ans = 0
for i in range(len(s)):
  if i == 0:
    li.append(s[i])
  else:
    if s[i] == li[-1] and s[i] == "0":
      li.append("1")
      ans += 1
    elif s[i] == li[-1] and s[i] == "1":
      li.append("0")
      ans += 1
    else:
      li.append(s[i])
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

def main():
    S = cin.string()
    m,n = 0,0
    for i,s in enumerate(S):
        if i % 2 == 0:
            if s == "0":
                m+=1
            else:
                n+=1
        else:
            if s == "0":
                n +=1
            else:
                m +=1
    print(min(n,m))
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans1 = 0
ans2 = 0
for i in range(N):
    if i % 2 == 0:
        if S[i] == "0":
            ans1 += 1
        else:
            ans2 += 1
    else:
        if S[i] == "1":
            ans1 += 1
        else:
            ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().rstrip()

def main():
    s1 = s[::2]
    s2 = s[1::2]
    res1 = s1.count('1') + s2.count('0')
    res2 = s1.count('0') + s2.count('1')
    return min(res1, res2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

d = {0:{0:0, 1:0}, 1:{0:0, 1:0}}

for i, s in enumerate(S):
  d[i%2][S[i]] += 1


ans = min(d[0][0]+d[1][1], d[0][1]+d[1][0])
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(input())

for i in range(len(S)):
    S[i] = int(S[i])

f = S[0]
ans = 0

for i in range(1,len(S)):
    if S[i]+S[i-1] != 1:
        ans += 1
        S[i] = int(not S[i])

print(ans)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
a=[]
b=[]
c=[0,1]
for i in range(N):
    a.append(c[i%2])
    b.append(c[(i+1)%2])

ans_a=0
ans_b=0


for i in range(N):
    s=int(S[i])
    if a[i]!=s:
        ans_a+=1
    if b[i]!=s:
        ans_b+=1
        
print(min(ans_a,ans_b))

Submission status: Accepted

Solution code:
import numpy as np
S = np.array(list(input()), dtype='int')

arr2 = np.zeros((len(S)), dtype='int')
arr2[::2] = 1
arr1 = np.ones((len(S)), dtype='int')
arr1[::2] = 0

ans = min(np.count_nonzero(S != arr1), np.count_nonzero(S != arr2))
print(ans)

Submission status: Accepted

Solution code:
s = input()
b = "10"*10**5
count1 = 0
count2 = 0
for i in range(len(s)):
    if s[i] == b[i]:
        count1 += 1
    else:
        count2 += 1
print(min(count1, count2))

Submission status: Accepted

Solution code:
S = list(input())

E = [s for i, s in enumerate(S) if i % 2 == 0]
O = [s for i, s in enumerate(S) if i % 2 == 1]

E_1 = [e for e in E if e == '1']
O_1 = [o for o in O if o == '1']

diffs_e1_o0 = len(E) - len(E_1) + len(O_1)
diffs_e0_o1 = len(O) - len(O_1) + len(E_1)

print(min(diffs_e0_o1, diffs_e1_o0))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s1 = []
s2 = []
for i in range(n):
    if i % 2 == 0:
        s1.append("0")
    else: s1.append("1")
for i in range(n):
    if i % 2 != 0:
        s2.append("0")
    else: s2.append("1")
s1_switch = 0
s2_switch = 0
for i in range(n):
    if s[i] != s1[i]:
        s1_switch += 1
    elif s[i] != s2[i]:
        s2_switch += 1
print(min(s1_switch, s2_switch))

Submission status: Accepted

Solution code:
S = input()
g = []
k = []
for i in range(len(S)):
  if i%2 == 0:
    k.append(S[i]) # 奇数個め
  else:
    g.append(S[i]) # 偶数個め

print(min(k.count('0') + g.count('1'), g.count('0') + k.count('1')))

Submission status: Accepted

Solution code:
S = list(input())
a=0
b=0
for i in S[::2]:
    if i=="1":
        a+=1
for k in S[1::2]:
    if k=="0":
        a+=1

for i in S[::2]:
    if i=="0":
        b+=1
for k in S[1::2]:
    if k=="1":
        b+=1
print(min(a,b))

Submission status: Accepted

Solution code:
import collections
s = list(input())

even = collections.Counter(s[0::2])
odd = collections.Counter(s[1::2])

print(min(len(s) - (even["0"] + odd["1"]), len(s) - (even["1"] + odd["0"])))

Submission status: Accepted

Solution code:
s = list(input())

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

print(ans)

Submission status: Accepted

Solution code:
import sys
 
def main():
    S = [int(i) for i in input()]
 
    N = len(S)
 
    ol = [0] * N
    lo = [0] * N
    for i in range(N):
        if i % 2 ==0:
            ol[i] = 0
            lo[i] = 1
        else:
            ol[i] = 1
            lo[i] = 0
 
    ol_cnt = 0
    lo_cnt = 0
    for j in range(N):
        if ol[j] == S[j]:
            ol_cnt += 1
        if lo[j] == S[j]:
            lo_cnt += 1
 
    print(min(ol_cnt, lo_cnt))
 
main()

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

Solution code:
#124_C

S=input()

a=''
b=''

lenS=len(S)

for i in range(lenS):
    if i%2==0:
        a+='1'
        b+='0'
    else:
        a+='0'
        b+='1'
        
ca=0
cb=0
for i in range(lenS):
    if a[i]!=S[i]:
        ca+=1
    if b[i]!=S[i]:
        cb+=1
print(min(ca,cb))

Submission status: Accepted

Solution code:
def main():
    s = input()
    N = len(s)
    S = []
    for j in range(N):
        S.append(s[j])
    result = 0
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            result += 1
            if S[i + 1] == "0":
                S[i + 1] = "1"
            else:
                S[i + 1] = "0"
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
sento1 = 0
sento0 = 0
for i in range(len(s)):

  if i % 2 == 0:
    
    if s[i] == '1':
      sento1 += 1
      
    elif s[i] == '0':
      sento0 += 1
      
  else:
    if s[i] == '0':
      sento1 += 1
    elif s[i] == '1':
      sento0 += 1
      
print(min(sento1,sento0))

Submission status: Accepted

Solution code:
s=input()
l="1"+"01"*(len(s)//2)
ans=0
for i in range(len(s)):
  if s[i]==l[i]:
    ans+=1
print(min(ans,len(s)-ans))

Submission status: Accepted

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

s1 = 0
s2 = 0

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

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

print(min(s1, s2))

Submission status: Accepted

Solution code:
s=input()
l=len(s)
sa=""
sb=""
for i in range(l):
    if i%2==0:
        sa+="0"
        sb+="1"
    else:
        sa+="1"
        sb+="0"
ca=0
cb=0
for i in range(l):
    if sa[i]!=s[i]:
        ca+=1
    if sb[i]!=s[i]:
        cb+=1
#print(ca)
#print(cb)
print(min(ca,cb))

Submission status: Accepted

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

# 0101010... または 1010101... のどちらかになるしかない。

count0 = 0
count1 = 0
for i, c in enumerate(s):
    if i % 2 == 0:
        if c == '0':
            count1 += 1
        else:
            count0 += 1
    else:
        if c == '0':
            count0 += 1
        else:
            count1 += 1

count = min(count0, count1)
print(count)

Submission status: Accepted

Solution code:
s = input()
c1,c2 = 0,0
for i in range(len(s)):
    if i%2 and s[i] == "1":
        c1 += 1
    elif i%2 and s[i] == "0":
        c2 += 1
    elif i%2==0 and s[i] == "0":
        c1 += 1
    else:
        c2 += 1
print(min(c1,c2))

Submission status: Accepted

Solution code:
import sys

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

    N = len(S)

    ol = [0] * N
    lo = [0] * N
    for i in range(N):
        if i % 2 ==0:
            ol[i] = 0
            lo[i] = 1
        else:
            ol[i] = 1
            lo[i] = 0

    ol_cnt = 0
    lo_cnt = 0
    for j in range(N):
        if ol[j] == S[j]:
            ol_cnt += 1
        if lo[j] == S[j]:
            lo_cnt += 1

    print(min(ol_cnt, lo_cnt))

main()

Submission status: Accepted

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

def paint(start):
    a = s[::]
    ret = 0
    if a[0] != start:
        ret += 1
        a[0] ^= 1
    for i in range(1, len(a)):
        if a[i] == a[i - 1]:
            ret += 1
            a[i] ^= 1
    return ret

print(min(paint(0), paint(1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
pattern01 = 0
pattern10 = 0
for i, v in enumerate(s):
	if i % 2 == int(v):
		pattern01 += 1
	else:
		pattern10 += 1
print(min(pattern01, pattern10))

Submission status: Accepted

Solution code:
import os, sys, re, math

S = input()

A = ('01' * 50000)[:len(S)]
B = ('10' * 50000)[:len(S)]

countA = 0
countB = 0
for i in range(len(S)):
    if A[i] != S[i]:
        countA += 1
    if B[i] != S[i]:
        countB += 1

print(min(countA, countB))

Submission status: Accepted

Solution code:
S = input()
l = len(S)
bw = '01' * (l // 2 + 1)
wb = '10' * (l // 2 + 1)
bw_count = len([ 1 for a, b in zip(S, bw) if a != b  ])
wb_count = len([ 1 for a, b in zip(S, wb) if a != b  ])
print(min(bw_count, wb_count))

Submission status: Accepted

Solution code:
s = input()
# 先頭が0, 1が決まれば次以降は確定してしまうのでは...
ans = int(1e5 + 1)
for i in range(2):
  b = i
  temp = 0
  for c in s:
    t = int(c)
    temp += (t != b)
    b = 0 if b else 1
  ans = min(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
S = input()
p1 = 0
p2 = 1

d1 = 0
d2 = 0
for s in S:
    s = int(s)
    if p1 != s:
        d1 += 1
    if p2 != s:
        d2 += 1
    p1 ^= 1
    p2 ^= 1

print(min(d1, d2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
S = input()

def zero_start(S):
    cnt = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] != '0':
                cnt += 1
        else :
            if S[i] != '1':
                cnt += 1
    return cnt

def one_start(S):
    cnt = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] != '1':
                cnt += 1
        else :
            if S[i] != '0':
                cnt += 1
    return cnt

paints = [zero_start(S), one_start(S)]

print(min(paints))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()
x = 0
y = 0
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "1":
        x = x+1
    if a[t] == "0" and t%2 == 1:
        x = x+1
        
for t in range(0,len(a)):
    if t%2 == 0 and a[t] == "0":
        y = y+1
    if  t%2 == 1 and a[t] == "1":
        y= y+1
        
print (min(y,x))

Submission status: Accepted

Solution code:
s=str(input())
br1=0
s=list(s)
s2=s
br2=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=='0':
            br1+=1
    else:
        if s[i]=='1':
            br1+=1

for i in range(len(s)):
    if i%2==1:
        if s[i]=='0':
            br2+=1
    else:
        if s[i]=='1':
            br2+=1
print(min(br1,br2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

count_a = 0
count_b = 0

for i in range(0, len(s)):
    if int(s[i])%2 == i%2:
        count_a += 1
    if int(s[i])%2 != i%2:
        count_b += 1

print(min(count_a, count_b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

S = input()

n1 = S[::2].count("0")+S[1::2].count("1")
n2 = S[::2].count("1")+S[1::2].count("0")

ans = len(S)-max(n1,n2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

x = y = 0
for i, c in enumerate(S):
    if i % 2:
        a, b = 0, 1
    else:
        a, b = 1, 0
    if int(c) == a:
        x += 1
    if int(c) == b:
        y += 1
print(min(x, y))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = "10" * (n // 2) + "1" * (n % 2)
b = "01" * (n // 2) + "0" * (n % 2)

print(min(bin(int(s,2) ^ int(a, 2)).count("1") , bin(int(s, 2) ^ int(b, 2)).count("1")))

Submission status: Accepted

Solution code:
S=input()
S0=S[::2]
S1=S[1::2]
print(min(len(S)-S0.count("0")-S1.count("1"),len(S)-S0.count("1")-S1.count("0")))

Submission status: Accepted

Solution code:
s = input()

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

print(min(b,w))

Submission status: Accepted

Solution code:
s=input()
ans=0
li=""
for i in range(len(s)):
    if i%2==0:
        li+="0"
    else:
        li+="1"
    if s[i]==li[i]:
        ans+=1
bns=len(s)-ans
print(min(ans,bns))

Submission status: Accepted

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

l1 = [i % 2 for i in range(n)]
l2 = [(i+1) % 2 for i in range(n)]
c1 = ''.join(map(str, l1))
c2 = ''.join(map(str, l2))


def diff(s, c):
    count = 0
    for i in range(n):
        if s[i] != c[i]:
            count += 1
    return count


print(min(diff(s, c1), diff(s, c2)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

n=s[::2].count("0")+s[1::2].count("1") 
print(min(n, len(s)-n))

Submission status: Accepted

Solution code:
s = input()

cnt1 = 0
cnt2 = 0

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

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S=list(input())
a,b=[],[]
for i in range(len(S)):
	if i%2==0:
		a.append(S[i])
	else:
		b.append(S[i])

#偶数番目の0の出現回数
zero_gu=a.count('0')
#偶数番目の1の出現回数
iti_gu=a.count('1')

#奇数番目の0の出現回数
zero_ki=b.count('0')
#奇数番目の1の出現回数
iti_ki=b.count('1')

#奇数番目を0,偶数番目を1にすると
ans1=iti_ki+zero_gu

#その逆
ans2=iti_gu+zero_ki

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

Solution code:
import copy
a=list(input())
b=a.copy()
count1=0
count2=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        count1+=1
        if a[i]=="0":
            a[i+1]="1"
        else:
            a[i+1]="0"

for i in range(len(b)-2,-1,-1):
    if b[i]==b[i+1]:
        count2+=1
        if b[i+1]=="0":
            b[i]="1"
        else:
            b[i]="0"
print(min(count1,count2))

Submission status: Accepted

Solution code:
a=list(input())
count=0

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

Submission status: Accepted

Solution code:
s=list(map(int,input()))
bw=0 #0101との差異
for i in range(len(s)):
	if (i%2==0 and s[i]==1) or (i%2==1 and s[i]==0):
		bw+=1
wb=0
for i in range(len(s)):
	if (i%2==0 and s[i]==0) or (i%2==1 and s[i]==1):
		wb+=1
print(min(bw,wb))

Submission status: Accepted

Solution code:
s = list(input())

s01 = []
s10 = []

for i in range(len(s)):
    if i % 2 == 0:
        s01.append('0')
        s10.append('1')
    else:
        s01.append('1')
        s10.append('0')

count01 = 0
count10 = 0

for i in range(len(s)):
    if s[i] != s01[i]:
        count01 += 1
    if s[i] != s10[i]:
        count10 += 1

print(min(count01, count10))

Submission status: Accepted

Solution code:
S = str(input())

tmp = '0'
ans1 = 0
for iro in S:
    if iro != tmp:
        ans1 += 1
    tmp = str(int(tmp)^1)

tmp = '1'
ans2 = 0
for iro in S:
    if iro != tmp:
        ans2 += 1
    tmp = str(int(tmp)^1)

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
ans = 0
t = S[0]
d = {"0":"1", "1":"0"}
for s in S[1:]:
    if s == t:
        ans += 1
        t = d[s]
    else:
        t = s
print(ans)

Submission status: Accepted

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

a = 0
if s[0] == 0:
    a = 0
else:
    a = 1

c = 0


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

print(c)

Submission status: Accepted

Solution code:
s = list(input())
ans = 0

for i in range(1, len(s)):
    if s[i-1] == s[i] and s[i-1] == "0":
        ans += 1
        s[i] = "1"
    if s[i-1] == s[i] and s[i-1] == "1":
        ans += 1
        s[i] = "0"
print(ans)

Submission status: Accepted

Solution code:
import math

S = list(input())

S1 = "01"*(len(S)//2)
if len(S1)<len(S):
    S1 += "0"
S2 = "10"*(len(S)//2)
if len(S2)<len(S):
    S2 += "1"

cnt1, cnt2 = 0, 0
for i in range(len(S)):
    if S[i] != S1[i]:
        cnt1 += 1
    if S[i] != S2[i]:
        cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
import numpy as np

s=np.array(list((map(int,input()))))

a=[0,1]*(int(len(s)/2))
b=[1,0]*(int(len(s)/2))

if len(s)%2==1:
    a.append(0)
    b.append(1)

acount=a^s
bcount=b^s

ca=np.count_nonzero(acount)
cb=np.count_nonzero(bcount)

print(min(ca,cb))

Submission status: Accepted

Solution code:
S = input()

seikai1 = [0 if i%2==0 else 1 for i in range(len(S))]
seikai2 = [0 if i%2==1 else 1 for i in range(len(S))]
count1, count2 = 0, 0
for i in range(len(S)):
    x = int(S[i])
    if x != seikai1[i]:
        count1 += 1
for i in range(len(S)):
    x = int(S[i])
    if x != seikai2[i]:
        count2 += 1
print(min(count1, count2))

Submission status: Accepted

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

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

print(min(cnt, leng-cnt))

Submission status: Accepted

Solution code:
a=list(input())
b=a[::-1]
n=len(a)
if n==1:
    print(0)
else:
    x=0
    y=0
    for i in range(n-1):
        if a[i]==a[i+1]:
            x+=1
            if a[i]=='0':
                a[i+1]='1'
            else:
                a[i+1]='0'
        if b[i]==b[i+1]:
            y+=1
            if b[i]=='0':
                b[i+1]='1'
            else:
                b[i+1]='0'
    print(min(x,y))

Submission status: Accepted

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