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:
#C
S = list(map(int, list(input())))
S0 = [i%2 for i in range(len(S))]
S1 = [(i+1)%2 for i in range(len(S))]

countS0 = 0
for i, j in enumerate(S):
    if j != S0[i]:
        countS0 += 1
        
countS1= 0
for i, j in enumerate(S):
    if j != S1[i]:
        countS1 += 1
        
print(min(countS0, countS1))

Submission status: Accepted

Solution code:
n = input()
length = len(n)
li = ["0","1"]
first=length
second=length
for i in range(length):
  j = i%2
  if n[i]==li[j]:
    first-=1
  else:
    second-=1
print(min(first,second))

Submission status: Accepted

Solution code:
tile_color = str(input())

odd_count = 0
for i in range(len(tile_color)):
  if int(tile_color[i]) % 2 == i % 2 :
    odd_count += 1

if len(tile_color)/2 < odd_count:
  print(len(tile_color)-odd_count)
else:
  print(odd_count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = list(input())
black = 0
white = 0

# 先頭を黒(0)として色をぬるケース
for i, n in enumerate(S):
    if i % 2 == 0:
        if n == '1':
            black += 1
    else:
        if n == '0':
            black += 1

# 先頭を城(1)として色をぬるケース
for i, n in enumerate(S):
    if i % 2 == 0:
        if n == '0':
            white += 1
    else:
        if n == '1':
            white += 1

print(min(black, white))

Submission status: Accepted

Solution code:
s=input()
l=len(s)
a=[]
b=[]
i=0
for _ in range(l//2):
  a.append(s[i])
  b.append(s[i+1])
  i+=2
if l%2==1:
  a.append(s[l-1])
a0=a.count('0')
a1=a.count('1')
b0=b.count('0')
b1=b.count('1')
x=max(a0+b1,a1+b0)
print(l-x)

Submission status: Accepted

Solution code:
s = input()
s = str(s)
s1 = ""
s2 = ""
for i in range(1,len(s)+1):
	if(i%2==0):
		s1=s1+"1"
	else:
		s1=s1+"0"
for i in range(1,len(s)+1):
	if(i%2==0):
		s2=s2+"0"
	else:
		s2=s2+"1"

c1=0
c2=0
for i in range(0,len(s)):
	if(s1[i:i+1]!=s[i:i+1]):
		c1=c1+1
	if(s2[i:i+1]!=s[i:i+1]):
		c2=c2+1
print(min(c1,c2))

Submission status: Accepted

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

def check(start,s_list):
    cnt = 0
    for s in s_list:
        if start != s:
            cnt += 1
        if start == 0:
            start = 1
        else:
            start = 0
    return cnt

print(min(check(0,s_list),check(1,s_list)))

Submission status: Accepted

Solution code:
S=input()
def s(a):return sum([(i^a^int(S[i]))&1 for i in range(len(S))])
print(min(s(0),s(1)))

Submission status: Accepted

Solution code:
S = input()
l = len(S)
# print(S, l)

ans = 0

def solve(S, b):
    ans = 0
    for s in S:
        ans += int(s) ^ b
        b ^= 1
    return ans

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

Submission status: Accepted

Solution code:
s = input()
res_s0 = 0
res_s1 = 0

#print("s0")
for i in range(len(s)):
    #print(i, end="")
    if i % 2 == 0:
        if s[i] != "0":
            res_s0 += 1
            #rint("!")
    else:
        if s[i] != "1":
            res_s0 += 1
            #print("!")

#print()
#print("s1")

for i in range(len(s)):
    #print(i, end="")
    if i % 2 == 0:
        if s[i] != "1":
            res_s1 += 1
            #print("!")
    else:
        if s[i] != "0":
            res_s1 += 1
            #print("!")

#print("---")
#print(res_s0)
#print(res_s1)
print(min(res_s0, res_s1))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
t0, t1 = 0, 1
a = 0
b = 0
for s in S:
	if s == "1":
		a += t0
	else:
		a += t1
	t0, t1 = t1, t0
print(min(a,N-a))

Submission status: Accepted

Solution code:
s = input()
cnt, cnt_ = 0, 0
a = "10" * (len(s)//2+1)
for i in range(len(s)):
    if s[i] != a[i]:
        cnt += 1
    if s[i] != a[i + 1]:
        cnt_ += 1
print(min(cnt, cnt_))

Submission status: Accepted

Solution code:
s = input()
a = ""
cnt, cnt_ = 0, 0
while len(a) <= len(s):
    a += "10"

for i in range(len(s)):
    if s[i] != a[i]:
        cnt += 1
    if s[i] != a[i + 1]:
        cnt_ += 1
print(min(cnt, cnt_))

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()

white_odd = 0
white_even = 0
N = len(S)

i = 0
while i < N:
    if S[i] == '1':
        white_odd += 1
    if not i+1 < N:
      break
    if S[i+1] == '0':
        white_odd += 1
    i += 2
white_even = N - white_odd


if white_odd < white_even:
    print(white_odd)
else:
    print(white_even)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
ans = 0
# 101010...に合わせる前提
for i in range(0, len(s), 2):
    if s[i] == '0':
        ans += 1
for j in range(1, len(s), 2):
    if s[j] == '1':
        ans += 1
# 101010...または010101...の最小値を取る
print(min(ans, len(s) - ans))

Submission status: Accepted

Solution code:
S = input()

t1 = t2 = 0
for i in range(len(S)):
    if S[i] != str(i%2): t1 += 1
    if S[i] != str((i+1)%2): t2 += 1

print(min(t1,t2))

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    S = input()
    N = len(S)
    count = 0
    count_ = 0
    for i in range(N):
        if i % 2 == 0:
            if S[i] == '0':
                count += 1
            else:
                count_ += 1
        else:
            if S[i] == '1':
                count += 1
            else:
                count_ += 1
    if count < count_:
        print(N - count_)
    else:
        print(N - count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

s0 = input()
s1 = s0
cnt0 = cnt1 = 0

for i in range(len(s0)):
    if (i%2 == 0) & (s0[i] == '1'):
        cnt0+=1
    elif (i%2 == 1) & (s1[i] == '0'):
        cnt0+=1

for i in range(len(s1)):
    if (i%2 == 0) & (s1[i] == '0'):
        cnt1+=1
    elif (i%2 == 1) & (s1[i] == '1'):
        cnt1+=1

print(np.minimum(cnt0,cnt1))

Submission status: Accepted

Solution code:
S = input()
l=0
m=0
hoge=0
ho=1

for i in S:
        hoge = (hoge+1)%2
        ho = (ho+1)%2
        if i=="1":
                l+=hoge
                m+=ho
        if i=="0":
                l+=ho
                m+=hoge

print(min(l,m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a, b = 0, 0

for i in range(0,len(S),2):
  if S[i] == "0":
    a += 1
  else:
    b += 1
for i in range(1,len(S),2):
  if S[i] == "1":
    a += 1
  else:
    b += 1
print(min(a, b))

Submission status: Accepted

Solution code:
s=input()
bin_num = int(s,2)
mask = 0
s_len = len(s)
for i in range(s_len):
    mask = (mask<<1) + (i%2)
mask_inv = (2**s_len-1)-mask
mask = bin_num ^ mask
mask_inv = bin_num ^ mask_inv
print(min(bin(mask).count("1"), bin(mask_inv).count("1")))

Submission status: Accepted

Solution code:
bool_zeroone = True
count = 0
sl = list(input())
for c in sl:
    if bool_zeroone and c == '0':
        count += 1
    elif not bool_zeroone and c == '1':
        count += 1
    bool_zeroone = not bool_zeroone

answer = min(count, len(sl) - count)
print(answer)

Submission status: Accepted

Solution code:
import numpy as np
# 完成状態は010101 or 101010

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()
answer = min(x1,x2)
print(answer)

Submission status: Accepted

Solution code:
s = list(map(int,list(str(input()))))
if len(s)==1:
    print(0)
    exit()
sum_odd = sum(s[0::2])
sum_even = sum(s[1::2])
if_odd = len(s[0::2])-sum_odd +sum_even
if_even = len(s[1::2])-sum_even +sum_odd
print(min([if_odd,if_even]))

Submission status: Accepted

Solution code:
# N, K = map(int, input().split())
# line = list(map(int, input().split()))
line = input()
ans = 0
isChange = False

for i in range(len(line)-1):
    if line[i] == line[i+1] and isChange == False:
        isChange = True
    elif line[i] == line[i+1] and isChange == True:
        isChange = False
    if isChange:
        ans += 1

if ans < len(line) - ans:
    print(ans)
else:
    print(len(line) - ans)

Submission status: Accepted

Solution code:
S = input()
N = int('10' + S, 2)

def make_alternate_binary(S):
    a = 0
    b = 0
    a += 1 << S + 1
    b += 1 << S + 1
    
    for i in range(S):
        a += (i % 2) << i
        b += ((i + 1) % 2) << i
    return a, b

co1, co2 = make_alternate_binary(len(S))
print(min(bin(N ^ co1).count('1'), bin(N ^ co2).count('1')))

Submission status: Accepted

Solution code:
S = input()
N = int('10' + S, 2)

def make_alternate_binary(S):
    a = 0
    b = 0
    a += 1 << S + 1
    b += 1 << S + 1
    
    for i in range(S):
        a += (i % 2) << i
        b += ((i + 1) % 2) << i
    return a, b

co1, co2 = make_alternate_binary(len(S))
print(min(bin(N ^ co1).count('1'), bin(N ^ co2).count('1')))

Submission status: Accepted

Solution code:
S = input()

count = 0

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

Submission status: Accepted

Solution code:
S = list(map(int, input()))
score = 0
length = len(S)

for i in range(length):
	goal = lambda x : 0 if x % 2 == 0 else 1
	score += abs(S[i] - goal(i))
	
if score < length / 2:
	print(score)
else:
	print(length - score)

Submission status: Accepted

Solution code:
S=input()

ans=[]
for i in range(2):
    cnt=0
    for j in range(len(S)):
        if int(S[j])%2!=(i+j)%2:
            cnt+=1
    ans.append(cnt)
print(min(ans))

Submission status: Accepted

Solution code:
S=[int(i) for i in input()]
print(min(S[0::2].count(0)+S[1::2].count(1),S[0::2].count(1)+S[1::2].count(0)))

Submission status: Accepted

Solution code:
S = list(input())
count_g = [0,0]
count_k = [0,0]
for index, x in enumerate(S):
    if index % 2 == 0:
        if x == '0':
            count_g[0] += 1
        else:
            count_g[1] += 1
        
    else:
        if x == '0':
            count_k[0] += 1
        else:
            count_k[1] += 1
a = [count_k[0]+count_g[1], count_k[1]+count_g[0]]
print(min(a))

Submission status: Accepted

Solution code:
s = input()

s1=""
s2=""

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

ans1=0
ans2=0

for i in range(len(s)):
    if(s[i:i+1]!=s1[i:i+1]): ans1+=1
    if(s[i:i+1]!=s2[i:i+1]): ans2+=1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()
count1 = 0
count2 = 0

for i in range(len(s)):
    if i%2 ==0 and s[i]=='0':
        count1 = count1 +1
    if i%2 ==1 and s[i]=='1':
        count1 = count1+1
    if i%2 ==1 and s[i]=='0':
        count2 = count2 +1
    if i%2 ==0 and s[i]=='1':
        count2 = count2+1

print(min(count1,count2))

Submission status: Accepted

Solution code:
s = input()

s01 = ''
s10 = ''
for i in range(len(s)):
    if i % 2 == 0:
        s01 += '0'
        s10 += '1'
    else:
        s01 += '1'
        s10 += '0'

cnt01 = 0
cnt10 = 0
for i in range(len(s)):
    if s[i] != s01[i]:
        cnt01 += 1
    if s[i] != s10[i]:
        cnt10 += 1

if cnt01 > cnt10:
    print(cnt10)
else:
    print(cnt01)

Submission status: Accepted

Solution code:
import numpy as np

S = np.array([int(i) for i in list(input())])
N = len(S)

def zebra(A):
    for i in range(N-1):
        if A[-1] == 0:
            A.append(1)
        elif A[-1] == 1:
            A.append(0)
    return A

A0 = np.array(zebra([0]))
A1 = np.array(zebra([1]))

dis0 = np.count_nonzero(S - A0)
dis1 = np.count_nonzero(S - A1)

print(min(dis0, dis1))

Submission status: Accepted

Solution code:
S = input()

count_0 = 0
count_1 = 0

for i,s in enumerate(S):
    if s == "0" and i%2==0:
        count_1 += 1
        continue
    elif s=="1" and i%2==0:
        count_0 += 1
        continue
    if s == "1" and i%2==1:
        count_1 += 1
    elif s=="0" and i%2==1:
        count_0 += 1

print(min(count_0,count_1))

Submission status: Accepted

Solution code:
S = input()

count_0 = 0
count_1 = 0

for i,s in enumerate(S):
    if s == "0" and i%2==0:
        count_1 += 1
    elif s=="1" and i%2==0:
        count_0 += 1

    if s == "1" and i%2==1:
        count_1 += 1
    elif s=="0" and i%2==1:
        count_0 += 1

print(min(count_0,count_1))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s = int(s,2)

if n % 2 == 0:
    a = int("10"*(int(n/2)),2)
    b = int("01"*(int(n/2)),2)
else:
    a = int("10"*(int((n-1)/2)) + "1", 2)
    b = int("01"*(int((n-1)/2)) + "0", 2)

ansa = bin(s^a).count("1")
ansb = bin(s^b).count("1")
print(min(ansa,ansb))

Submission status: Accepted

Solution code:
# 01010101か10101010かなのでどっちもやってみて比較
w, b = 0, 0
s = input()
for i, sv in enumerate(s):
    if i % 2 == 0:
        if sv == "0":
            b += 1
        else:
            w += 1
    else:
        if sv == "0":
            w += 1
        else:
            b += 1

print(min(w, b))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s = int(s,2)

if n%2 == 0:
  a = int("10"*(int(n/2)),2)
  b = int("01"*(int(n/2)),2)
else:
  a = int("10"*(int((n-1)/2)) + "1",2)
  b = int("01"*(int((n-1)/2)) + "0",2)

ansa = bin(s^a).count("1")
ansb = bin(s^b).count("1")
print(min(ansa,ansb))

Submission status: Accepted

Solution code:
S = input()
a = S[0]

if len(set(S))==1:
	print(len(S)//2)
	exit()

cnt=0
for i in range(len(S)):
	if i % 2 ==0:
		if S[i]!=a:
			cnt +=1
	if i % 2 ==1:
		if S[i]==a:
			cnt +=1
tmp=0
for i in range(len(S)):
	if i % 2 ==1:
		if S[i]!=a:
			tmp +=1
	if i % 2 ==0:
		if S[i]==a:
			tmp +=1
print(min(tmp,cnt))

Submission status: Accepted

Solution code:
s = input()
s1 = s[::2]
s2 = s[1::2]
count1 = 0
count2 = 0
count3 = 0
count4 = 0

for i in s1:
    if i == "1":
        count1 += 1
    else:
        count2 += 1
for j in s2:
    if j == "1":
        count3 += 1
    else:
        count4 += 1

answer1 = count2 + count3
answer2 = count1 + count4

if answer1 >= answer2:
    print(answer2)
else:
    print(answer1)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(s)):
  s[i]=int(s[i])
  if i%2 == 0:
    a.append(1)
    b.append(0)
  else:
    a.append(0)
    b.append(1)
    
ansa=0
ansb=0

for i in range(len(s)):
  if a[i]!=s[i]:
    ansa=ansa+1
  if b[i]!=s[i]:
    ansb=ansb+1
    
print(min(ansa,ansb))

Submission status: Accepted

Solution code:
S = input()

cost1 = S[::2].count("1") + S[1::2].count("0")
cost2 = S[::2].count("0") + S[1::2].count("1")

print(min(cost1, cost2))

Submission status: Accepted

Solution code:
S=input()
n=len(S)
A=('01'*n)[:n]
B=('10'*n)[:n]
a=0
b=0
for i in range(n):
    if S[i]!=A[i]:
        a+=1
    else:
        b+=1
print(min(a,b))

Submission status: Accepted

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

expected = []

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

union = []

for i in range(len(s)):
    union.append((s[i] + expected[i]) % 2)

cnt_0 = union.count(0)
cnt_1 = union.count(1)

print(min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
import numpy as np

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

expected = []

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

expected = np.array(expected)

union = s + expected
union = union % 2
union = union.tolist()

cnt_0 = union.count(0)
cnt_1 = union.count(1)

print(min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
S = input()
count1 = 0
count2 = 0

check = 0
for char in S:
    if int(char) != check:
        count1 += 1
    check = (check+1)%2
check = 1
for char in S:
    if int(char) != check:
        count2 += 1
    check = (check+1)%2

print(min([count1,count2]))

Submission status: Accepted

Solution code:
s=input()

ans=0
for i, x in enumerate(s):
  if i%2==0:
    if x!=s[0]:
      ans+=1
  else:
    if x==s[0]:
      ans+=1
print(ans)

Submission status: Accepted

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

a = 0
b = 0
for i in range(len(s)):
    if s[i] != comp[i]:
        a += 1
    else:
        b += 1

print(min(a, b))

Submission status: Accepted

Solution code:
s = input()

ans1 = 0
ans2 = 0

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

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
from collections import Counter
n=input()
a=n[::2]
b=n[1::2]
aa=Counter(a)
bb=Counter(b)
a0=aa["0"]
a1=aa["1"]
b0=bb["0"]
b1=bb["1"]
print(min(a0+b1,a1+b0))

Submission status: Accepted

Solution code:
S = input()
S1 = S[::2]
S2 = S[1::2]
if len(S1) == len(S2):
    if S1.count('0') >= S2.count('0'):
        ans = S1.count('1') + S2.count('0')
    else:
        ans = S1.count('0') + S2.count('1')
else:
    if S1.count('0') < S1.count('1'):
        ans = S1.count('0') + S2.count('1')
    else:
        ans = S1.count('1') + S2.count('0')
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
s = np.array([int(i) for i in input()])
a = np.array([i%2 for i in range(len(s))])
b = np.array([1]+[i%2 for i in range(len(s)-1)])

print(min(np.sum(np.abs(s-a)),np.sum(np.abs(s-b))))

Submission status: Accepted

Solution code:
s = input()


#0101...の順にした場合に必要な操作数
a = s[0::2].count("1") + s[1::2].count("0")
#1010...の順にした場合に必要な操作数
b = s[0::2].count("0") + s[1::2].count("1")

print(min(a,b))

Submission status: Accepted

Solution code:
S = input()

count = 0
black = 0 
white = 0
for i in list(S):
  if count % 2 == 0:
    black += 1 if i != '0' else 0
    white += 1 if i != '1' else 0
  else: 
    black += 1 if i != '1' else 0
    white += 1 if i != '0' else 0
  count += 1

print(min(black, white))

Submission status: Accepted

Solution code:
s = input()
ans1 = 0
ans2 = 0
ideal1 = []
ideal2 = []
for x in range(len(s)):
    if x % 2 == 0:
        ideal1.append('1')
        ideal2.append('0')
    else:
        ideal1.append('0')
        ideal2.append('1')
for inp,i1,i2 in zip(s,ideal1,ideal2):
    if inp == i1:
        pass
    else :
        ans1 += 1
    if inp == i2:
        pass
    else:
        ans2 += 1

print(min(ans1,ans2))

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()

can1 = 0
can2 = 0

for i in range(len(S)):
    if abs(int(S[i])-i%2) == 1:
        can1 += 1
    elif abs(int(S[i])-(i+1)%2) == 1:
        can2 += 1

if can1 > can2:
    print(can2)
else:
    print(can1)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n%2 == 0:
    s1 = '10'*(n//2)
else:
    s1 = '10'*(n//2) +'1'

s1cnt = 0

for i in range(n):
        if s1[i] == s[i]:
            s1cnt +=1
s2cnt = n - s1cnt
print(min(s1cnt,s2cnt))

Submission status: Accepted

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

for i in range(n):
	if i % 2 == int(s[i]):
		# # print(s[i])
		# if s[i] == '0':
		ans += 1
			# print('a')
	# else:
	# 	if s[i] == '1':
	# 		ans += 1
# print(ans)

print(min(ans,n-ans))

Submission status: Accepted

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

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

print(min(ans,n-ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_h = s[0]

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

ans = 0
for i in range(len(s)):
    if s[i] != s_h[i]:
        ans += 1
    else:
        continue

print(ans)

Submission status: Accepted

Solution code:
s = list(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
    
    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:
if __name__ == "__main__":
    tile = input()
    
    a = tile[0::2].count("1") + tile[1::2].count("0")
    b = tile[0::2].count("0") + tile[1::2].count("1")

    print(min(a, b))

Submission status: Accepted

Solution code:
*a,=input()
c=0
for i in range(len(a)-1):
    if a[i]=="0" and a[i+1]=="0":
        a[i+1]="1"
        c+=1
    elif a[i]=="1" and a[i+1]=="1":
        a[i+1]="0"
        c+=1
print(c)

Submission status: Accepted

Solution code:
s = list(input())
count = 0
n = len(s)
if n % 2 == 0:
    for i in range(0,int(n/2)):
        if s[(2*i)+1] == "0":
            count = count + 1
    for j in range(0,int(n/2)):
        if s[2*j] == "1":
            count = count + 1
else:
    for i in range(0,int((n-1)/2)+1):
        if s[2*i] == "0":
            count = count + 1
    for j in range(0,int(((n-1)/2))):
        if s[2*j + 1] == "1":
            count = count + 1
count2 = n - count
print(min(count,count2))

Submission status: Accepted

Solution code:
S = list(input())
R1 = [(1 + (-1)**i)/2 for i in range(len(S))]
R2 = [(1 + (-1)**(i+1))/2 for i in range(len(S))]
count1 = 0
count2 = 0
for i in range(len(S)):
    if int(S[i]) != R1[i]:
        count1 += 1
for i in range(len(S)):
    if int(S[i]) != R2[i]:
        count2 += 1
print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

cnd0 = 0
cnd1 = 0

target = '01' * (len(S) // 2)
if len(S) % 2 == 1:
    target = target + '0'
for idx, ch in enumerate(S):
    if ch != target[idx]:
        cnd0 += 1

target = '10' * (len(S) // 2)
if len(S) % 2 == 1:
    target = target + '1'
for idx, ch in enumerate(S):
    if ch != target[idx]:
        cnd1 += 1

print(min(cnd0, cnd1))

Submission status: Accepted

Solution code:
S = list(input())

S0 = []
S1 = []

for i in range(len(S)):
    S0.append(str(i%2))
    S1.append(str(int(not i%2)))

#  print(S)
#  print(S0)
#  print(S1)

S0_count = 0
S1_count = 0


for i in range(len(S)):
    if S[i] != S0[i]:
        S0_count += 1
    if S[i] != S1[i]:
        S1_count += 1

print(min(S0_count, S1_count))

Submission status: Accepted

Solution code:
s1 = input()

n1 = list(s1)
c1 = 0
c2 = 0
for i1 in range(len(n1)):
    if i1 % 2 == 0:
        if n1[i1] == "1":
            c1 += 1
    else:
        if n1[i1] == "0":
            c1 += 1

for i2 in range(len(n1)):
    if i2 % 2 == 0:
        if n1[i2] == "0":
            c2 += 1
    else:
        if n1[i2] == "1":
            c2 += 1
print(min(c1, c2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
def reverse(str):
  if str == '0':
    str = '1'
  else:
    str = '0'
  return str


S = raw_input()
S = list(S)
N = len(S)
ans = 0

for i in xrange(N-1):
  if S[i] == S[i+1]:
    S[i+1] = reverse(S[i+1])
    ans += 1

print ans

Submission status: Accepted

Solution code:
S = input()
n = len(S)
SS = list(map(int, S))
A1 = [x&1 for x in range(n)]
A2 = [x&1 for x in range(1, n+1)]

cnt = [0, 0]
for i in range(n):
    cnt[0] += abs(SS[i] - A1[i])
    cnt[1] += abs(SS[i] - A2[i])

print(min(cnt))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
for i in range(n):
    if i%2 == 0:
        count += int(s[i])
    else:
        count += 1-int(s[i])
if count <= n//2:
    print(count)
else:
    print(n - count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
b = []

for i in range(len(s)):
    if s[i] == '0':
        b.append(False)
    else:
        b.append(True)

switch = False
c1 = 0
for i in range(len(b)):
    if b[i] != switch:
        c1 += 1
    switch = not switch

switch = True
c2 = 0
for i in range(len(b)):
    if b[i] != switch:
        c2 += 1
    switch = not switch

print(min(c1, c2))

Submission status: Accepted

Solution code:
def resolve():
    S = input()
    comp = "".join([ str(i % 2) for i in range(len(S))])
    cnt = 0
    for i in range(len(S)):
        if S[i] == comp[i]:
            cnt = cnt + 1
    return min(cnt, len(S)-cnt)

if '__main__' == __name__:
    print(resolve())

Submission status: Accepted

Solution code:
s=input()
a=sum(s[i]!="0" for i in range(0,len(s),2))
b=sum(s[i]!="1" for i in range(1,len(s),2))
c=sum(s[i]!="1" for i in range(0,len(s),2))
d=sum(s[i]!="0" for i in range(1,len(s),2))
print(min(a+b,c+d))

Submission status: Accepted

Solution code:
S=input()

Length=len(S)
Counta=0
Countb=0

if Length%2==0:
    Sa="01"*(Length//2)
    Sb="10"*(Length//2)
else:
    Sa="01"*(Length//2)+"0"
    Sb="10"*(Length//2)+"1"
    
for i in range(Length):
    if S[i]!=Sa[i]:
        Counta+=1
    if S[i]!=Sb[i]:
        Countb+=1
        
print(min(Counta,Countb))

Submission status: Accepted

Solution code:
s = input()
tile_01 = ['0' if i % 2 == 0 else '1' for i in range(len(s))]
tile_10 = ['1' if i % 2 == 0 else '0' for i in range(len(s))]
tile_01 = ''.join(tile_01)
tile_10 = ''.join(tile_10)

s_01 = bin(int('0b' + s, 2) ^ int('0b' + tile_01, 2)).split('b')[1].zfill(len(s))
s_10 = bin(int('0b' + s, 2) ^ int('0b' + tile_10, 2)).split('b')[1].zfill(len(s))
short_01 = 0
short_10 = 0
for i in range(len(s_01)):
    if s_01[i] == '1':
        short_01 += 1
    elif s_10[i] == '1':
        short_10 += 1

print(min(short_01, short_10))

Submission status: Accepted

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

w=[i%2 for i in range(len(n))]
b=[(i+1)%2 for i in range(len(n))]
x,y=0,0
for i in range(len(n)):
  if n[i]!=w[i]:
    x+=1
  if n[i]!=b[i]:
    y+=1
if x<y:
  print(x)
else:
  print(y)

Submission status: Accepted

Solution code:
S = input()

def cd(S, R):
    return sum([1 for s, r in zip(S, R) if s != r])
print(min(cd(S, '01' * (len(S)+1//2)), cd(S, '10' * (len(S)+1//2))))

Submission status: Accepted

Solution code:
import sys

def main():
    sinputl = sys.stdin.readline

    input = sinputl().strip()
    length = len(input)
    string1 = "10" * (length // 2) + "1" * (length % 2)
    string2 = "01" * (length // 2) + "0" * (length % 2)
    count1 = 0
    count2 = 0

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

    for i in range(length):
        if input[i] != string2[i]:
            count2 += 1

    print(min(count1, count2))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

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

  c1=c2=0
  f=True
  for x in s:
    if f:
      if x=='0':
        c1+=1
      f=False
    else:
      if x=='1':
        c1+=1
      f=True

  f=False
  for x in s:
    if f:
      if x=='0':
        c2+=1
      f=False
    else:
      if x=='1':
        c2+=1
      f=True

  # print(c1,c2)
  return min(c1,c2)

print(main())

Submission status: Accepted

Solution code:
n=list(input())
S=0
for i,l in zip(range(len(n)),n):
  if i%2==0 and int(l)==0:
    S=S
  elif i%2==0 and int(l)==1:
    S=S+1
  elif i%2==1 and int(l)==0:
    S=S+1
  else:
    S=S
M=0
for i,l in zip(range(len(n)),n):
  if i%2==0 and int(l)==0:
    M=M+1
  elif i%2==0 and int(l)==1:
    M=M
  elif i%2==1 and int(l)==0:
    M=M
  else:
    M=M+1
print(min(M,S))

Submission status: Accepted

Solution code:
def resolve():
	S=input()
	Slist=[int(i) for i in list(S)]
	N=len(S)
	
	if N%2==0:
		s1='10'*(N//2)
		s2='01'*(N//2)
	else:
		s1='10'*(N//2)+'1'
		s2='01'*(N//2)+'0'
	s1List=[int(i) for i in list(s1)]
	s2List=[int(i) for i in list(s2)]
	
	print(min(sum([1 for i in range(N) if Slist[i]!=s1List[i]]),sum([1 for i in range(N) if Slist[i]!=s2List[i]])))
resolve()

Submission status: Accepted

Solution code:
def resolve():
	S=input()
	Slist=[int(i) for i in list(S)]
	N=len(S)
	
	if N%2==0:
		s1='10'*(N//2)
		s2='01'*(N//2)
	else:
		s1='10'*(N//2)+'1'
		s2='01'*(N//2)+'0'
	s1List=[int(i) for i in list(s1)]
	s2List=[int(i) for i in list(s2)]
	
	print(min(sum([1 for i in range(N) if Slist[i]!=s1List[i]]),sum([1 for i in range(N) if Slist[i]!=s2List[i]])))

resolve()

Submission status: Accepted

Solution code:
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

c = input()
color_list = list(map(int, list(c)))

N= len(color_list)

f0_num = 0
filter_0 = [i % 2 for i in range(N)]
f1_num = 0
filter_1 = [i % 2 for i in range(1, N + 1)]

for c, f0, f1 in zip(color_list, filter_0, filter_1):
    if c != f0:
        f0_num += 1
    if c != f1:
        f1_num += 1

print(min(f0_num, f1_num))

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()
T1 = [k % 2 for k in range(len(S))]
T2 = [1 - k % 2 for k in range(len(S))]
c1 = 0
c2 = 0
for l in range(len(S)):
    if int(S[l]) == T1[l]:
        c1 += 1
    else:
        c2 += 1

print(min(c1, c2))