Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

000

Sample Output 1

1

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

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

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

s = [int(s) for s in list(input()) if s != '\n']

odd = sum(s[::2])
even = sum(s[1::2])
if even >= odd:
    ans = len(s)//2-even+odd
elif len(s) % 2 == 1:
    ans = len(s)//2-odd+even+1
else:
    ans = len(s)//2-odd+even
print(ans)

Submission status: Accepted

Solution code:
S1_str = str(input())
S1 = list(S1_str)
S2 = list(S1_str)

num1 = 0

for i in range(len(S1) - 1):
    if S1[i] == S1[i + 1]:
        S1[i + 1] = str((int(S1[i]) + 1) % 2)
        num1 += 1

num2 = 1
S2[0] = str((int(S2[0]) + 1) % 2)
for i in range(len(S2) - 1):
    if S2[i] == S2[i + 1]:
        S2[i + 1] = str((int(S2[i]) + 1) % 2)
        num2 += 1

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

Submission status: Accepted

Solution code:
s = input()
print(s[0::2].count(str(1-int(s[0]))) + s[1::2].count(s[0]))

Submission status: Accepted

Solution code:
S=list(input())
print(len(S)-max(S[1::2].count('0')+S[0::2].count('1'),S[1::2].count('1')+S[0::2].count('0')))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()


def get_change_nums(start,s):
    count = 0
    for p in enumerate(s):
        i,x = p
        if int(x) != (i + start) % 2:
            count += 1
    return count
    
s0 = get_change_nums(0,s)
s1 = get_change_nums(1,s)

print(min(s0,s1))

Submission status: Accepted

Solution code:
import numpy as np
S = input()

s_list = [int(s) for s in S]

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

s_list_array = np.array(s_list)
case_1_array = np.array(case_1)
case_2_array = np.array(case_2)
result_1_list = (s_list_array + case_1_array).tolist()
result_2_list = (s_list_array + case_2_array).tolist()
result_1 = result_1_list.count(1)
result_2 = result_2_list.count(1)

print(min(result_1, result_2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = n
for j in range(2):
    cnt = 0
    for i in range(n):
        if((i%2==j and s[i]=="0") or (i%2!=j and s[i]=="1")):
            cnt += 1
    ans = min(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
s = input()

si = []
so = []
for i in range(len(s)):
  si.append(int(s[i]))
  so.append(int(s[i]))

so[0] = (so[0] + 1) % 2

cnti = 0
cnto = 1
for i in range(1, len(s)):
  if si[i] == si[i-1]:
    si[i] = (si[i] + 1) % 2
    cnti += 1
  if so[i] == so[i-1]:
    so[i] = (so[i] + 1) % 2
    cnto += 1

print(min(cnti, cnto))

Submission status: Accepted

Solution code:
s = input()
set = [0, 1]
diff = 0

for i in range(len(s)):
    set.reverse()
    if set[1] == int(s[i]):
        diff += 1

print(min([diff, len(s)-diff]))

Submission status: Accepted

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

s1=s[0]
count_1=0
#1枚目をそのまま使う
for i in range(1,n):
    if i%2==0:
        if s[i]!=s1:
            count_1+=1
    else:
        if s[i]==s1:
            count_1+=1

count_2=1
for i in range(1,n):
    if i%2==0:
        if s[i]==s1:
            count_2+=1
    else:
        if s[i]!=s1:
            count_2+=1

if count_1>count_2:
    print(count_2)
else:
    print(count_1)

Submission status: Accepted

Solution code:
sl = list(input())

ans1 = 0
ans2 = 0
for idx, i in enumerate(sl):
    if idx % 2 == int(i):
        ans2 += 1
    else:
        ans1 += 1
        
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
x=0
y=0
for i in range(0,len(s)):
  if i%2==0:
    if s[i]=="0":
      x+=1
  else:
    if s[i]=="1":
      x+=1
      
for j in range(0,len(s)):
  if j%2==0:
    if s[j]=="1":
      y+=1
  else:
    if s[j]=="0":
      y+=1
      
print(min(x,y))

Submission status: Accepted

Solution code:
s = list(str(input()))
w_1 = 0  # 1
b_1 = 0  # 0と違う個数

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "0":
            w_1 += 1
        else:
            b_1 += 1
    else:
        if s[i] == "1":
            w_1 += 1
        else:
            b_1 += 1


print(min(b_1, w_1))

Submission status: Accepted

Solution code:
s = input()
cnt = 0
for i in range(1,len(s)):
    if s[i-1] == s[i]:
        new = (int(s[i])+1)%2
        """
        s_li = list(s)
        s_li[i] = str(new)
        s = ''.join(s_li)
        """
        s = s[:i] + str(new) + s[i+1:]
        cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:

s = input()

a="0"
b="1"
count=0
for i in range(len(s)):
  if i%2==0:
    count+= int(s[i]==a)
  else:
    count+= int(s[i]==b)
tmp1=count

a="1"
b="0"
count=0
for i in range(len(s)):
  if i%2==0:
    count+= int(s[i]==a)
  else:
    count+= int(s[i]==b)
tmp2=count

print(min(tmp1,tmp2))

Submission status: Accepted

Solution code:
s=input()
s_1="1"
s_0="0"
count_1=0
count_0=0

if len(s)%2:
  s_0+="10"*(len(s)//2)
  s_1+="01"*(len(s)//2)
else:
  s_0+="10"*(int(len(s)/2+1))
  s_1+="01"*(int(len(s)/2+1))

for i in range(len(s)):
  if s[i]==s_1[i]:
    count_1+=1
  if s[i]==s_0[i]:
    count_0+=1
print(min(len(s)-count_1,len(s)-count_0))

Submission status: Accepted

Solution code:
def main():
    S = list(map(int,input()))
    length = len(S)

    if length%2 == 0:
        array1 = [0,1]*int(length/2)
        array2 = [1,0]*int(length/2)
    else:
        array1 = [0,1]*int((length-1)/2)+[0]
        array2 = [1,0]*int((length-1)/2)+[1]

    count1 = 0
    count2 = 0
    for i in range(length):
        if S[i] != array1[i]:
            count1 += 1
        if S[i] != array2[i]:
            count2 += 1
    print(min(count1,count2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
a = "".join(str(i % 2) for i in range(len(s)))
b = "".join(str(i % 2) for i in range(1, len(s) + 1))
da = bin(int(a, 2) ^ int(s, 2)).count("1")
db = bin(int(b, 2) ^ int(s, 2)).count("1")
print(min(da, db))

Submission status: Accepted

Solution code:
from collections import Counter
S = list(input())
len_s = len(S)
a = Counter(S[::2])["1"] + Counter(S[1::2])["0"]
b = Counter(S[1::2])["1"] + Counter(S[::2])["0"]

print(a if a < b else b)

Submission status: Accepted

Solution code:
S=input()
ez=0
oz=0
eo=0
oo=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=="0":
      ez+=1
    else:
      eo+=1
  else:
    if S[i]=="0":
      oz+=1
    else:
      oo+=1
print(min(eo+oz,ez+oo))

Submission status: Accepted

Solution code:
s = list(input())
s_len = len(s)
ans_0 = 0
ans_1 = 0
for i in range(s_len):
  if i % 2 == 0 and s[i] == "0":
    ans_0+= 1
  elif i % 2 == 0 and s[i] == "1":
    ans_1+= 1
  elif i % 2 != 0 and s[i] == "0":
    ans_1+= 1
  else:
    ans_0 += 1
print(min(ans_0,ans_1))

Submission status: Accepted

Solution code:
s = input()

# 0 スタートの文字列に変換
ans1 = s[::2].count('1') + s[1::2].count('0')
# 1 スタートの文字列に変換
ans2 = s[::2].count('0') + s[1::2].count('1')
ans = min(ans1, ans2)

print(ans)

Submission status: Accepted

Solution code:
import math
S = input()

def convert(arr):
    H = []
    for value in arr:
        H.append(int(value))
    return H

def fix0(arr):
    count = 0
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            arr[i] = math.fabs(arr[i-1] - 1)
            count = count + 1
    return count

def fix1(arr):
    count = 0
    if arr[0] == arr[1]:
        count = count + 1

    if len(arr) > 2:
        for i in range(2,len(arr)):
            if arr[i] == arr[i-1]:
                arr[i] = math.fabs(arr[i-1] - 1)
                count = count + 1
    return count

def compare(x,y):
    if x < y:
        return x
    else:
        return y

def main(arr):
    if len(arr) > 1:
        # 0 fixed
        # 1 fixed
        count1 = fix0(arr.copy())
        count2 = fix1(arr.copy())
        return compare(count1,count2)
    else:
        return 0


print(main(convert(S)))

Submission status: Accepted

Solution code:
S = input()
bit = 0
c = ["0","1"]
count = 0
for s in S:
    if s == c[bit]:
        count += 1
    bit ^= 1
print(min(count,len(S)-count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

S = input()
S_list = []
N = len(S)
for i in range(N):
    S_list.append(S[i])

even_0 = S_list[1::2].count('0')
odd_0 = S_list[::2].count('0')
print(max(min(even_0+math.ceil(N/2)-odd_0, odd_0+math.trunc(N/2)-even_0), 0))

Submission status: Accepted

Solution code:
S = input()

count = sum(int(s) != i%2 for i, s in enumerate(S))
print(min(count, len(S) - count))

Submission status: Accepted

Solution code:
hamming_distance = lambda S1,S2:sum(s1 != s2 for s1,s2 in zip(S1,S2))

S = input()
end_s_1 = ''.join([str(i%2) for i in range(len(S))])
end_s_2 = ''.join([str((i+1)%2) for i in range(len(S))])

# print(end_s_1, hamming_distance(S, end_s_1))
# print(end_s_2, hamming_distance(S, end_s_2))
ret = min(hamming_distance(S, end_s_1), hamming_distance(S, end_s_2))
print(ret)

Submission status: Accepted

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

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != '0':
            count1 += 1
        else:
            count2 += 1
    else:
        if S[i] != '1':
            count1 += 1
        else:
            count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
colormap = input('')
colormaplist = [int(i) for i in colormap]
changecounter = 0
for i in range(len(colormaplist)-1):
    if colormaplist[i+1] == colormaplist[i]:
        colormaplist[i+1] = 1-colormaplist[i+1]
        changecounter+=1
print(changecounter)

Submission status: Accepted

Solution code:
s = input()
option_1 = ['1' if i % 2 == 0 else '0' for i in range(len(s))]
option_2 = ['0' if i % 2 == 0 else '1' for i in range(len(s))]
ans_1 = 0
ans_2 = 0
for i, c in enumerate(s):
  if option_1[i] != c:
    ans_1 += 1
  if option_2[i] != c:
    ans_2 += 1
print(min(ans_1, ans_2))

Submission status: Accepted

Solution code:
s = list(input())

idx_even = [s[x] for x in range(0, len(s), 2)]
idx_odd = [s[x] for x in range(1, len(s), 2)]

# print(s, idx_even, idx_odd)

ans = min(
    idx_even.count("0") + idx_odd.count("1"), idx_even.count("1") + idx_odd.count("0")
)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
S=list(s)
for i in range(len(S)):
    S[i]=int(S[i])
ans=0
count=0
count1=0
N=list(s)
if len(S)==1:
    ans=0
else:
    for j in range(1,len(N)-1):
        if N[j-1]==N[j]==N[j+1]:
            if N[j]!=0:
                N[j]=0
            else:
                N[j]=1
            count+=1
        elif N[j-1]==N[j] and N[j+1]!=N[j]:
            N[j-1]=N[j+1]
            count+=1
        elif N[j-1]!=N[j] and N[j+1]==N[j]:
            N[j+1]=N[j-1]
            count+=1
    for k in range(len(S)-2,0,-1):
        if S[k-1]==S[k]==S[k+1]:
            if S[k]!=0:
                S[k]=0
            else:
                S[k]=1
            count1+=1
        elif S[k-1]==S[k] and S[k+1]!=S[k]:
            S[k-1]=S[k+1]
            count1+=1
        elif S[k-1]!=S[k] and S[k+1]==S[k]:
            S[k-1]=S[k+1]
            count1+=1
    if count>count1:
        ans=count1
    else:
        ans=count
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

s = stdin.readline().rstrip()
point = 0

li = ["0","1"]

start = li.pop(li.index(s[0]))
last = li[-1]

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

print(point)

Submission status: Accepted

Solution code:
s = input()
# ls = [i for i in s]
ls = list(s)
# ils = [map(int, ls)] ・・・✖
ils = list(map(int, ls))
# print(ils)
# print(len(s))
n = len(s)
cnt = 0
for i in range(1, n):
    if ils[i] == ils[i-1] and ils[i] == 0:
        cnt += 1
        ils[i] = 1
    elif ils[i] == ils[i-1] and ils[i] == 1:
        cnt += 1
        ils[i] = 0
print(cnt)

Submission status: Accepted

Solution code:
list1 = list(input())
count = 0
#貪欲
for i in range(1,len(list1)):
	if list1[i] == list1[i-1]:
		if list1[i] == "1":
			list1[i] = "0"
		else:
			list1[i] = "1"
		count += 1
print(count)

Submission status: Accepted

Solution code:
S=input()
if len(S)==1:
    print(0)
else:
    l=0
    r=0
    T=S[::-1]
    for i in range(1,len(S)):
        if S[i]==S[i-1]:
            if S[i]=='1':
                S=S[:i]+'0'+S[i+1:]
            else:
                S=S[:i]+'1'+S[i+1:]
            l+=1
    #print(l)
    #print(T)
    for i in range(1,len(T)):
        if T[i]==T[i-1]:
            if T[i]=='1':
                T=T[:i]+'0'+T[i+1:]
            else:
                T=T[:i]+'1'+T[i+1:]
            r+=1
    #print(r)
    print(min(l,r))

Submission status: Accepted

Solution code:
#2019/10/24
# S = list(map(int, list(open(0).read())))
S = list(map(int, input()))
# print(S)
print(S[::2].count(0) + S[1::2].count(1) if S[0]==1 else S[::2].count(1) + S[1::2].count(0))

Submission status: Accepted

Solution code:
# ABC120 C - Coloring Colorfully
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

S = si()

ans_1 = 0
ans_2 = 0

cnt_1 = 0
cnt_2 = 0

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

for i,s in enumerate(S):
    if i%2 == 0:
        # 0101
        if s == '1':
            cnt_1 += 1
        # 1010
        if s == '0':
            cnt_2 += 1
    elif i%2 == 1:
        # 0101
        if s == '0':
            cnt_1 += 1
        # 1010
        if s == '1':
            cnt_2 += 1

print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
slis=list(map(int,input()))
e_slis=[]
o_slis=[]
for i in range(len(slis)):
	if i%2==0:
		o_slis.append(slis[i])
	else:
		e_slis.append(slis[i])
print(min(o_slis.count(0)+e_slis.count(1),o_slis.count(1)+e_slis.count(0)))

Submission status: Accepted

Solution code:
S = input()
p1 = ["1" if i%2==0 else "0" for i in range(len(S))]
p2 = ["0" if i%2==0 else "1" for i in range(len(S))]
print(min(bin((int(S,2)^int("".join(p1),2))).count("1"),bin((int(S,2)^int("".join(p2),2))).count("1")))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

import math

even_s=[]
odd_s=[]

for i in range(len(S)):
        if i%2 == 0:
                even_s.append(int(S[i]))
        else:
                odd_s.append(int(S[i]))

e_1num = even_s.count(1)
e_0num = even_s.count(0)

o_1num = odd_s.count(1)
o_0num = odd_s.count(0)

res = min(e_1num+o_0num, e_0num+o_1num)

print(res)

Submission status: Accepted

Solution code:
S = str(input())
X=[]
ans = 0

for s in S:
    X.append(int(s))

for n in range(1,len(X)):
    if X[n-1] == X[n]:
        ans += 1
        if X[n] == 1:
            X[n] = 0
        else:
            X[n] = 1

print(ans)

Submission status: Accepted

Solution code:
s=input()
a=0

for i in range(len(s)):
    #print(i%2,s[i])
    if i % 2 != int(s[i]):
        a += 1

if len(s)-a < a:
    print(len(s)-a)
else:
    print(a)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a0="01"*(n//2) + "0"*(n%2)
a1="10"*(n//2) + "1"*(n%2)
ans0=sum(s[i]!=a0[i] for i in range(n))
ans1=sum(s[i]!=a1[i] for i in range(n))
print(min(ans0,ans1))

Submission status: Accepted

Solution code:
S = input()
cnt = 0
for i, s in enumerate(S):
    cnt += (int(s)==(i%2))
print(min(cnt, len(S)-cnt))

Submission status: Accepted

Solution code:
s = input()

cntoz = 0
cntzo = 0
for i in range(len(s)):
	if (i%2) == 0:
		if s[i] == '0':
			cntoz += 1
		else:
			cntzo += 1
	else:
		if s[i] == '0':
			cntzo += 1
		else:
			cntoz += 1
		
print(min(cntoz, cntzo))

Submission status: Accepted

Solution code:
s=input()
o1=s[::2].count('1')
o0=len(s[::2])-o1
e1=s[1::2].count('1')
e0=len(s[1::2])-e1
print(min(o1+e0,o0+e1))

Submission status: Accepted

Solution code:
s = input()
tmp = ""
count = 0
for i in range(len(s)):
    if i % 2 == 0:
        tmp += "0"
    elif i % 2 == 1:
        tmp += "1"
    if s[i] != tmp[i]:
        count += 1
print(count if count*2 <= len(s) else len(s)-count)

Submission status: Accepted

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

for i in range(len(s)):
    if i % 2 == 0:
        a.append(s[i])
    else:
        b.append(s[i])
        
for i in range(len(a)):
    if a[i] == "0":
        n += 1
        
for i in range(len(b)):
    if b[i] == "1":
        n += 1
        
m = len(s) - n

if n > m:
    print(m)
else:
    print(n)

Submission status: Accepted

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

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

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S = input()

multi = len(S) // 2

if len(S) % 2 == 0:
	S1 = "10" * multi
	S2 = "01" * multi
	
else:
	S1 = "10" * multi + "1"
	S2 = "01" * multi + "0"
	
con1 = 0
con2 = 0	 
	
for i in range(0,len(S)):
	if S[i] != S1[i]:
		con1 += 1
	if S[i] != S2[i]:
		con2 += 1
		
print(min(con1,con2))

Submission status: Accepted

Solution code:
s_L = [str(val) for val in input()]
n = len(s_L)

p_1,p_2 = [],[]
for val in range(n):
    if val%2 ==0:
        p_1.append("0")
        p_2.append("1")
    else:
        p_1.append("1")
        p_2.append("0")
counter1,counter2 = 0,0

for val in range(n):
    if p_1[val] == s_L[val]:
        counter1 +=1
    else:
        counter2 +=1
print(min(counter1,counter2))

Submission status: Accepted

Solution code:
s = list(input())
sk = s[0::2]
sg = s[1::2]
print(min(len(s)-sk.count("0")-sg.count("1"),len(s)-sk.count("1")-sg.count("0")) )

Submission status: Accepted

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

n = len(s)
 
ans_l = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    ans_l += 1
    if s[i] == 0:
      s[i+1] = 1
    else:
      s[i+1] = 0
print(ans_l)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t1 = 0
    t2 = 0
    b = True
    for i in range(len(s)):
        if bool(int(s[i])) != b:
            t1 += 1
        if bool(int(s[i])) == b:
            t2 += 1
        b = not b
    print(min(t1, t2))


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

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

print(min(ans))

Submission status: Accepted

Solution code:
def main():
    S = input()
    cnt = S[::2].count("0") + S[1::2].count("1")
    print(min(cnt, len(S) - cnt))
    return


main()

Submission status: Accepted

Solution code:
def repaint(S):
    return S[::2].count("0") + S[1::2].count("1")


def main():
    S = input()
    print(min(repaint(S), len(S) - repaint(S)))

    return


main()

Submission status: Accepted

Solution code:
def main():
    S = [int(i) for i in input()]
    x = - (-len(S) // 2) - sum(S[::2]) + sum(S[1::2])
    print(min(x, len(S) - x))

    return


main()

Submission status: Accepted

Solution code:
def main():
    S = [int(i) for i in input()]
    print(min(sum(S[::2]) + len(S) + (-len(S) // 2) - sum(S[1::2]),
              - (-len(S) // 2) - sum(S[::2]) + sum(S[1::2])))

    return


main()

Submission status: Accepted

Solution code:
s=list(input())
o0=o1=e0=e1=0
for i in range(len(s)//2):
    if s[i*2]=="0":
        o0+=1
    elif s[i*2]=="1":
        o1+=1
    if s[i*2+1]=="0":
        e0+=1
    elif s[i*2+1]=="1":
        e1+=1
if len(s)%2==1:
    if s[len(s)-1]=="0":
        o0+=1
    else:
        o1+=1
print(min( o1+e0,e1+o0 ))

Submission status: Accepted

Solution code:
S = input()

list = list(S)
#print(list)

ref = []
ref.append(list[0])
count = 0
for i in range(len(list)-1):
    if int(ref[i]) == int(list[i+1]):#つぎの　値が同値ならカウント
        count += 1
        if int(list[i+1]) == 1:
            ref.append(0) # refの次の参照値を反転して作成
        else:
            ref.append(1) # refの次の参照値を反転して作成
    else:
        ref.append(list[i+1]) # refの次の参照値を作成

print(count)

Submission status: Accepted

Solution code:
s = 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)
if 2 == N:
    S_0 = "01" * (N // 2)
    S_1 = "10" * (N // 2)
else:
    S_0 = "01" * (N // 2) + "0"
    S_1 = "10" * (N // 2) + "1"

cnt_0 = 0
cnt_1 = 0
for i in range(N):
    if S[i] != S_0[i]:
        cnt_0 += 1
    if S[i] != S_1[i]:
        cnt_1 += 1

print(min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
tmp = S[0]
for i in range(0,len(S)-1,2):
    if tmp != S[i]:
        ans += 1
        S[i] = tmp
    if S[i] == S[i+1]:
        ans += 1
if len(S)%2 == 1:
    if S[-1] != tmp:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

prev = "-1"
count = 0
for ss in s:
  if prev == ss:
    count+=1
    if ss == "0":
      prev="1"
    else:
      prev="0"
  else:
  	prev = ss
    
print(count)

Submission status: Accepted

Solution code:
s = input()
min = 9999999999999
for i in range(2):
    count = 0
    for j in range(len(s)):
        if int(s[j]) == (j + i) % 2:
            count += 1
    if min > count:
        min = count
print(min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=str(input())

lists=list(s)
n=len(lists)

ans1=0
ans2=0

for i in range(n):
	if i%2==0:
		if lists[i]=="0":
			ans1=ans1+1
	elif i%2==1:
		if lists[i]=="1":
			ans1=ans1+1
			
for i in range(n):
	if i%2==0:
		if lists[i]=="1":
			ans2=ans2+1
	elif i%2==1:
		if lists[i]=="0":
			ans2=ans2+1

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=list(input())
S=list(map(int,S))
count=0

for i in range(len(S)-1):
    if S[i]^S[i+1]==0:
        S[i+1]=S[i+1]^1
        count+=1

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

Submission status: Accepted

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

R_0 = [s for i, s in enumerate(S) if s != (i % 2)]
R_1 = [s for i, s in enumerate(S) if s == (i % 2)]

print(min(len(R_0), len(R_1)))

Submission status: Accepted

Solution code:
S = list(map(int , input()))
lst0 = []
lst1 = []
for i in range(len(S)):
    lst1.append(i % 2)
    lst0.append((i + 1) % 2)
cnt0 = 0
cnt1 = 0
for i in range(len(S)):
    if S[i] != lst0[i]:
        cnt0 += 1
    if S[i] != lst1[i]:
        cnt1 += 1
print(min(cnt0,cnt1))

Submission status: Accepted

Solution code:
S = input()
c = '0'
ans1 = 0
for i in range(len(S)):
    if S[i] != c:
        ans1 += 1
    if c == '0':
        c = '1'
    else:
        c = '0'

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

Submission status: Accepted

Solution code:
s=input()

# 01010101や10101010としたい
ans=""
for i in range(len(s)+1):
    if i%2==0:
        ans+="0"
    else:
        ans+="1"
ans1=ans[:-1]
ans2=ans[1:]

cnt1=0
cnt2=0
for i in range(len(s)):
    if s[i]!=ans1[i]:
        cnt1+=1
    if s[i]!=ans2[i]:
        cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()

a=0 
for i in range(len(s)):
  if int(s[i])%2==i%2:
    a+=1
b=0
for i in range(len(s)):
  if int(s[i])%2!=i%2:
    b+=1
print(min(a,b))

Submission status: Accepted

Solution code:
s = input()
l = [int(i) for i in s[0::2]]
r = [int(i) for i in s[1::2]]

if len(s) == 1:
    print(0)
else:
    l_count1 = l.count(1)
    l_count0 = len(l)-l_count1
    r_count1 = r.count(1)
    r_count0 = len(r)-r_count1
    l_1 = l_count0+r_count1
    l_0 = l_count1+r_count0
    if (l_count1==len(l) and r_count0==len(r)) or (l_count0==len(l) and r_count1==len(r)):
        print(0)
    elif l_1 < l_0:
        print(l_1)
    else:
        print(l_0)

Submission status: Accepted

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

# 最終状態は0,1,0,1,...か1,0,1,0,...しかない
END1 = [0]
END2 = [1]

for _ in range(N-1):
    END1.append(END1[-1] ^ 1)
    END2.append(END2[-1] ^ 1)

for idx in range(N):
    END1[idx] = END1[idx] ^ S[idx]
    END2[idx] = END2[idx] ^ S[idx]

print(min(sum(END1),sum(END2)))

Submission status: Accepted

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

cnt1 = 0
for i in range(N):
    if int(S[i]) % 2 == i % 2:
        cnt1 += 1

cnt2 = 0
for i in range(N):
    if int(S[i]) % 2 != i % 2:
        cnt2 += 1

ans = min(cnt1, cnt2)
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
a = 0
b = 0
for i in range (0,N):
  if (i % 2 == 0) and (int(S[i]) == 1):
    a = a + 1
  elif (i % 2 == 1) and (int(S[i]) == 0):
    a = a + 1
 
for i in range (0,N):
  if (i % 2 == 0) and (int(S[i]) == 0):
    b = b + 1
  elif (i % 2 == 1) and (int(S[i]) == 1):
    b = b + 1
ans = min(a,b)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = len(S)
s1 = "".join([str(i%2) for i in range(n)])
s2 = "".join([str((i+1)%2) for i in range(n)])
S = int(S, 2)
ans1 = bin(int(s1, 2)^S).count('1')
ans2 = bin(int(s2, 2)^S).count('1')
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
tiles = list(map(int, list(input())))
length = len(tiles)
reverse = {0: 1, 1: 0}
cnt = 0

for i in range(1, length):
    if tiles[i] == tiles[i - 1]:
        tiles[i] = reverse[tiles[i]]
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import copy
s = list(map(str,input()))
S=copy.copy(s)
cnt1=0
cnt2=0
for i in range(len(s)):
    #print(i,s[i])
    if i%2==0 and s[i]=='1':
        s[i] = '0'
        cnt1+=1
    if i%2==1 and s[i]=='0':
        s[i] = '1'
        cnt1+=1
    if i%2==0 and S[i]=='0':
        S[i] = '1'
        cnt2+=1
    if i%2==1 and S[i]=='1':
        S[i] = '0'
        cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s=input()
a=[]
b=[]
for i in range(len(s)):
  if i%2==0:
    a.append(0)
  else:
    a.append(1)
    
for i in range(len(s)):
  if i%2==0:
    b.append(1)
  else:
    b.append(0)

a_count=0
b_count=0

for i in range(len(s)):
  if s[i]!=str(a[i]):
    a_count+=1
for i in range(len(s)):
  if s[i]!=str(b[i]):
    b_count+=1
ans=[a_count,b_count]
print(min(ans))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
p1 = [0 for _ in range(n)]
p2 = p1.copy()
for i in range(n):
    if i % 2 == 1: p1[i] = 1
    else: p2[i] = 1
ans1, ans2 = 0, 0
for i in range(n):
    if int(s[i]) != p1[i]: ans1 += 1
    else: ans2 += 1
print(ans1) if ans1 < ans2 else print(ans2)

Submission status: Accepted

Solution code:
s = input()

n = len(s)

req1 = '10'*10**5
req2 = '01'*10**5

diff = sum([1 for x, y in zip(s, req1) if x != y])

diff2 = sum([1 for x, y in zip(s, req2) if x != y])

print(min(diff, diff2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

p1 = 0
p2 = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

counter_1 = 0
for i in range(len(s)):
  # 101010...
  if i%2==0:
    if s[i] == '0':counter_1 += 1
  
  if i%2!=0:
    if s[i] == '1':counter_1 += 1
      
counter_2 = 0
for i in range(len(s)):
  # 01010...
  if i%2==0:
    if s[i] == '1':counter_2 += 1
  
  if i%2!=0:
    if s[i] == '0':counter_2 += 1
      
print(min(counter_1, counter_2))

Submission status: Accepted

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