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 = open(0).read().rstrip()

from itertools import cycle

count1 = 0
for c,d in zip(s,cycle('10')):
#     print(c,d)
    if c!= d:
        count1 += 1
        
count2 = 0
for c,d in zip(s,cycle('01')):
#     print(c,d)
    if c!= d:
        count2 += 1

print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)
z = "01" * n
print(
    min(sum(s[i] != z[i] for i in range(n)),
        sum(s[i] != z[i + 1] for i in range(n))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
ans = 0
for i in range(len(s)-1):
    if s[i] == s[i+1] and s[i] == "0":
        ans += 1
        s = s[:i+1] + "1" + s[i+2:]
    elif s[i] == s[i+1] and s[i] == "1":
        ans += 1
        s = s[:i+1] + "0" + s[i+2:]   
print(ans)

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:
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'
            count+=1
        else:
            S[i]='0'
            count+=1
print(count)

Submission status: Accepted

Solution code:
S = input()
White = '10'*(len(S)//2)+'1'*(len(S)%2)
Black = '01'*(len(S)//2)+'0'*(len(S)%2)
WD = len([X for X in map(set,zip(S,White)) if len(X)==2])
BD = len([X for X in map(set,zip(S,Black)) if len(X)==2])
print(min(WD,BD))

Submission status: Accepted

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

Submission status: Accepted

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

a = [i%2 for i in range(len(s))]
b = [(i+1)%2 for i in range(len(s))]

a_sum = sum(abs(x-y) for x, y in zip(s, a))
b_sum = sum(abs(x-y) for x, y in zip(s, b))
print(min(a_sum, b_sum))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

if S[0] == '0':
    A = '01' * len(S)
else:
    A = '10' * len(S)

cnt = 0
for i in range(len(S)):
    if S[i] != A[i]:
        cnt += 1

print(min(cnt, abs(len(S) - cnt)))

Submission status: Accepted

Solution code:
S = input()
counter = 0
for i in range(1, len(S)):
    previous_color = S[i - 1]
    checking_color = S[i]
    if previous_color == checking_color:
        counter += 1
        if previous_color == '0':
            S = S[:i] + '1' + S[i + 1:]
        else:
            S = S[:i] + '0' + S[i + 1:]
print(min(counter, abs(len(S) - counter)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

if S[0] == '0':
    A = '01' * len(S)
else:
    A = '10' * len(S)
    
cnt = 0
for i in range(len(S)):
    if S[i] != A[i]:
        cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
S=np.array(list(input()),dtype=np.int8)
L=len(S)
A=np.arange(L)&1
B=1-A
x1=(A!=S).sum()
x2=(B!=S).sum()
print(min(x1,x2))

Submission status: Accepted

Solution code:
S=input()
d0=0
d1=0
for i in range(len(S)):
    d0+=int(S[i])!=i%2
    d1+=int(S[i])!=(i+1)%2
print(min(d0,d1))

Submission status: Accepted

Solution code:
s=list(input())
s=[int(s[i]) for i in range(len(s))]
tile=s[0]
cnt=0
for i in range(1,len(s)):
    if s[i]==tile:
        cnt+=1
    if tile==1:
        tile=0
    else:
        tile=1
print(cnt)

Submission status: Accepted

Solution code:
S = list(input())

odd0, odd1 = 0, 0
even0, even1 = 0, 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s == "0":
            even0 += 1
        else:
            even1 += 1
    else:
        if s == "0":
            odd0 += 1
        else:
            odd1 += 1
print(min(even0+odd1, even1+odd0))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
s1=["0"for i in range(n)]
s2=["1"for i in range(n)]
for i in range(0,n,2):
    s1[i]="1"
    s2[i]="0"
tmp1=0
tmp2=0
for i in range(n):
    if s[i]!=s1[i]:
        tmp1+=1
    if s[i]!=s2[i]:
        tmp2+=1
print(min(tmp1,tmp2))

Submission status: Accepted

Solution code:
s = list(input())
len_s = len(s)
half_len_s = len_s // 2 + 1
str_01 = "01" * half_len_s
str_10 = "10" * half_len_s
list_01 = list(str_01[:len_s])
list_10 = list(str_10[:len_s])
count1 = 0
count2 = 0
for v1, v2 in zip(s, list_01):
    if v1 == v2:
        count1 += 1
for v1, v2 in zip(s, list_10):
    if v1 == v2:
        count2 += 1
print(min(count1, count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        S = S[:i] + str(1 - int(S[i])) + S[i+1:]
        ans += 1
print(ans)

Submission status: Accepted

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

X=0

Z=0
for s in S:
    if s!=Z:
        X+=1
    Z^=1
    
Y=0

Z=1
for s in S:
    if s!=Z:
        Y+=1
    Z^=1

print(min(X,Y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
p=[]
q=[]
cnt_p=0
cnt_q=0

if n%2!=0:
  m=(n-1)//2
  p.extend(['0','1']*m)
  p.append('0')
  q.extend(['1','0']*m)
  q.append('1')
else:
  m=n//2
  p.extend(['0','1']*m)
  q.extend(['1','0']*m)
for i in range(n):
  if s[i]==p[i]:
    cnt_p+=1
  else:
    cnt_q+=1
print(min(cnt_p,cnt_q))

Submission status: Accepted

Solution code:
s=input()
S=[s[i] for i in range(len(s))]
A=['0','1']
B=[A[i%2] for i in range(len(S))]
count=0
for i in range(len(S)):
  if S[i]!=B[i]:
    count=count+1
print(min(count,len(S)-count))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

s = [int(ch) for ch in input()]

ans = [0]*2

for t in range(2):
    tmp = s[:]
    if t == 0:
        for i in range(len(s)-1):
            if i == 0 and tmp[i] == tmp[i+1]:
                tmp[i+1] ^= 1
                ans[t] += 1
            elif i == 0 and tmp[i] != tmp[i+1]:
                pass
            elif tmp[i] == tmp[i+1]:
                tmp[i+1] ^= 1
                ans[t] += 1
    if t == 1:
        for i in range(len(s)-1):
            if i == 0 and tmp[i] == tmp[i+1]:
                tmp[i] ^= 1
                ans[t] += 1
            elif i == 0 and tmp[i] != tmp[i+1]:
                tmp[i] ^= 1
                tmp[i+1] ^= 1
                ans[t] += 2
            elif tmp[i] == tmp[i+1]:
                tmp[i+1] ^= 1
                ans[t] += 1

print(min(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

s = [int(ch) for ch in input()]

ans = [0]*2

for t in range(2):
    tmp = s[:]
    if t == 0:
        for i in range(len(s)-1):
            if i == 0 and tmp[i] == tmp[i+1]:
                tmp[i+1] ^= 1
                ans[t] += 1
            elif i == 0 and tmp[i] != tmp[i+1]:
                pass
            elif tmp[i] == tmp[i+1]:
                tmp[i+1] ^= 1
                ans[t] += 1
    if t == 1:
        for i in range(len(s)-1):
            if i == 0 and tmp[i] == tmp[i+1]:
                tmp[i] ^= 1
                ans[t] += 1
            elif i == 0 and tmp[i] != tmp[i+1]:
                tmp[i] ^= 1
                tmp[i+1] ^= 1
                ans[t] += 2
            elif tmp[i] == tmp[i+1]:
                tmp[i+1] ^= 1
                ans[t] += 1
s
print(min(ans))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
dp = [[0] * 2 for _ in range(n)]
s = int(S[0])
dp[0][s] = 0
dp[0][1-s] = 1
for i, s in enumerate(S[1:], 1):
    s = int(s)
    dp[i][s] = dp[i-1][1-s]
    dp[i][1-s] = dp[i-1][s] + 1
print(min(dp[n-1]))

Submission status: Accepted

Solution code:
S=[0 if c =='0' else 1 for c in input()]
a = S[0::2]
b = S[1::2]
x = a.count(1)
y = b.count(1)
if x > y:
    ans = (len(a)-x) + (y)
else:
    ans = (len(b)-y) + (x)
print(ans)

Submission status: Accepted

Solution code:
n = input()
a,b = "",""
for i in range(len(n)//2):
    a += "01"
    b += "10"
if len(n) != len(a):
    a += "0"
    b += "1"

acount,bcount = 0,0
for i in range(len(n)):
    if n[i] != a[i]:
        acount += 1
    if n[i] != b[i]:
        bcount += 1
print(min(acount,bcount))

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

origin = list(map(int, input().rstrip('\n')))
# print(origin)

t1 = []
t2 = []
for i in range(len(origin)):
    if i % 2 == 0:
        t1.append(0)
        t2.append(1)
    else:
        t1.append(1)
        t2.append(0)

n1 = 0
n2 = 0
for i in range(len(origin)):
    if t1[i] != origin[i]:
        n1 += 1
    if t2[i] != origin[i]:
        n2 += 1

print(min(n1, n2))

Submission status: Accepted

Solution code:
s = input()
b = 0
w = 0
for i in range(len(s)):
  if s[i] == '0':
    if i % 2 == 0:
      # 偶数番目が0
      w += 1
    else:
      # 奇数番目が0
      b += 1
  else:
    if i % 2 == 0:
      # 偶数番目が1
      b += 1
    else:
      # 奇数番目が1
      w += 1
print(min(b, w))

Submission status: Accepted

Solution code:
import numpy as np

S = np.array(list(input()))
S = S.astype('int32')
length = len(S)

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

check_array1 = np.zeros(length, int)
for i in range(1, length, 2):
    check_array1[i] = 1

check_array2 = np.append(check_array1[1:], check_array1[-2])


checked1_S = S + check_array1
checked2_S = S + check_array2

checked1_total = (checked1_S == 1).sum()
checked2_total = (checked2_S == 1).sum()

answer = min(checked1_total, checked2_total)

print(answer)

Submission status: Accepted

Solution code:
S = list(input())
ans1 = 0
ans2 = 0

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

Submission status: Accepted

Solution code:
s = input()

ans = 100100100100

for i in range(2):
    cnt = 0
    t = str(i)
    for i in s:
        if t != i:
            cnt += 1
            
        t = 1 - int(t)    
        t = str(t)
    
    ans = min(ans,cnt)
    
print(ans)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()

cnt0 = 0
cnt1 = 0
for i in range(len(s)):
	if i%2 == 0 :
		if s[i] == "0":
			cnt1 += 1
		else:
			cnt0 += 1
	else:
		if s[i] == "1":
			cnt1 += 1
		else:
			cnt0 += 1
print( min(cnt0, cnt1) )

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = s()

memo = s[0]
cnt = 0
#print(0,"番目の:",memo)
for i in range(1,len(s)):
	if s[i] == memo:
		cnt += 1
		#print("×")
		if memo == "0":
			memo = "1"
		else:
			memo = "0"
	else:
		memo = s[i]
	#print(i,"番目の:",memo)
print(cnt)

Submission status: Accepted

Solution code:
s = input()
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = input()

first_0 = 0
first_1 = 0

for i, s in enumerate(S):
    if i % 2 == 0:
        if s == "0":
            first_1 += 1
        else:
            first_0 += 1
    else:
        if s == "0":
            first_0 += 1
        else:
            first_1 += 1

print(min(first_0, first_1))

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    zero = 0
    one = 0
    for i in range(len(S)):
        if i%2 == 0 and S[i] != "0" or i%2 == 1 and S[i] != "1":
            zero += 1
        elif i%2 == 0 and S[i] != "1" or i%2 == 1 and S[i] != "0":
            one += 1
    print(min(one, zero))
resolve()

Submission status: Accepted

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

cnt1, cnt2 = 0, 0
for i in range(len(s)):
    if s[i] == i % 2:
        cnt1 += 1
    else:
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
s = input()
LEN = len(s)
if LEN == 1:
    print(0)
    exit()
    
even = s[::2]
odd = s[1::2]

ew = even.count('1')
eb = (LEN+1)//2 - ew
ow = odd.count('1')
ob = (LEN)//2 - ow

print(min(eb + ow, ew + ob))

Submission status: Accepted

Solution code:
s = input()
phase = 'Odd'
ptn10 = 0
ptn01 = 0
for i in s:
  if phase == 'Odd':
    if i == '1':
      ptn01 += 1
    else:
      ptn10 += 1
    phase = 'Even'
  else:
    if i == '0':
      ptn01 += 1
    else:
      ptn10 += 1
    phase = 'Odd'
print(min(ptn10, ptn01))

Submission status: Accepted

Solution code:
import numpy as np
S=list(input())
S=[True if i=="0" else False for i in S]
stripeA=[True]*len(S)
stripeB=[True]*len(S)
for i in range(len(S)):
    if i%2==0:
        stripeA[i]=False
    else:
        stripeB[i]=False
stripeA=list(np.logical_xor(S,stripeA))
stripeB=list(np.logical_xor(S,stripeB))
stripeA=stripeA.count(True)
stripeB=stripeB.count(True)
if stripeA>stripeB:
    print(stripeB)
else:
    print(stripeA)

Submission status: Accepted

Solution code:
S = input()
n = len(S)
counter2n0=0
counter2n1=0
counter1n0=0
counter1n1=0
for i in range(n):
    if i%2 ==0:
        if S[i] == '0':
            counter2n0 +=1
        else:
            counter2n1 +=1
    if i%2 == 1:
        if S[i] == '0':
            counter1n0 +=1
        else:
            counter1n1 +=1
print(min(counter2n0+counter1n1,counter2n1+counter1n0))

Submission status: Accepted

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


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    ans = [0, 0]  # 偶数番目、奇数眼目の1の個数
    for i in range(N):
        if S[i] == "1":
            ans[i % 2] += 1
    return min(ans[0]+N//2-ans[1], N//2+N%2-ans[0]+ans[1])


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
a = 0
b = 0
apple = ("10" * n)[:n]
orange = ("01" * n)[:n]
for i in range(n):
    if apple[i] != s[i]:
        a += 1
    if orange[i] != s[i]:
        b += 1
print(min(a, b))

Submission status: Accepted

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

Submission status: Accepted

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

tile1=('10'*N)[:N]
tile0=('01'*N)[:N]

ans1=0
ans0=0
for i in range(N):
    ans1+=S[i]!=tile1[i]
    ans0+=S[i]!=tile0[i]

print(min(ans1,ans0))

Submission status: Accepted

Solution code:
def mi(): return map(int,input().split())
def lmi(): return list(map(int,input().split()))
def ii(): return int(input())
def isp(): return input().split()
 
s=input()
n=len(s)
s10=[]
for i in range(n):
  if i%2==0:
    s10.append(1)
    
  else:
    s10.append(0)
    
s01=[]
for i in range(n):
  if i%2==0:
    s01.append(0)
    
  else:
    s01.append(1)
cnt10=0
cnt01=0
for i in range(n):
  if int(s[i])!=s10[i]:
    cnt10+=1
    
  if int(s[i])!=s01[i]:
    cnt01+=1
   
    
print(min(cnt10,cnt01))

Submission status: Accepted

Solution code:
S = list(map(int,list(input())))
N = len(S)

sirokuro =[i%2 for i in range(0,N,1)]
kurosiro =[(i+1)%2 for i in range(0,N,1)]

loss1 = 0
for i in range(0,N,1):
    if S[i]!=sirokuro[i]:
        loss1 +=1

loss2 = 0
for i in range(0,N,1):
    if S[i]!=kurosiro[i]:
        loss2+=1

print(min(loss1,loss2))

Submission status: Accepted

Solution code:
s = input()
ev = "10"*(10**5)
od = "01"*(10**5)
evcnt = 0
odcnt = 0
for cnt, i in enumerate(s):
	if i == ev[cnt]:
		evcnt += 1
	if i == od[cnt]:
		odcnt += 1
print(len(s)-max(evcnt, odcnt))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from copy import deepcopy
s=list(map(int,input()))
t=deepcopy(s)
if t[0]==1:
    t[0]=0
else:
    t[0]=1

cnt=0
rev_cnt=1

for i in range(1,len(s)):
    if s[i-1]==s[i]:
        if s[i]==0:
            s[i]=1
        else:
            s[i]=0
        cnt+=1

for i in range(1,len(t)):
    if t[i-1]==t[i]:
        if t[i]==0:
            t[i]=1
        else:
            t[i]=0
        rev_cnt+=1

print(min(cnt, rev_cnt))

Submission status: Accepted

Solution code:
s=[]
S=input()
for i in S:
    s+=[int(i)]
#print(s)
ans=0
if s[0]==0:
    for i in s[0::2]:
        if i!=0:
            ans+=1
            #print(0,i,ans)
    for i in s[1::2]:
        if i!=1:
            ans+=1
            #print(1,i,ans)
#print(s[0::2],s[1::2])
if s[0]==1:
    for i in s[0::2]:
        if i!=1:
            ans+=1
    for i in s[1::2]:
        if i!=0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

s = input()

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

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
for j in range(n):
  s[j] = int(s[j])
a = 0
b = 0

for i in range(n):
  if i%2 == 0 and s[i] == 0:
    a += 1
  elif i%2 == 0 and s[i] == 1:
    b += 1
  elif i%2 == 1 and s[i] == 0:
    b += 1
  else:
    a += 1
print(min(a,b))

Submission status: Accepted

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

if N%2==0:
  S1="10"*(N//2)
  count=0
  for i in range(N):
    if S[i]==S1[i]:
      count+=1
  if count >= N//2:
    print(N-count)
  else:
    print(count)
else:
  S2="10"*((N-1)//2)+"1"
  count=0
  for i in range(N):
    if S[i]==S2[i]:
      count+=1
  if count >= (N+1)//2:
    print(N-count)
  else:
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s1 = s[0::2]
s2 = s[1::2]

t1 = s1.count('1') + s2.count('0')
t2 = s1.count('0') + s2.count('1')
print(min(t1, t2))

Submission status: Accepted

Solution code:
import copy
def change(k):
  if k==0:
    return int(1)
  else:
    return int(0)
t=0
m=0
S=list(map(int,list(input())))
M=copy.copy(S)
T=copy.copy(S)
N=len(S)
for i in range(N):
  if i==0:
    if T[i]==0:
      t+=1
      T[0]=1
    else:
      m+=1
      M[0]=0
  else:
    if T[i]==T[i-1]:
      T[i]=change(T[i])
      t+=1
    if M[i]==M[i-1]:
      M[i]=change(M[i])
      m+=1
print(min(t,m))

Submission status: Accepted

Solution code:
S = input()

ans = 0

def f(i):
  ans = 0
  for c in S:
    if int(c)==i: ans += 1
    i = (i+1)%2
  return ans

ans = min(f(0),f(1))

print(ans)

Submission status: Accepted

Solution code:
S = list(input())

import numpy as np

S = np.array(S)

zeroichi = ["0","1"]*(len(S)//2)+["0"]*(len(S)%2)
ichizero = ["1","0"]*(len(S)//2)+["1"]*(len(S)%2)

zeroichi = np.array(zeroichi)
ichizero = np.array(ichizero)

print(min(list(S == ichizero).count(False),list(S == zeroichi).count(False)))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
A = list(S)
a = 0
b = 0
for i in range(N):
  if i%2 == 0:
    #010101
    if S[i] != "0":
      a += 1
    #101010
    else:
      b += 1
  #mod2 = 1
  else:
    #010101
    if S[i] != "1":
      a += 1
    #101010
    else:
      b += 1
print(min(a,b))

Submission status: Accepted

Solution code:
s = input()

c01 = 0
c02 = 0

#01パターン
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "1":
            c01 += 1
    else:
        if s[i] == "0":
            c01 += 1

#10パターン
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "0":
            c02 += 1
    else:
        if s[i] == "1":
            c02 += 1

if all(x == 0 for x in [c01, c02]):
    print(0)
else:
    print(min(c01,c02))

Submission status: Accepted

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

B = ['0' for i in range(N)]
W = ['1' for i in range(N)]
for i in range(0,N,2):
    B[i] = '1'
    W[i] = '0'

X = 0
Y = 0
for i in range(N):
    if S[i] != B[i]:
        X += 1
    if S[i] != W[i]:
        Y += 1

print(min(X,Y))

Submission status: Accepted

Solution code:
S = input()
s = []
for _ in S:
  s.append(int(_))
s1 = [1]
s2 = [0]
for i in range(1,len(s)):
  if s1[i-1] == 0:
    s1.append(1)
  else:
    s1.append(0)
  if s2[i-1] == 0:
    s2.append(1)
  else:
    s2.append(0)
    
a = 0
b = 0
for j in range(len(s)):
  if s[j] != s1[j]:
    a += 1
  if s[j] != s2[j]:
    b += 1
print(min(a,b))

Submission status: Accepted

Solution code:
s = list(input())

length = len(s)
count = 0

for i in range(length-1):
    if i == length:
        break
    if s[i] == s[i+1]:
        if s[i] == '0':
            s[i+1] = '1'
            count += 1
        else:
            s[i+1] = '0'
            count += 1


print(count)

Submission status: Accepted

Solution code:
import collections

s = map(int,list(raw_input()))

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

Submission status: Accepted

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

if n%2==0:
    odd=even=n//2
else:
    even=n//2
    odd=even+1
    
odd_black=0
even_black=0

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

odd_white=odd-odd_black
even_white=even-even_black

if odd_black<=even_black:
    count=odd_black+even_white
else:
    count=odd_white+even_black

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
S = input()

min1 = 0 # 01010101
min2 = 0 # 10101010


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

print(min(min1,min2))

Submission status: Accepted

Solution code:
s=input()
i=0
c=0
for m in s:
  if i % 2 ==0:
    if int(m) ==1:
      c+=1
  else:
    if int(m)==0:
      c+=1
  i+=1
print(min(c,len(s)-c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

a = ['1', '0']*10**5
b = ['0', '1']*10**5

A = a[:len(s)]
B = b[:len(s)]
cnt = 0
ans = 0
for i in range(len(s)):
    if s[i] != A[i]:
        cnt += 1
    if s[i] != B[i]:
        ans += 1
print(min(cnt, ans))

Submission status: Accepted

Solution code:
S = input()
S_odd = S[1::2]
S_even = S[0::2]

oddlist = []
evenlist = []

for i in range(len(S_odd)):
    oddlist.append(int(S_odd[i]))
for i in range(len(S_even)):
    evenlist.append(int(S_even[i]))

EvenSum = sum(evenlist)
OddSum = sum(oddlist)


if EvenSum <= OddSum:
    ans = len(oddlist) - OddSum
    ans += EvenSum
else:
    ans = len(evenlist) - EvenSum
    ans += OddSum

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
a=[]
for i in range(0,len(s)//2*2,2):
  a.append(s[i:i+2])
a10=a.count('10')
a01=a.count('01')

if len(s)%2:
  s1=int(s[-1])
else:s1=-1

if a10>a01:
  if s1==0:
    cnt=len(a)-a10+a01+1
  else:
    cnt=len(a)-a10+a01
elif a01>a10:
  if s1==1:
    cnt=len(a)-a01+a10+1
  else:
    cnt=len(a)-a01+a10
else:
  cnt=len(a)
print(cnt)

Submission status: Accepted

Solution code:
s = input()
a = ''
b = ''
for i in range(len(s)):
  if i % 2 == 0:
    a += '0'
    b += '1'
  else:
    a += '1'
    b += '0'
c = 0
for x, y in zip(s, a):
  if x != y:
    c += 1
d = 0
for x, y in zip(s, b):
  if x != y:
    d += 1
print(min(c, d))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)-1
a = [1]+[0]*n
b = [0]+[1]*n
difA = 0
difB = 0

for i in range(1,n+1):
    a[i] = 0 if a[i-1] == 1 else 1
    b[i] = 0 if b[i-1] == 1 else 1

for j in range(n+1):
    if a[j] != int(s[j]):
        difA += 1
    if b[j] != int(s[j]):
        difB += 1

ans = min(difA,difB)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
S=list(input())
Acnt=0
Bcnt=0
AList=[]
BList=[]
for i in range(len(S)):
    if i%2==0:
        AList.append(0)
    else:
        AList.append(1)

for j in range(len(S)):
    if j%2==0:
        BList.append(1)
    else:
        BList.append(0)
    
#print(AList)
#print(BList)
    
for k in range(len(S)):
    if int(S[k])!=AList[k]:
        Acnt+=1
    if int(S[k])!=BList[k]:
        Bcnt+=1
        
print(min(Acnt,Bcnt))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
a = ['1']+['0']*(n-1)
b = ['0']+['1']*(n-1)

for i in range(1,n):
    if a[i-1] == '1':
        a[i] = '0'
    elif a[i-1] == '0':
        a[i] = '1'

    if b[i-1] == '1':
        b[i] = '0'
    elif b[i-1] == '0':
        b[i] = '1'

difA = 0
difB = 0

for j in range(n):
    if a[j] != s[j]:
        difA += 1

    if b[j] != s[j]:
        difB += 1

ans = min(difA,difB)

print(ans)

Submission status: Accepted

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

def sim(temp):
    ret = 0
    for i in range(length):
        if S[i] != str(temp):
            ret += 1
        if temp == 0:
            temp = 1
        else:
            temp = 0 
    return ret
    
res1 = sim(0)
res2 = sim(1)
ans = min(res1, res2)
print(ans)

Submission status: Accepted

Solution code:
#

# import sys
# input=sys.stdin.readline

def main():
    S=input()
    Z1=["1" if i%2==0 else "0" for i in range(len(S))]
    c1=0
    c2=0
    for i in range(len(S)):
        if S[i]!=Z1[i]:
            c1+=1
        else:
            c2+=1
    print(min(c1,c2))
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s)
    l = r = -1
    ans = 0
    for i in range(1, n):
        if s[i] == s[i - 1]:
            if l == -1:
                l = i
            else:
                r = i
        if r != -1:
            ans += r - l
            r = l = -1
    if l != -1:
        ans += n - l
    print(min(ans, n - ans))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = list(input())
a1 = 0
a2 = 0
for i in range(len(s)):
    a1 += int(s[i]) == i % 2
    a2 += int(s[i]) != i % 2
print(min(a1, a2))

Submission status: Accepted

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

ans_1=0
ans_2=0
for i in range(1,len(S)+1):
    if i%2!=0:
        if S[i-1]!=0:
            ans_1+=1
    else:
        if S[i-1]==0:
            ans_1+=1
        

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

print(min(ans_1,ans_2))