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:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()

zerokara = S[0::2]
onekara = S[1::2]

ans1 = zerokara.count("1")+onekara.count("0")
ans2 = zerokara.count("0")+onekara.count("1")
ans = min(ans1,ans2)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
s = str(input())
ans1=0
for i in range(len(s)):
  if(i%2==0 and s[i]!='0'):ans1+=1
  if(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
  if(i%2==1 and s[i]!='0'):ans2+=1
ans=min(ans1,ans2)
print(ans)

Submission status: Accepted

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

n = len(s)
ans1 = [i % 2 for i in range(n)]
ans2 = [i % 2 for i in range(1,n+1)]
#print(ans1)
#print(ans2)
count1 = 0
count2 = 0
for i in range(n):
    if int(s[i]) != ans1[i]:
        count1 += 1
    if int(s[i]) != ans2[i]:
        count2 += 1
print(min(count1, count2))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

ss = [int(i) for i in STR()]
s = deepcopy(ss)
ans1 = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = int(not s[i - 1])
        ans1 += 1
s = deepcopy(s)
s[0] = int(not s[0])
ans2 = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = int(not s[i - 1])
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

s = [int(i) for i in STR()]
flag = False
ans = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = int(not s[i - 1])
        if flag:
            flag = False
            ans += 1
        else:
            flag = False
            ans += 1
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

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

def main():
    c1 = s[::2].count('1') + s[1::2].count('0')
    c2 = s[::2].count('0') + s[1::2].count('1')
    print(min(c1, c2))

if __name__ ==  '__main__':
    main()

Submission status: Accepted

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

s1 = [0]*n
s2 = [1]*n
for i in range(1,n,2):
  s1[i] = 1
  s2[i] = 0

count1 = 0
count2 = 0
for i in range(n):
  if s[i]!=s1[i]: count1 += 1
  if s[i]!=s2[i]: count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = np.array(list(sr()), np.int8)
length = len(S)
complete = np.arange(length) & 1
r1 = (S == complete).sum()
r2 = (S != complete).sum()
answer = min(r1, r2)
print(answer)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    pr = S[0] # 前の色
    cnt = 0
    for i in range(1,len(S)):
        if S[i] != pr:
            pr = S[i]
        else:
            cnt += 1
            if pr == '0':
                pr = '1'
            else:
                pr = '0'
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
s = list(input())
cnt0 = 0
cnt1 = 0
for i, ss in enumerate(s):
    if i % 2 == 0 :
        if ss == '0':
            cnt1 += 1
        else:
            cnt0 += 1
    else:
        if ss == '1':
            cnt1 += 1
        else:
            cnt0 += 1
print(min(cnt0,cnt1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = list(map(int, list(sr())))
count = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        S[i+1] = 1 - S[i+1]
        count += 1

answer = min(count, len(S) - count)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

z_g = 0
z_k = 0
o_g = 0
o_k = 0

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

if (z_g + o_k) > (z_k + o_g):
    print(z_k + o_g)
else:
    print(z_g + o_k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

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

print(min(cost1, cost2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
ans = len(s)
for i in range(0, 2):
    cnt = 0
    for j in range(0, 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:
#!/usr/bin/env python3
s = input()
ans = len(s)
for i in range(0, 2):
    cnt = 0
    for j in range(0, 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:
def modelAnswer(s:list) -> int:
   white = "1"
   ans_w = 0
   black = "0"
   ans_b = 0
   for i in s:
      if(i != white):
         ans_w +=1
      else:
         ans_b += 1
      white = "0" if(white == "1") else "1"
      black = "0" if(black == "1") else "1"
   return min(ans_b,ans_w)

def main():
   s = list(input())
   print(modelAnswer(s))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:

def myAnswer(s:list) -> str:
   ans = 0
   pre =s.pop(0)
   for i in s:
      if(pre == i):
         ans += 1
      pre = "1" if(pre == "0") else "0"
   return ans

def modelAnswer():
   tmp=1
def main():
   s = list(input())
   print(myAnswer(s))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def myAnswer(s:list) -> str:
   ans = 0
   pre =s.pop(0)
   for i in s:
      if(pre == i):
         ans += 1
         pre = "1" if(i == "0") else "0"
      else:
         pre = i
   return ans

def modelAnswer():
   tmp=1
def main():
   s = list(input())
   print(myAnswer(s))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ans = 0
if S[0] == '0':
    ans += S[2::2].count('1')
    ans += S[1::2].count('0')
else:
    ans += S[2::2].count('0')
    ans += S[1::2].count('1')

print(ans)

Submission status: Accepted

Solution code:
s=input();a=int(("10"*10**5)[:len(s)],2);s=int(s,2);c=lambda x: str(bin(x^s)).count("1");print(min(c(a),c(a>>1)))

Submission status: Accepted

Solution code:
s = input()
a = int(("10"*10**5)[:len(s)], 2)
s = int(s, 2)
c = lambda x: str(bin(x^s)).count("1")
print(min(c(a), c(a>>1)))

Submission status: Accepted

Solution code:
S = input()

S1 = S
count1 = 0
prev1 = '0'
for s in S1:
    if prev1 == s == '0':
        s = '1'
        count1 += 1
    if prev1 == s == '1':
        s = '0'
        count1 += 1
    prev1 = s

S2 = S
count2 = 0
prev2 = '1'
for s in S2:
    if prev2 == s == '0':
        s = '1'
        count2 += 1
    if prev2 == s == '1':
        s = '0'
        count2 += 1
    prev2 = s

print(min(count1, count2))

Submission status: Accepted

Solution code:
receber = input()
contador = 0
contaor = 0
casoUm=""
casoDois=""
if receber[0] == "1":
    for i in range(len(receber)):
        if i%2==0:
            casoUm+="1"
        else:
            casoUm+="0"
    for k in range(len(receber)):
        if receber[k] != casoUm[k]:
            contador+=1
else:
    for i in range(len(receber)):
        if i%2==0:
            casoDois+="0"
        else:
            casoDois+="1"
    for k in range(len(receber)):
        if receber[k] != casoDois[k]:
            contador+=1

print(contador)

Submission status: Accepted

Solution code:
s = [int(x) for x in input()]
correto_0 = []
correto_1 = []
for i in range(len(s)):
    if i % 2 != 0:
        correto_0.append(0)
        correto_1.append(1)
    else:
        correto_0.append(1)
        correto_1.append(0)
for i in range(len(s)):
    correto_0[i] = correto_0[i] - s[i]
    correto_1[i] = correto_1[i] - s[i]
resp_0 = [abs(x) for x in correto_0]
resp_1 = [abs(x) for x in correto_1]
print(min(sum(resp_0),sum(resp_1)))

Submission status: Accepted

Solution code:
def main():
    s = input()
    mudancas=0;
    mudancasn=0;
    s=list(s)
    n=[]
    for i in range(0, len(s)):
        n.append(s[len(s)-1-i])
    
    if(len(s)==1):
        print("0")
        return;

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

        if(n[i]==n[i-1]):
            mudancasn+=1
            if(n[i]=='0'):
                n[i]='1'
            else:
                n[i]='0'

    if(mudancas>mudancasn):
        print(mudancasn)
    else:
        print(mudancas)
        
    return 0
    
main()

Submission status: Accepted

Solution code:
s = input()
s = list(s)
to_black = 0
to_white = 0
last = '0' if s[0] == '1' else '1'
pos = 0
for c in s:
    if c == last and c == '0':
        to_white+=1
        s[pos] = '1'
        c = '1'
    elif c == last and c == '1':
        to_black+=1
        s[pos] = '0'
        c = '0'
    last = c
    pos+=1
print(to_black+to_white)

Submission status: Accepted

Solution code:
string = input()
predicted_value = 0
last_colour = bool(int(string[0]))
for s in string[1:]:
    was_white = bool(int(s))
    if last_colour == was_white:
        predicted_value += 1
        last_colour = not was_white
    else:
        last_colour = was_white
print(predicted_value)

Submission status: Accepted

Solution code:
s = input()

count = 0
previous = ''
for c in s:
    if c == previous:
        count += 1
        if c == '1':
            previous = '0'
        if c == '0':
            previous = '1'
    else:
        previous = c

print(count)

Submission status: Accepted

Solution code:
def mismatch(S, T, n):
    count = 0
    for i in range(n):
        if S[i] != T[i]:
            count += 1
    return count

S = input()
n = len(S)
T1 = ""
T2 = ""
for i in range(n):
    if i % 2 == 0:
        T1 += "0"
        T2 += "1"
    else:
        T1 += "1"
        T2 += "0"
print(min(mismatch(S, T1, n), mismatch(S, T2, n)))

Submission status: Accepted

Solution code:

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

for i in range(len(s)):
    if i%2==0:
        if s[i]!="1":
            p2 += 1
    else:
        if s[i]!="0":
            p2 += 1
            
print(min(p1, p2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ans = 10e9

prev = '1'
res = 0
for s in S:
    if prev == s:
        res += 1
        prev = '1' if s == '0' else '0'
    else:
        prev = s
ans = min(ans, res)

prev = '0'
res = 0
for s in S:
    if prev == s:
        res += 1
        prev = '1' if s == '0' else '0'
    else:
        prev = s
ans = min(ans, res)

print(ans)

Submission status: Accepted

Solution code:
S = input()
odd, even = '', ''
for i, s in enumerate(S):
    if i % 2:
        odd += s
    else:
        even += s
n = odd.count('1')+even.count('0')
print(min(n, len(S)-n))

Submission status: Accepted

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


s1 = ['0']
s2 = ['1']
for i in range(2,digit+1):
  if i%2==0:
    s1.append('1')
    s2.append('0')
  else:
    s1.append('0')
    s2.append('1')
count1 = 0
count2 = 0
for i in range(digit):
  if n[i]!=s1[i]:
    count1 += 1
  if n[i]!=s2[i]:
    count2 += 1
print(min(count1,count2))

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
        else:
            b += 1
    else:
        if s[i] == '0':
            a += 1
        else:
            b += 1

print(min(a, b))

Submission status: Accepted

Solution code:
s=list(input())
s1=len(s)
c=[]
k=[]
c1=0
k1=0
for i in range(s1):
    if i%2==0:
        c.append('1')
        k.append('0')
        if s[i]==c[i]:k1+=1
        else:c1+=1
    else:
        c.append('0')
        k.append('1')
        if s[i]==c[i]:k1+=1
        else:c1+=1
print(min(c1,k1))

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


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

    S = list(iss())
    t = S[::2].count("0") + S[1::2].count("1")
    print(min(t, len(S) - t))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = str(input())
S = [int(s[i]) for i in range(len(s))]
a = []
b = []
counta = 0
countb = 0
for i in range(len(S)):
    if i == 0 or i%2==0:
        a.append(0)
        b.append(1)
    else:
        a.append(1)
        b.append(0)
for i in range(len(S)):
    if S[i] != a[i]:
        counta += 1
    elif S[i] != b[i]:
        countb += 1
print(min(counta,countb))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
x = int(S[0])
c = 0
for i in range(1,N):
  if int(S[i]) == x:
    c +=1
    if x == 0:
      x = 1
    else:
      x = 0
  else:
    x = int(S[i])
print(c)

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
        else:
            cnt2 += 1
    else:
        if s[i] == '0':
            cnt2 += 1
        else:
            cnt1 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S = input()
ex1 = ''
while len(ex1) < len(S):
    ex1 += '1'
    if len(ex1) < len(S):
  	    ex1 += '0'
ex2 = ''
while len(ex2) < len(S):
    ex2 += '0'
    if len(ex2) < len(S):
        ex2 += '1'
ans1 = 0
ans2 = 0
for i in range(len(S)):
    if ex1[i] == S[i]:
        ans2 += 1
    else:
        ans1 += 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
k = []
for i in range(len(S)):
    k.append(S[i])
position = 0
ans = 0
for i in range(10**6):
    if position >= len(S)-1:
        break
    else:
        if k[position] == k[position+1]:
            if k[position+1] == "0":
                k[position+1] = "1"
            else:
                k[position+1] = "0"
            ans += 1
        position += 1
print(ans)

Submission status: Accepted

Solution code:
n = input()
n_l = list(n)
a = [str(i % 2) for i in range(0, len(n))]
b = [str(i % 2) for i in range(1, len(n) + 1)]

count_a = 0
for i in range(len(n)):
    if n_l[i] != a[i]:
        count_a += 1

count_b = 0
for i in range(len(n)):
    if n_l[i] != b[i]:
        count_b += 1

print(min(count_a, count_b))

Submission status: Accepted

Solution code:
s = input()
 
y1 = [0 if x % 2 ==0 else 1 for x in range(len(s))]
y2 = [0 if x % 2 !=0 else 1 for x in range(len(s))]
 
ans1 = sum([1 for i,j in zip(s,y1) if int(i)==j])
ans2 = sum([1 for i,j in zip(s,y2) if int(i)==j])
print(min([ans1,ans2]))

Submission status: Accepted

Solution code:
s = input()

y1 = [0 if x % 2 ==0 else 1 for x in range(len(s))]
y2 = [0 if x % 2 !=0 else 1 for x in range(len(s))]

ans1 = sum([1 for i,j in zip(s,y1) if int(i)==j])
ans2 = sum([1 for i,j in zip(s,y2) if int(i)==j])
print(min([ans1,ans2]))

Submission status: Accepted

Solution code:
s = input()
a = s[1::2].count("0") + s[::2].count("1")
b = s[1::2].count("1") + s[::2].count("0")

print(min(a, b))

Submission status: Accepted

Solution code:
s = input()
cnt = len(s)
R = s[1::2]
L = s[::2]

cntL = L.count("0")
cntR = R.count("0")

paintL0 = 0 - -cnt//2 - cntL
paintR0 = cnt//2 - cntR

paintLR0 = paintL0 + cntR
paintLR1 = cntL + paintR0

print(min(paintLR0, paintLR1))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
'''
S = input()
n = len(S)

ans_0 = '01'*(n//2) + '0'*(n%2)
ans_1 = '10'*(n//2) + '1'*(n%2)

c_0 = c_1 = 0

for i in range(n):
    if ans_0[i] != S[i]:
        c_0 += 1
    if ans_1[i] != S[i]:
        c_1 += 1

print(min(c_0, c_1))
'''
S = input()
n = len(S)
a = 0
cnt_0 = cnt_1 = 0
for moji in S:
    cnt_0 += int(moji) ^ a
    a ^= 1

a = 1
for moji in S:
    cnt_1 += int(moji) ^ a
    a ^= 1

print(min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

S = input()
n = len(S)

ans_0 = '01'*(n//2) + '0'*(n%2)
ans_1 = '10'*(n//2) + '1'*(n%2)

c_0 = c_1 = 0

for i in range(n):
    if ans_0[i] != S[i]:
        c_0 += 1
    if ans_1[i] != S[i]:
        c_1 += 1

print(min(c_0, c_1))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

s = input()
S = s[0]
N = len(s)
cnt = 0
for i in range(N-1):
    if S[i]=='0':
        if s[i+1] == '0':
            #S += '1'
            cnt += 1
        S += '1'

    else:
        if s[i+1] == '1':
            #S += '0'
            cnt += 1
        S += '0'

print(cnt)

Submission status: Accepted

Solution code:
N=list(input())

counter=0

pre = N.pop(0)
for n in N:
    if(pre == n):
        counter+=1
    if(pre == "0"):
        pre="1"
    else:
        pre="0"

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = input()
N = len(x)
x1 = "01" * (N//2)
x2 = "10" * (N//2)
if N%2 == 1:
  x1 = x1 + "0"
  x2 = x2 + "1"
count1 = 0
count2 = 0
for x, y, z in zip(x, x1, x2):
  if x != y:
	  count1 += 1
  if x != z:
	  count2 += 1
count = min(count1, count2)
print(count)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s1 = ''.join(str(i%2) for i in range(n))
s2 = ''.join(str((i+1)%2) for i in range(n))
s1cnt = 0
s2cnt = 0
for i in range(n):
    if s[i] != s1[i]:
        s1cnt += 1
    if s[i] != s2[i]:
        s2cnt += 1
print(min(s1cnt, s2cnt))

Submission status: Accepted

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

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

sum_a = 0
for i in range(n):
    if s[i] != a[i]: sum_a += 1

sum_b = 0
for i in range(n):
    if s[i] != b[i]: sum_b += 1

print(min(sum_a, sum_b))

Submission status: Accepted

Solution code:
s = str(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 = list(input())
ans = 0
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        s[i] = "0" if s[i] == "1" else "1"
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S) # タイルの数

flip = sum( 1 ^ int(S[i]) for i in range(0, N, 2))
flip += sum( 0 ^ int(S[i]) for i in range(1, N, 2))

print(min(flip, N - flip))

Submission status: Accepted

Solution code:
S = input()
N = len(S) # タイルの数

a = sum((1 << i) for i in range(0, N, 2)) # 0b ...0101
a_flip = bin(a ^ int(S, base = 2))[2:].count('1')

print(min(a_flip, N - a_flip))

Submission status: Accepted

Solution code:
S = input()
N = len(S) # タイルの数

a = sum((1 << i) for i in range(0, N, 2)) # 0b ...0101
b = sum((1 << i) for i in range(1, N, 2)) # 0b ...1010

a_flip = bin(a ^ int(S, base = 2))
b_flip = bin(b ^ int(S, base = 2))

print(min(a_flip[2:].count('1'), b_flip[2:].count('1')))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
cand1 = '10' * (len(s)//2) + '1' * (len(s)%2)
cand2 = '01' * (len(s)//2) + '0' * (len(s)%2)

print(min(sum([x != y for x, y in zip(s, cand1)]), sum([x != y for x, y in zip(s, cand2)])))

Submission status: Accepted

Solution code:
s = input()
count1 = 0
count2 = 0
for i in range(0, len(s)):
    if(i%2 == 0):
        if(s[i] == "0"):
            count1 += 1
    if(i%2 == 1):
        if(s[i] == "1"):
            count1 += 1

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

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def func(q, S):
    ret = 0
    for s in S:
        if q == s:
            ret += 1
        q = '1' if q == '0' else '0'
    return ret


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

    S = list(iss())
    print(min(func('0', S), func('1', S)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def func(S):
    tmp = ""
    ret = 0
    for s in S:
        if tmp == s:
            ret += 1
            tmp = '1' if s == '0' else '0'
        else:
            tmp = s
    return ret


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

    S = list(iss())
    ret = func(S)
    SS = S[::-1]
    ret = min(ret, func(SS))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# python 3.4.3
import sys
input = sys.stdin.readline
import numpy as np

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()

N = len(S)
ans0 = 0 # S[0]==0 とする場合 : 偶数0 奇数1に
ans1 = 0 # S[0]==1 とする場合 : 偶数1 奇数0に

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

print(min(ans0,ans1))