Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

000

Sample Output 1

1

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

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

Solution code:
import collections
S = list(input())
S_g = [S[i] for i in range(len(S)) if i%2 == 0]
S_k = [S[i] for i in range(len(S)) if i%2 != 0]

S_g_count = collections.Counter(S_g)
S_k_count = collections.Counter(S_k)

S_g_count = sorted(S_g_count.items(),key = lambda x:x[1],reverse=True)
S_k_count = sorted(S_k_count.items(),key = lambda x:x[1],reverse=True)

count = 0
if len(S_g_count) == 0 or len(S_k_count) == 0:
  print(0)
  exit()
if len(S_g_count) == 2 and len(S_k_count) == 2:
  if S_g_count[0][0] != S_k_count[0][0]:
    count = len(S_g)-S_g_count[0][1] + len(S_k)-S_k_count[0][1]
  else:
    if S_k_count[0][1] >= S_g_count[0][1]:
      count = len(S_k)-S_k_count[0][1] + len(S_g)-S_g_count[1][1]
    else:
      count = len(S_g)-S_g_count[0][1] + len(S_k)-S_k_count[1][1]
elif len(S_g_count) == 1 and len(S_k_count) == 1:
  if S_g_count[0][0] == S_k_count[0][0]:
    count = min(S_g_count[0][1],S_k_count[0][1])
  else:
    count = 0
else:
  if len(S_g_count) == 1:
    if S_g_count[0][0] == S_k_count[0][0]:
      count = len(S_k) - S_k_count[1][1]
    else:
      count = len(S_k) - S_k_count[0][1]
  else:
    if S_k_count[0][0] == S_g_count[0][0]:
      count = len(S_g) - S_g_count[1][1]
    else:
      count = len(S_g) - S_g_count[0][1]
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = input().rstrip()

if s == "0" or s == "1":
    print("0")
    exit()

length = len(s)

shou = length // 2
amari = length % 2
a = "10"*shou
b = "01"*shou
if amari == 1:
    a = a + "1"
    b = b + "0"

bins = int(s,2)
bina = int(a,2)
binb = int(b,2)

saxor = bin(bina ^ bins)
sbxor = bin(binb ^ bins)

saxor_cnt1 = sum(map(int, str(saxor.lstrip("0b"))))
sbxor_cnt1 = sum(map(int, str(sbxor.lstrip("0b"))))

out = min (saxor_cnt1, sbxor_cnt1)

print(out)

Submission status: Accepted

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

len_val = len(list_input)
ans_a = []
ans_b = []

a_count = 0
b_count = 0

for i in range(len_val):

    ans_a.append(i%2)
    ans_b.append((i+1)%2)

for i in range(len_val):
    if ans_a[i] == list_input[i]:
        b_count += 1
    else:
        a_count += 1

if a_count >= b_count:
    print(b_count)
else:
    print(a_count)

Submission status: Accepted

Solution code:
S = [digit for digit in input()]
s_len = len(S)

pattern1 = [str(i % 2) for i in range(s_len)]
pattern2 = [str(1) if i % 2 == 0 else str(0) for i in range(s_len)]


def get_diff_num(pattern, compared):
    diff_num = 0
    for p, c in zip(pattern, compared):
        if not p == c:
            diff_num += 1
    return diff_num

p1_diff = get_diff_num(pattern1, S)
p2_diff = get_diff_num(pattern2, S)
print(min(p1_diff, p2_diff))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
cnt_0 = 0
cnt_1 = 0

for i in range(N):
    if i%2 != int(S[i]):
        cnt_0 += 1
    else:
        cnt_1 += 1

print(min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
ta=list(input())
sz=len(ta)
ans0=0
ans1=0
ans=0
for i in range(sz):
    if(i%2==0):
        if(ta[i]=="0"):
            ans0=ans0+1
    else:
        if(ta[i]=="1"):
            ans0=ans0+1
for i in range(sz):
    if(i%2==0):
        if(ta[i]=="1"):
            ans1=ans1+1
    else:
        if(ta[i]=="0"):
            ans1=ans1+1
ans+=min(ans0,ans1)
print(ans)

Submission status: Accepted

Solution code:
def gene(n,leng):
    r = []
    for i in range(leng):
        r.append(n)
        n = 1 - n
    return r

def nuri(lis):
    zerone = gene(0,len(lis))
    zo = 0
    onezero = gene(1,len(lis))
    oz = 0

    for i in range(len(lis)):
        if zerone[i] != lis[i]:
            zo += 1
        if onezero[i] != lis[i]:
            oz += 1
    if zo < oz:
        ans = zo
    else:
        ans = oz
    return ans

        

tyle = list(input())
tyle = [int (i) for i in tyle]
print(nuri(tyle))

Submission status: Accepted

Solution code:
master = list(input())
change = 0
cn = 0
cn_r = 0
l = master.copy()
r = master.copy()
for i in range(len(l)-1):
    if l[i] == l[i+1]:
        if l[i] == "0":
            change = "1"
        else:
            change = "0"
        l[i+1] = change
        cn += 1
for i in reversed(range(1,len(l))):
    if r[i] == r[i-1]:
        if r[i] == "0":
            change = "1"
        else:
            change = "0"
        r[i-1] = change
        cn_r += 1

print(min(cn,cn_r))

Submission status: Accepted

Solution code:
s = []
S = input()

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

sum = 0
for i in range(len(S)):
    s.append(S[i])

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

print(sum)

Submission status: Accepted

Solution code:
s = input()
lists = []
for i in s:
    lists.append(i)

preword = lists[0]
count = 0
for i in range(1,len(lists)):
    if lists[i] == preword:
        count += 1
        if lists[i] == "0":
            preword = "1"
        else:
            preword = "0"
    else:
        preword = lists[i]

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = input()

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

n = len(s)
c = 0

base = s[0]

for i in range(1, n):

    if s[i] == base:
        c += 1
        if s[i] == '0':
            base = '1'
        else:
            base = '0'
        
        continue
    
    base = s[i]

print(c)

Submission status: Accepted

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

num=input()
L=len(num)
count=0

if L == 1 :
    print(0)
    sys.exit()

for i in range(L):
    flg=False
    if num[i] == num[i+1]:
        count+=1
        flg=True

    if i+1 == L-1 :
        break
    
    if flg == True:
        if num[i] == '0':
            num_CHG = num[:i+1] + '1'+ num[i+2:]
            num = num_CHG
        else:
            num_CHG = num[:i+1] + '0'+ num[i+2:]
            num = num_CHG
print(count)

Submission status: Accepted

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

t1 = [0,1]
t2 = [1,0]
num1 = num2 = 0
for i in range(n):
    tmp = i%2
    num1 += abs(int(s[i]) - t1[tmp])
    num2 += abs(int(s[i]) - t2[tmp])

if num1 >= num2:
    print(num2)
else:
    print(num1)

Submission status: Accepted

Solution code:
#coding:utf-8

if __name__ == "__main__":
    S = input()
    N = len(S)
    if S[0] == "0":
        Sn = [int(S[n]) for n in range(N)]
    else:
        Sn = [(int(S[n])+1)%2 for n in range(N)]

    total0 = 0
    total1 = 0

    # 0101...
    for n in range(N):
        # n文字目は(n%2)になってほしい
        if Sn[n] != n%2:
            total0 += 1
    # 1010...
    for m in range(N):
        # n文字目は((n+1)%2)になってほしい
        if Sn[m] != (m+1)%2:
            total1 += 1

    print(min(total0, total1))

Submission status: Accepted

Solution code:

m=input()
round = len(m)

n = 0

for i in range(round):
    if i % 2 == 0:
        if m[i] == '0':
            n = n+1
            
    else:
        if m[i] =='1':
            
            n = n+1

if n>round/2:
    print(round-n)
else:
    print(n)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
import bisect
import heapq

rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


s = rs()
one_even = []
one_odd = []
for i, char in enumerate(s):
    if i % 2 == 0 and char == '1':
        one_even.append(True)
    elif i % 2 == 1 and char == '0':
        one_even.append(True)
    else:
        one_even.append(False)

for i, char in enumerate(s):
    if i % 2 == 1 and char == '1':
        one_odd.append(True)
    elif i % 2 == 0 and char == '0':
        one_odd.append(True)
    else:
        one_odd.append(False)

one_even.sort()
one_odd.sort()
index1 = 0
for i, boolean in enumerate(one_even):
    if boolean:
        index1 = i
        break

index2 = 0
for i, boolean in enumerate(one_odd):
    if boolean:
        index2 = i
        break

print(min(index1, index2))

Submission status: Accepted

Solution code:
import sys

# 文字列の読み込み&変換
st = input()
fl = [ int(x) for x in st]

N = len(st)

# 奇数番目の総和と偶数番目の総和を計算
sgn = 1
# sgn = 0 even 0, 2, 4,  
# sgn = 1 odd 1, 3, 5,
fl_sum = [0.0, 0.0]
len_sum = [0, 0]

for i in range(N):
  sgn = int(sgn - (-1)**float(i)) 
  fl_sum[sgn] += fl[i]
  len_sum[sgn] += 1

# 総和の小さい方をすべて0に変える
# 総和の大きい方をすべて1に変える
# のに必要な手数を計算
if fl_sum[0] <= fl_sum[1]:
  x = 0
  y = 1
else:
  x = 1
  y = 0
# すべてを
num = int(fl_sum[x] + (len_sum[y] - fl_sum[y]))
print(num)

Submission status: Accepted

Solution code:
S = list(input())

s = S + ['\n']

sl = len(s)

count = 0
limit = sl // 2 + 1
for i in range(1, sl):
    if s[i-1] == s[i]:
        count += 1
        if s[i-1] == '0':
            s[i] = '1'
        else:
            s[i] = '0'
    if count > limit:
        break

if count > limit:
    count = 0
    s = ['\n'] + S
    for i in range(1, sl):
        ind = -1 * (i+1)
        if s[-1 * i] == s[ind]:
            count += 1
            if s[ind] == '0':
                s[ind] = '1'
            else:
                s[ind] = '0'

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
a= input()
c=0
for i in range(len(a)):
    if i==0:
        if a[i]=='0':
            flag=True
        else:
            flag=False
    else:
        if a[i]=='0' and flag==True:
            c+=1
            flag=False
        elif a[i]=='0' and flag==False:
            pass
            flag=True
        elif a[i]=='1' and flag==True:
            pass
            flag=False
        elif a[i]=='1' and flag==False:
            c+=1
            flag=True
                
print(c)

Submission status: Accepted

Solution code:
s=input()
num_st=[0,0]
for i, c in enumerate(list(s)):
	if int(c) == i % 2:
		num_st[0]+=1
	else:
		num_st[1]+=1

ret = min(num_st)
print(int(ret))

Submission status: Accepted

Solution code:

S = list(input())
result = 0

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

print(result)

Submission status: Accepted

Solution code:
S = input()
S = list(S)
S_ = []
for s in S:
    S_.append(int(s))

if len(S_) == 0: 
    ans = 0
    
elif S_[0] == 1:
    r, l = 0, 1 # 右端と左端のインデックス
    ans = 0
    while l < len(S_):
        #print(l)
        if S_[r] > S_[l]:
            r += 1
            l += 1
        elif S_[r] == S_[l]:
            if S_[l-1] == 1:
                S_[l] = 0
                r += 1
                l += 1
                ans += 1
            else:
                S_[l] = 1
                r += 1
                l += 1
                ans += 1
        else:
            r += 1
            l += 1

elif S_[0] == 0:
    r, l = 0, 1 # 右端と左端のインデックス
    ans = 0
    while l < len(S_):
        if S_[r] < S_[l]:
            r += 1
            l += 1
        elif S_[r] == S_[l]:
            if S_[l-1] == 0:
                S_[l] = 1
                r += 1
                l += 1
                ans += 1
            else:
                S_[l] = 0
                r += 1
                l += 1
                ans += 1
        else:
            r += 1
            l += 1
            
print(ans)

Submission status: Accepted

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

import sys
import copy

# input = sys.stdin.readline

# ---------------------------------------------------------

S = input().rstrip()

cnt1 = 0
cnt2 = 0

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

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

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:
n = input()


tmp0 = []
tmp1 = []
for i in range(len(n)):
    if (i % 2 == 0):
        tmp0.append("0")
        tmp1.append("1")
    else:
        tmp0.append("1")
        tmp1.append("0")


ans0 = 0
ans1 = 0


for i in range(len(n)):
    if(tmp0[i] != n[i]):
        ans0 += 1
    else:
        ans1 += 1


print(min(ans0,ans1))

Submission status: Accepted

Solution code:
l = list(input())

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

Submission status: Accepted

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

d = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] == '0':
            d += 1
    else:
        if s[i] == '1':
            d += 1

print(min(c,d))

Submission status: Accepted

Solution code:
import math

s = input()
half_len = math.ceil(len(s) / 2)

b_s = int(s, base=2)
b_10 = int(('10' * half_len)[:len(s)], base=2)
b_01 = int(('01' * half_len)[:len(s)], base=2)

print(min(["{0:b}".format(b_s ^ b_10).count('1'), "{0:b}".format(b_s ^ b_01).count('1')]))

Submission status: Accepted

Solution code:
from sys import stdin
S = list(map(int, list(stdin.readline().rstrip())))

n = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        if S[i+1]==1: S[i+1]=0
        elif S[i+1]==0: S[i+1]=1
        n += 1
print(n)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a=sum(i%2^int(s[i])for i in range(n))
print(min(a,n-a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	S = input()
	S = list(S)

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

	fst = []
	snd = []
	for i, val in enumerate(S):
		if i == len(S)-1:
			break
		if i % 2 == 0:
			fst.append(val)
		else:
			snd.append(val)

	fst1 = collections.Counter(fst)
	snd1 = collections.Counter(snd)

	#print(fst1["0"])
	#print(snd1["0"])

	ans = 0
	if fst1["0"] <= snd1["0"]:
		ans = fst1["0"] + snd1["1"]
	else:
		ans = fst1["1"] + snd1["0"]
	

	print(ans)

	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
# coding:utf-8

# 0101~ か 1010~のどちらの列が最適かを判定
# 0:0101~ , 1:1010~
def getOptimumPattern(tiles):
	n = len(tiles)
	zero = [ "0" if i%2 == 0 else "1" for i in range(n)]
	one = [ "1" if i%2 == 0 else "0" for i in range(n)]
	zero_count = 0
	one_count = 0
	for l,z in zip(tiles,zero):
		if l != z:
			zero_count = zero_count + 1

	for l,o in zip(tiles,one):
		if l != o:
			one_count = one_count + 1

	if zero_count <= one_count:
		return zero_count
	else:
		return one_count

tiles= list(input())
result = getOptimumPattern(tiles)
print(result)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    length = len(s)
    o = "10" * (length // 2 + (length % 2))
    o_len = len([i for i, j in zip(s, o) if i == j])
    z_len = len([i for i, j in zip(s, o[::-1]) if i == j])
    print(length - max([z_len, o_len]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()


#偶数を0,奇数を1にする場合
count01 = 0
for i in range(len(S)):
  if i%2 == 0:#偶数番目のとき
    if S[i] != "0":
      count01 += 1
  else:
    if S[i] != "1":
      count01 += 1
#偶数を1,奇数を0にする場合
count10 = 0
for i in range(len(S)):
  if i%2 == 0:#偶数番目のとき
    if S[i] != "1":
      count10 += 1
  else:
    if S[i] != "0":
      count10 += 1
      
print(min(count01,count10))

Submission status: Accepted

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

S = input()

list_a = S[0::2]
list_b = S[1::2]

#result_a: 010101 にする場合の回数
#result_b: 101010 にする場合の回数
result_a, result_b = 0,0

for l in list_a:
  black = l.count("0")
  white = l.count("1")
  result_a += white
  result_b += black

for l in list_b:
  black = l.count("0")
  white = l.count("1")
  result_a += black
  result_b += white

result = min([result_a, result_b])
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#124-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=S()
fb,fw=0,0
for i in range(len(S)):
    if i%2==0:
        if S[i]=='0':
            fw+=1
        else:
            fb+=1
    else:
        if S[i]=='0':
            fb+=1
        else:
            fw+=1
print(min(fb,fw))

Submission status: Accepted

Solution code:
s = input()
a = []

for i in range(len(s)):
  a.append(s[i])
  
a = list(map(int, a))

if len(a) == 1:
  print('0')
elif len(a) == 2:
  if a[0] == a[1]:
    print('1')
  else:
    print('0')
else:
  cnt = 0
  i = 0
  while True:
    if a[i] == a[i+1] and a[i+1] == a[i+2]:
      if a[i+1] == 0:
        a[i+1] = 1
      else:
        a[i+1] = 0
      i += 1
      cnt += 1
    elif a[i] == a[i+1]:
      if a[i+1] == 0:
        a[i+1] = 1
      else:
        a[i+1] = 0
      i += 1
      cnt += 1
    else:
      i += 1
      
    if i + 2 > len(a) - 1:
      break
      
  if a[i] == a[i+1]:
    if a[i+1] == 0:
      a[i+1] = 1
    else:
      a[i+1] = 0
    cnt += 1

  print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()

even0 = 0
even1 = 0
odd0 = 0
odd1 = 0

for i in range(len(s)):
    if (i % 2 == 0):
        if int(s[i]) == 0:
            even0 += 1
        else:
            even1 += 1
    else:
        if int(s[i]) == 0:
            odd0 += 1
        else:
            odd1 += 1

max = max(even0, even1, odd0, odd1)

if max == even0 or max == odd1:
    cnt = even1 + odd0
elif max == even1 or max == odd0:
    cnt = even0 + odd1

print(cnt)

Submission status: Accepted

Solution code:
tiles = input()

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

for i, t in enumerate(tiles):
    if i % 2 == 0:
        if t == '0':
            even_0 += 1
        else:
            even_1 += 1
    else:
        if t == '0':
            odd_0 += 1
        else:
            odd_1 += 1

# print(even_0, even_1, odd_0, odd_1)

if even_0 + odd_1 >= even_1 + odd_0:
    print(even_1 + odd_0)
else:
    print(even_0 + odd_1)

Submission status: Accepted

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

for i in range(n):
    if i%2==0 and s[i]=='0':
        ans+=1
    if i%2==1 and s[i]=='1':
        ans+=1

print(min(ans,n-ans))

Submission status: Accepted

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = [int(x) for x in input()]

ans1 = [x%2 for x in range(len(S))]
ans2 = [x%2 for x in range(1,len(S)+1)]
count1 = 0
count2 = 0
for i in range(len(S)):
    if S[i] != ans1[i]:
        count1 += 1

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

Submission status: Accepted

Solution code:
c=list(input())
a=c[::2]
b=c[1::2]
print(min(a.count('0')+b.count('1'),a.count('1')+b.count('0')))

Submission status: Accepted

Solution code:
N = list(map(int,list(input())))
l = len(N)
start1 =0
start0 =0

for i in range(l):
    if(N[i] != 0 and i%2 == 0):
        start0 += 1
    elif(N[i] != 1 and i%2 == 1):
        start0 += 1
    
    if(N[i] != 1 and i%2 == 0):
        start1 += 1
    elif(N[i] != 0 and i%2 == 1):
        start1 += 1

print(min((start0,start1)))

Submission status: Accepted

Solution code:
li=list(input())
odd_0 = li[0::2].count("0")
even_0 = li[1::2].count("0")
odd_1 = li[0::2].count("1")
even_1 = li[1::2].count("1")

#
# if odd_0 >= even_0:
#     print(odd_1+even_0)
# else:
#     print(odd_0+even_1)


if odd_0 > even_0:
    print(odd_1+even_0)
elif odd_0 < even_0:
    print(odd_0+even_1)
else:
    print(min(odd_1+even_0,odd_0+even_1))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
t = list("10"*((n+1)//2))
if len(t) != n : t = t[:-1]
a = len(list(filter(lambda x: x[0] != x[1], [(s[i],t[i]) for i in range(n)])))
print(min(a, n-a))

Submission status: Accepted

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

S = input()

print(min(S[0::2].count('0')+S[1::2].count('1'), S[0::2].count('1')+S[1::2].count('0')))

Submission status: Accepted

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

num1 = 0
num2 = 0

i = 0
while(i < no):
    if(n[i] == '0'):
        num1 += 1
    if(n[i] == '1'):
        num2 += 1
    i += 1
    if(i < no):
        if(n[i] == '1'):
            num1 += 1
        if(n[i] == '0'):
            num2 += 1
    i += 1
    #print(i," ", num1, " ", num2)

if(num1 < num2):
    ans = num1
else:
    ans = num2

print(ans)

Submission status: Accepted

Solution code:
s = list(input())

last = s[0]

c = 1

ans = 0

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

Submission status: Accepted

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    t = [int(c) for c in lines[0]]

    return (t, )


def solve(t, ):

    if debug:
        log("t=%s" % t)
    
    tmp = []
    for e in t:
        if e == 0:
            tmp.append(False)
        else:
            tmp.append(True)
    
    result = 0
    if len(t) == 1:
        pass
    else:
        for i in range(1, len(tmp)):
            if tmp[i-1] == tmp[i]:
                tmp[i] = not tmp[i-1]
                result = result + 1
        # while True:
        #     if debug:
        #         log("tmp=%s" % tmp)
        #     result_tmp = result
        #     for i in range(1, len(tmp)):
        #         if tmp[i-1] == tmp[i]:
        #             tmp[i] = not tmp[i-1]
        #             result = result + 1
        #             break
        #     if result_tmp == result:
        #         break
                

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
s = input()
l = len(s)
t = 0
for i in range(l):
  t = t + (int(s[i])*2-1)*(-1)**i
if t < 0:
  t = -t
print(int((l-t)/2))

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
count=0
count_10=0
count_00=0
num=0
if (N%2)!=0:
    NS=N-1
    a=1
else:
    NS =N
    a=0
    
count=0
for i in range(0,NS,2):
    num=int(S[i]+S[i+1])
    if num==10:
        count=count+1
        #print(num)
    elif num==1:
        count_10=count_10 + 1
        #print(num)
    else:
        count_00=count_00+1

count=min(count,count_10)
count=count*2
count=count+count_00
if a==1:
   if S[0]!=S[N-1]:
       count=count+1

print(count)

Submission status: Accepted

Solution code:
s_in = list(input())
S = [int(i) for i in s_in]
count = 0
Ans=[i % 2 for i in range(len(S))]
for i in range(len(S)):
    if S[i] != Ans[i]:
        count = count + 1
if count <= (len(S)//2):
    print(count)
else:
    print(len(S) - count)

Submission status: Accepted

Solution code:
str=input()
N=len(str)
s=list(str)
tehon=[]
if N%2==0:
    kai=N/2
    i=0
    while i<kai:
        tehon.append(1)
        tehon.append(0)
        i=i+1
else:
    kai=(N-1)/2
    i=0
    while i<kai:
        tehon.append(1)
        tehon.append(0)
        i=i+1
    tehon.append(1)
ss=0
cc=0
while cc<N:
    a=int(s[cc])
    b=int(tehon[cc])
    if a==b:
        ss=ss+1
    cc=cc+1
nn=N-ss
if nn<=ss:
    print(nn)
else:
    print(ss)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

N = len(S)

count = 0

for n in range(N-1):
	if S[n] == S[n+1]:
		count += 1
		if S[n+1] == "0":
			S = S[:n+1] + "1" + S[n+2:]
		else:
			S = S[:n+1] + "0" + S[n+2:]

ccount = N - count

print(min(count, ccount))

Submission status: Accepted

Solution code:
s=str(input())
cnt=0
temp=[]
temp2=[]
nagasa=len(s)
lis=[]
cnt2=0
for p in s:
    lis.append(p)

if nagasa%2==0:
    for i in range(nagasa//2):
        temp.append("1")
        temp.append("0")
    for i in range(nagasa//2):
        temp2.append("0")
        temp2.append("1")
    
    for i in range(nagasa):
        if lis[i]!=temp[i]:
            cnt+=1
        elif lis[i]!=temp2[i]:
            cnt2+=1
        
else:
    for i in range(nagasa//2):
        temp.append("1")
        temp.append("0")
    temp.append("1")
    for i in range(nagasa//2):
        temp2.append("0")
        temp2.append("1")
    temp2.append("0")
    
    for i in range(nagasa):
        if lis[i]!=temp[i]:
            cnt+=1
        elif lis[i]!=temp2[i]:
            cnt2+=1
    

print(min(cnt,cnt2))

Submission status: Accepted

Solution code:
import copy

S = input()
s = list(S)
l = len(s)
t = copy.copy(s)

count_0 = 0
count_1 = 0


for i in range(0,l-1):
    if s[i] == "0":
        if s[i+1] != "1":
            s[i+1] = "1"
            count_0 += 1
    else:
        if s[i+1] != "0":
            s[i+1] = "0"
            count_0 += 1

if s[0] == "0":
    count_1 += 1
    t[0] = "1"
else:
    count_1 += 1
    t[0] = "0"

for j in range(0,l-1):
    if t[j] == "0":
        if t[j+1] != "1":
            t[j+1] = "1"
            count_1 += 1
    else:
        if t[j+1] != "0":
            t[j+1] = "0"
            count_1 += 1

n = min(count_0,count_1)
print(n)

Submission status: Accepted

Solution code:
S = str(input())
s0=0
s1=0
for i in range(len(S)):
    if i%2==0 and S[i]=="0":
        s1+=1
    elif i%2==0 and S[i]=="1" :
        s0+=1
    elif i%2==1 and S[i]=="0":
        s0+=1

    elif i%2==1 and S[i]=="1":
        s1+=1

print(min(s0,s1))

Submission status: Accepted

Solution code:
s = list(map(int,input()))
s1 = s
ans1,ans2 = 0,0
for i in range(1,len(s)):
  if s[i] != s[i-1]:
    continue
  elif s[i]==0:
    s[i]=1
    ans1+=1
  else:
    s[i]=0
    ans1+=1

if s1[0] == 0:
  s1[0] = 1
else:
  s1[0] = 0
  
for i in range(1,len(s)):
  if s1[i] != s1[i-1]:
    continue
  elif s1[i]==0:
    s1[i]=1
    ans2+=1
  else:
    s1[i]=0
    ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
li = list(input())
sums = 0
leng = int(len(li))

for i in range(leng):
    now = i
    if (now + 1) >= leng:
        break
    if(li[now] == li[now + 1]):
        if(li[now + 1] == '0'):
            li[now + 1] = '1'
        else:
            li[now + 1] = '0'
        sums += 1
print(sums)

Submission status: Accepted

Solution code:
mozi = input()

front = mozi[0]
result = 0
for temp in mozi[1:]:
    if temp == front:
        result += 1
        if front == '1':
            front = '0'
        else:
            front = '1'
    else:
        front = temp
        

    
print(result)

Submission status: Accepted

Solution code:
S = input()
pre = ""
count = 0
for i, s in enumerate(S): 
  if i == 0:
    pre = s
  else:
    if s == pre:
      if pre == "1":
        pre = "0"
        count += 1
      else:
        pre = "1"
        count += 1
    else:
      if pre == "1":
        pre = "0"
      else:
        pre = "1"
print(count)

Submission status: Accepted

Solution code:
S = input()
kuro1 = 0
siro1 = 0
kuro2 = 0
siro2 = 0

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

print(min(siro2+kuro1, kuro2+siro1))

Submission status: Accepted

Solution code:
s = input()

changes = len([i for i, tile in enumerate(s) if (i%2) != int(tile)])

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

Submission status: Accepted

Solution code:
n=input()
l=list(n)
L=[]
for i in l:
    t=int(i)
    L.append(t)
m=len(L)
kisu=0
gusu=0
for i,k in enumerate(L):
    if(i%2==k):
        kisu+=1
    if(i%2!=k):
        gusu+=1
print(min(kisu,gusu))

Submission status: Accepted

Solution code:
def f(s,a):
    ans=0
    for i in range(len(s)):
        if i%2==0:
            if s[i]!=a:
                ans+=1
        else:
            if s[i]==a:
                ans+=1
    return ans


s=list(input())
print(min(f(s,'0'),f(s,'1')))

Submission status: Accepted

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

Submission status: Accepted

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

s = [int(n) for n in s]
s1 = [0, 1] * int(n/2)
s2 = [1, 0] * int(n/2)

if(n%2 == 1):
    s1.append(0)
    s2.append(1)

c1, c2 = 0, 0

for i in range(n):
    if(s[i] != s1[i]):
        c1 += 1
    if(s[i] != s2[i]):
        c2 += 1

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

Submission status: Accepted

Solution code:
S = input()
bin_S = int(S, 2)
N = len(S)

b = 0
w = 1
#
bw = []
for i in range(int(N / 2)):
    bw.append(b)
    bw.append(w)
if len(bw) < N:
    bw.append(b)
bw = ''.join(map(str, bw))

bin_bw = int(bw, 2)

#
wb = []
for i in range(int(N / 2)):
    wb.append(w)
    wb.append(b)
if len(wb) < N:
    wb.append(w)
wb = ''.join(map(str, wb))

bin_wb = int(wb, 2)
#
bw_xor_S = format(bin_bw ^ bin_S, 'b')
wb_xor_S = format(bin_wb ^ bin_S, 'b')
bwcout = 0
wbcout = 0
for i in range(len(bw_xor_S)):
    if bw_xor_S[i] == '1':
        bwcout += 1

for i in range(len(wb_xor_S)):
    if wb_xor_S[i] == '1':
        wbcout += 1

print(min(bwcout,wbcout))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
s=input()

can1=""
can2=""

match1=0
match2=0

for i in range(len(s)):
    if i%2:
        can1=can1+"0"
        can2=can2+"1"
    else:
        can1=can1+"1"
        can2=can2+"0"
    if can1[i]==s[i]:
        match1=match1+1
    else:
        match2=match2+1

if match1>match2:
    print(match2)
else:
    print(match1)