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:
def solve(init, s):
    ideal = init  # 初期値 黒 or 白
    result = 0  # 塗り替える数
    for color in s:
        if color != ideal:
            result += 1
        ideal ^= 1  # 排他的論理和, 白黒逆になる
    return result


s = input()
s = list(map(int, s))
print(min(solve(0, s), solve(1, s)))

Submission status: Accepted

Solution code:
S = list(input())
W = 0 #最初が白の時
B = 0 #最初が黒の時

for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '0': #偶数番目が黒色のとき
            W += 1
        else:
            B += 1
    else:
        if S[i] == '1': #偶数番目が黒色のとき
            W += 1
        else:
            B += 1

print (min(W, B))

Submission status: Accepted

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

ans1 = 0
ans2 = 0

for i in range(int((N+1)/2)):
    if orig[2*i] != '1':
        ans1 = ans1 + 1

for i in range(int(N/2)):
    if orig[2*i+1] != '0':
        ans1 = ans1 + 1

for i in range(int((N+1)/2)):
    if orig[2*i] != '0':
        ans2 = ans2 + 1

for i in range(int(N/2)):
    if orig[2*i+1] != '1':
        ans2 = ans2 + 1

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

Submission status: Accepted

Solution code:
S = list(input())

count_0 = 0
count_1 = 0

for i in range(len(S)):
	if (i % 2 == 1) ^ (S[i] == '1'):
		count_0 += 1
	else:
		count_1 += 1
		
print(min(count_0, count_1))

Submission status: Accepted

Solution code:
S=input()
N=len(S)
A=len([i for i in range(N) if str(i%2)==S[i]])
print(min(A,N-A))

Submission status: Accepted

Solution code:
S=input()
N=len(S)
A="".join([str(i%2) for i in range(N)])
B="".join([str((i+1)%2) for i in range(N)])
print(min(sum([1 for i in range(N) if S[i]!=A[i]]),sum([1 for i in range(N) if S[i]!=B[i]])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
s0 = S[::2]
s1 = S[1::2]

count_0 = 0
count_1 = 0

for i in s0:
    if i == 0:
        count_0 += 1
    else:
        count_1 += 1

for i in s1:
    if i == 1:
        count_0 += 1
    else:
        count_1 += 1

if count_0 > count_1:
    print(count_1)
else:
    print(count_0)

Submission status: Accepted

Solution code:

def main():
    S = input()
    a = ["1" if i % 2 == 0 else "0" for i in range(len(S))]
    b = ["0" if i % 2 == 0 else "1" for i in range(len(S))]
    if comparison(S, a) <= comparison(S, b):
        print(comparison(S, a))
    else:
        print(comparison(S, b))


def comparison(S, n):
    count = 0
    for i in range(len(S)):
        if not n[i] == S[i]:
            count += 1
    return count


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
x = 0
count0 = 0
count1 = 0
for i in s:
    count0 = count0+1 if i==str(x) else count0
    x = int(not(x))
x = 1
for i in s:
    count1 = count1 + 1 if i == str(x) else count1
    x = int(not(x))
print(min(count0, count1))

Submission status: Accepted

Solution code:
s = input()

x = 0
count0 = 0
count1 = 0

for i in s:
    #if i == str(x):
     #   count0 += 1
    count0 = count0+1 if i==str(x) else count0
    x = int(not(x))

x = 1
for i in s:
    #if i == str(x):
    #    count1 += 1
    count1 = count1 + 1 if i == str(x) else count1
    x = int(not(x))

print(min(count0, count1))

Submission status: Accepted

Solution code:
s = input()

x = 0
count0 = 0
count1 = 0

for i in s:
    if i == str(x):
        count0 += 1
    x = int(not(x))

x = 1
for i in s:
    if i == str(x):
        count1 += 1
    x = int(not(x))

print(min(count0, count1))

Submission status: Accepted

Solution code:
s = input()

x = 0
count0 = 0
count1 = 0

for i in s:
    if i == str(x):
        count0 += 1
    x = int(not(x))

x = 1
for i in s:
    if i == str(x):
        count1 += 1
    x = int(not(x))
#print("count0:" + str(count0))
#print("count1:" + str(count1))
print(min(count0, count1))

Submission status: Accepted

Solution code:
S = input()

B = [] * len(S)
ans = 0

for i in range(len(S)) :
    if not int(S[i]) == (i%2) :
        ans += 1

ans = min(ans , len(S) - ans)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
s = input()
s1 = s0 = 0
for j in range(len(s)):
    if j % 2 == 0 and int(s[j]) == 0:
        pass
    elif j % 2 == 1 and int(s[j]) == 1:
        pass
    else:
        s0 += 1
    if j % 2 == 0 and int(s[j]) == 1:
        pass
    elif j % 2 == 1 and int(s[j]) == 0:
        pass
    else:
        s1 += 1
print(min(s1, s0))

Submission status: Accepted

Solution code:
s = input()
if len(s) % 2 == 0:
  s1 = "10" * int(len(s) / 2)
  s2 = "01" * int(len(s) / 2)
else:
  s1 = "10" * int(len(s) / 2) + "1"
  s2 = "01" * int(len(s) / 2) + "0"
a1 = int(s) + int(s1)
a2 = int(s) + int(s2)
a1 = str(a1).count("1")
a2 = str(a2).count("1")
print(min(a1,a2))

Submission status: Accepted

Solution code:

def problem():
    s = str(input())
    print(algorithm(s))

def algorithm(s: str):
  counter1 = 0
  counter2 = 0

  for index in range(len(s)):
    if index % 2 == 0:
      if s[index] == '0':
        counter1 += 1
    else:
      if s[index] == '1':
        counter1 += 1

  for index in range(len(s)):
    if index % 2 == 0:
      if s[index] == '1':
        counter2 += 1
    else:
      if s[index] == '0':
        counter2 += 1   

  return counter1 if counter1 < counter2 else counter2

problem()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = input()
input_len = len(s)

# 先頭に1を足す
s = "1" + s

# 正解になるパターンの作成(先頭に1を入れておく)
str1 = "1" + "01" * (input_len//2)
str2 = "1" + "10" * (input_len//2)

if(input_len%2 == 1):
	#要素数が奇数の場合は1個足す
	str1 = str1 + "0"
	str2 = str2 + "1"

# print(str1)
# print(str2)

#2進数に変換
input_num = int(s, 2)
num1 = int(str1, 2)
num2 = int(str2, 2)

# print(input_num, num1, num2)
# print(bin(input_num), bin(num1), bin(num2))

# 排他的論理和を求める
ans1 = input_num ^ num1
ans2 = input_num ^ num2
# print(ans1, ans2)
# print(bin(ans1), bin(ans2))

#ビットが立っている数を数える
ans_str1 = list(bin(ans1)[2:])
ans_list1 = list(filter(lambda x: x == "1", ans_str1)) 
a1 = len(ans_list1)

ans_str2 = list(bin(ans2)[2:])
ans_list2 = list(filter(lambda x: x == "1", ans_str2)) 
a2 = len(ans_list2)

if a1 < a2:
	print(a1)
else:
	print(a2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC124C - Coloring Colorfully
import sys
input = sys.stdin.readline

s = input().rstrip()
a = s[0]
ans = 0
for i, j in enumerate(s):
    if i % 2 == 0:
        if j != a:
            ans += 1
    else:
        if j == a:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# ABC124C - Coloring Colorfully
s = input()
a = s[0]
ans = 0
for i, j in enumerate(s):
    if i % 2 == 0:
        if j != a:
            ans += 1
    else:
        if j == a:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()
cnt = 0
if(s[:1] == '0'):
  for i in range(len(s) // 2):
    if(s[2*i+1:2*i+2] == '0'):
      cnt += 1
    if(s[2*i+2:2*i+3] == '1'):
      cnt += 1
else:
  for i in range(len(s) // 2):
    if(s[2*i+1:2*i+2] == '1'):
      cnt += 1
    if(s[2*i+2:2*i+3] == '0'):
      cnt += 1  
print(cnt)

Submission status: Accepted

Solution code:
s=input();sl=len(s)
t=['01'*(sl//2),'10'*(sl//2)]
a,b=0,0
if sl%2:
	t[0]+='0';t[1]+='1'
for i,j,k in zip(s,t[0],t[1]):
	if i==j: a+=1
	if i==k: b+=1
print(min(a,b))

Submission status: Accepted

Solution code:
s = [int(i) for i in list(input())]
a = []
b = []
for i in range(len(s)):
    if i % 2 == 0:
        a.append(0)
    else:
        a.append(1)
for i in range(len(s)):
    if i % 2 == 1:
        b.append(0)
    else:
        b.append(1)
count_a = 0
count_b = 0
for i, j in zip(s, a):
    if i != j:
        count_a += 1
for i, j in zip(s, b):
    if i != j:
        count_b += 1
print(min(count_a, count_b))

Submission status: Accepted

Solution code:
S = input()
count_0 = 0
count_1 = 0
for i, c in enumerate(S):
    if int(c) == i%2:
        count_1 += 1

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

Submission status: Accepted

Solution code:
S = input()
count_0 = 0
count_1 = 0
for i, c in enumerate(S):
    if int(c) == i%2:
        count_1 += 1
    else:
        count_0 += 1
print(min(count_1, count_0))

Submission status: Accepted

Solution code:
s = input()

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

print(min(wb, bw))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = [] #010101…
for i in range(n):
  if i%2 == 1:
    a.append(1)
  else:
    a.append(0)

k = 0
for i in range(n):
  if int(s[i]) != a[i]:
    k = k + 1
print(min(k, n-k))

Submission status: Accepted

Solution code:
S = input()

BW = '01' * (10**6)
WB = '10' * (10**6)

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

Submission status: Accepted

Solution code:
import sys
import os


S=list(map(int,list(input())))

A=[i%2 for i in range(len(S))]
B=[(i+1)%2 for i in range(len(S))]

C=[(x+y)%2 for (x,y) in zip(A,S)]
D=[(x+y)%2 for (x,y) in zip(B,S)]

print(min(sum(C),sum(D)))

Submission status: Accepted

Solution code:
s=input()
s=list(s)
n=len(s)
acnt=1
bcnt=1
flag=False
for i in range(n):
    if i!=n-1 and s[i]==s[i+1]:
        flag=True
        a=s[:]
        if s[i]=='0':
            s[i]='1'
        else:
            s[i]='0'
        for j in range(n):
            if j!=n-1 and s[j]==s[j+1]:
                if s[j]=='0': 
                    s[j+1]='1'
                    acnt+=1
                else:
                    s[j+1]='0'
                    acnt+=1
                        
        if a[i]=='0':
            a[i+1]='1'
        else:
            a[i+1]='0'
        for k in range(n):
            if k!=n-1 and a[k]==a[k+1]:
                if a[k]=='0':
                    a[k+1]='1'
                    bcnt+=1
                else:
                    a[k+1]='0'
                    bcnt+=1
                    
        break
if n==1 or flag==False: print(0)
else: print(min(bcnt,acnt))

Submission status: Accepted

Solution code:
S = str(input())
N = len(S)
T1=[]
T2=[]
a=0
b=0
for i in range(N):
  if i%2==1:
  	T1.append('0')
  else:
  	T1.append('1')
for i in range(N):
  if i%2!=1:
  	T2.append('0')
  else:
  	T2.append('1')  
for i in range(N):
  if S[i]!=T1[i]:
    a=a+1
  else:
    a=a
    
for i in range(N):
  if S[i]!=T2[i]:
    b=b+1
  else:
    b=b

if a>b:
  print("%d"% b)
else:
  print("%d"% a)

Submission status: Accepted

Solution code:
s=input()
zerofirst="0"
onefirst="1"
for i in range(1,len(s)):
  if i%2!=0:
    zerofirst=zerofirst+"1"
    onefirst=onefirst+"0"
  else:
    zerofirst=zerofirst+"0"
    onefirst=onefirst+"1"
zerodif=0
onedif=0
for j in range(len(s)):
  if s[j]!=zerofirst[j]:
    zerodif+=1
  if s[j]!=onefirst[j]:
    onedif+=1
print(min(zerodif,onedif))

Submission status: Accepted

Solution code:
S=list(input())
N=len(S)
ans1=0
ans2=0
for i in range(N): #101010...
    if i%2==0 and S[i]!='1':
        ans1+=1
    if i%2==1 and S[i]!='0':
        ans1+=1
for i in range(N): #01010...
    if i%2==0 and S[i]!='0':
        ans2+=1
    if i%2==1 and S[i]!='1':
        ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()

even_s = s[1::2]
odd_s = s[::2]

num_1 = even_s.count('1')+odd_s.count('0')
num_2 = even_s.count('0')+odd_s.count('1')

print(min(num_1 , num_2))

Submission status: Accepted

Solution code:
S = input()

cnt = [0,0]
ans = [0,1]

for i in range(len(S)):
    for j in range(2):
        if int(S[i]) != ans[j]:
            cnt[j] += 1
        
        ans[j] = 1 - ans[j]
            

print(min(cnt))

Submission status: Accepted

Solution code:
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


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve(S, n):
    ans = 0

    for i in range(len(S)):
        if int(S[i]) == n:
            pass
        else:
            ans += 1

        n = 1 - n

    return ans


def main():
    S = input()

    print(min(solve(S, 0), solve(S, 1)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(map(int, input()))
odd = s[0]
even = abs(s[0] - 1)

ans = 0
for v in s[::2]:
    if v != odd:
        ans += 1
        
for v in s[1::2]:
    if v != even:
        ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
s = input()

final_1 = []
final_2 = []

final_1_cnt = 0
final_2_cnt = 0

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

    if final_1[i] == s[i]:
        final_2_cnt += 1
    else:
        final_1_cnt += 1

print(min(final_1_cnt, final_2_cnt))

Submission status: Accepted

Solution code:
s=input()

l_1=[0 if i%2==0 else 1 for i in range(len(s))]
l_2=[1 if j%2==0 else 0 for j in range(len(s))]

ans_1=0
ans_2=0
for k in range(len(s)):
    if int(s[k])!=l_1[k]:
        ans_1+=1
    if int(s[k])!=l_2[k]:
        ans_2+=1

print(min(ans_1,ans_2))

Submission status: Accepted

Solution code:
ans = 0
S =input()
for i,j in enumerate(S):
  j = int(j)
  if i%2 == j:
    ans += 1
print(min(ans,len(S)-ans))

Submission status: Accepted

Solution code:
S = input()

N = len(S)
#make 010101... and 101010... of length N
A = "" #010101...
B = "" #101010...

for i in range(N):
    if i % 2 == 0:
        A += "0"
        B += "1"
    else:
        A += "1"
        B += "0"

#compare the difference between S and A,B and count
difA = 0
difB = 0
for i in range(N):
    if S[i] != A[i]:
        difA += 1
    if S[i] != B[i]:
        difB += 1

#the answer is the smaller of difA and difB
print(min(difA,difB))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

l = len(S)
ans1 = 0
ans2 = 0

for i in range(l):
    if i%2 == 0:
        if S[i] == '0':
            ans1 += 1
    else:
        if S[i] == '1':
            ans1 += 1
            
for i in range(l):
    if i%2 == 0:
        if S[i] == '1':
            ans2 +=1
    else:
        if S[i] == '0':
            ans2 += 1
            
print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 入力
S = input()

# 白黒白黒... に塗り替える場合と　黒白黒白... に塗り替える場合の塗り替え枚数を比較し解を求める
ans = min(
    sum(S[i] == str(i % 2) for i in range(len(S))),
    sum(S[i] == str((i + 1) % 2) for i in range(len(S)))
)

# 出力
print(ans)

Submission status: Accepted

Solution code:
s=input()

odd_0=0
even_0=0
odd_1=0
even_1=0

for i in range(len(s)):
	if i%2==1:
		if s[i]=='0':
			odd_0+=1
		else:
			odd_1+=1
	if i%2==0:
		if s[i]=='0':
			even_0+=1
		else:
			even_1+=1
print(min([even_1+odd_0,even_0+odd_1]))

Submission status: Accepted

Solution code:
mass = input()
mass = list(mass) #入力した文字列をリストで管理する
mass = [int(n) for n in mass]
count = 0

for i in range(0, len(mass)):
        if(i == len(mass) - 1):
            break
        if(mass[i] == mass[i+1]): #同じ数字が続くか判定する
            mass[i+1] = (mass[i+1] + 1) % 2 #0なら1に、1なら0に数字を入れ替える
            count += 1

print(count)

Submission status: Accepted

Solution code:
mass = input()
mass = list(mass) #入力した文字列をリストで管理する
mass = [int(n) for n in mass]
count = 0

for i in range(0, len(mass)):
    try:
        if(mass[i] == mass[i+1]): #同じ数字が続くか判定する
            mass[i+1] = (mass[i+1] + 1) % 2 #0なら1に、1なら0に数字を入れ替える
            count += 1
    except IndexError: #すべての文字を比較したときの処理
        print(count)

Submission status: Accepted

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

for i in range(0, len(mass)):

    try:
        if(mass[i] == mass[i+1]):
            mass[i+1] = (int(mass[i+1]) + 1) % 2
            mass[i+1] = str(mass[i+1])
            count += 1
    except IndexError:
        print(count)

Submission status: Accepted

Solution code:
import numpy as np
import heapq

# n = int(input())
# V = list(map(int, input().split()))

s = input()
l = len(s)

f1 = '10'*(l//2)
f2 = '01'*(l//2)

if l%2 == 1:
    f1 += '1'
    f2 += '0'

s = int(s, 2)    

print(min(format(s ^ int(f1, 2), 'b').count('1'), format(s ^ int(f2, 2), 'b').count('1')))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans = ''
ans2 = ''
counter = 0
counter2 = 0
for i in range(int(len(S)/2)):
    ans += '10'
    ans2 += '01'
if len(S) % 2 == 1:
    ans += '1'
    ans2 += '0'

for i in range(len(S)):
    if S[i] != ans[i]:
        counter += 1
    if S[i] != ans2[i]:
        counter2 += 1
print(min(counter, counter2))

Submission status: Accepted

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

count0 = 0
count1 = 0

for i in range(0,n,2):
  if(l[i] == '0'):
    count0 += 1
  if(i<n-1 and l[i+1]=='1' ):
    count1 += 1

print(min(count0+count1,n-count0-count1))

Submission status: Accepted

Solution code:
import math
s=str(input())
b=''
c=0
d=math.ceil(len(s)/2)
if s[0]=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
if len(s) != len(b):
    b = b[:-1]
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)

Submission status: Accepted

Solution code:
S = input()
tile_1 = str()
tile_2 = str()
flag = True
for ii in range(len(S)):
    if flag:
        tile_1 += '1'
        tile_2 += '0'
        flag = False
    else:
        tile_1 += '0'
        tile_2 += '1'
        flag = True
        
count_1, count_2 = 0, 0
for s in range(len(S)):
    if S[s] != tile_1[s]:
        count_1 += 1
    
    if S[s] != tile_2[s]:
        count_2 += 1
        
print(min(count_1, count_2))

Submission status: Accepted

Solution code:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

S = SI().strip()

N = len(S)

zero_start = 0
zero_start_counter = 0
for i in range(N):
    if not zero_start == int(S[i]):
        zero_start_counter += 1
    zero_start = (zero_start+1)%2

one_start_counter = N - zero_start_counter

print(min(zero_start_counter, one_start_counter))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s = int(s,2)
a,b=("","")
for i in range(n):
    if i%2==0:
        a+="0"
        b+="1"
    else:
        a+="1"
        b+="0"
a = int(a,2)
b = int(b,2)
k = s^a
l = s^b
f=0
y=0
for i in bin(k):
    if i=="1":
        f += 1
for j in bin(l):
    if j=="1":
        y+=1
print(min(f,y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    s = input()

    mask1 = ""
    mask2 = ""

    for i in range(len(s)):
        mask1 += str(0 ^ i%2)
        mask2 += str(1 ^ i%2)

    cnt1 = 0
    cnt2 = 0
    for i in range(len(s)):
        if s[i] == mask1[i]:
            cnt1 += 1
        if s[i] == mask2[i]:
            cnt2 += 1
    print(min(cnt1, cnt2))

main()

Submission status: Accepted

Solution code:
string = input()
c1=0
c2=0

for i, s in enumerate(string):
    if i%2==0:
        if(s=='0'): c1+=1
        if(s=='1'): c2+=1        
    else :
        if(s=='0'): c2+=1
        if(s=='1'): c1+=1        

print(min(c1,c2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
文字列を01のリストに変換
010101 or 101010 の行列を作り、XORの演算
その結果1になった個数が、変更しなければいけない回数
"""
import numpy as np
S = np.array(list(map(int,list(input()))))  # 入力を0,1,のベクトルに
N=len(S)

ans_even = np.zeros(N)
ans_odd = np.zeros(N)
for i in range(N):
    if i %2 == 0:
        ans_even[i] = 1
    if i %2 == 1:
        ans_odd[i] = 1

a = np.sum(np.logical_xor(S, ans_even).astype(int))

b = np.sum(np.logical_xor(S, ans_odd).astype(int))

print(min(a,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sub():
    ss = [e for e in input()]
    if len(ss) == 1:
        print("0")
        return
    dp = {}
    if ss[0] == "0":
        dp[(0,0)] = 0
        dp[(0,1)] = 1
    else:
        dp[(0,0)] = 1 
        dp[(0,1)] = 0 
    N = len(ss)
    for i in range(1, N):
        cI = ss[i]
        if cI == "0":
            dp[(i,0)] = dp[(i-1,1)]
            dp[(i,1)] = dp[(i-1,0)] + 1
        else:
            dp[(i,0)] = dp[(i-1,1)] + 1
            dp[(i,1)] = dp[(i-1,0)]

    count = min(dp[(N-1,0)], dp[(N-1,1)])

    print("{}".format(count))

sub()

Submission status: Accepted

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

print(min(count1, count2))

Submission status: Accepted

Solution code:
from sys import stdin

def solve(s):
    cnt = 0
    for i, color in enumerate(s):
        if i == 0:
            continue
        if s[i - 1] == color:
            s[i] = '0' if color == '1' else '1'
            cnt = cnt + 1
    return cnt


def main():
    s = list(stdin.readlines()[0])
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
  diff = 0
  for k, v in enumerate(string):
    if (k % 2 == 1 and v == '1') or (k % 2 == 0 and v == '0'):
      diff += 1
  return min(diff, len(string) - diff)

def main():
  string = input()
  ans = solve(string)
  print(ans)
  
main()

Submission status: Accepted

Solution code:
string = input()
ans_01 = 0
ans_10 = 0

tile = 0
for s in string:
    if s != str(tile % 2):
        ans_01 += 1
    tile += 1

tile = 1
for s in string:
    if s != str(tile % 2):
        ans_10 += 1
    tile += 1

if ans_01 >= ans_10:
    print(ans_10)
else:
    print(ans_01)

Submission status: Accepted

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

for i in range(len(S)):
    if i == 0:
        s1 = '0'
        s2 = '1'
    elif i % 2 == 1:
        s1 += '1'
        s2 += '0'
    else:
        s1 += '0'
        s2 += '1'

for i in range(len(S)):
    if S[i] == s1[i]:
        c2 += 1
    else:
        c1 += 1

print(min(c1, c2))

Submission status: Accepted

Solution code:
#-*- coding:utf-8 -*-
S = list(map(int, list(input())))

# 0 start, 1 start
count = [0, 0]

# from 0 
for i, s in enumerate(S):
    if i % 2 == 0: # even
        if s != 0:
            count[0] += 1        
    elif i % 2 == 1: # odd
        if s != 1:
            count[0] += 1

# from 1
for i, s in enumerate(S):
    if i % 2 == 0: # even
        if s != 1:
            count[1] += 1        
    elif i % 2 == 1: # odd
        if s != 0:
            count[1] += 1

print(min(count))

Submission status: Accepted

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

if len(s) % 2 == 0:
    a = [1,0] * (len(s) // 2)
    b = [0,1] * (len(s) // 2)
    aa = 0
    bb = 0
    for i in range(len(s)):
        if s[i] != a[i]:
            aa += 1
        if s[i] != b[i]:
            bb += 1
    c = min(aa,bb)
else:
    a = [1,0] * (len(s) // 2) + [1]
    b = [0,1] * (len(s) // 2) + [0]
    aa = 0
    bb = 0
    for i in range(len(s)):
        if s[i] != a[i]:
            aa += 1
        if s[i] != b[i]:
            bb += 1
    c = min(aa, bb)

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lst = [int(i) for x in input().split() for i in x]
length = len(lst)
idealLst1 =[ i&1 for i in range(1,length+1)]
idealLst2 = [i&1 for i in range(length)]
count1 = 0
count2 = 0

for i in range(length):
    if(lst[i] != idealLst1[i]):
        count1+=1    

for i in range(length):
    if(lst[i] != idealLst2[i]):
        count2+=1
print(min(count1,count2))

Submission status: Accepted

Solution code:
args = input()

black_result = 0
white_result = 0
c = 0
for s in args:
    if int(s) == c % 2:
        black_result += 1
    else:
        white_result += 1
    c += 1

print(min(black_result, white_result))

Submission status: Accepted

Solution code:
#Coding:Utf-8

S = list(map(int, input()))
N=len(S)
count=0


def rev(x):
    if x==0:
        return 1
    else:
        return 0


if N==1:
    print(0)
    exit()

for i in range(N-1):
    if S[i]==S[i+1]:
        S[i+1]=rev(S[i+1])
        count+=1
print(count)

Submission status: Accepted

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

n = len(s)
ans = 0

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

Submission status: Accepted

Solution code:
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import numpy as np
S = input()
l = len(S)
n = list(map(int, str(S)))
a = np.arange(l) # 12345...
b = np.where(a%2==0, 0, 1) # 010101010...
c = np.where(a%2==1, 0, 1) # 101010101...
bool1 = np.logical_xor(n, b)
bool2 = np.logical_xor(n, c)
 
count1 = np.sum(bool1)
count2 = np.sum(bool2)
 
if count1 < count2:
    print(count1)
else:
    print(count2)

Submission status: Accepted

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


e = [0, 1] * (int(len(s)/2) + 1)

h = [0, 0]
h[0] = sum([x == ei for x, ei in zip(s,e[0:len(s)])])
h[1] = sum([x == ei for x, ei in zip(s,e[1:len(s)+1])])

print(min(h))

Submission status: Accepted

Solution code:

def main():
    s = input()
    tmp = '0'
    ans = 0
    for i in range(len(s)):
        if tmp == '0':
            if s[i] != '0':
                ans += 1
            tmp = '1'
        else:
            if s[i] != '1':
                ans += 1
            tmp = '0'
    tmp = '1'
    ans2 = 0
    for i in range(len(s)):
        if tmp == '0':
            if s[i] != '0':
                ans2 += 1
            tmp = '1'
        else:
            if s[i] != '1':
                ans2 += 1
            tmp = '0'
    print(min(ans, ans2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

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

ans = min([count, len(S)-count])
print(ans)

Submission status: Accepted

Solution code:
S = input()

correct = S[0]
answer = 0

for i in range(len(S)):
  if (correct != S[i]):
    answer += 1

  if (correct == "0"):
    correct = "1"
  else:
    correct = "0"
    
print(answer)

Submission status: Accepted

Solution code:
l = list(map(int, input()))
l_zero = [0]*len(l)
l_one = [0]*len(l)
    
for i in range(len(l)):
    if i%2 == 0 or i == 0:
        pass
    else:
        l_zero[i] = 1
    
for i in range(len(l)):
    if i%2 == 0 or i == 0:
        l_one[i] = 1
    else:
        pass
    
# print(l_zero)
# print(l_one)

cnt_zero = 0
for n in range(len(l)):
    if l[n] == l_zero[n]:
        cnt_zero += 1
    else:
        pass
    
cnt_one = 0
for n in range(len(l)):
    if l[n] == l_one[n]:
        cnt_one += 1
    else:
        pass

rlt = 0
if cnt_zero < cnt_one:
    rlt = cnt_zero
elif cnt_one < cnt_zero:
    rlt = cnt_one
else:
    rlt = cnt_zero

print(rlt)

Submission status: Accepted

Solution code:
s = input()

sum1 = sum([(i % 2 == 0 and s[i] == '0') or (i % 2 == 1 and s[i] == '1') \
    for i in range(len(s))])
sum2 = sum([(i % 2 == 1 and s[i] == '0') or (i % 2 == 0 and s[i] == '1') \
    for i in range(len(s))])

print(min(sum1, sum2))