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 = list(input())

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

Submission status: Accepted

Solution code:
s = input()
c = 0
for i, a in enumerate(s):
    if i % 2 == 0 and a == '0':
        c += 1
    if i % 2 == 1 and a == '1':
        c += 1
print(min(c, len(s)-c))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	# '0'=黒 '1'=白
	S = input()
	N = len(S)
	BNum=0
	BNumEven=0
	for i in range(len(S)):
		if(S[i]=='0'):
			BNum+=1
		if(S[i]=='0' and i%2==1):
			BNumEven+=1
	NEven = N//2
	NOdd = N - NEven
	BNumOdd = BNum - BNumEven
	WNum=N-BNum
	WNumEven=N//2-BNumEven
	WNumOdd = WNum - WNumEven

	min_change = 100001
	#B even W odd
	if(WNumEven + BNumOdd<min_change):
		min_change = WNumEven + BNumOdd
	#B odd W even
	if(WNumOdd + BNumEven<min_change):
		min_change = WNumOdd + BNumEven

	print(min_change)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

bin_0 = "".join(["0" if i % 2 == 0 else "1" for i in range(len(S))])
bin_1 = "".join(["1" if i % 2 == 0 else "0" for i in range(len(S))])
lis_S = [ i for i in S]
# 差が小さい方を使用
if abs(int(S,2) - int(bin_0,2)) <= abs(int(S,2) - int(bin_1,2)):
# 01010...を採用
	res = sum([ 1  for i in range(len(S)) if bin_0[i] != lis_S[i]])
else:
# 10101...を採用
	res = sum([ 1  for i in range(len(S)) if bin_1[i] != lis_S[i]])
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
BLACK = "0"
WHITE = "1"
S = input()
even_black = 0
even_white = 0
odd_black = 0
odd_white = 0

for i in range(len(S)):
  if i%2 == 0:
    even_black += S[i]==BLACK
    even_white += S[i]==WHITE
  else:
    odd_black += S[i]==BLACK
    odd_white += S[i]==WHITE
if even_black+odd_white < even_white+odd_black:
  print("{}" .format(even_black+odd_white))
else:
  print("{}" .format(even_white+odd_black))

Submission status: Accepted

Solution code:
list = list(map(int,list(input())))
odds =[list[i] for i in range(0,len(list),2)]
evens =[list[i] for i in range(1,len(list),2)]
a = odds.count(0)
b = len(odds) - a
c = evens.count(0)
d = len(evens) - c
print(min(a+d,b+c))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
num = 0
i=0
X=num%2
while num<N:
  if S[num] == "0":
    i+=1
  if not num==X+N-1:
    if S[num+1] == "1":
      i+=1
  num+=2
if N-i>i:
  print(i)
else:
  print(N-i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np

n = list(input())
n_size = len(n)
count = 0
#print(n_size)  
new_list = []
new_list.append(int(n[0]))
for i in range(n_size-1):
  if new_list[i] == 0:
    new_list.append(1)
  else:
    new_list.append(0)

#print(new_list)
    
for i in range(n_size):
  if (int(n[i]) != int(new_list[i])):
    count+=1

#print(new_list)    
if n_size == 1:
  print(0)
else:
#  ans = n_size-count    
  print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l =[int(i) for i in list(str(input()))]
ans = 0
num =0
n = 0

if l[0] == 1:
    l=[abs(i-1) for i in l]

for i in l:
    if num%2 ==0:
        if i == 1:
            ans = ans +1
    else:
        if i == 0:
            ans =ans +1
    num = num +1
print(ans)

Submission status: Accepted

Solution code:
s=input()

oi=0
io=0
ctr=0

for c in str(s):
    if c == str(ctr):
        oi+=1
    else:
        io+=1
    if ctr:
        ctr=0
    else:
        ctr=1

print(min(oi,io))

Submission status: Accepted

Solution code:
ans = 0
str = list(input())

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

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n=input()
cnt1=len(n)
cnt2=0
cnt3=0

x="0"
for i in range(cnt1):
	if n[i] != x:
		cnt2+=1
	if x=="0":
		x="1"
	else:
		x="0"

x="1"
for i in range(cnt1):
	if n[i] != x:
		cnt3+=1
	if x=="0":
		x="1"
	else:
		x="0"

if cnt2 < cnt3:
	print(cnt2)
else:
	print(cnt3)

Submission status: Accepted

Solution code:
S = input()
c_odd, c_even = 0,0
# c_oddはiがoddの時1になるよーに。evenは逆。

for i in range(len(S)):
  if S[i] == '0':
    if i%2 == 0: #even
      c_even += 1
    else:
      c_odd += 1
  else:
    if i%2 == 0: #even
      c_odd += 1
    else:
      c_even += 1
      
print(min(c_odd, c_even))

Submission status: Accepted

Solution code:
tiles = str(input())
size = len(tiles)
one = 0
zero = 0

for i in range(size):
	one_i = (i+1) % 2
	zero_i = i % 2
	one += abs(one_i - int(tiles[i]))
	zero += abs(zero_i - int(tiles[i]))

print(min(one, zero))

Submission status: Accepted

Solution code:
s=input()
l=len(s)//2
s0="01"*l
if len(s)%2!=0:
    s0+="0"
s1="10"*l
if len(s)%2!=0:
    s1+="1"
ans0=0
ans1=0
for i in range(len(s)):
    if s[i]!=s0[i]:
        ans0+=1
    if s[i]!=s1[i]:
        ans1+=1
print(min(ans0,ans1))

Submission status: Accepted

Solution code:
s = input()
i = 0
ans = 0
while i < len(s):
    if int(s[i]) == i % 2:
        ans += 1
    i += 1
print(min(ans,i-ans))

Submission status: Accepted

Solution code:

#input S
S=input()

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

print(count)

Submission status: Accepted

Solution code:
s=input()
a=b=[]
ac=bc=0
for i in range(len(s)):
    a.append('0')
    b.append('1')
    if s[i]!=a[i]:
        ac+=1
    else: bc+=1
print(min(ac,bc))

Submission status: Accepted

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

Submission status: Accepted

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

S = input()

Se, So = S[0::2], S[1::2]
Se0, Se1, So0, So1 = Se.count('0'), Se.count('1'), So.count('0'), So.count('1')
print(min(Se0 + So1, Se1 + So0))

Submission status: Accepted

Solution code:
color = input()

even = color[::2]
odd = color[1::2]

# 0 start
count1 = even.count('0') + odd.count('1')

# 1 start
count2 = even.count('1') + odd.count('0')

if (count1 < count2):
    print(count1)
else:
    print(count2)

Submission status: Accepted

Solution code:
ar = input()
c1 = 0
c2 = 0
for i in range(len(ar)):
    if i % 2 == 0:
        if ar[i] == "0":
            c1 += 1
        elif ar[i] == "1":
            c2 += 1
    elif i % 2 == 1:
        if ar[i] == "0":
            c2 += 1
        elif ar[i] == "1":
            c1 += 1
print(min(c1,c2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_distance(s1, s2):
    dis = 0
    for c1, c2 in zip(s1, s2):
        if c1 != c2:
            dis = dis + 1
    return dis

S = str(input())

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

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

ans = min(get_distance(S, S0), get_distance(S, S1))
print(ans)

Submission status: Accepted

Solution code:
S = input()

ans0 = 0
ans1 = 0
target = 0
for i in range(len(S)):
  if S[i] == str(target):
    ans0 += 1
  else:
    ans1 += 1
  target = 1 - target
print(min(ans0, ans1))

Submission status: Accepted

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

num = n[0]
total = 0
for i in range(1,len(n)):
    if n[i] == n[i-1]:
        total += 1
        if n[i] == 1:
            n[i] = 0
        else:
            n[i] = 1

print(total)

Submission status: Accepted

Solution code:
S = input()
ans1 = ''
ans2 = ''
for i in range(len(S)):
    ans1 += str(i % 2)
    ans2 += str((i+1)%2)
count1 = 0
count2 =0
for i in range(len(S)):
    if S[i] !=ans1[i]: count1 += 1
    if S[i] != ans2[i]: count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
S = input()
count = [0,0]

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

print(min(count))

Submission status: Accepted

Solution code:
import numpy as np

S = list(map(int,input()))
S = np.array(S)
l = len(S)
ptnA = np.tile((1,0), l)
ptnA = ptnA[0:l]
ptnB = np.tile((0,1),l)
ptnB = ptnB[0:l]

xorsumA = sum(np.logical_xor(S, ptnA))
xorsumB = sum(np.logical_xor(S, ptnB))

print(min((xorsumA,xorsumB)))

Submission status: Accepted

Solution code:
s = input()
N = len(s)
count_w = 0
for i in range(N):
    if ((i%2) == 0 and int(s[i]) == 0) or ((i%2) == 1 and int(s[i]) == 1):
        count_w += 1
count_b = 0
for i in range(N):
    if ((i%2) == 0 and int(s[i]) == 1) or ((i%2) == 1 and int(s[i]) == 0):
        count_b += 1
print(min(count_b,count_w))

Submission status: Accepted

Solution code:
s = input()
N = len(s)
left_white=[]
for i in range(N):
    if (i%2) == 0:
        left_white.append(1)
    else:
        left_white.append(0)
left_black=[]
for i in range(N):
    if (i%2) == 0:
        left_black.append(0)
    else:
        left_black.append(1)
count_w = 0
for i in range(N):
    if int(s[i]) != left_white[i]:
        count_w = count_w+1
count_b = 0
for i in range(N):
    if int(s[i]) != left_black[i]:
        count_b += 1
print(min(count_w,count_b))

Submission status: Accepted

Solution code:
import sys
inp=[i.strip() for i in sys.stdin.readlines()]
if len(inp)==1:
    if len(inp[0].split())==2:
        A,B=map(int,inp[0].split())
        print(max(2*A-1,2*B-1,A+B))
    else:
        S=inp[0]
        N=len(S)
        X=""
        Y=""
        for i in range(N):
            if i%2==0:
                X=X+"0"
                Y=Y+"1"
            else:
                X=X+"1"
                Y=Y+"0"
        A=0
        B=0
        for i in range(N):
            if X[i]!=S[i]:
                A+=1
            if Y[i]!=S[i]:
                B+=1
        print(min(A,B))
else:
    if len(inp[0].split())==1:
        N=int(inp[0])
        H=[int(i) for i in inp[1].split()]
        ans=1
        for i in range(1,N):
            flag=1
            for j in range(i):
                if H[j]>H[i]:
                    flag=0
                    break
            if flag==1:
                ans+=1
        print(ans)
    else:
        N,K=map(int,inp[0].split())
        S=inp[1]
        L=[0]
        tmp="1"
        for i in range(N):
            if tmp!=S[i]:
                L.append(1)
            else:
                L[-1]+=1
            tmp=S[i]
        if tmp=="0":
            L.append(0)
        M=len(L)
        if M<=2*K+1:
            print(N)
            exit()
        X=[0 for i in range(M+1)]
        for i in range(M):
            X[i+1]=L[i]+X[i]
        ans=0
        for i in range(0,M-2*K,2):
            ans=max(ans,X[i+2*K+1]-X[i])
        print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0

for i, v in enumerate(s):
    r = i % 2
    if int(v) != r:
        ans += 1

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

Submission status: Accepted

Solution code:
S = list(input())

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

count_0_0 = list_0.count(0)
count_1_0 = list_1.count(1)

count_0_1 = list_0.count(1)
count_1_1 = list_1.count(0)

sum_0 = count_0_0 + count_1_0
sum_1 = count_0_1 + count_1_1

print(min(sum_0, sum_1))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter

# prime numbers
_nprime = 10 ** 5 + 1
primes = list(range(int(_nprime) + 1))
primes[1] = 0
for i in range(2, int((_nprime + 1) ** 0.5) + 1):
    if primes[i]:
        for j in range(2 * i, _nprime + 1, i):
            primes[j] = 0

def main():
    S = SI()
    ans = [0, 0]
    i = 0
    for s in S:
        if int(s) == i:
            ans[0] += 1
        else:
            ans[1] += 1
        i = 1 - i
    ans = min(ans)
    return ans

print(main())

Submission status: Accepted

Solution code:
#coding:utf-8

S = input()
N = len(S)
ans = 0
SR = []
if S[0] == '0':
	for i in range(N):
		SR.append('0')
		SR.append('1')
else:
	for i in range(N):
		SR.append('1')
		SR.append('0')

for i in range(N):
	if S[i] != SR[i]:
		ans += 1
		
print(ans)

Submission status: Accepted

Solution code:
S = input()
even_0,even_1 =0,0
odd_0 ,odd_1 = 0,0

for i,s in enumerate(S):
    if (i+1)%2==0:
        if s == "0":
            even_0 += 1
        elif s == "1":
            even_1 += 1
    else:
        if s == "0":
            odd_0 += 1
        elif s == "1":
            odd_1 += 1

print(min([odd_1+even_0,odd_0+even_1]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-


def main():
    S = [(True if c == '1' else False) for c in input() ]

    min_ = float('inf')

    for c in (True, False):
        num = 0
        for s in S:
            if s != c:
                num += 1
            c = not c
        min_ = min(num, min_)

    print(min_)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

a = "01" * (len(S) // 2) 

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

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

Submission status: Accepted

Solution code:
s = input()

count1=0
count2=0

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

Submission status: Accepted

Solution code:
s=input()
a,b=s[::2],s[1::2]
a_lst=[i for i in a]
a0=a_lst.count("0")
a1=a_lst.count("1")
b_lst=[i for i in b]
b0=b_lst.count("0")
b1=b_lst.count("1")
print(min(a0+b1,a1+b0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
S = input()
a = "01"*math.ceil(len(S))
b = "10"*math.ceil(len(S))
a_diff = 0
b_diff = 0
for i in range(len(S)):
    a_diff += a[i] != S[i] 
    b_diff += b[i] != S[i]
print(min(a_diff, b_diff))

Submission status: Accepted

Solution code:
s=input()

h=""
if s[0]=="0":
    if len(s)%2==0:
        for i in range(int(len(s)/2)):
            h+="0"
            h+='1'
    else:
        for i in range(int(len(s)/2)):
            h+='0'
            h+='1'
        h+='0'
else:
    if len(s)%2==0:
        for i in range(int(len(s)/2)):
            h+="1"
            h+='0'
    else:
        for i in range(int(len(s)/2)):
            h+='1'
            h+='0'
        h+='1'

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

print(ans)

Submission status: Accepted

Solution code:
# S = '0'
S = input()

def cnt_even(prev):
    global S
    cnt = 0

    for x, y in enumerate(list(S)):
        y = int(y)
        if prev == y:
            cnt += 1
            y = 1 if y == 0 else 0
        prev = y
    return cnt

A = cnt_even(0)
B = cnt_even(1)

print(min(A, B))

Submission status: Accepted

Solution code:
S = input()
even_black_num = 0
even_white_num = 0
odd_black_num = 0
odd_white_num = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s == "1":
            even_white_num += 1
        else:
            even_black_num += 1
    else:
        if s == "1":
            odd_white_num += 1
        else:
            odd_black_num += 1

print(min(even_black_num + odd_white_num, odd_black_num + even_white_num))

Submission status: Accepted

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

from sys import stdin



############################################

#from sys import stdin
import numpy as np

# read data for n sequences.
data = stdin.readline().split()
#data=str(data)
#data2=[]
#for a in data:
#    data2.append(int(a))
data2 = str(data)[1:-1]

# 0101...
count1=0
count2=0
data = data[1:-1]

for i,a in enumerate(data2[1:-1]):
    a = int(a)
    if i %2 == 0:
        if a == 1:
            count1+=1
        else:
            count2+=1
    else:
        if a == 0:
            count1+=1
        else:
            count2+=1
    
if count1<count2:
    count=count1
else:
    count=count2
print(count)
#count2=0
# 1010..

Submission status: Accepted

Solution code:
def getInt(): return int(input())

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def color(start, tiles):
    count = 0
    for i in range(len(tiles)):
        if i % 2 == 0 and tiles[i] != start:
            count += 1
        elif i % 2 == 1 and tiles[i] == start:
            count += 1
    return count


def prob():
    d = Debug()
    d.off()
    S = input()
    count1 = color('0', S)
    count2 = color('1', S)
    d.dmp((count1,count2),'count1,count2')
    return min(count1, count2)

ans = prob()
print(ans)

Submission status: Accepted

Solution code:
S = [int(c) for c in input()]
pairs = (len(S)+1) // 2

zeroone = 0
onezero = 0

for _ in range(pairs):

    last = S.pop()

    if last == 1:
        zeroone += 1
    else:
        onezero += 1

    if S:
        last = S.pop()
        if last == 0:
            zeroone += 1
        else:
            onezero += 1

print(min(zeroone, onezero))

Submission status: Accepted

Solution code:
S = input()
left0 = 0
# 0101010...
left1 = 0
# 1010101...

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

Submission status: Accepted

Solution code:
S = str(input())
ans = 0
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(ans, len(S)-ans))

Submission status: Accepted

Solution code:

#input
#N = list(map(int,input().split()))
#H = list(map(int,input().split()))
S = str(input())
ans = 0
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(ans,len(S)-ans))

Submission status: Accepted

Solution code:
s = str(input())
a = 0
b = 0

# 010101...
for i in range(len(s)):
    if i % 2 == 0 and int(s[i]) == 1:
        a += 1
    if i % 2 == 1 and int(s[i]) == 0:
        a += 1

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

Submission status: Accepted

Solution code:
S = input()
s1 = list(S)
s2 = list(S)

ans1 = 0
ans2 = 0
for i,t in enumerate(s1):
    if i%2 == 0:
        if t == "0":
            ans1 += 1
    else:
        if t == "1":
            ans1 += 1


for i,t in enumerate(s1):
    if i%2 == 0:
        if t == "1":
            ans2 += 1
    else:
        if t == "0":
            ans2 += 1
print(min (ans1,ans2))

Submission status: Accepted

Solution code:
S = input()

S_int = [int(S[i]) for i in range(len(S))]

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

S = list(input())

N = len(S)
N1 = len(S[::2])
N2 = N - N1

c = Counter(S[::2])
cnt1 = abs(c['1'] - N1)
cnt2 = abs(c['0'] - N1)

c = Counter(S[1::2])
cnt1 += abs(c['0'] - N2)
cnt2 += abs(c['1'] - N2)

print(min(cnt1, cnt2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import os
import random
import re
import sys
from collections import defaultdict

# sys.stdin = open('input.in', 'r')
# sys.stdout = open('output.out', 'w') 

def onezero(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 0:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 1:
			count += 1
	return count

def zeroone(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 1:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 0:
			count += 1
	return count


def count(n):
	return min(onezero(n),zeroone(n))

if __name__ == '__main__':
	N = [int(d) for d in input()]
	print(count(N))

Submission status: Accepted

Solution code:
s = input()
ifone = True
onecount = zerocount = 0
for i in s:
	if int(i) != int(ifone):
		onecount += 1
	else:
		zerocount += 1
	ifone = not ifone
print(min(onecount,zerocount))

Submission status: Accepted

Solution code:
S = input()

num_flip = 0 # タイルの反転回数

if len(S) == 1:
    print(num_flip)

# 前のタイルとだけ比較する
else:
    for i in range(1, len(S)):
        if S[i-1] == S[i] :
            num_flip += 1
            
            # つぎかえ
            if S[i] == "0":
                S = S[:i] + "1" + S[i+1:]
            else:
                S = S[:i] + "0" + S[i+1:]

    print(num_flip)

Submission status: Accepted

Solution code:
def solve(n):
  cnt = 0
  for i in range(len(S)):
    if (i + n) % 2:
      if S[i] == '0':
        cnt += 1
    else:
      if S[i] == '1':
        cnt += 1
  return cnt

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

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

# 四方向
dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]
INF = float("inf")

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))

S = input()

s_one = "".join([ "0" if i % 2 == 1 else "1" for i in range(len(S))])
s_two = "".join([ "1" if i % 2 == 1 else "0" for i in range(len(S))])

ans = INF
tmp = 0
for si, oi in zip(S, s_one):
    if si != oi:
        tmp += 1

ans = min(ans, tmp)

tmp = 0
for si, oi in zip(S, s_two):
    if si != oi:
        tmp += 1

ans = min(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
S = "0b" + input()

N = len(S) - 2

A = "0b" + "10" * (N // 2) + "1" * (N % 2)
B = "0b" + "01" * (N // 2) + "0" * (N % 2)

s = int(S, 2)
a = int(A, 2)
b = int(B, 2)

num_a = bin(s ^ a).count("1")
num_b = bin(s ^ b).count("1")

print(min([num_a, num_b]))

Submission status: Accepted

Solution code:
s = input()
a = [int(b) for b in s]
c01, c10 = 0,0
for i in range(len(a)):
	d = i%2
	if a[i] != d:
		c01+=1
	else:
		c10+=1
print(c01 if c01<c10 else c10)

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
list_ans =[]
for i in range(2):
        ans = 0
        if i == 0:
                for j in range(len_s):
                                if j % 2 == 0:
                                        if s[j] == "0":
                                                ans += 1
                                else:
                                        if s[j] == "1":
                                                ans += 1
        else:
                for j in range(len_s):
                        if j % 2 == 0:
                                if s[j] == "1":
                                        ans += 1
                        else:
                                if s[j] == "0":
                                        ans += 1
        list_ans.append(ans)
print(min(list_ans))

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input()

    ans = 0
    cs = int(S[0])

    for s in S[1:]:
        s = int(s)
        if s == cs:
            ans += 1
            cs = 1 - s
        else:
            cs = s

    print(ans)


main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = input()
    
    l = []
    #even
    l.append([v for k, v in enumerate(S) if k % 2 == 0]) 
    #odd
    l.append([v for k, v in enumerate(S) if k % 2 == 1])
    
    ans = []
    #01
    ans.append(l[0].count('0') + l[1].count('1'))
    #10
    ans.append(l[0].count('1') + l[1].count('0'))
    
    print(min(ans))
    
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
S=list(s)
L=len(s)
s=0

if S[0]=='1':
    for i in range(0,L):
        if i%2==1:
            if S[i]=='1':
                s=s+1
            else:
                continue
        else:
            if S[i]=='0':
                s=s+1
            else:
                continue

else:
    for i in range(0,L):
        if i%2==1:
            if S[i]=='0':
                s=s+1
            else:
                continue
        else:
            if S[i]=='1':
                s=s+1
            else:
                continue

m=1
if S[0]=='1':
    for i in range(0,L):
        if i%2==1:
            if S[i]=='0':
                m=m+1
            else:
                continue
        else:
            if S[i]=='1':
                m=m+1
            else:
                continue

else:
    for i in range(0,L):
        if i%2==1:
            if S[i]=='1':
                m=m+1
            else:
                continue
        else:
            if S[i]=='0':
                m=m+1
            else:
                continue
if m>s:
    print(s)
else:
    print(m)