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 bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)
s_01 = ('01' * N)[:N]
s_10 = ('10' * N)[:N]

S = np.array(list(S), dtype=str)
s_01 = np.array(list(s_01), dtype=str)
s_10 = np.array(list(s_10), dtype=str)
a = np.count_nonzero(S != s_01)
b = np.count_nonzero(S != s_10)
print(min(a, b))

Submission status: Accepted

Solution code:
s = input()

n = len(s)
p = s[::2].count("1") + s[1::2].count("0")

ans = min(p, n-p)
print(ans)

Submission status: Accepted

Solution code:
A=input()
count1=0

for i in range(0,len(A),2):
  if A[i]!="0":
    count1+=1
for j in range(1,len(A),2):
  if A[j]!="1":
    count1+=1
print(min(count1,len(A)-count1))

Submission status: Accepted

Solution code:
s = input()
l = len(s)
ans1 = 0
ans2 = 0
#print(s[0])

if int(s[0])==0:
    for i in range(l):
        #print("a")
        n1 = i % 2
        n2 =(i+1) %2
        #print(n1)
        #print(n2)
        if int(s[i])!=n1:
            ans1 += 1
        if int(s[i])!=n2:
            ans2 += 1
else:
    for i in range(l):
        #print("b")
        n1 =(i+1) % 2
        n2 = i % 2
        if int(s[i])!=n1:
            ans1 += 1
        if int(s[i])!=n2:
            ans2 += 1

#print(ans1)
#print(ans2)
if ans1>=ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s = list(input())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S=input()

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


c1,c2 = 0,0
for j in range(s_len):
        if (a[j] != S[j]):
                c1 += 1
        if (b[j] != S[j]):
            c2 += 1

print(min(c1,c2))

Submission status: Accepted

Solution code:
s = list(input())

ans0 = 0
ans1 = 0

for i,se in enumerate(s):
    if i%2==0:
        if se=='0':
            ans1 += 1
        else: ans0 += 1
    else:
        if se=='0':
            ans0 += 1
        else: ans1 += 1

print(min(ans0, ans1))

Submission status: Accepted

Solution code:
S=[int(i) for i in input()]
N=len(S)
e=[]
o=[]
for i in range(N):
    if i%2==0:
        e.append(S[i])
    else:
        o.append(S[i])

e0=e.count(0)
e1=e.count(1)
o0=o.count(0)
o1=o.count(1)
print(N-max(e0+o1,e1+o0))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#010101…と101010…の2通り
#2通りともコストを計算して小さい方を採用するだけ。
#文字列処理のほうが楽。if文注意
s = input()
even = True
ans1=0#010101…
ans2=0#101010…
for c in s:
  if even:
    even = False
    if c == '0':
      ans2 += 1
    else:
      ans1 += 1
  else:
    even = True
    if c == '0':
      ans1 += 1
    else:
      ans2 += 1
print(min([ans1,ans2]))

Submission status: Accepted

Solution code:
s = list(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
else:
    if ans1 < ans2:
        ans = ans1
    else:
        ans = ans2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def solve3():
    """solve1の変形
    ２種類のパターンしかないので分岐して調べる
    """
    S = list(input())
    c1, c2 = 0, 0
    for i in range(len(S)):
        # 正解を1010...とした場合
        if i % 2 == 0 and S[i] == '0':
            c1 += 1
        if i % 2 == 1 and S[i] == '1':
            c1 += 1
        # 正解を0101...とした場合
        if i % 2 == 0 and S[i] == '1':
            c2 += 1
        if i % 2 == 1 and S[i] == '0':
            c2 += 1
    return(min(c1, c2))

def solve2():
    l = list(str(input()))
    l = [int(i) for i in l]
    cnt = 0
    # チェックをしたのち次のものを適切な色に変更する
    # 全てのタイルに適用することで間違いをカウントすることができる
    for i in range(len(l)-1):
        if(l[i]==l[i+1]):
            cnt+=1
        if(l[i]==0):
            l[i+1]=1
        elif(l[i]==1):
            l[i+1]=0
    return cnt

def solve1():
    s = input()
    n = len(s)

    counter_bw = 0
    counter_wb = 0

    # 指定された長さに従って正解の文字列を作ってしまう
    if n % 2 == 0:
        bw = "01" * (n // 2)
        wb = "10" * (n // 2)
    else:
        bw = "01" * (n // 2) + "0"
        wb = "10" * (n // 2) + "1"

    # 作成した正解文字列と違うところを比較
    for i in range(n):
        if s[i] != bw[i]:
            counter_bw += 1
        if s[i] != wb[i]:
            counter_wb += 1

    # 2種類しかないので違いが少ないほうの違いの数を示せばいい
    return min(counter_bw, counter_wb)

# print(solve1())
print(solve2())

Submission status: Accepted

Solution code:
s=input()
w=str()
b=str()
cnt1=0
cnt2=0
for i in range(len(s)):
    if i%2==0:
        w+='1'
        b+='0'
    else:
        w+='0'
        b+='1'
for i in range(len(s)):
    if s[i]!=w[i]:
        cnt1+=1
    if s[i]!=b[i]:
        cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:


S = input()
length = len(S)
p1 = [0 if i % 2 == 0 else 1 for i in range(length)]
p2 = [0 if i % 2 != 0 else 1 for i in range(length)]

p1dif = 0
for i in range(length):
  if int(p1[i]) != int(S[i]):
    p1dif += 1

p2dif = 0
for i in range(length):
  if int(p2[i]) != int(S[i]):
    p2dif += 1

print(min(p1dif, p2dif))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a="".join(["0" if i%2==0 else "1" for i in range(n)])
b="".join(["1" if i%2==0 else "0" for i in range(n)])
tmp1=0
tmp2=0
for i,j,k in zip(s,a,b):
  if i!=j:
    tmp1+=1
  if i!=k:
    tmp2+=1
print(min(tmp1,tmp2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
S = list(map(int, S))
N = len(S)
A = [0,1]*N
B = [1,0]*N
A = A[:N]; B = B[:N]
acnt = 0
bcnt = 0

for s, a, b in zip(S, A, B):
    if s != a:
        acnt += 1
    if s != b:
        bcnt += 1
print(min(acnt, bcnt))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = [int(x) for x in input()]
l1 = [i % 2 for i in range(len(s))]
l2 = [1] + l1[:len(l1) - 1]
d1 = len([sv for sv, lv in zip(s, l1) if sv != lv])
d2 = len([sv for sv, lv in zip(s, l2) if sv != lv])
print(d1 if d1 < d2 else d2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = [int(x) for x in input()]
l1 = [i % 2 for i in range(len(s))]
l2 = [1] + l1[:len(l1) - 1]
d1 = len([x for i, x in enumerate(s) if s[i] != l1[i]])
d2 = len([x for i, x in enumerate(s) if s[i] != l2[i]])
print(d1 if d1 < d2 else d2)

Submission status: Accepted

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

flg = (s[0] == '1')
ans = 0
for v in s[1:]:
  if (flg and v == '1'):
    ans += 1
    flg = False
  elif (not flg and v == '0'):
    ans += 1
    flg = True
  else:
    flg = (v == '1')
print(ans)

Submission status: Accepted

Solution code:
S= list(map(int,list(input())))
cntOD0=0
cntOD1=0
for i in range(len(S)):
  if i%2==0 and S[i]==1:
    cntOD0+=1
  elif i%2==1 and S[i]==0:
    cntOD0+=1
  elif i%2==0 and S[i]==0:
    cntOD1+=1
  elif i%2==1 and S[i]==1:
    cntOD1+=1
print(min(cntOD0,cntOD1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
even=len(S)//2
odd=len(S)-even
odd0=0
even0=0
for i,s in enumerate(S):
  if s=="0":
    if (i+1)%2==0:
      even0 += 1
    else:
      odd0  += 1
even1=even-even0
odd1=odd-odd0
print(min(odd1+even0,odd0+even1) )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

#最初が0とする場合
a = s[0::2].count('1')+s[1::2].count('0')

#最初が1とする場合
b = s[0::2].count('0')+s[1::2].count('1')

print(min(a,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
a=[0]
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        a.append(i)
a.append(len(s))
x=0;y=0
for i in range(1,len(a)):
    if i%2==0:
        x+=a[i]-a[i-1]
    else:
        y+=a[i]-a[i-1]
#print(x,y)
print(min(x,y))

Submission status: Accepted

Solution code:
l=list(str(input()))
l=[int(i) for i in l]
cnt=0
for i in range(len(l)-1):
  if(l[i]==l[i+1]):
    cnt+=1
    if(l[i]==0):
      l[i+1]=1
    elif(l[i]==1):
      l[i+1]=0
print(cnt)

Submission status: Accepted

Solution code:
s = input()
i = len(s)//2
count1 = 0
count2 = 0
if len(s)%2 == 0:
    s1 = '01'*i
    s2 = '10'*i
else:
    s1 = '01'*i + '0'
    s2 = '10'*i + '1'
for x,y,z in zip(s,s1,s2):
    if x != y:
        count1 += 1
    if x != z:
        count2 += 1
print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

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

counter_bw = 0
counter_wb = 0

if n % 2 == 0:
  bw = "01" * (n // 2)
  wb = "10" * (n // 2)
else:
  bw = "01" * (n // 2) + "0"
  wb = "10" * (n // 2) + "1"

for i in range(n):
  if s[i] != bw[i]:
    counter_bw += 1
  if s[i] != wb[i]:
    counter_wb += 1

print(min(counter_bw, counter_wb))

Submission status: Accepted

Solution code:
S = input()
ans_0 = 0
ans_1 = 0
check = "0"
for i in S:
    if i == check:
        ans_0 += 1
    else:
        ans_1 += 1
    
    if check == "0":
        check = "1"
    else:
        check = "0"
print(min(ans_0,ans_1))

Submission status: Accepted

Solution code:
S=list(input())
ans1 = 0 #0から
ans2 = 0 #1から
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '1':
            ans1 += 1
        else:
            ans2 += 1
    else:
        if S[i] == '0':
            ans1 += 1
        else:
            ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:

def main():
    S = list(input())
    c1, c2 = 0, 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] == '0':
            c1 += 1
        if i % 2 == 1 and S[i] == '1':
            c1 += 1

        if i % 2 == 0 and S[i] == '1':
            c2 += 1
        if i % 2 == 1 and S[i] == '0':
            c2 += 1
    print(min(c1, c2))




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

S = input().rstrip()
A = [int(s) for s in S]

ans = []
for i in range(2):
	count = 0
	# i==0 の時、 101010、i==1の時、01010とする
	for idx,a in enumerate(A):
		if i==idx%2 and a==0:count+=1
		elif i!=idx%2 and a==1:count+=1
	ans.append(count)

print(min(ans))

Submission status: Accepted

Solution code:
s=list(input())
m=0
if s[0]=="0":
    for i in range(1,len(s),2):
        if s[i]=="0":
            m+=1
    for i in range(2,len(s),2):
        if s[i]=="1":
            m+=1
if s[0]=="1":
    for i in range(1,len(s),2):
        if s[i]=="1":
            m+=1
    for i in range(2,len(s),2):
        if s[i]=="0":
            m+=1
print(m)

Submission status: Accepted

Solution code:
S = list(input())
a = ['0' if x%2==0 else '1' for x in range(len(S))]
b = ['1' if x%2==0 else '0' for x in range(len(S))]
ca, cb = 0, 0
         
for i in range(len(S)):
  if S[i] != a[i]:
    ca += 1
  if S[i] != b[i]:
    cb += 1
    
print(min(ca, cb))

Submission status: Accepted

Solution code:
import math
import sys

def main():
    s = input()
    a = [(ch) for ch in s]

    ans = 0

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

    print(ans)

if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

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


def main():
    s = input()
    s_list = list(s)
    count = 0
    for i in range(len(s_list) - 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)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

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

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

Submission status: Accepted

Solution code:
s=input()
even=[int(x) for i,x in enumerate(s) if i%2==0]
odd=[int(x)for i,x in enumerate(s) if i%2==1]

tmp=sum([x!=0 for x in even])+sum([x!=1 for x in odd])
tmp=min(sum([x!=1 for x in even])+sum([x!=0 for x in odd]),tmp)
print(tmp)

Submission status: Accepted

Solution code:

def ABC124C_ColoringColorfully():
    S = list(input().strip())

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

def main():
    ABC124C_ColoringColorfully()

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#124C
import sys
s = sys.stdin.readline().rstrip()
n = len(s)

cnt = 0
for i in range(n):
    if i % 2==0: #偶数
        if s[i] != '0':
            cnt +=1
    else:
        if s[i] != '1':
            cnt +=1

print(min(cnt, n-cnt))

Submission status: Accepted

Solution code:
import math
S = input()
pt1 = "01"*math.ceil(len(S)/2)
pt2 = "10"*math.ceil(len(S)/2)
if len(pt1) != len(S):
    pt1 = pt1[:-1]
    pt2 = pt2[:-1]
ans = []
tmp1 = 0
tmp2 = 0
for i in range(len(S)):
    if S[i] != pt1[i]:
        tmp1 += 1
    if S[i] != pt2[i]:
        tmp2 += 1
print(min([tmp1,tmp2]))

Submission status: Accepted

Solution code:
def p_c():
    *S, = map(int, input())
    ans = [0] * 2
    for i, s in enumerate(S):
        ans[(i + s) % 2] += 1
    print(min(ans))
    
p_c()

Submission status: Accepted

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

ans1=0
ans2=0
for i in range(n):
    #黒始まり
    if i%2==1 and s[i]=="0":
        ans1+=1
    elif i%2==0 and s[i]=="1":
        ans1+=1
    #白始まり
    if i%2==1 and s[i]=="1":
        ans2+=1
    elif i%2==0 and s[i]=="0":
        ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()
count = 0
for i in range(len(s)):
    if i %2 == 0:
        tile = "0"
    else:
        tile = "1"
    if s[i] == tile:
        count += 1
if len(s) //2 + 1 > count:
    print(count)
else:
    print(len(s)-count)

Submission status: Accepted

Solution code:
S=input()

ptn1=0
ptn2=0
for i in range(len(S)):
    if i%2==0:
        if int(S[i])==0:
            ptn1+=1
        else:
            ptn2+=1
        #print(i,S[i],'ptn1',ptn1,'ptn2',ptn2)
    else:
        if int(S[i])==0:
            ptn2+=1
        else:
            ptn1+=1
        #print(i,S[i],'ptn1',ptn1,'ptn2',ptn2)
        
if ptn1>ptn2:
    print(len(S)-ptn1)
else:
    print(len(S)-ptn2)

Submission status: Accepted

Solution code:
s = input()
cnt1 = 0 # 1010101の並びになっていない数をカウント
cnt2 = 0 # 0101010の並びになっていない数をカウント
for oddLetter in s[0::2]:
    if oddLetter != '1':
        cnt1 += 1
    else:
        cnt2 += 1
for evenLetter in s[1::2]:
    if evenLetter != '0':
        cnt1 += 1
    else:
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S = str(input())

cnt_1 = 0
cnt_2 = 0
for i in range(len(S)):
    if i%2==1:
        if S[i] == '1':
            cnt_1 += 1
        if S[i] == '0':
            cnt_2 += 1
    else:
        if S[i] == '0':
            cnt_1 += 1
        if S[i] == '1':
            cnt_2 += 1
    #print(cnt_1,cnt_2)
print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def solve():
    return


def main():
    S = input()
    ans1, ans2 = 0, 0
    for i in range(len(S)):
        if i % 2 == 0:
            ans1 += S[i] != '0'
            ans2 += S[i] != '1'
        else:
            ans1 += S[i] != '1'
            ans2 += S[i] != '0'

    print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
a = "0"
b = "1"
for _ in range(len(s)-1):
    if a[-1] == '1':
        a += '0'
    else:
        a += '1'
    
    if b[-1] == '1':
        b += '0'
    else:
        b += '1'
        
a_ans, b_ans = 0, 0
for i in range(len(s)):
    if a[i] != s[i]:
        a_ans += 1
    if b[i] != s[i]:
        b_ans += 1

print(min(a_ans, b_ans))

Submission status: Accepted

Solution code:
a = list(input())
s = a[0]
count = 0
if s == "0":
    for i in range(1, len(a)):
        if int(a[i]) != i % 2:
            count += 1
elif s == "1":
    for i in range(1, len(a)):
        if int(a[i]) != (i + 1) % 2:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def print_ans(S):
    """Test Case
    >>> print_ans("000")
    1
    >>> print_ans("10010010")
    3
    >>> print_ans("0")
    0
    """
    before = "2"
    ans = 0
    for s in S:
        if s == before:
            ans += 1
            if s == "1":
                before = "0"
            else:
                before = "1"
        else:
            before = s

    print(ans)

if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

zero_start_diff = 0
one_start_diff = 0

for i in range(len(S)):
    if i%2 == 0:
        if int(S[i]) == 1:
            zero_start_diff +=1
        elif int(S[i]) == 0:
            one_start_diff +=1
    else:
        if int(S[i]) == 1:
            one_start_diff +=1
        elif int(S[i]) == 0:
            zero_start_diff +=1
print(min(zero_start_diff,one_start_diff))

Submission status: Accepted

Solution code:
S = input()

count = 0

before_s = ""
for s in S:
    if before_s == "":
        before_s = s
        continue
    else:
        if before_s == s:
            if s == "1":
                before_s = "0"
            elif s == "0":
                before_s = "1"
            count += 1
        else:
            before_s = s
print(count)

Submission status: Accepted

Solution code:
S = input()

ans = [0, 0]
c = [['0', '1'], ['1', '0']]

for idx, s in enumerate(S):
    if s != c[idx%2][0]: ans[0] += 1
    if s != c[idx%2][1]: ans[1] += 1
    
print(min(ans))

Submission status: Accepted

Solution code:
s = input()

slen = len(s)
s1 = ""
f = "0"
for i in range(slen) :
  s1 += f
  f = "1" if f=="0" else  "0"
  
  
s2 = ""
f = "1"
for i in range(slen) :
  s2 += f
  f = "1" if f=="0" else  "0"

b = int(s,2)
p1 = int(s1,2)
p2 = int(s2,2)

r1 = b^p1
r2 = b^p2

ans1 = format(r1,"b")
ans2 = format(r2,"b")

print(min(ans1.count("1"),ans2.count("1")))

Submission status: Accepted

Solution code:
S=list(map(int,input()))
ONE=0
ZERO=0
if S[0]==0:
  for i in range(1,len(S)):
    if i%2!=0:
      if S[i]==0:
        S[i]=1
        ZERO += 1
    else:
      if S[i]==1:
        S[i]=0
        ZERO += 1
else:
  for i in range(1,len(S)):
    if i%2!=0:
      if S[i]==1:
        S[i]=0
        ONE += 1
    else:
      if S[i]==0:
        S[i]=1
        ONE += 1
print(ONE+ZERO)

Submission status: Accepted

Solution code:
#14:35
s = input()
n = len(s)
scr = 0
for i in range(n):
  a = int(s[i])
  if i == 0:
    b = 0
  else:
    b = 1 - b
  if a != b:
    scr += 1
#print(scr)
print(min(scr,n-scr))

Submission status: Accepted

Solution code:
s = input()
a,b = 0,0
for key,i in enumerate(s):
  if (key % 2):
    if i == "0":
      a += 1
    else:
      b += 1
  else:
    if i == "0":
      b += 1
    else:
      a += 1
print(min(a,b))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

cntA = 0
cntB = 0

# 10101010
for i in range(len_S):
    if i%2==0 and S[i]=="0":
        cntA +=1
    elif i%2==1 and S[i]=="1":
        cntA +=1

# 01010101
for i in range(len_S):
    if i%2==1 and S[i]=="0":
        cntB +=1
    elif i%2==0 and S[i]=="1":
        cntB +=1

print(min(cntA,cntB))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
S_1 = []
S_2 = []
for i in range(len(S)):
    if i % 2 == 0:
        S_1.append("0")
        S_2.append("1")
    else:
        S_2.append("0")
        S_1.append("1")
s_1 = 0
s_2 = 0
for j in range(len(S)):
    if S_1[j] != S[j]:
        s_1 += 1
    if S_2[j] != S[j]:
        s_2 += 1
print(min(s_1,s_2))

Submission status: Accepted

Solution code:
li = list(input())
counter = 0
counter1 = 0
import copy
lii = copy.deepcopy(li)

for i in range(len(li)-1):
    if li[i] == li[i+1] and li[i+1] == "0":
         li[i+1] = "1"
         counter += 1
    if li[i] == li[i+1] and li[i+1] == "1":
         li[i+1] = "0"
         counter += 1
if lii[0] == "0":
    lii[0] == "1"
else:
    lii[0] == "0"
for i in range(len(lii)-1):
    if lii[i] == lii[i+1] and lii[i+1] == "0":
         lii[i+1] = "1"
         counter1 += 1
    if lii[i] == lii[i+1] and lii[i+1] == "1":
         lii[i+1] = "0"
         counter1 += 1
print(max(counter1,counter))

Submission status: Accepted

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

# odd: white
rep1 = 0
for i in range(len_s):
    if (i % 2 == 0):
        if (s[i] == "0"):
            rep1 += 1
    else:
        if (s[i] == "1"):
            rep1 += 1

# even: white
rep2 = 0
for i in range(len_s):
    if (i % 2 == 0):
        if (s[i] == "1"):
            rep2 += 1
    else:
        if (s[i] == "0"):
            rep2 += 1

print(min(rep1, rep2))

Submission status: Accepted

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

for i in range(len(S)):
   if i % 2:
      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:
A = [int(c) for c in input()]
n = A[0]
cnt1 = 0
for c in A[1:]:
    if c == n:
        cnt1 += 1
    n ^= 1
n = A[0] ^ 1
cnt2 = 1
for c in A[1:]:
    if c == n:
        cnt2 += 1
    n ^= 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S=str(input())
count_A=0
count_B=1
N=len(S)
for i in range(2,N,2):
  if S[i]!=S[0]:
    count_A +=1
  else:
    count_B +=1
for j in range(1,N,2):
  if S[j]==S[0]:
    count_A +=1
  else:
    count_B +=1
print(min(count_A,count_B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Ans1=0
Ans2=0

if N%2==0:
    s1='10'*(N//2)
    s2='01'*(N//2)

    for i in range(N):
        if S[i]!=s1[i]:
            Ans1 += 1
        else:
            Ans2 += 1
    
else:
    s1='10'*(N//2)+'1'
    s2='01'*(N//2)+'0'
    for i in range(N):
        if S[i]!=s1[i]:
            Ans1 += 1
        else:
            Ans2 += 1

print(min(Ans1, Ans2))

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:
S=input()
s0=""
s1=""
for i in range(len(S)):
  if i%2==0:
    s0+="0"
    s1+="1"
  else:
    s0+="1"
    s1+="0"

s0c=0
s1c=0
for i in range(len(S)):
  if S[i]!=s0[i]:
    s0c+=1
  if S[i]!=s1[i]:
    s1c+=1
    
print(min(s0c,s1c))

Submission status: Accepted

Solution code:
S = list(input())
odd_zero = 0
even_zero = 0
odd_one = 0
even_one = 0
for n in range(len(S)):
    if n%2 == 0:
        if S[n] == '0':
            even_zero += 1
        else:
            even_one += 1
    else:
        if S[n] == '0':
            odd_zero += 1
        else:
            odd_one += 1
print(len(S)-max(even_zero+odd_one, even_one+odd_zero))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

test0 = [x%2 for x in range(len(s))]
test1 = [x%2 for x in range(len(s) - 1)]
test1.insert(0, 1)

cnt0 = 0
cnt1 = 0

for i, v in enumerate(s):
    if int(v) != test0[i]:
        cnt0+=1
    if int(v) != test1[i]:
        cnt1+=1

print(min(cnt0, cnt1))

Submission status: Accepted

Solution code:
S = list(input())
count = 0
for i in range(len(S)):
    if(i%2==1):
        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 = list(input())
count = [0, 0]
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            count[0] += 1
        else:
            count[1] += 1
    else:
        if S[i] == "1":
            count[0] += 1
        else:
            count[1] += 1
print(min(count))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    S=list(map(int,list(input())))
    ans=0
    nuri=False
    for i in range(len(S)-1):
        if nuri==False:
            if S[i+1] == S[i]:
                ans+=1
                nuri=True
            else:
                pass
        else:
            if S[i+1] == S[i]:
                nuri=False
            else:
                ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
re1 = 0
re2 = 0

for i in range(0,n,2):
    if s[i] == "1":
        re1 += 1

for i in range(1,n,2):
    if s[i] == "0":
        re1 += 1
        
for i in range(0,n,2):
    if s[i] == "0":
        re2 += 1
        
for i in range(1,n,2):
    if s[i] == "1":
        re2 += 1
        
print(min(re1,re2))

Submission status: Accepted

Solution code:
s = list(input())

num1 = 0
num2 = 0

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

print(min(len(s)-num1, len(s)-num2))

Submission status: Accepted

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

odd = sum(s[::2])
even = sum(s[1::2])
if even >= odd:
    ans = len(s)//2-even+odd
elif len(s) % 2 == 1:
    ans = len(s)//2-odd+even+1
else:
    ans = len(s)//2-odd+even
print(ans)