Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

000

Sample Output 1

1

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

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

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

def make_target(n):
    target1_bin = '01' * (n//2)
    target2_bin = '10' * (n//2)
    if (n%2 == 1):
        target1_bin += '0'
        target2_bin += '1'
    return([target1_bin, target2_bin])

s = int(s_bin, 2)
target1, target2 = [int(i, 2) for i in make_target(n)]

diff1 = bin(s ^ target1)
diff2 = bin(s ^ target2)

cost1 = diff1.count('1')
cost2 = diff2.count('1')

print(min([cost1, cost2]))

Submission status: Accepted

Solution code:
S = [int(c) for c in input()]
S2 = S
beside_color = (S[0]+1)%2
count1 =0
for i in range(len(S)):
    if beside_color == S[i]:
        count1 +=1
        S[i] = (S[i]+1)%2
    beside_color = S[i]
count2 = 0
beside_color = S2[0]
for i in range(len(S)):
    if beside_color == S2[i]:
        count2 +=1
        S2[i] = (S2[i]+1)%2
    beside_color = S2[i]
if count2 < count1:
    ans = count2
else:
    ans = count1
print(ans)

Submission status: Accepted

Solution code:
def flip(c):
    if c == '0':
        return '1'
    else:
        return '0'

def main():
    S = input()

    # 黒白...
    count1 = 0
    target = '0'
    for s in S:
        if s != target:
            count1 += 1
        target = flip(target)

    # 白黒...
    count2 = 0
    target = '1'
    for s in S:
        if s != target:
            count2 += 1
        target = flip(target)

    print(min(count1, count2))

main()

Submission status: Accepted

Solution code:
S = input()

cnt1=0
start="1"
for i in range(len(S)):
    if i%2==0:
        if S[i]!=start:
            cnt1+=1
    else:
        if S[i]==start:
            cnt1+=1
cnt2=0
start="0"
for i in range(len(S)):
    if i%2==0:
        if S[i]!=start:
            cnt2+=1
    else:
        if S[i]==start:
            cnt2+=1
if cnt1 < cnt2:
    print(cnt1)
else:
    print(cnt2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
cnt = 0
for i in range(len(N)):
    if i % 2 == 0:
        cnt += (abs(int(N[i])-1))
    else:
        cnt += (abs(int(N[i])))
print(min(cnt, len(N)-cnt))

Submission status: Accepted

Solution code:
s = input()
t = int(s, 2)
N = len(s)
if N%2==0:
    a = '10'*(N//2)
    b = '01'*(N//2)
else:
    a = '10'*(N//2)+'1'
    b = '01'*(N//2)+'0'
a = int(a, 2)
b = int(b, 2)
print(min(str(bin(t^a))[2:].count('1'), str(bin(t^b))[2:].count('1')))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""

S = list(input())
c1 = 0
c2 = 0
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '0':
            c1 += 1
    else:
        if S[i] == '1':
            c1 += 1
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '1':
            c2 += 1
    else:
        if S[i] == '0':
            c2 += 1
print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()
ct_a = 0
ct_b = 0
for i in range(S.__len__()):
    if i % 2 == 0:
        if S[i] == "0":
            ct_a += 1
        else:
            ct_b += 1
    else:
        if S[i] == "0":
            ct_b += 1
        else:
            ct_a += 1

print(min(ct_a,ct_b))

Submission status: Accepted

Solution code:
t = input()
t = str(t)
t = list(t)
t = [int(s) for s in t]
n = len(t)
c_a = 0
c_b = 0
for i in range(n):
    if i%2==0:
        if t[i] != 0:
            c_a += 1
    else:
        if t[i] != 1:
            c_a += 1

for i in range(n):
    if i%2==0:
        if t[i] != 1:
            c_b += 1
    else:
        if t[i] != 0:
            c_b += 1
    
if c_a >= c_b:
    print(c_b)
else:
    print(c_a)

Submission status: Accepted

Solution code:
A = input()
x = 0
lens = len(A)
C = list(A)

for i in range(1, lens):
  if C[i-1] == C[i]:
    x += 1
    
    if C[i] == '0':  
      C[i] = '1'
    else:
      C[i] = '0'
  else:
    continue

print(x)

Submission status: Accepted

Solution code:
S = input()

SSize = len(S)

bws = "".join([str(i%2) for i in range(SSize)])
wbs = "".join([str((i+1)%2) for i in range(SSize)])

#print(bws)
#print(wbs)

diffCountBws = 0
diffCountWbs = 0

for i in range(SSize):
	if S[i] != bws[i]:
		diffCountBws += 1
	
	if S[i] != wbs[i]:
		diffCountWbs += 1
		
print(min(diffCountBws,diffCountWbs))

Submission status: Accepted

Solution code:
S = input()
s_list = [int(s) for s in S]
n = len(s_list)
s_first = s_list[0]
cnt1 = 0
cnt2 = 1
if s_first == 0:
    for i in range(1, n):
        if (i % 2 == 1) & (s_list[i] == 0):
            cnt1 += 1
        if (i % 2 == 0) & (s_list[i] == 1):
            cnt1 += 1
        if (i % 2 == 1) & (s_list[i] == 1):
            cnt2 += 1
        if (i % 2 == 0) & (s_list[i] == 0):
            cnt2 += 1
    print(min(cnt1, cnt2))
else:
    for i in range(1, n):
        if (i % 2 == 1) & (s_list[i] == 1):
            cnt1 += 1
        if (i % 2 == 0) & (s_list[i] == 0):
            cnt1 += 1
        if (i % 2 == 1) & (s_list[i] == 0):
            cnt2 += 1
        if (i % 2 == 0) & (s_list[i] == 1):
            cnt2 += 1
    print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S = input()
oddnumlist = []
evennumlist = []
sepnum = 0

for index in S:
    if sepnum % 2 == 0:
        evennumlist.append(index)
    else:
        oddnumlist.append(index)
    sepnum += 1

if evennumlist.count("1") + oddnumlist.count("0") <= evennumlist.count("0") + oddnumlist.count("1"):
    print(evennumlist.count("1") + oddnumlist.count("0"))
else:
    print(evennumlist.count("0") + oddnumlist.count("1"))

Submission status: Accepted

Solution code:
s = input()
od = []
ev = []

if len(s)==1:
    print(0)
else:
    for i in range(len(s)):
        if i%2 == 0:
            od.append(int(s[i]))
        else:
            ev.append(int(s[i]))
    
    a = len(od)-sum(od)+sum(ev)
    b = len(ev)-sum(ev)+sum(od)
    print(min(a,b))

Submission status: Accepted

Solution code:
S = input()
word_01 = '01'
word_10 = '10'
q, mod = divmod(len(S), 2)
if mod == 0:
    word_01 = word_01 * q
    word_10 = word_10 * q
else:
    word_01 = word_01 * q + '0'
    word_10 = word_10 * q + '1'
S_list = list(S)
word_01_list = list(word_01)
word_10_list = list(word_10)
counter1 = 0
counter2 = 0
for num1, num2, num3 in zip(S_list, word_01_list, word_10_list):
    if num1 != num2:
        counter1 += 1
    if num1 != num3:
        counter2 += 1
result = min(counter1, counter2)
print(result)

Submission status: Accepted

Solution code:
import math
s = input()

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

ans1 = 0
ss = '01'*math.ceil(len(s)/2)
ss = ss[:len(s)]
for i in range(len(s)):
    if not ss[i] == s[i]:
        ans1 += 1

ans2 = 0
ss = '10'*math.ceil(len(s)/2)
ss = ss[:len(s)]
for i in range(len(s)):
    if not ss[i] == s[i]:
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
import numpy as np

N = np.array(list(map(int, list(input()))))

m = len(N)

A = np.array([i%2 for i in range(m)])
B = np.array([1 if i == 0 else 0 for i in A])

AA = np.count_nonzero((A-N) == 0)
BB = np.count_nonzero((B-N) == 0)

if AA > BB:
  print(m - AA)
else:
  print(m - BB)

Submission status: Accepted

Solution code:
import numpy as np
S = np.array(list(input()))
l1 = np.array([str(i%2) for i in range(S.size)])
l2 = np.array([str((i+1)%2) for i in range(len(S))])
a1 = np.array(S == l1)
a2 = np.array(S == l2)
b1 = np.sum(a1)
b2 = np.sum(a2)

if b1 < b2:
    print(b1)
else :
    print(b2)

Submission status: Accepted

Solution code:
S = input()

def get_dif(length, str1, str2):
    c = 0
    for i in range(length):
        if str1[i] != str2[i]:
            c += 1
    return c

l = len(S)
if l % 2 == 0:
    S1 = "01" * (l // 2)
    S2 = "10" * (l // 2)
else:
    S1 = "01" * ((l - 1) // 2) + "0"
    S2 = "10" * ((l - 1) // 2) + "1"

c1 = get_dif(l, S, S1)
c2 = get_dif(l, S, S2)

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

Submission status: Accepted

Solution code:
def diffStr(a, b):
    i = 0
    diff = 0
    lenA = len(a)
    lenB = len(b) 
    while True:
        if i == lenA:
            break
        if i == lenB:
            break
        if a[i] != b[i]:
            diff += 1
        i += 1
    diff += abs(lenA - lenB)
    return diff

s = input()
n = len(s)
a = b = ''
c = False
for i in range(n):
    a += '1' if c else '0'
    b += '0' if c else '1'
    c = not c

diffA = diffStr(s, a)
diffB = diffStr(s, b)
print(min(diffA, diffB))

Submission status: Accepted

Solution code:
S = input()
p01 = 0
p10 = 0
p00 = 0
p11 = 0
for i in range(0, (len(S)//2 * 2), 2):
    if S[i:i+2] == '01':
        p01 += 1
    elif S[i:i+2] == '10':
        p10 += 1
    elif S[i:i+2] == '00':
        p00 += 1
    else:
        p11 += 1
#print(p01,p10,p00,p11)
c = 0
if (p01 == 0) and (p10 == 0):
    c = len(S) // 2
elif p01 >= p10:
    c = p10 * 2 + p00 + p11
    if len(S) & 1:
        if S[-1] == S[-2]:
            c += 1
else:
    c = p01 * 2 + p00 + p11
    if len(S) & 1:
        if S[-1] == S[-2]:
            c += 1
print(c)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
f = 0

test1 = ['0'] * n 
test2 = ['0'] * n


for i in range(n):
    if i % 2 == 0:
        test1[i] = '0'
        test2[i] = '1'
    else:
        test1[i] = '1'
        test2[i] = '0'



if len(s) == 1:
    print(count)
    f = 1
else:
    c0 = 0
    c1 = 0
    for i in range(n):
        if s[i] == '0':
            c0 += 1
        else:
            c1 += 1
    
    if c0 >= c1:
        if s[0] == '1' and s[-1] == '0':
            
            if n % 2 == 0:
                for i in range(n):
                    if test2[i] != s[i]:
                        count += 1
            else:
                for i in range(n):
                    if test1[i] != s[i]:
                        count += 1
        else:
            
            if s[0] == '0':
                for i in range(n):
                    if test1[i] != s[i]:
                        count += 1
                        
            else:
                for i in range(n):
                    if test2[i] != s[i]:
                        count += 1
    else:
        if s[0] == '0' and s[-1] == '1':
            
            if n % 2 == 0:
                for i in range(n):
                    if test1[i] != s[i]:
                        count += 1
            else:
                for i in range(n):
                    if test2[i] != s[i]:
                        count += 1
        else:
            if s[0] == '1':
                for i in range(n):
                    if test2[i] != s[i]:
                        count += 1
            else:
                for i in range(n):
                    if test1[i] != s[i]:
                        count += 1


if f == 0:
    print(count)

Submission status: Accepted

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

N = input()

N_list = list(N)
num = []

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


for a in range(len(N_list)):
    if a % 2 == 0: #odd
        if N_list[a] == "0":
            odd_0 += 1
        elif N_list[a] == "1":
            odd_1 += 1

    elif a % 2 == 1: #even
        if N_list[a] == "0":
            even_0 += 1
        elif N_list[a] == "1":
            even_1 += 1

if max(even_0,even_1,odd_0,odd_1) == even_0:
    print(even_1 + odd_0 )

elif max(even_0,even_1,odd_0,odd_1) == even_1:
    print(even_0 + odd_1 )

elif max(even_0,even_1,odd_0,odd_1) == odd_0:
    print(even_0 + odd_1 )

elif max(even_0,even_1,odd_0,odd_1) == odd_1:
    print(even_1 + odd_0 )

Submission status: Accepted

Solution code:
import numpy as np
s = np.array([int(i) for i in list(input())])
if len(s)%2==0:
  t1 = np.array([int(i) for i in list("10"*int(len(s)/2))])
  t2 = np.array([int(i) for i in list("01"*int(len(s)/2))])
else:
  t1 = np.array([int(i) for i in list("10"*int((len(s)-1)/2)+"1")])
  t2 = np.array([int(i) for i in list("01"*int((len(s)-1)/2)+"0")])
ans = min(len(np.where((t1+s) == 1)[0]), len(np.where((t2+s) == 1)[0]))
print(ans)

Submission status: Accepted

Solution code:
ls = input()
count = 0
if len(ls) == 0:
  print('0')
else:
  temp = ls[0] #一つ前のやつ
  ls = ls[1:]
  for i in ls:
    if i == temp:
      count += 1
      if i == '0':
        temp = '1'
      else:
        temp = '0'
    else:
      temp = i
print(count)

Submission status: Accepted

Solution code:
s = list(input())
r = ''
if s[0] == '0':
  r = ['0' if i % 2 == 0 else '1' for i in range(len(s))]
elif s[0] == '1':
  r = ['1' if i % 2 == 0 else '0' for i in range(len(s))]

mul = [str(int(s[i]) + int(r[i])) for i in range(len(s))]

print(mul.count('1'))

Submission status: Accepted

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

print(c)

Submission status: Accepted

Solution code:
c = list(input())
ans = [0, 0]
for i in range(len(c)):
    if i % 2 == 0 and c[i] == '0' or i % 2 == 1 and c[i] == '1':
        ans[0] += 1
    if i % 2 == 0 and c[i] == '1' or i % 2 == 1 and c[i] == '0':
        ans[1] += 1
print(min(ans))

Submission status: Accepted

Solution code:
s = input()
print(min(sum(s[i] != '0' if i & 1 else s[i] != '1' for i in range(len(s))),
    sum(s[i] != '1' if i & 1 else s[i] != '0' for i in range(len(s)))))

Submission status: Accepted

Solution code:

line = raw_input()
odd_one = 0
even_one = 0
for i, val in enumerate(line):
    if val == '1':
        if (i + 1)% 2 == 0:
            even_one += 1
        else:
            odd_one += 1

odd_zero = (len(line)+1) / 2 - odd_one
even_zero = len(line) / 2 - even_one

result = 0
if odd_one + even_zero > even_one + odd_zero:
    result = even_one + odd_zero
else:
    result = odd_one + even_zero

print result

Submission status: Accepted

Solution code:
import sys
import random
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
s = input().rstrip()
n = len(s)
ans2 = 0
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
for i in range(n):
    if i%2 == 0 and s[i] != "1":
        ans2 +=1
    if i%2 == 1 and s[i] != "0":
        ans2 += 1
print(min(ans2,ans))

Submission status: Accepted

Solution code:
s = str(input())

a = []
b = []

if s[0] == '1':
    c = '0'
else:
    c = '1'

if len(s) % 2 == 1:
    s = s + c
    

for i in range(int(len(s)/2)):
    a.append(s[i * 2])
    b.append(s[i * 2 -1])

print(a.count(c) + b.count(s[0]))

Submission status: Accepted

Solution code:
state = input()
length = len(state)

adder = 0
ans_1=""
ans_2=""

#make right answer
for a in range(length):
  adder = (adder + 1)%2 
  ans_1 = ans_1 +str(adder)
  #ans_2 = ans_2 +str((adder+1)%2)

#Pattern match
counter = 0
for b in range(length):
  if state[b] == ans_1[b]:
    counter += 1

if counter >= length/2:
  counter = length - counter

#print(ans_1)
print(counter)

Submission status: Accepted

Solution code:
S = input()

start1count = 0
start0count = 0

nextisblack = False

for tile in S:
    if nextisblack:
        nextisblack = False
        if tile == "1":
            start1count += 1
    else:
        nextisblack = True
        if tile == "0":
            start1count += 1

nextisblack = True

for tile in S:
    if nextisblack:
        nextisblack = False
        if tile == "1":
            start0count += 1
    else:
        nextisblack = True
        if tile == "0":
            start0count += 1

print(min(start1count,start0count))

Submission status: Accepted

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

# 101010101010 か 010101010101 のどちらかになる。
A = str()
B = str()
if N%2 == 0:
  for i in range(int(N/2)):
    A += '10'
    B += '01'
else:
  for i in range(int((N-1)/2)):
    A += '01'
    B += '10'
  A += '0'
  B += '1'

# SとA,Bの差分：abs(S[i]-A[i])の和のminを取ればいい。
a = 0
b = 0
for i in range(N):
  a += abs(int(S[i])-int(A[i]))
  b += abs(int(S[i])-int(B[i]))

num = min(a, b)
print(num)

Submission status: Accepted

Solution code:
S = str(input())

temp_0 = "0"
temp_1 = "1"
count_0 = 0
count_1 = 0
for x in S:
    if x == temp_0:
        count_0 += 1
        if temp_0 == "1":
            temp_0 = "0"
        else:
            temp_0 = "1"
    else:
        if temp_0 == "1":
            temp_0 = "0"
        else:
            temp_0 = "1"
            
for x in S:
    if x == temp_1:
        count_1 += 1
        if temp_1 == "1":
            temp_1 = "0"
        else:
            temp_1 = "1"
    else:
        if temp_1 == "1":
            temp_1 = "0"
        else:
            temp_1 = "1"

print(min(count_0,count_1))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans1 = sum(a != b for a, b in zip(('01'*10**5)[:n], s))
ans2 = sum(a != b for a, b in zip(('10'*10**5)[:n], s))
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = raw_input();
n = len(s);

p1 = "";
p2 = "";

ap1 = 0;
ap2 = 0;

for i in range(n):
	if (i % 2 == 0):
		p1 += "0";
		p2 += "1";
	else:
		p1 += "1";
		p2 += "0";

for i in range(n):
	if s[i] != p1[i]:
		ap1 += 1;

	if s[i] != p2[i]:
		ap2 += 1;

if ap1 < ap2:
	print(ap1);

else:
	print(ap2);

Submission status: Accepted

Solution code:
def replace(a):
    if a == "0":
        a = "1"
    else:
        a = "0"
    return a

n = str(input())
l = [str(x) for x in list(str(n))]

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

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque

def paint(n):
    if n == 1:
        return 0
    else:
        return 1

S = stdin.readline().rstrip()
data = deque([int(x) for x in S])

before = data.popleft()
cnt = 0

while data:
    if data[0] == before:
        cnt += 1
        before = paint(data.popleft())
    else:
        before = data.popleft()

print(cnt)

Submission status: Accepted

Solution code:
yama=input()
kisuu=yama[0::2]      
guusuu=yama[1::2]
iti=kisuu.count("0")
ni=guusuu.count("1")
kari=iti+ni
zentai=len(yama)

if kari*2>zentai:
  kari=zentai-kari
print(kari)

Submission status: Accepted

Solution code:
import sys

def solve(tile):
    count = 0
    prev = ""
    for i in xrange(len(tile)):
       if tile[i] == prev:
           count += 1
           if tile[i] == "0":
               prev = "1"
           else:
               prev = "0"
       else:
           prev = tile[i]

    return count

if __name__ == '__main__':

    tile = sys.stdin.readline().strip()
    ans = solve(tile)
    print ans

Submission status: Accepted

Solution code:

S=input()

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

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

print(min(count1,count2))

Submission status: Accepted

Solution code:
S = str(input())
tmp1 = "01" *100000
tmp2 = "10" *100000
count = 0
if S[0] == "0":
    for i in range(len(S)):
        if tmp1[i] != S[i]:
            count += 1
else:
    for i in range(len(S)):
        if tmp2[i] != S[i]:
            count += 1
print(count)

Submission status: Accepted

Solution code:
S = list(input())

SCheckA = []
SCheckB = []
for i in range(len(S)):
  if i % 2 == 0:
    SCheckA.append("1")
    SCheckB.append("0")
  else:
    SCheckA.append("0")
    SCheckB.append("1")
countA = 0
countB = 0
for j in range(len(S)):
  if SCheckA[j] != S[j]:
    countA += 1
  if SCheckB[j] != S[j]:
    countB += 1
    
if countA >= countB:
  print(countB)
else:
  print(countA)

Submission status: Accepted

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

print(counter)

Submission status: Accepted

Solution code:
List=list(input())
result = []
if List[0] == "0":
    result.append("0")
    for i in range(1,len(List)):
        if(i%2==0):
            result.append("0")
        else:
            result.append("1")
elif List[0] == "1":
    result.append("1")
    for i in range(1,len(List)):
        if(i%2==0):
            result.append("1")
        else:
            result.append("0")
count = 0
for i in range(len(List)):
    if(List[i]!=result[i]):
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
import sys

def main(inp):
    S=next(inp)
    l=len(S)-1
    ns=int(S,2)
    
    wh=1
    bl=0
    for i in range(l-1):
        if(i%2==0): 
            wh = (wh << 1)
            bl = (bl << 1) + 1
        else: 
            wh = (wh << 1) +1
            bl = (bl << 1)
            
    return min(bin(ns^wh).count("1"),bin(ns^bl).count("1"))
    
print(main(sys.stdin))

Submission status: Accepted

Solution code:
s = input()

count_left = 0
count_right = 0
n = len(s)
i = 0
while i < n:
  if n % 2 == 0:
    if i % 2 == 0: #odd
      if s[i] == "0":
        count_left += 1
      if s[n-i-1] == "0":
        count_right += 1
    else: #even
      if s[i] == "1":
        count_left +=1
      if s[n-i-1] == "1":
        count_right += 1
  else:
    if i % 2 == 0: #odd
      if s[i] == "0":
        count_left += 1
      if s[n-i-1] == "1":
        count_right += 1
    else: #even
      if s[i] == "1":
        count_left +=1
      if s[n-i-1] == "0":
        count_right += 1
  i += 1
    
    
print(min(count_left, count_right))

Submission status: Accepted

Solution code:
*S,=map(int,input());f,g=S[::2],S[1::2];u=sum(f)-sum(g);print(min(len(g)+u,len(f)-u))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

S2 = S.copy()

counter = 0
counter2 = 0

switch = True
for i in range(len(S)):
    if switch:
        if S[i] == '1':
            S[i] = '0'
            counter+=1
        
        if S2[i] == '0':
            S2[i] = '1'
            counter2+=1

    else:
        if S[i] == '0':
            S[i] = '1'
            counter+=1
        
        if S2[i] == '1':
            S2[i] = '0'
            counter2+=1

    if switch:
        switch = False
    else:
        switch = True

if counter < counter2:
    print(counter)
else:
    print(counter2)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

S=list(input())[:-1]
c=0
for i in range(len(S)-1):
  if S[i+1]==S[i]:
    S[i+1]= '0' if S[i+1]=='1' else '1'
    c+=1
print(c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
num = str(input())
list = list(num)
list = [int(i) for i in list]

counter = 0
for ii in range(1, len(list)):
    if list[ii - 1] == list[ii]:
        list[ii] = (list[ii] + 1) % 2
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input()

ans1=0
ans2=0
# 01にする
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '1':
            ans1+=1
    else:
        if s[i] == '0':
            ans1+=1
# 10にする
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            ans2+=1
    else:
        if s[i] == '1':
            ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
num = str(input())
list_num = list(num)
list_num = [int(s) for s in list_num]

#print(list_num)

count_0 = 0
count_1 = 0

def _return_next_val(cur_num):
  if cur_num == 0:
    return 1
  else:
    return 0

check_num = 0

## 0101010101....にする場合のカウント
for i in range(len(list_num)):
  if list_num[i] != check_num:
    count_0 += 1
  check_num=_return_next_val(check_num) 

check_num = 1
## 101010101....にする場合のカウント
for i in range(len(list_num)):
  if list_num[i] != check_num:
    count_1 += 1
  check_num=_return_next_val(check_num) 

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

s = ns()
n = len(s)
if n % 2 == 0:
    s0 = "01" * int(n/2)
else:
    s0 = "01" * int(n/2) + "0"

c0 = 0
c1 = 0
for i in range(n):
    if s[i] == s0[i]:
        c0 += 1
    else:
        c1 += 1

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

Submission status: Accepted

Solution code:
a = [int(n) for n in input()]
counter=0
for n in range(1, len(a)):
  if a[n-1]==a[n]:
    if a[n-1]==1:
      a[n]=0
    else:
      a[n]=1
    counter+=1
print(counter)

Submission status: Accepted

Solution code:
S = str(input())
slist = []
for i in range(len(S)):
    slist.append(S[i])
ans = 0

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

Submission status: Accepted

Solution code:
import math                                        

n = list(raw_input())
      
cnt = 0                                            
k = 0                                              
g = 0                                              
for i in n:
    i = int(i)                                     
    if cnt % 2 == 0 and i == 0:                    
        g += 1                                     
    elif cnt % 2 != 0 and i == 0:
        k += 1                                     
    cnt += 1                                       
   
k2 = int(math.floor((len(n)/2.0))-k)               
g2 = int(math.ceil((len(n)/2.0))-g)                

a1 = k2 + g                                        
a2 = k + g2                                        

print min(a1,a2)                                   
#print k,g, int(math.floor((len(n)/2.0))-k), int(math.ceil((len(n)/2.0))-g)

Submission status: Accepted

Solution code:
S = list(str(input()))
pre = -1
now = -1
count = 0

for i in range(1,len(S)):
    pre = int(S[i-1])
    now = int(S[i])
    if pre == now and now == 1:
        S[i] = 0
        count += 1
    elif pre == now and now == 0:
        S[i] = 1
        count += 1
                        

print(count)

Submission status: Accepted

Solution code:
S = input().rstrip()
zero_zero = 0
one_zero = 0
zero_one = 0
one_one = 0
one = 0
zero = 0
for i in range(-(-len(S)//2)):
    tmp = S[i*2:i*2+2]
    if tmp == "00":
        zero_zero += 1
    elif tmp == "01":
        zero_one += 1
    elif tmp == "10":
        one_zero += 1
    elif tmp == "11":
        one_one += 1
    elif tmp == "1":
        one += 1
    else:
        zero += 1
counter = 0
if zero_one > one_zero:
    counter += one_zero*2 + zero_zero + one_one + one
elif zero_one < one_zero:
    counter += zero_one*2 + zero_zero + one_one + zero
else:
    counter += zero_one*2 + zero_zero + one_one
print(counter if len(S) != 1 else 0)

Submission status: Accepted

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

ans0 = ''
ans1 = ''

for i in range(N):
	if i%2 == 0:
		ans0 += '0'
		ans1 += '1'
	else:
		ans0 += '1'
		ans1 += '0'

leven0 = 0
leven1 = 0

for i in range(N):
	if S[i]!=ans0[i]:
		leven0 += 1
	if S[i]!=ans1[i]:
		leven1 += 1


if leven0>leven1:
	print(leven1)
else:
	print(leven0)

Submission status: Accepted

Solution code:
string = input()
list1 = []
for i in string:
  list1.append(int(i))
  
prev = list1[0]
sum = 0
for i, char in enumerate(list1):
  if (i > 0):
    if (char == prev):
      prev = 1 if char == 0 else 0
      sum += 1
    else:
      prev = char
print(sum)

Submission status: Accepted

Solution code:
def main():
    minu = 0
    S = input()
    N = len(S)
    S = int(S, 2)
    f01 = int('01' * (N//2) + '0' * (N%2), 2)
    f10 = int('10' * (N//2) + '1' * (N%2), 2)
    minu = min(str(bin(f01 ^ S)).count('1'), str(bin(f10 ^ S)).count('1'))
    print(minu)


main()

Submission status: Accepted

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

a = input()

L = len(a)

ans1 = 0
ans2 = 0

for i in range(L):
    if i%2 == 0:
        ans1 += 0 ^ int(a[i])
        ans2 += 1 ^ int(a[i])
    else:
        ans1 += 1 ^ int(a[i])
        ans2 += 0 ^ int(a[i])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
x = 0
y = 0

check = "0"
for i in range(len(s)):
  if s[i] != check:
    x += 1
  if check == "0":
    check = "1"
  else:
    check = "0"
check = "1"
for j in range(len(s)):
  if s[j] != check:
    y += 1
  if check == "0":
    check = "1"
  else:
    check = "0"
  
if x<=y:
  ans = x
else:
  ans = y
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

n = len(s)
ans = n

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

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

print(min(ans, num_0, num_1))

Submission status: Accepted

Solution code:
colors = input()
l = len(colors)
count1 = 0
for i in range(l):
	if int(colors[i]) == (i % 2):
		count1 += 1
print(min(count1, l-count1))

Submission status: Accepted

Solution code:
# coding: utf-8

tiles = input()
pattern0 = ''
pattern1 = ''
l = len(tiles)
sum0 = 0
sum1 = 0

for i in range(l):
  if i % 2 == 0:
    pattern0 += '0'
    pattern1 += '1'
  else:
    pattern0 += '1'
    pattern1 += '0'

for i in range(l):
  if tiles[i] != pattern0[i]:
    sum0 += 1
  if tiles[i] != pattern1[i]:
    sum1 += 1

if sum0 < sum1:
  print(sum0)
else:
  print(sum1)