Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

000

Sample Output 1

1

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

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    s = get_str()
    b = int("0" + s, 2)
    zo = "01" * ((len(s) // 2) + 1)
    x = int("0" + zo[0:len(s)], 2)
    y = int("0" + zo[1:len(s)+1], 2)
    print(min(bin(b ^ x).count("1"), bin(b ^ y).count("1")))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

arr1_dif = 0
arr2_dif = 0
for i in range(n):
  if i%2 == 0:
    if x[i] == '0':
      arr1_dif += 1
    else:
      arr2_dif += 1
  else:
    if x[i] == '0':
      arr2_dif += 1
    else:
      arr1_dif += 1

print(arr1_dif if arr1_dif<arr2_dif else arr2_dif)

Submission status: Accepted

Solution code:
s = input()
ans = [0,0]

for i in range(len(s)):
  if (int(s[i])+i)%2==0:
    ans[0] += 1
  else:
    ans[1] += 1
print(min(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
a = list(map(int, input()))
#print(a)

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

cnt = 0
for i, v in enumerate(a):
  if i == 0:
    prev = v
  else:
    if v != rev01(prev):
#      print(i,v)
      cnt += 1
      prev = rev01(v)
    else:
      prev = v
      
print(cnt)

Submission status: Accepted

Solution code:
val = input()
zero = '0'
one = '1'
c = 0
l = list(val)
for i in range(len(l)):
  if i == 0:
    continue
  if l[i - 1] == l[i]:
    if l[i - 1] == zero:
      l[i] = one
    else:
      l[i] = zero
    c = c + 1
print(c)

Submission status: Accepted

Solution code:
S = input()
s = list(map(int, S))
t = s.copy()
n = len(s)
x = 0
y = 1

if t[0] == 0:
    t[0]=1
else:
    t[0]=0

for i in range(n-1):
    if s[i+1]==0 and s[i+1] == s[i]:
    	s[i+1]=1
    	x +=1
    elif s[i+1]==1 and s[i+1]==s[i]:
    	s[i+1]=0
    	x +=1
    
for i in range(n-1):
    if t[i+1]==0 and t[i+1] == t[i]:
    	t[i+1]=1
    	y +=1
    elif t[i+1]==1 and t[i+1]==t[i]:
    	t[i+1]=0
    	y +=1

print(min([x,y]))

Submission status: Accepted

Solution code:
#白黒白・・か黒白黒・・か
S = input()
N = len(S)
A = 0
B = 0
for i in range(0,N,2):
    if S[i] == "0":
        A += 1
    if i+1==N:
        break
    if S[i+1] == "1":
        B += 1
if A + B <= N//2:
    print(A + B)
else:
    print(N-(A+B))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt=0
prev=0
for i, t in enumerate(T):
  if prev == t:
    cnt+=1
    prev= 1 if t==0 else 0
  else:
    prev=t

    
print(min(cnt,len(T)-cnt))

Submission status: Accepted

Solution code:
s = list(input())

cnt = 0

for i in range(int(len(s))):
    if i == int(len(s)):
        break
    elif i == 0:
        continue
    else:
        if s[i] == s[i-1]:
            cnt += 1
            if s[i] == '0':
                s[i] = '1'
            else:
                s[i] = '0'

print(cnt)

Submission status: Accepted

Solution code:
s = input()

# 最初の文字を0にするケース
ptn1 = s[::2].count("1") + s[1::2].count("0")
# 最初の文字を1にするケース
ptn2 = s[::2].count("0") + s[1::2].count("1")

print(min(ptn1, ptn2))

Submission status: Accepted

Solution code:
S = list(str(input()))
# 101010... or 010101... とすう必要がある。両方のパターンで調べて、どっちか小さい方でいいんじゃないか？

a1 = 0
a2 = 1
re1 = 0
re2 = 0
for s in S:
    if int(s) != a1:
        re1 += 1
    if int(s) != a2:
        re2 +=1
        
    a1 = (a1+1) % 2
    a2 = (a2+1) % 2
    
if re1 < re2:
    print(re1)
else:
    print(re2)

Submission status: Accepted

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

if n % 2 == 0:
    mihon0 = '01' * (n//2)
    mihon1 = '10' * (n//2)
else:
    mihon0 = '0' + '10' * (n//2)
    mihon1 = '1' + '01' * (n//2)

ans0, ans1 = 0, 0
for i in range(n):
    if S[i] != mihon0[i]:
        ans0 += 1
    if S[i] != mihon1[i]:
        ans1 += 1

print(min(ans0, ans1))

Submission status: Accepted

Solution code:
s = input()

first_c = s[0]
ans = 0
for c in s:
    if first_c != c:
        ans += 1
    if first_c == '0':
        first_c = '1'
    else:
        first_c = '0'
print(ans)

Submission status: Accepted

Solution code:
S = list(map(int, input()))
ans1 = 0
ans2 = 0
for i in range (len(S)):
  if i % 2 == 0:
    if S[i] == 0:
      ans1 += 1
  else:
    if S[i] == 1:
      ans1 += 1
for i in range(len(S)):
  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 = list(map(int, input()))
ans1 = 0
ans2 = 0
for i in range (len(S)):
  if i % 2 == 0 and S[i] == 0:
      ans1 += 1
  elif i %2 ==1 and S[i] == 1:
      ans1 += 1
for i in range(len(S)):
  if i % 2 == 0 and S[i] == 1:
      ans2 += 1
  elif i % 2 ==1 and S[i] == 0:
      ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
tile=list(map(int,input()))
n=len(tile)
sum=0
for i in range(n):
  sum+=(i-tile[i])%2
print(min(sum,n-sum))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
len_S = len(S)
cnt1 = 0

if len_S%2 == 0:
  ans = "01"*(len_S//2)
else:
  ans = "01"*(len_S//2)+"0"
for i in range(len_S):
  if S[i]!=ans[i]:
    cnt1 += 1
final_ans = min(len_S-cnt1,cnt1)
print(final_ans)

Submission status: Accepted

Solution code:
import collections
S = list(input())
c_odd = collections.Counter(S[::2])
c_evn = collections.Counter(S[1::2])
if c_odd['0'] > c_evn['0']:
    a = c_odd['1'] + c_evn['0']
else:
    a = c_odd['0'] + c_evn['1']

if c_odd['1'] > c_evn['1']:
    b = c_odd['0'] + c_evn['1']
else:
    b = c_odd['1'] + c_evn['0']
print(min(a, b))

Submission status: Accepted

Solution code:
n=input()
x=[n[i] for i in range(0,len(n),2)]
y=[n[i] for i in range(1,len(n),2)]
a=x.count('0')+y.count('1')
print(min(a,len(n)-a))

Submission status: Accepted

Solution code:
S = list(input())
#swt = 0 なら黒、 swt = 1 なら白
def counting(swt):
    cnt = 0
    for i in S:
        if swt == 0 and i == "1":
            i = "0"
            cnt += 1
            swt = 1
        elif swt == 1 and i == "0":
            i = "1"
            cnt += 1
            swt = 0
        else:
            if swt == 0:
                swt = 1
            else:
                swt = 0
    return cnt

print(min(counting(0),counting(1)))

Submission status: Accepted

Solution code:
s = str(raw_input())
a = s[::2].count('0') + s[1::2].count('1')
b = s[::2].count('1') + s[1::2].count('0')
print(min(a, b))

Submission status: Accepted

Solution code:
s = input()
t = len(s)
a = '01'*int(t/2) + '0'*int(t%2)
b = '10'*int(t/2) + '1'*int(t%2)
cta = 0
ctb = 0
for i in range(t):
    if s[i] == a[i]:
        cta += 1
    elif s[i] == b[i]:
        ctb += 1
if cta <= ctb:
    print(cta)
else:
    print(ctb)

Submission status: Accepted

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

s = input()
s_list1 = list(s)
s_list2 = list(s)
count1 = 0
#count2 = 0

# 最初塗り替えない
s_len = len(s_list1)
pre = int(s_list1.pop(0))
for i in range(s_len-1):
    if pre == int(s_list1.pop(0)):
        pre = 1 - pre
        count1 += 1
    else:
        pre = 1 - pre
if count1 <= s_len//2:
    print(count1)
else:
    print(s_len-count1)

Submission status: Accepted

Solution code:
S=list(map(int,input()))
N=len(S)
print(min([sum([(i%2-S[i]+m)%2 for i in range(N)]) for m in range(2)]))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(1,len(inpl)+1):
    if i % 2 != 0:
        if inpl[i-1] == '0':
            c1 += 1
    else:
        if inpl[i-1] == '1':
            c1 += 1

for i in range(1,len(inpl)+1):
    if i % 2 != 1:
        if inpl[i-1] == '0':
            c2 += 1
    else:
        if inpl[i-1] == '1':
            c2 += 1
print(c1 if c1 < c2 else c2)

Submission status: Accepted

Solution code:
S = str(input())
temp, temp2 = "", ""
ans1, ans2 = 0, 0
for i in range(len(S)):
    if i % 2 == 0:
        temp += "0"
        temp2 += "1"
    else:
        temp += "1"
        temp2 += "0"
    if temp[i] == S[i]:
        ans1 += 1
    elif temp2[i] == S[i]:
        ans2 += 1
        
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
white_start = 0
black_start = 0
for i in range(n):
    if s[i] == '0' and i%2 == 0:
        black_start += 1
    elif s[i] == '0' and i%2 == 1:
        white_start += 1
    elif s[i] == '1' and i%2 == 0:
        white_start += 1
    else:
        black_start += 1
print(min(black_start,white_start))

Submission status: Accepted

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

#print(l)

x = [0] * len(l)

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

#print(x)

count = 0

for i in range(0,len(l)):
    if l[i] != x[i]:
        count += 1
    
print(min(count,len(l)-count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(n):
	odd = "1"
	even= "0"
	if(n[0] =="0"):
		# zero mode
		odd = "0"
		even= "1"
	a = sum((((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n),2))
	b = sum((((i % 2 == 0) and n[i] == even)) for i in range(0, len(n),2))
	return a+b

print(main(input()))

Submission status: Accepted

Solution code:
def main(n):
	odd = "1"
	even= "0"
	if(n[0] =="0"):
		# zero mode
		odd = "0"
		even= "1"
	#return sum((((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n)))
	a = sum((((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n),2))
	b = sum((((i % 2 == 0) and n[i] == even)) for i in range(0, len(n),2))
	return a+b

print(main(input()))
#assert(1 == main("000"))
#assert(3 == main("10010010"))
#assert(0 == main("0"))

Submission status: Accepted

Solution code:
def main(n):
	odd = "1"
	even= "0"
	if(n[0] =="0"):
		# zero mode
		odd = "0"
		even= "1"
	return sum((((i % 2 == 0) and (n[i] == even)) or ((i % 2 != 0) and n[i] == odd)) for i in range(1, len(n)))

print(main(input()))

Submission status: Accepted

Solution code:
s = [int(x) for x in list(input())]
a = [x%2 for x in range(len(s))]
b = [(1 - x%2) for x in range(len(s))]
c1=0
c2=0
for i in range(len(s)):
    if a[i] != s[i]:
        c1 += 1
    if b[i] != s[i]:
        c2 += 1

print(min([c1,c2]))

Submission status: Accepted

Solution code:
def main(n):
	r = 0
	if(n[0] =="0"):
		# zero mode
		return sum((((i % 2 == 0) and (n[i] == "1")) or ((i % 2 != 0) and n[i] == "0")) for i in range(1, len(n)))
	else:
		# one mode
		return sum((((i % 2 == 0) and (n[i] == "0")) or ((i % 2 != 0) and n[i] == "1")) for i in range(1, len(n)))

print(main(input()))
#assert(1 == main("000"))
#assert(3 == main("10010010"))
#assert(0 == main("0"))

Submission status: Accepted

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

l1 = []
for i in range(len(sl)):
  l1.append(i%2)

d1 = 0
for i in range(len(sl)):
  if sl[i] != l1[i]:
    d1 += 1

print(min(d1,len(sl)-d1))

Submission status: Accepted

Solution code:
def main(n):
	r = 0
	f = n[0]
	if(f =="0"):
		# zero mode
		for i in range(1, len(n)):
			if(i % 2 == 0): # 偶
				# 1
				if(n[i]=="1"):
					r+=1
			else: # basic
				# 0
				if(n[i]=="0"):
					r+=1
	else:
		# one mode
		for i in range(1, len(n)):
			if(i % 2 == 0): # 偶
				# 1
				if(n[i]=="0"):
					r+=1
			else: # basic
				# 0
				if(n[i]=="1"):
					r+=1
	# sum(result)
	return r

print(main(input()))
#assert(1 == main("000"))
#assert(3 == main("10010010"))
#assert(0 == main("0"))

Submission status: Accepted

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

l1 = []
l2 = []
for i in range(len(sl)):
  l1.append(i%2)
  l2.append((i+1)%2)

d1 = 0
d2 = 0
for i in range(len(sl)):
  if sl[i] != l1[i]:
    d1 += 1
  if sl[i] != l2[i]:
    d2 += 1

print(min(d1,d2))

Submission status: Accepted

Solution code:
cnt_st0 = 0
cnt_st1 = 0
in_str = str(input())
for i, m in enumerate(in_str):
  if i % 2 == 0:
    if str(m) == '0':
      cnt_st1 += 1
    else:
      cnt_st0 += 1
  else:
    if str(m) == '0':
      cnt_st0 += 1
    else:
      cnt_st1 += 1
print(min(cnt_st0, cnt_st1))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
BstartS_count = 0
WstartS_count = 0

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

output = BstartS_count
if WstartS_count < output:
    output = WstartS_count

print(output)

Submission status: Accepted

Solution code:
strS = list(str(input()))
S = [int(n) for n in strS]
N =len(S)
cnt = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
        if S[i] == 0:
            S[i+1] = 1
        else:
            S[i+1] = 0

print(cnt)

Submission status: Accepted

Solution code:
inp = list(input())

cost_start_with_zero = 0
cost_start_with_one = 0

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

print(min(cost_start_with_one,cost_start_with_zero))

Submission status: Accepted

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

s=input()

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

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

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
# ABC124_D

N = input()
count = 0

for i in range(len(N)):
    if(int(N[i]) != (i % 2)):
        count = count + 1

if(count > (len(N) / 2)):
    count = len(N) - count

print(count)

Submission status: Accepted

Solution code:
S = list(input())

for s in S[:1]:
    flag = int(s)
count = 0

for s in S[1:]:
    if s == "0":
        if flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
    else:
        if flag == 1:
            count += 1
            flag = 0
        else:
            flag = 1
print(count)

Submission status: Accepted

Solution code:
s = input()



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

odd_b = odd_s.count('0')
odd_w = odd_s.count('1')
even_b = even_s.count('0')
even_w = even_s.count('1')

change_num = min(odd_w + even_b, odd_b + even_w)


print(change_num)

Submission status: Accepted

Solution code:
cash = input()
S = list(cash)
cash0 = ""
cash1 = ""
for i in range(len(S)):
	if i % 2 == 0:
		cash0 = cash0 + "0"
		cash1 = cash1 + "1"
	else:
		cash0 = cash0 + "1"
		cash1 = cash1 + "0"
cash0 = list(cash0)
cash1 = list(cash1)
num0=0
num1=0
for i in range(len(S)):
	if S[i]==cash0[i]:
		num0=num0+1
	if S[i]==cash1[i]:
		num1=num1+1
print(min(num0,num1))

Submission status: Accepted

Solution code:
s=input()

length=len(s)

s1=''
s2=''
count1=0
count2=0

for i in range(int(length/2)):
    s1+='10'
if int(length%2)==1:
    s1+='1'

for i in range(int(length/2)):
    s2+='01'
if int(length%2)==1:
    s2+='0'




for i in range(length):
    if s[i]!=s1[i]:
        count1+=1
        
for i in range(length):
    if s[i]!=s2[i]:
        count2+=1


print(min(count1,count2))

Submission status: Accepted

Solution code:
s = input()
L = [str(i % 2) for i in range(len(s))]
start0 = "".join(L)
start1 = "".join(L[1:])
if len(s) % 2 == 0:
    start1 += "0"
else:
    start1 += "1"
count_start0 = 0
count_start1 = 0

for i in range(len(s)):
    if s[i] != start0[i]:
        count_start0 += 1

for i in range(len(s)):
    if s[i] != start1[i]:
        count_start1 += 1
print(min(count_start0,count_start1))

Submission status: Accepted

Solution code:
a = input()
b = len(a)
k = 0
str = []
str = list(a)
for i in range(1,b):
    if str[i-1] == "0" and str[i] == "0":
        str[i] = "1"

        k = k + 1
    
    if str[i-1] == "1" and str[i] == "1":
        str[i] = "0"
        k = k + 1

print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
tiles = input()
left = tiles[0]
count = -1
num = 0
for color in tiles:
    if left == color:
        count += 1
        if num == 0:
            left = color
        else:
            left = '0' if color == '1' else '1'
    else:
        left = color
    num += 1
print(count)

Submission status: Accepted

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

even = tiles[0::2]
odd = tiles[1::2]

even0 = even.count(0)
even1 = even.count(1)
odd0 = odd.count(0)
odd1 = odd.count(1)

if even0 >= max(even1, odd0, odd1) or odd1 >= max(even0, even1, odd0):
    print (even1 + odd0)

elif even1 >= max(even0, odd0, odd1) or odd0 >= max(even0, even1, odd1):
    print (even0 + odd1)

Submission status: Accepted

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

even = tiles[0::2]
odd = tiles[1::2]

if even.count(0) >= even.count(1):
    ans1 = even.count(1) + odd.count(0) 

else:
    ans1 = even.count(0) + odd.count(1)
    
if odd.count(0) >= odd.count(1):
    ans2 = odd.count(1) + even.count(0) 

else:
    ans2 = odd.count(0) + even.count(1)

print (min(ans1, ans2))

Submission status: Accepted

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

# 初期値は大きい値
ans = len(s)

# iは最初に使う色（0 or 1）
for i in range(2):
    # 変える必要があるタイル数
    cnt = 0

    for j in range(len(s)):
        if (j % 2 == 0) ^ (s[j] == i):
            cnt = cnt +1
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
S = input()

cost0 = 0
cost1 = 0

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

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

print(min(cost0,cost1))

Submission status: Accepted

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

if len(s)%2 == 0:
    s0 = [0,1] *(len(s)//2)
    s1 = [1,0] *(len(s)//2)
else:
    s0 = [0,1] *(len(s)//2)
    s0.append(0)
    s1 = [1,0] *(len(s)//2)
    s1.append(1)

sum0 = 0
sum1 = 0
for i in range(len(s)):   
    if s0[i] != s[i]:
        sum0 = sum0 +1
    if s1[i] != s[i]:
        sum1 = sum1 +1

ans = min(sum0, sum1)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
ans1 = 0
ans2 = 0
t = True
for char in s:
    t = not t
    if((char == "0") ^ t):
        ans1 += 1
    else:
        ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
from sys import stdin

s = [int(x) for x in stdin.readline().rstrip()]
n = len(s)

#0番目を1にする
res = 0
for i,name in enumerate(s):
    if i%2 == 0 and name == 0:
        res += 1
    elif i%2 == 1 and name == 1:
        res += 1

#0番目を0にする
res2 = 0
for i,name in enumerate(s):
    if i%2 == 0 and name == 1:
        res2 += 1
    elif i%2 == 1 and name == 0:
        res2 += 1
print(min(res,res2))

Submission status: Accepted

Solution code:
tile_list = list(map(str, input()))

odd_diff_count = 0
even_diff_count = 0

for i in range(len(tile_list)):
    
    if i % 2 == 0:
        if tile_list[i] != "0":
            odd_diff_count += 1
        else:
            even_diff_count += 1
    else:
        if tile_list[i] != "1":
            odd_diff_count += 1
        else:
            even_diff_count += 1

if odd_diff_count >= even_diff_count:
    print(even_diff_count)
else:
    print(odd_diff_count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ss = input()
ans = 1
fir_kuro = 0
fir_siro = 0
counter = 0
for s in ss:
    if counter%2 == 0:
        fir_kuro += 0 if s == '1' else 1
        fir_siro += 0 if s == '0' else 1
    else:
        fir_kuro += 0 if s == '0' else 1
        fir_siro += 0 if s == '1' else 1
    counter += 1
print(min(fir_kuro, fir_siro))

Submission status: Accepted

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

prev = 0
ans1 = 0
for i in s:
    if prev != int(i):
        ans1 += 1
    if prev == 1:
        prev = 0
    else:
        prev = 1


prev = 1
ans2 = 0
for i in s:
    if prev != int(i):
        ans2 += 1
    if prev == 1:
        prev = 0
    else:
        prev = 1

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
l = len(S)
OZ = '10' * int(l/2)
ZO = '01' * int(l/2)
if(l%2!=0):
    OZ += '1'
    ZO += '0'
cntOZ=0
cntZO=0
for i in range(l):
    if(S[i]==OZ[i]):
        cntOZ+=1
    else:
        cntZO+=1
#print(cntOZ)
#print(cntZO)
if(cntOZ <= cntZO):
    print(cntOZ)
else:
    print(cntZO)

Submission status: Accepted

Solution code:



tile_list = input()

ansfz = 0
ansfo = 0

for i,s in enumerate(tile_list):
    # print(i,':',s,i % 2,int(s) == (i % 2))
    if int(s) == (i % 2):
        ansfz += 1
    else :
        ansfo += 1

print(min(ansfz,ansfo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C - Coloring Colorfully
import sys
input = sys.stdin.readline
s = list(input())

cost_0, cost_1 = 0, 0

for i in s[::2]:
	if i == "1":
		cost_0 += 1
for i in s[1::2]:
	if i == "0":
		cost_0 += 1

for i in s[::2]:
	if i == "0":
		cost_1 += 1
for i in s[1::2]:
	if i == "1":
		cost_1 += 1
		 
print(min(cost_0, cost_1))

Submission status: Accepted

Solution code:
import re
import sys
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    S = ii(str)
    a = 0
    b = 0
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == "0":
                a += 1
            else:
                b += 1
        else:
            if s == "0":
                b += 1
            else:
                a += 1
    return min(a, b)


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

Submission status: Accepted

Solution code:
#C - Coloring Colorfully

s = list(input())

cost_0, cost_1 = 0, 0

for i in s[::2]:
	if i == "1":
		cost_0 += 1
for i in s[1::2]:
	if i == "0":
		cost_0 += 1

for i in s[::2]:
	if i == "0":
		cost_1 += 1
for i in s[1::2]:
	if i == "1":
		cost_1 += 1
		 
print(min(cost_0, cost_1))

Submission status: Accepted

Solution code:
a=list(input())
s=0
for i in range(len(a)):
    if i%2==int(a[i]):
        s=s+1
m=min(s,len(a)-s)  
print(m)

Submission status: Accepted

Solution code:
s = list(map(int, input()))
o = s[::2]
e = s[1::2]
l_o = len(o)
l_e = len(e)
o_o = sum(o)
o_e = sum(e)

print(min(l_o - o_o + o_e, o_o + l_e - o_e))

Submission status: Accepted

Solution code:
s = list(input())

count = 0
for i in range(len(s)):
    if i == 0:
        continue
    if int(s[i]) == int(s[i-1]):
        count += 1
        if int(s[i]) == 0:
            s[i] = '1'
        else:
            s[i] = '0'

print(count)

Submission status: Accepted

Solution code:
numbers = input()

count = 0
for i, num in enumerate(numbers):
    if int(num) != i % 2:
        count += 1

if count <= len(numbers)/2:
    print(count)
else:
    print(len(numbers)-count)

Submission status: Accepted

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

S1 =[];
for i in range(len(S)):
    if i%2 ==0:
        S1.append("1");
    else:
        S1.append("0");

change1 =0;
change2 =0;

for i in range(len(S)):
    if S[i] !=S1[i]:
        change1 +=1;
    else:
        change2 +=1;
        
print(min(change1,change2));

Submission status: Accepted

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

for i, si in enumerate(s):
  ti = '0' if i%2 == 0 else '1'
  if si != ti:
    cnt += 1

print(min(cnt, n - cnt))

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	else: return y

S = raw_input()
n = len(S)
tile = ['0', '1']
cnt1 = 0
cnt2 = 0
for i in range(0, n):
	if tile[i%2] == S[i]:
		cnt1 += 1
	else: cnt2 += 1
print smaller(cnt1, cnt2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans1 = 0 # 101010101...
ans2 = 0 # 010101010...
for i, s in enumerate(S):
    if s == '0' and i % 2 == 0:
        ans1 += 1
    elif s == '0' and i % 2 == 1:
        ans2 += 1
    elif s == '1' and i % 2 == 0:
        ans2 += 1
    else:
        ans1 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = input()
wb = ["0" if i % 2 == 0 else "1" for i in range(len(S))]
bw = ["1" if i % 2 == 0 else "0" for i in range(len(S))]

cnt_wb = 0
cnt_bw = 0
for i in range((len(S))):
  if wb[i] != S[i]:
    cnt_wb += 1
  if bw[i] != S[i]:
    cnt_bw += 1
    
print (min(cnt_wb, cnt_bw))

Submission status: Accepted

Solution code:
S =  input()
countA =0
countB =0
for i in range(len(S)):
    if i % 2 == 0:
        if int(S[i]) == 1:
            countA += 1
        else:
            countB += 1
    else:
        if int(S[i]) == 1:
            countB += 1
        else:
            countA += 1            
if countA > countB:
    print(countB)
else:
    print(countA)

Submission status: Accepted

Solution code:

s = input()

firstTile = s[0]
lastTile = s[-1]

def isOneColor():
    t = None
    for c in s:
        if t is None:
            t = c
        else:
            if c is not t:
                return False
    return True

def reverse(tile):
    if tile is "0":
        return "1"
    else:
        return "0"

def shouldZeroStart():
    z = 0
    o = 0
    currentTile = "0"
    for tile in s:
        if tile is not currentTile:
            z = z + 1
        currentTile = reverse(currentTile)
    currentTile = "1"
    for tile in s:
        if tile is not currentTile:
            o = o + 1
        currentTile = reverse(currentTile)
    if z < o:
        return True
    else:
        return False

result = 0
currentTile = "1"
if isOneColor():
    if firstTile is "0":
        currentTile = "0"
else:
    if shouldZeroStart():
        currentTile = "0"
for i in range(len(s)):
    if s[i] is not currentTile:
        result = result + 1
    currentTile = reverse(currentTile)



print(result)

Submission status: Accepted

Solution code:
L=list(input())
if L[::2].count("0") > L[1::2].count("0") :
  print( L[::2].count("1")+L[1::2].count("0"))
else :
  print( L[::2].count("0")+L[1::2].count("1"))

Submission status: Accepted

Solution code:
S  = str(input())
even_black = 0
even_white = 0
odd_black = 0
odd_white = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            even_black += 1
        else:
            even_white += 1
    else:
        if S[i] == '0':
            odd_black += 1
        else:
            odd_white += 1
bw = even_white + odd_black
wb = even_black + odd_white
print (min(wb, bw))

Submission status: Accepted

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

evens = s[::2]
odds = s[1::2]

ans_0 = evens.count('0') + odds.count('1')
ans_1 = evens.count('1') + odds.count('0')

print(len_s - max(ans_0,ans_1))

Submission status: Accepted

Solution code:
s = list(input())
na = []
for i in range(len(s)):
    if i%2 == 0:
        na.append("0")
    else:
        na.append("1")
count = 0
for i in range(len(s)):
    if na[i] == s[i]:
        count += 1
print(min(len(s)-count,count))

Submission status: Accepted

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

# print(s)

c = 0
count_start_0 = 0
for i in range(len(s)):
    if int(s[i]) == c:
        count_start_0 += 1
    c = 0 if c == 1 else 1

count_start_1 = len(s) - count_start_0

print(min([count_start_0, count_start_1]))

Submission status: Accepted

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


def problem(s):
    size = len(s)

    evens = s[::2]
    odds = s[1::2]

    p1 = size - (evens.count('0') + odds.count('1'))
    p2 = size - (evens.count('1') + odds.count('0'))

    return min(p1, p2)


def main():
    s = input()

    print(problem(s))


if __name__ == '__main__':
    main()