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 = [int(i) for i in list(input())]
count = 0
pre = -1
for x in s:
    if x == pre:
        count = count + 1
        pre = (pre+1) % 2
    else:
        pre = x

print(count)

Submission status: Accepted

Solution code:
S = list(input())
import copy
S1 = copy.copy(S)
S1[0] = '0' if S1[0] == '1' else '1'
ans = 0
ans1 = 1
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        S[i] = '0' if S[i-1] == '1' else '1'
        ans+=1
    # print(''.join(map(str, S)))

for i in range(1, len(S1)):
    if S1[i] == S1[i-1]:
        S1[i] = '0' if S1[i-1] == '1' else '1'
        ans1+=1
    # print(''.join(map(str, S1)))

print(min(ans, ans1))

Submission status: Accepted

Solution code:
import numpy as np

S = np.array([int(s) for s in input()])
p1 = np.tile(np.arange(2), len(S) // 2 + 1)[:len(S)]
p2 = np.tile([1,0], len(S) // 2 + 1)[:len(S)]

c1 = np.abs(S - p1).sum()
c2 = np.abs(S - p2).sum()

print(min(c1, c2))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
T = ['{}'.format(i % 2) for i in range(n)]
tmp = 0
for i in range(n):
    if S[i] == T[i]:
        tmp += 1
if tmp >= n - tmp:
    ans = n - tmp
else:
    ans = tmp
print(ans)

Submission status: Accepted

Solution code:
S = str(input())
BW, WB = 0, 0
for n in range(0, len(S)):
    if n % 2 == 0:
        # 偶数番目(0, 2, 4)
        if S[n] == "0":
            # B
            WB += 1
        else:
            # W
            BW += 1
    else:
        # 奇数番目(1, 3, 5)
        if S[n] == "0":
            # B
            BW += 1
        else:
            # W
            WB += 1

if BW < WB:
    print(BW)
else:
    print(WB)

Submission status: Accepted

Solution code:
a=str(input())
n=len(a)
def hamming_dis(b,c,n):
    count=0
    for i in range(n):
        if b[i]!=c[i]:
            count+=1
    return count
c=[0]*n
d=[1]*n
e=''
f=''
for i in range(0,n,2):
    c[i]=1
    d[i]=0
for i in range(0,n):
    e=e+str(c[i])
    f=f+str(d[i])
s=hamming_dis(a,e,n)
t=hamming_dis(a,f,n)
print(min(s,t))

Submission status: Accepted

Solution code:
m = str(input())
n = len(m)
s = 0

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

if(2 * s > n):
    s = n - s
    
print(s)

Submission status: Accepted

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

def func(colors):
  count = 0
  prev_color = colors[0]
  for i in range(1, len(colors)):
    if colors[i] == prev_color:
      colors[i] = 1 if prev_color == 0 else 0
      count += 1
    prev_color = colors[i]
  return count

print(max(func(colors), func(list(reversed(colors)))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
if N % 2 == 0:
    S1 = "10"*round((N/2))
    S2 = '01'*round((N/2))
else:
    S1 = "10"*round((N/2))+'1'
    S2 = '01'*round((N/2))+'0'

s1 = N - sum([a==b for a, b in zip(S,S1)])
s2 = N - sum([a==b for a, b in zip(S,S2)])
print(min(s1,s2))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
i = n-1
B = ["0","1"]
n0,n1,b = 0,0,0
while i>=0:
  if S[i]==B[b] : n0+=1
  else : n1+=1
  b = 1-b
  i -= 1
if n0>n1 : print(n1)
else : print(n0)

Submission status: Accepted

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S = read_str()
N = len(S)

def solve():
    ans = 0
    if N == 1:
        return ans
    ans_01 = 0
    ans_10 = 0
    # 01
    for i in range(-(-N//2)):
        if i * 2 == N - 1:
            if S[2*i] == '1': ans_01 += 1
        else:
            if S[2*i:2*i + 2] == '00' or S[2*i:2*i + 2] == '11':
                ans_01 += 1
            elif S[2*i:2*i + 2] == '10':
                ans_01 += 2
    #10
    for i in range(-(-N//2)):
        if i * 2 == N - 1:
            if S[2*i] == '0': ans_10 += 1
        else:
            if S[2*i:2*i + 2] == '00' or S[2*i:2*i + 2] == '11':
                ans_10 += 1
            elif S[2*i:2*i + 2] == '01':
                ans_10 += 2
    ans = min(ans_01, ans_10)
    return ans


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
# coding: utf-8
S = input()
t = len(S)
ans = 0

for i in range(t):
  if S[i:i+1] in S[i+1:i+2]:
    ans +=1
    if S[i+1:i+2] in "0":
      S = S[:i+1]+"1"+S[i+2:] 
    else:
      S = S[:i+1]+"0"+S[i+2:] 
    
print(ans)

Submission status: Accepted

Solution code:

S = input()

ans = 0

if len(S) == 0:
    print(0)
    exit()

# 0始まり
z = sum(x == '1' for x in S[0::2]) + sum(x == '0' for x in S[1::2])

# 1始まり
o = sum(x == '0' for x in S[0::2]) + sum(x == '1' for x in S[1::2])


print(min(z, o))

Submission status: Accepted

Solution code:
S = list(input())
s_1 = S[0::2]
s_2 = S[1::2]
s_1_w = s_1.count('0')
s_2_w = s_2.count('0')
s_1_b = s_1.count('1')
s_2_b = s_2.count('1')

if s_1_w+s_2_b <= s_1_b+s_2_w:
  print(s_1_w+s_2_b)
elif s_1_b+s_2_w <= s_1_w+s_2_b:
  print(s_1_b+s_2_w)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(raw_input())
count0 = 0
for i in range(int(len(s)/2)):
	if s[2*i] == '0':
		count0 += 1
	if s[2*i+1] == '1':
		count0 += 1
if len(s) % 2 == 1:
	if s[-1] == '0':
		count0 += 1
print min(count0, len(s)-count0)

Submission status: Accepted

Solution code:

S = input()

res = 0
t = '0'
for s in S:
    if s != t:
        res += 1
    if t == '0':
        t = '1'
    else:
        t = '0'
res_1 = res

res = 0
t = '1'
for s in S:
    if s != t:
        res += 1
    if t == '0':
        t = '1'
    else:
        t = '0'
res_2 = res

if res_1 >= res_2:
    print(res_2)
else:
    print(res_1)

Submission status: Accepted

Solution code:
def main():
    S = input()
    odd_cnt = [0,0]
    even_cnt = [0,0]

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

    if even_cnt[0] + odd_cnt[1] < even_cnt[1] + odd_cnt[0]:
        print(even_cnt[0] + odd_cnt[1])
    else:
        print(even_cnt[1] + odd_cnt[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=list(input())

flag = True
if s[0] == '0':
    flag = True
else:
    flag = False

c = 0
for i in s:
    if i == '0' and flag:
        flag = not flag
    elif i == '1' and not flag:
        flag = not flag
    else:
        flag = not flag
        c += 1

print(c)

Submission status: Accepted

Solution code:
from sys import stdin
S = stdin.readline().rstrip()
# print(S)
N = len(S)
s0 = ''
s1 = ''
c0 = 0
c1 = 0
for itr in range(0,N):
    if itr%2 == 0:
        s0 += "0"
        s1 += "1"
    else:
        s0 += "1"
        s1 += "0"
# print("s0:",s0)
# print("s1:",s1)

for itr in range(0,N):
    if S[itr] != s0[itr]: c0 += 1
    if S[itr] != s1[itr]: c1 += 1

# print('c0:',c0,'c1:',c1)
if c0 >= c1:
    print(c1)
else:
    print(c0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def generator(length, prev):
    start = prev
    dic = {'0':'1', '1':'0'}
    while len(start) < length:
        next = dic[prev]
        start += next
        prev = next

    return start

first_zero = generator(N, '0')
first_one = generator(N, '1')

cnt_zero = 0
for i in range(N):
    if first_zero[i] == S[i]:
        cnt_zero += 1


cnt_one = 0
for i in range(N):
    if first_one[i] == S[i]:
        cnt_one += 1

print(min(cnt_zero, cnt_one))

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

Solution code:
import sys

a=input()
count1=0
count2=0
for x in range(len(a)):
    if x%2==0:
        if a[x] != "0":
            count1=count1+1
    else:
        if a[x] != "1":
            count1=count1+1
for x in range(len(a)):
    if x%2==0:
        if a[x] != "1":
            count2=count2+1
    else:
        if a[x] != "0":
            count2=count2+1
        
if count1>count2:
    print(count2)
    sys.exit()
print(count1)

Submission status: Accepted

Solution code:
S = input()

p = [0, 0]
for i, c in enumerate(S):
	p[0] += 0 if i % 2 == int(c) else 1
	p[1] += 1 if i % 2 == int(c) else 0
print(min(p))

Submission status: Accepted

Solution code:
S = [x for x in input()]
N = len(S)

T1_ = "0"
T2_ = "1"

c1 = c2 = 0

for i in range(N):
    if T1_ == "0":
        T1 = "1"
    if T1_ == "1":
        T1 = "0"
    if T2_ == "0":
        T2 = "1"
    if T2_ == "1":
        T2 = "0"
    if S[i] != T1:
        c1 += 1
    if S[i] != T2:
        c2 += 1

    T1_ = T1
    T2_ = T2

print(min(c1, c2))

Submission status: Accepted

Solution code:
s = [int(i) for i in list(input())]
n = len(s)
start0 = []
start1 = []
for i in range(n):
    if i % 2 == 0:
        start0.append(0)
        start1.append(1)
    else:
        start0.append(1)
        start1.append(0)

idx = 0
tmp0 = 0
tmp1 = 0
for i in s:
    if i != start0[idx]:
        tmp0 += 1
    if i != start1[idx]:
        tmp1 += 1
    idx += 1

print(min(tmp0,tmp1))

Submission status: Accepted

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

diffBlackWhite = 0
diffWhiteBlack = 0
index = 0
for c in s:
  if index % 2 == 0:
    if c == '0':
      diffWhiteBlack += 1
    else:
      diffBlackWhite += 1
  else:
    if c == '0':
      diffBlackWhite += 1
    else:
      diffWhiteBlack += 1
  index += 1

print(min(diffBlackWhite, diffWhiteBlack))

Submission status: Accepted

Solution code:
s = input()
s1 = ''
s2 = ''
s1s = '0'
s2s = '1'
dems1 = 0
dems2 = 0
for i in range(len(s)):
    s1+=s1s
    if s1s != s[i]:
        dems1+=1
    tam = s1s
    s1s = s2s
    s2+=s2s
    if s2s != s[i]:
        dems2+=1
    s2s = tam
print(min(dems1,dems2))

Submission status: Accepted

Solution code:
s=input()
lists=list(s)
lists=list(map(int,lists))
a=len(lists)
li=[0]*a
for i in range (0,a):
  if i%2==0:
    li[i]=1
counts=0
for j in range (0,a):
  if li[j]==lists[j]:
    counts=counts+1
if counts>=(a-counts):
  print(a-counts)
else:
  print(counts)

Submission status: Accepted

Solution code:
s = str(input())
bk = 0
wk = 0
bg = 0
wg = 0
k = s[::2]
g = s[1::2]
bk = k.count('0')
wk = k.count('1')
bg = g.count('0')
wg = g.count('1')
if bk + wg > wk + bg:
  print(wk + bg)
else:
  print(bk + wg)

Submission status: Accepted

Solution code:
S=input()
Sgusu=[S[i] for i in range(0,len(S),2)]
Skisu=[S[i] for i in range(1,len(S),2)]
answer1=Sgusu.count("1")+Skisu.count("0")
answer2=Sgusu.count("0")+Skisu.count("1")
answer=min([answer1,answer2])
print(answer)

Submission status: Accepted

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

if len(s) % 2 == 0:
  ideal1 = '01' * int(l / 2)
  ideal2 = '10' * int(l / 2)
else:
  ideal1 = '01' * (l // 2) + '0'
  ideal2 = '10' * (l // 2) + '1'

cnt1, cnt2 = 0, 0

for si, i1i, i2i in zip(s, ideal1, ideal2):
  if si != i1i:
    cnt1 += 1
  if si != i2i:
    cnt2 += 1
    
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
n = input ()
m = list(n)
cnt = 0
for i in range(len(m)-1):
  if m[i] != m[i+1] :
    pass
  elif m[i] == m[i+1] and m[i] == '0':
    m[i+1] = '1'
    cnt += 1
  elif m[i] == m[i+1] and m[i] == '1':
    m[i+1] = '0'
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def main():

    S = input()

    n = len(S)

    candid0 = [i % 2 for i in range(n)]
    candid1 = [1 - (i % 2) for i in range(n)]

    count0 = 0
    count1 = 0
    for i in range(n):
        if int(S[i]) == candid0[i]:
            count0 += 1
        if int(S[i]) == candid1[i]:
            count1 += 1

    print(min(count0, count1))


main()

Submission status: Accepted

Solution code:
s = input() #文字列


difCount = 0
col = 1 #最初に比べる桁は黒にする
for i in range(len(s)):
  if s[i:i+1] != str(col): #色が違えば
    difCount += 1
  col = abs(col - 1)
  
print(min(difCount,len(s)-difCount))

Submission status: Accepted

Solution code:
s=str(input())
acont=0 #0101...
bcont=0 #1010...
for i in range(len(s)):
	if i%2==0:
		if s[i]=="0":
			bcont+=1
		else:
			acont+=1
	if i%2==1:
		if s[i]=="0":
			acont+=1
		else:
			bcont+=1
print(min(acont,bcont))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:07 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""
S = str(input())

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

    for i in range(len(S)):
        if int(S[i]) != i%2:
            cnt_01 +=1
    print(min(cnt_10, cnt_01))
    
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
#input
S = str(input())
ans = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "1":
            ans += 1
    else:
        if S[i] == "0":
            ans += 1
print(min(ans,len(S)-ans))

Submission status: Accepted

Solution code:
s = input()
count_o = 0
count_z = 0

for i in range(0, len(s), 2):
	if s[i] == '1':
		count_o += 1
	else :
		count_z += 1
	if i + 1 < len(s):
		if s[i+1] == '0':
			count_o += 1
		else :
			count_z += 1
print(min(count_z, count_o))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

'''
考え方

1.奇数番目、偶数番目に0,1のいずれが何個多いのか、を確認する。
1-1.それぞれ0,1,と異なる数字の方が多く出現する。
それぞれの奇数＆偶数番目の少数派の数字を合わせる。

1-2.奇数・偶数共に同じ数字が多く出現する
多く出現する方をその数字に合わせる。
'''

len_S = len(S)

# 奇数番目
odd_0 = 0
for s in range(0,len_S,2):
  if S[s] == '0':
    odd_0 += 1

# 偶数番目
even_0 = 0
for s in range(1,len_S,2):
  if S[s] == '0':
    even_0 += 1

# 状況整理
import math
odd_1 = math.ceil(len_S / 2) - odd_0
even_1 = math.floor(len_S / 2) - even_0

# ans
# 1.奇数列において０が過半数
if odd_0 >= odd_1:
  # 1-1.偶数列の方が多く0が出現.(偶数列における1の数) + (奇数列における0の数)
  if odd_0 <= even_0:
    ans = even_1 + odd_0
  # 1-2.偶数列の方が0出現頻度が小さい.(偶数列における0の数) + (奇数列における1の数)
  else:
    ans = even_0 + odd_1
# 2.奇数列において１が過半数
else:
  # 2-1.偶数列の方が1が多い.(偶数列の０) + (奇数列の1)
  if odd_1 <= even_1:
    ans = even_0 + odd_1
  else:
    ans = even_1 + odd_0
    
print(ans)

Submission status: Accepted

Solution code:
import sys

S = input()

if len(S) == 1:
    print(0)
    sys.exit()


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


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

Submission status: Accepted

Solution code:
a = input()
b = []
c = []
bb = 0
cc = 0
for i in range(len(a)):
    if i % 2 == 0:
        b.append("0")
    else:
        b.append("1")
for i in range(len(a)):
    if i % 2 == 0:
        c.append("1")
    else:
        c.append("0")
for i in range(len(a)):
    if a[i] != b[i]:
        bb += 1
for i in range(len(a)):
    if a[i] != c[i]:
        cc += 1
print(min(bb, cc))

Submission status: Accepted

Solution code:
S=list(input())
S1 = S[:]
S2 = S[:]
N=len(S)
output=0
n1=0
n2=0
if N>1:
    for i in range(1,N):
        if int(S1[i])==int(S1[i-1]):
            S1[i]=str(1-int(S1[i]))
            n1 += 1
    n2 += 1
    S2[0]=str(1-int(S2[0]))
    for i in range(1,N):
        if int(S2[i])==int(S2[i-1]):
            S2[i]=str(1-int(S2[i]))
            n2 += 1

    output = min(n1,n2)

print(output)

Submission status: Accepted

Solution code:
S = input()

SO = S[::2]  #奇数番目
SE = S[1::2] #偶数番目

SOC0 = SO.count("0")
SOC1 = SO.count("1")
SEC0 = SE.count("0")
SEC1 = SE.count("1")

#print(SOC0, SOC1, SEC0, SEC1)
print(min(SOC0+SEC1, SOC1+SEC0))

Submission status: Accepted

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

s_ = "10"*(l//2) + "1"*(l%2)

x = 0
for a,b in zip(s, s_):
    if a != b:
        x += 1

if x > l/2:
    x = l-x

print(x)

Submission status: Accepted

Solution code:
def bc(x):
  return bin(x).count("1")

n = input()
s = int('0b' + n, 2)
m1 = ('01' * len(n))[:len(n)]
m2 = ('10' * len(n))[:len(n)]
b1 = int('0b' + m1, 2)
b2 = int('0b' + m2, 2)

c1 = s ^ b1
c2 = s ^ b2

print(min(bc(c1), bc(c2)))

Submission status: Accepted

Solution code:
s = list(map(int, input()))
s = list(map(bool, s))
should = not s[0]
counter = 0

for color in s[1:]:
    if not color == should:
        counter += 1
    should = not should
print(counter)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
# import numpy as np
n=list((input()))  #数値入力

n = [int(s) for s in n]
count = 0

for i in range(len(n)-1):
    onezero = n[i]
    #print('i = '+str(n[i]))
    if onezero == n[i+1]:
        count += 1
        if n[i+1] == 0:
            n[i+1] = 1
        else:
            n[i+1] = 0

        
print(count)

Submission status: Accepted

Solution code:
import math

S = input()

n = len(S)

case1 = [0, 1] * int(math.floor(n/2))
case2 = [1, 0] * int(math.floor(n/2))

if n % 2 == 1:
    case1.append(0)
    case2.append(1)


# print(case1)
# print(case2)

c1 = 0
c2 = 0
for i in range(n):
    if int(S[i]) != case1[i]:
        c1 += 1
    if int(S[i]) != case2[i]:
        c2 += 1

if c1 < c2:
    print(c1)
else:
    print(c2)

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
s_o = S[::2]
s_e = S[1::2]

cnt_o = Counter(s_o).most_common(1)
cnt_e = Counter(s_e).most_common(1)

if len(S) == 1:
    print(0)
else:
    if cnt_o[0][1] >= cnt_e[0][1] and cnt_o[0][0] == '0':
        print(s_o.count('1')+s_e.count('0'))
    elif cnt_o[0][1] >= cnt_e[0][1] and cnt_o[0][0] == '1':
        print(s_o.count('0')+s_e.count('1'))
    elif cnt_o[0][1] < cnt_e[0][1] and cnt_e[0][0] == '0':
        print(s_o.count('0')+s_e.count('1'))
    else:
        print(s_o.count('1')+s_e.count('0'))

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
S2 = input()
N = len (S2)
Z2 = '0'
O2 = '1'
for i in range(1,N):
    if (i+1)%2==0:
        Z2+='1'
        O2+='0'
    else:
        Z2+='0'
        O2+='1'

S10 = int(S2,2)
Z10 = int(Z2,2)
O10 = int(O2,2)
ChangeSZ=bin(S10^Z10).count('1')
ChangeSO=bin(S10^O10).count('1')
print(min(ChangeSZ,ChangeSO))

Submission status: Accepted

Solution code:
def get_next_expect_color(color) :
    if (color == "1") :
        return "0"
    else :
        return "1"

S = input()

must_reversed_count = 0
expect_color = S[0]

must_reversed_count2 = 1 # 最初が反転なので1にする
expect_color2 = get_next_expect_color(S[0])

for i in range(1,len(S)) :
    if (S[i] == expect_color) :
        must_reversed_count += 1
    
    if (S[i] == expect_color2) :
        must_reversed_count2 += 1

    expect_color = get_next_expect_color(expect_color)
    expect_color2 = get_next_expect_color(expect_color2)

# print(must_reversed_count)
# print(must_reversed_count2)
print(min([must_reversed_count,must_reversed_count2]))

Submission status: Accepted

Solution code:
s=input()
lst = list(s)
l=[]
for i in range(len(lst)):
    l.append(int(lst[i]))

cnt=0

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
res = [0, 0]
flag = 0
while(S != ""):
    res[abs(int(S[0]) - flag)] += 1
    S = S[1:]
    flag = 1 - flag
print(min(res[0], res[1]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
S = input()
x = y = ''
for i in range(len(S)):
    if i % 2 == 0:
        x += S[i]
    else:
        y += S[i]

c1 = x.count('1') + y.count('0')
c2 = x.count('0') + y.count('1')
print(min(c1, c2))

Submission status: Accepted

Solution code:
N=input()
count = 0

for i in range(len(N)):
    P = int(N[i])
    if i%2 == 0:
        if P == 1:
            count += 1
    else:
        if P == 0:
            count += 1
N =str(N)
print(min([count,len(N)-count]))

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(x)

Submission status: Accepted

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

start_0 = 0
start_1 = 0

for i in range(len(colors)):
	color = int(colors[i])
	if i % 2:
		if color == 1:
			start_0 += 1
		else:
			start_1 += 1
	else:
		if color == 1:
			start_1 += 1
		else:
			start_0 += 1

print(min(start_0, start_1))

Submission status: Accepted

Solution code:
S = input()

odd = []
even = []

for i in range(len(S)):
    if i % 2 == 0:
        even.append(int(S[i]))
    else:
        odd.append(int(S[i]))


count = 0
if sum(even) == sum(odd):
    if len(even) > len(odd):
        count = len(odd) - sum(odd) + sum(even)
    else:
        count = len(even) - sum(even) + sum(odd)
elif sum(even) > sum(odd):
    count = len(even) - sum(even) + sum(odd)
else:
    count = len(odd) - sum(odd) + sum(even)

print(count)

Submission status: Accepted

Solution code:
import numpy as np


S = [True if i == '1' else False for i in list(input())]

pat1 = [True, False] * (len(S) // 2)
pat2 = [False, True] * (len(S) // 2)
if len(S) % 2 == 1:
    pat1.append(True)
    pat2.append(False)

print(min(
    np.sum(np.logical_xor(S, pat1) == False),
    np.sum(np.logical_xor(S, pat2) == False)
))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

Se = [s for i, s in enumerate(S) if i % 2 == 0]
So = [s for i, s in enumerate(S) if i % 2 == 1]
result = min(Se.count('0') + So.count('1'), Se.count('1') + So.count('0'))
print(result)

Submission status: Accepted

Solution code:
S = list(str(input()))
ini0,ini1 = 0,0
for i,s in enumerate(S):
    if i%2 == 0:
        if s == '0':
            ini1 += 1
        else:
            ini0 += 1
    else:
        if s == '0':
            ini0 += 1
        else:
            ini1 += 1
print(min(ini0,ini1))

Submission status: Accepted

Solution code:
def main() -> None:
    S = input()
    a1 = cou(S, '0', '1')
    a2 = cou(S, '1', '0')
    print(min(a1, a2))


def cou(S, f, s):
    num = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == f:
                num += 1
            else:
                pass
        elif i % 2 != 0:
            if S[i] == s:
                num += 1
            else:
                pass
    return num


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

S = str(input())

ans_S = [str(0) for i in range(len(S))]
ans_1 = 0
for i in range(len(S)):
    if i%2==0:
        ans_S[i] = str(1)

    if ans_S[i]!=S[i]:
        ans_1 += 1

ans_2 = 0
ans_S = [str(0) for i in range(len(S))]
for i in range(len(S)):
    if i%2==1:
        ans_S[i] = str(1)

    if ans_S[i]!=S[i]:
        ans_2 += 1

ans = min(ans_1,ans_2)
print(ans)

Submission status: Accepted

Solution code:
S_list = list(input())
result = 0
level = S_list.pop(0)
for s in S_list:
    if level == s and s == "0":
        level = "1"
        result += 1
    elif level == s and s == "1":
        level = "0"
        result += 1
    else:
        level = s
print(result)

Submission status: Accepted

Solution code:
l=list(map(int,input()))
le=len(l)
p1,p2=[],[]
a,b=1,0
for i in range(le):
    p1.append(a)
    p2.append(b)
    a,b=b,a
m1,m2=0,0
for i in range(le):
    m1+=abs(l[i]-p1[i])
    m2+=abs(l[i]-p2[i])
print(min(m1,m2))

Submission status: Accepted

Solution code:
S_str = input()
S_lists=[ int(S) for S in S_str]
print(min(sum([ abs(S-i)%2 for i,S in enumerate(S_lists)]),sum([ abs(S-i+1)%2 for i,S in enumerate(S_lists)])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

if S[0] == "1":
  print(S[::2].count("0")+S[1::2].count("1"))
else:
  print(S[::2].count("1")+S[1::2].count("0"))

Submission status: Accepted

Solution code:
S = input()

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

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

print(min(count1, count2))

Submission status: Accepted

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

def main():
    S=list(map(str,input().split()))
    # S=input()
    S=S[0]
    # print(type(S))
    N=len(S)

    s0=0
    s1=0
    for i in range(N):
        if i%2==0:
            if S[i]=="0":
                s1+=1
            else:
                s0+=1
        else:
            if S[i]=="1":
                s1+=1
            else:
                s0+=1
    print(min(s0,s1))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def count(li, first):
    if first == '0':
        isZero = True
    else:
        isZero = False
    counter = 0
    for i in li[1:]:
        if i == '0' and isZero:
            counter += 1
            isZero = False
        elif i == '1' and (not isZero):
            counter += 1
            isZero = True
        else:
            isZero = not isZero
    return counter


S = input()

print(min([count(list(S), S[0]), count(list(S)[::-1], list(S)[::-1][0])]))