Problem:


Score : 300 points

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Sample Input 1

000

Sample Output 1

1

The condition can be satisfied by repainting the middle tile white.

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

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

Submission status: Accepted

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

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

ca, cb = 0, 0
for i in range(n):
    if a[i] != s[i]:
        ca += 1
    if b[i] != s[i]:
        cb += 1

print(min(ca,cb))

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))
c01 = sum([1 for i, j in enumerate(s) if i % 2 == j])
c10 = sum([1 for i, j in enumerate(s) if i % 2 != j])
print(min(c01, c10))

Submission status: Accepted

Solution code:
s = list(input())
t = s
S = s+ ['0']
T = t+ ['1']
answ = 0
ansb = 0

for i in range(len(s)):
  if S[i] == '0' and S[i-1] == '0':
    S[i] = '1'
    answ += 1
  elif S[i] == '1' and S[i-1] == '1':
    S[i] = '0'
    answ += 1
    
  if T[i] == '1' and T[i-1] == '1':
    T[i] = '0'
    ansb += 1
  elif T[i] == '0' and T[i-1] == '0':
    T[i] = '1'
    ansb += 1
    
print(min(ansb,answ))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

l0 = [0 if i % 2 == 0 else 1 for i in range(len(S))]
l1 = [1 if i % 2 == 0 else 0 for i in range(len(S))]

gap0 = 0
gap1 = 0
for i in range(len(S)):
    if l0[i] != int(S[i]):
        gap0 += 1
    if l1[i] != int(S[i]):
        gap1 += 1

print(min(gap0, gap1))

Submission status: Accepted

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

# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############



S = S()

S1 = list(map(int,S[::2]))
S2 = list(map(int,S[1::2]))
ans = sum(S1)+len(S2)-sum(S2)
P(min(len(S)-ans,ans))

Submission status: Accepted

Solution code:
s=[int(i) for i in input()]
ans=0
for i in range(1,len(s)):
	ans+=s[~-i]==s[i]
	s[i]=not s[~-i]
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
T = [S[i] for i in range(N)]
c1 = 0

for i in range(1,N):
  if T[i] == T[i-1]:
    if T[i-1] == '0':
      T[i] = '1'
      c1 += 1 
    else:
      T[i]= '0'
      c1 += 1

if  S[0] == '0':
  S[0] = '1'
else:
  S[0] = '0'
c2 = 1
for i in range(1,N):
  if S[i] == S[i-1]:
    if S[i-1] == '0':
      S[i] = '1'
      c2 += 1 
    else:
      S[i]= '0'
      c2 += 1

print(min(c1,c2))

Submission status: Accepted

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

# 01010101...
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == '1':
      ans2 += 1
  if i % 2 != 0:
    if S[i] == '0':
      ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
A = '01'*(len(S)//2)+'0'*(len(S)%2)

c = 0

for i,j in zip(S,A):
    if i != j:
        c +=1

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a=''
if n!=0:
  a+=('10'*(n//2)+'1')
else:
  a+='10'*(n//2)
ans=0
for i in range(n):
  if a[i]==s[i]:
    ans+=1
print(min(ans,n-ans))

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]= '0' if S[i]=='1' else '1'
print(ans)

Submission status: Accepted

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

# check
length = len(S)
if len == 1:
    print(0)
else:
    bwb = ["0", "1"]
    wbw = ["1", "0"]
    cnt = [0] * 2
    for i in range(length):
        if S[i] == bwb[i % 2]:
            cnt[0] += 1
        if S[i] == wbw[i % 2]:
            cnt[1] += 1

    print(min(cnt))

Submission status: Accepted

Solution code:
s = list(input())
a = len(s)

def f(b):
    count = 0
    for i in range(a):
        if s[i] != b:
            count += 1

        if b == '0':
            b = '1'
        else:
            b = '0'
    return count

print(min(f('0'), f('1')))

Submission status: Accepted

Solution code:
S = list(input())

pattern_01 = 0
pattern_10 = 0

for idx, s in enumerate(S):
    if idx % 2 == 0 and s == "1":
        pattern_01 += 1
    elif idx % 2 == 0 and s == "0":
        pattern_10 += 1
    elif idx % 2 == 1 and s == "1":
        pattern_10 += 1
    elif idx % 2 == 1 and s == "0":
        pattern_01 += 1

print(min(pattern_01, pattern_10))

Submission status: Accepted

Solution code:
s = input()
s_len = len(s)
if s_len == 1:
    print(0)
else:
    dum1 = s[0::2].count("0")
    dum2 = s[1::2].count("1")
    ans1 = s_len-dum1-dum2

    dum3 = s[0::2].count("1")
    dum4 = s[1::2].count("0")
    ans2 = s_len-dum3-dum4
    print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
ans1 = 0
ans2 = 0
flag = True
for s in S:
    if flag:
        flag = False
        if s == '0':
            ans1 += 1
        else:
            ans2 += 1
    else:
        flag = True
        if s == '0':
            ans2 += 1
        else:
            ans1 += 1
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = len(s)
bo=s[::2].count('0')
be=s[1::2].count('0')
ans = 0
if be>=bo:
    ans += l//2-be + bo
elif l%2!=0:
    ans += l//2+1-bo + be
else:
    ans += l//2-bo + be
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
S = input()
N = len(S)


def create(N, b, c):
    a = ""
    i = 0
    while i < (N // 2):
        a += b + c
        i += 1
    if N % 2 == 1:
        a += b
    lst = [0 for i in range(N) if a[i] == S[i]]
    return len(lst)


print(min(create(N, '1', '0'), create(N, '0', '1')))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
S=list(input())
N=len(S)
n=N//2
if S[0]=='0':
  L=['0','1']*(n+1)
else:
  L=['1','0']*(n+1)
ans=0
for n in range(N):
  if S[n]!=L[n]:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
S = input()
count_1 = 0
count_2 = 0
for i,s in enumerate(S):
    if i % 2 == 0 and s == '0':
        count_1 += 1
    elif i % 2 != 0 and s == '1':
        count_1 += 1
for i,s in enumerate(S):
    if i % 2 == 0 and s == '1':
        count_2 += 1
    elif i % 2 != 0 and s == '0':
        count_2 += 1
print(min(count_1,count_2))

Submission status: Accepted

Solution code:
S = input()
l_even = len(S[0::2])
l_odd = len(S[1::2])

white_even = S[0::2].count('0')
black_even = l_even - white_even
white_odd = S[1::2].count('0')
black_odd = l_odd - white_odd

print(min(white_even + black_odd, white_odd + black_even))

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

temp = S[0]
ans = 0
for i in S[1:]:
    if i==temp:
        i = '1' if temp == '0' else '0'
        ans += 1
    temp = i 

print(ans)

Submission status: Accepted

Solution code:
S = input()
c1, c2 = 0, 0

for i, b in enumerate(S):
    b = int(b)
    if b != i%2:
        c1 += 1
    if b != (i+1)%2:
        c2 += 1

print(min(c1, c2))

Submission status: Accepted

Solution code:
t = list(input())
S = [int(x) for x in t]
cnt1 = 0
cnt2 = 0

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

Submission status: Accepted

Solution code:
s=input()
l = []
l.append(s[0])
c = 0
for i in range(1, len(s)):
  if s[i] == l[i-1]:
    c += 1
    l.append(str(-(int(s[i])-1)))
  else:
    l.append(s[i])
print(c)

Submission status: Accepted

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


def solve(S: str):
    a = S[::2].count("1") + S[1::2].count("0")
    b = S[::2].count("0") + S[1::2].count("1")
    print(min(a, b))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    

    def calc_diff(s1, s2):
        n = len(s1)
        cnt = 0
        for i in range(n):
            if s1[i] != s2[i]:
                cnt += 1
        return cnt
    

    s = input()
    n = len(s)
    
    zero_one = [None] * n
    one_zero = [None] * n
    tmp = [['0', '1'], ['1', '0']]
    for i in range(n):
        zero_one[i] = tmp[i % 2][0]
        one_zero[i] = tmp[i % 2][1]
    
    print(min(calc_diff(s, ''.join(zero_one)), calc_diff(s, ''.join(one_zero))))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=input()
a=""
b=""
l=len(n)
for i in range(l):
    if i%2==0:
        a+="0"
        b+="1"
    else:
        a+="1"
        b+="0"
a_ans=0
b_ans=0
for j in range(l):
    if a[j]!=n[j]:
        a_ans+=1
    else:
        b_ans+=1
print(min(a_ans,b_ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
rcount = 0
for i in range(n):
  if int(s[0]) % 2 == 0:
    if i % 2 == 0:
      if int(s[i]) % 2 == 1:
        rcount += 1
    else:
      if int(s[i]) % 2 == 0:
        rcount += 1
  if int(s[0]) % 2 == 1:
    if i % 2 == 0:
      if int(s[i]) % 2 == 0:
        rcount += 1
    else:
      if int(s[i]) % 2 == 1:
        rcount += 1
print(rcount)

Submission status: Accepted

Solution code:
n = input()

black = []
white = []
bit = 0
for i in range(len(n)):
    black.append(bit)
    white.append(bit ^ 1)
    bit ^= 1

black_cnt = 0
white_cnt = 0
for i in range(len(n)):
    if black[i] != int(n[i]):
        black_cnt += 1
    if white[i] != int(n[i]):
        white_cnt += 1

print(min(black_cnt, white_cnt))

Submission status: Accepted

Solution code:
s = list(map(int,input()))
n_s = []
r_s = []

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

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

cnt = 0
cnt_n = 0
for i in range(len(s)):
    if s[i] != n_s[i]:
        cnt+=1
    if s[i] != r_s[i]:
        cnt_n+=1

print(min(cnt_n,cnt))

Submission status: Accepted

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

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

expected_b = s[0]
ans = 0
for b in s:
    if b != expected_b:
        ans += 1
    expected_b = not expected_b

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
count_0 = 0
count_1 = 0

l = len(s)

# start with 0
for i in range(l):
    # print(" i : ", i)
    if i % 2 == 0:
        if s[i] == "1":
            count_0 += 1
    else:
        # print("odd")
        # print(s[i])
        if s[i] == "0":
            count_0 += 1
            # print(count_0)

# start with 1
for i in range(l):
    if i % 2 == 0:
        if s[i] == "0":
            count_1 += 1
    else:
        if s[i] == "1":
            count_1 += 1



# print(count_0)
# print(count_1)
print(min(count_0, count_1))

Submission status: Accepted

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

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

def solve(s):
    n = len(s)
    val1 = 0
    # 010101...
    for i in range(n):
        if i % 2 == 0 and s[i] != '0':
            val1 += 1
        elif i % 2 == 1 and s[i] != '1':
            val1 += 1
    val2 = 0
    #1010...
    for i in range(n):
        if i % 2 == 0 and s[i] != '1':
            val2 += 1
        elif i % 2 == 1 and s[i] != '0':
            val2 += 1
    return min(val1, val2)

def main():
    print(solve(input()))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy

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

count2 = 0
for i in range(len(s)):
    if i % 2 == 0 and s[i] != "1":
        count2 += 1
    if i % 2 != 0 and s[i] == "1":
        count2 += 1

print(min(count1,count2))

Submission status: Accepted

Solution code:
import math
import copy

neko = 0
nuko = 0
s = input()
a = ["0","1"]
for i in range(len(s)):
    if s[i] == a[i%2]:
        neko += 1
    if s[i] == a[(i+1)%2]:
        nuko += 1
if neko > nuko:
    neko = nuko
print(neko)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    S = input().rstrip('\n')
    l = len(S)
    ws = bs = ''
    for i in range(l):
        if i%2 == 0:
            ws += '0'
            bs += '1'
        else:
            ws += '1'
            bs += '0'
    wsc = bsc = 0
    for i in range(l):
        if S[i] != ws[i]:
            wsc += 1
        if S[i] != bs[i]:
            bsc += 1
    print(min(wsc, bsc))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    S = input().rstrip('\n')
    l = len(S)
    ws = bs = ''
    for i in range(l):
        if i%2 == 0:
            ws += '0'
            bs += '1'
        else:
            ws += '1'
            bs += '0'
    wsc = bsc = 0
    for i in range(l):
        if S[i] != ws[i]:
            wsc += 1
        if S[i] != bs[i]:
            bsc += 1
    ans = min(wsc, bsc)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
e=0
o=0
n=len(s)

for i in range(n):
    if i%2==0 and s[i]=="1":
        e+=1
    elif i%2==0 and s[i]=="0":
        o+=1
    elif i%2==1 and s[i]=="0":
        e+=1
    else:
        o+=1
print (min(e,o))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    cunt1=0
    for i,ss in enumerate(s):
        if int(ss)==i%2:cunt1+=1
    cunt2=0
    for i,ss in enumerate(s):
        if int(ss)!=i%2:cunt2+=1   
    print(min(cunt1,cunt2))

if __name__=='__main__':
    main()

Submission status: Accepted

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

plan_0 = [i % 2 for i in range(len(S))]
plan_1 = [i % 2 for i in range(1, len(S)+1)]

x = sum([(plan_0[i] - S[i]) != 0 for i in range(len(S))])
y = sum([(plan_1[i] - S[i]) != 0 for i in range(len(S))])

print(min(x, y))

Submission status: Accepted

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

plan_0 = [i % 2 for i in range(len(S))]
plan_1 = [i % 2 for i in range(1, len(S)+1)]

x = len(S) - sum([(plan_0[i] - S[i])==0 for i in range(len(S))])
y = len(S) - sum([(plan_1[i] - S[i])==0 for i in range(len(S))])

print(min(x, y))

Submission status: Accepted

Solution code:
s = input()
cnt = 0
check = '10'*(len(s)//2) + '1'*(len(s) % 2)
for a, b in zip(s, check):
    if a != b:
        cnt += 1
print(min(cnt, len(s)-cnt))

Submission status: Accepted

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


now=s[0]
cnt=0
for i in range(1,n):
    if s[i]==now:
        cnt+=1
        if s[i]=='0':
            s[i]='1'
            now='1'
        else:
            s[i]='0'
            now='0'
    else:
        now=s[i]

print(cnt)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
t = 0
odd = 0
even = 0
while t < n:
  odd += int(s[t])
  t += 2
u = 1
while u < n:
  even += int(s[u])
  u += 2
if n%2 == 0:
  print(min(n//2+odd-even,n//2+even-odd))
else:
  print(min(n//2+odd-even,n//2+even+1-odd))

Submission status: Accepted

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    s=S()
    b_start=0
    w_start=1
    num_whenbstart=0
    num_whenwstart=0
    for i in range(len(s)):
        if int(s[i])!=b_start:
            num_whenbstart+=1
        if int(s[i])!=w_start:
            num_whenwstart+=1
        b_start=0 if b_start%2==1 else 1
        w_start=0 if w_start%2==1 else 1
    print(min(num_whenwstart,num_whenbstart))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
l = len(s)
S =[]
for i in range(l):
    S.append(int(s[i]))
m = [1]
n = [0]
for i in range(1,l):
    if i % 2 == 1:
        m.append(0)
        n.append(1)
    else:
        m.append(1)
        n.append(0)
ans1 = 0
ans2 = 0
for i in range(l):
    if m[i] != S[i]:
        ans1 += 1
    if n[i] != S[i]:
        ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
cnt=0
l=list(input())

for i in range(len(l)-1):
    if l[i]==l[i+1]:
        if l[i]=='0':
            l[i+1]='1'
            cnt +=1
        else:
            l[i+1]='0'
            cnt+=1
     
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = len(s)
one = 0
two = 0
for i in range(l):
  if i % 2 == 0:
    if s[i] == '0':
      one += 1
    else:
      two += 1
  else:
    if s[i] == '1':
      one += 1
    else:
      two += 1

print(min(one , two))

Submission status: Accepted

Solution code:
s = input()
ans = 0
p = s[0]
for i in range(1, len(s)):
    if s[i] != p:
        p = s[i]
    else:
        ans += 1
        p = '0' if s[i] == '1' else '1'
print(ans)

Submission status: Accepted

Solution code:
s = input()
cnt_b = 0
cnt_w = 0
i = 1
for l in s:
    if i % 2 == 1:
        if l == '1':
            cnt_b += 1
        else:
            cnt_w += 1
    else:
        if l == '1':
            cnt_w += 1
        else:
            cnt_b += 1
    i += 1
print(min(cnt_b, cnt_w))

Submission status: Accepted

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

Submission status: Accepted

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

zero = []
one = []

zerocount = 0
onecount = 0

for i in range(len(S)):
    if i%2 == 0:
        zero.append(0)
        one.append(1)
    else:
        zero.append(1)
        one.append(0)

for i in range(len(S)):
    if zero[i] != S[i]:
        zerocount += 1
    if one[i] != S[i]:
        onecount += 1

if zerocount<onecount:
    print(zerocount)
else:
    print(onecount)

Submission status: Accepted

Solution code:
A=list(input())
A=list(map(int,A))
ansA=0
ansB=0
for i in range(len(A)):
    if i%2==0:
        if A[i]==0:
            pass
        else:
            ansA+=1
    else:
        if A[i]==1:
            pass
        else:
            ansA+=1
for i in range(len(A)):
    if i%2==1:
        if A[i]==0:
            pass
        else:
            ansB+=1
    else:
        if A[i]==1:
            pass
        else:
            ansB+=1
print(min(ansA,ansB))

Submission status: Accepted

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

count1 = 0
count2 = 0
for i in range(N):
    if S[i] != cand1[i]:
        count1 += 1
    if S[i] != cand2[i]:
        count2 += 1
        
ans = min(count1, count2)
print(ans)

Submission status: Accepted

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