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
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = input().rstrip()
    N = len(S)
    cnt_a = 0
    cnt_b = 0
    for i in range(N):
        if i%2 == 0 and S[i] == '0':
            cnt_a += 1
        elif i%2 == 1 and S[i] == '1':
            cnt_a += 1
        elif i%2 == 0 and S[i] == '1':
            cnt_b += 1
        elif i%2 == 1 and S[i] == '0':
            cnt_b += 1
    print(min(cnt_a,cnt_b))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
odd_num_0 = 0
eve_num_0 = 0
S = input()
N = len(S)
for idx, s in enumerate(S):
  if s == '0':
    if idx%2 == 0: eve_num_0 += 1
    else: odd_num_0 += 1

if N%2 == 1:eve_num = N//2+1
else:eve_num = N//2
odd_num = N//2

print(min(eve_num-eve_num_0+odd_num_0,odd_num-odd_num_0+eve_num_0))

Submission status: Accepted

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

def main():
    S = input().strip()

    white = 0
    black = 0
    for i, v in enumerate(S):
        if i % 2 == 0:
            if v != '0':
                white += 1
            else:
                black += 1
        else:
            if v != '1':
                white += 1
            else:
                black += 1

    print(min(white, black))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
res1 = 0
sample = "0"
tmp = "1"
for i in range(N):
    if S[i] != sample:
        res1 += 1
    sample, tmp = tmp, sample

res2 = 0
sample = "1"
tmp = "0"
for i in range(N):
    if S[i] != sample:
        res2 += 1
    sample, tmp = tmp, sample


print(min(res1, res2))

Submission status: Accepted

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

gate1 = 0

cnt1 = 0
cnt2 = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#124c
S = str(input())
#################01234567
ans_b_start = 0 #01010101…
ans_w_start = 0 #10101010…

for i in range(len(S)):
    if i%2==0:
        if S[i]=="0":
            ans_w_start+=1
        if S[i]=="1":
            ans_b_start+=1
    if i%2==1:
        if S[i]=="0":
            ans_b_start+=1
        if S[i]=="1":
            ans_w_start+=1
        
if ans_w_start > ans_b_start:
    print(ans_b_start)
else:
    print(ans_w_start)

Submission status: Accepted

Solution code:
s_list = list(map(int,(input())))
count_odd1 = 0
count_odd0 = 0
count_even1 = 0
count_even0 = 0
s_len = len(s_list)
for i in range(s_len):
    if i%2 == 0 and s_list[i] == 1:
        count_odd1 += 1
    if i%2 == 1 and s_list[i] == 1:
        count_even1 += 1

    if i%2 == 0 and s_list[i] == 0:
        count_odd0 += 1
    if i%2 == 1 and s_list[i] == 0:
        count_even0 += 1
# print(count_even0)
# print(count_odd1)
# print(count_even1)
# print(count_odd0)
print(min(s_len - count_even0 - count_odd1,s_len - count_even1 - count_odd0))

Submission status: Accepted

Solution code:
s = list(input())
t = list(reversed(s))
ans1 = 0
for i in range(len(s)-1):
  if s[i]==s[i+1]=="0":
    s[i+1] ="1"
    ans1+=1
  elif s[i]==s[i+1]=="1":
    s[i+1] ="0"
    ans1+=1
ans2 = 0
for i in range(len(t)-1):
  if t[i]==t[i+1]=="0":
    t[i+1] ="1"
    ans2+=1
  elif t[i]==t[i+1]=="1":
    t[i+1] ="0"
    ans2+=1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()
Aans = 0
Bans = 0
A=[]
B=[]
for i in range(len(s)):
    if i%2 == 0:
        A.append(0)
        B.append(1)
    else:
        A.append(1)
        B.append(0)

for i in range(len(s)):
    if int(s[i]) != A[i] :
        Aans += 1
    elif int(s[i]) != B[i] :
        Bans += 1
print(min(Aans,Bans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = 0
b = 0
for i in range(len(s)):
    if i%2 == 0:
        a += 2**i
    else:
        b += 2**i
s = int(s, 2)
print(min(bin(a^s).count('1'), bin(b^s).count('1')))

Submission status: Accepted

Solution code:
S = list(input())

#print(S[0])
N = len(S)
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        count += 1
        #print('カウント')
        if S[i+1] == '0':
            S[i + 1] = '1'
            #print('1のとき')
        elif S[i+1] == '1':
            S[i+1] = '0'
            #print('０のとき')
print(count)

Submission status: Accepted

Solution code:
s = list(input())
for i in range(len(s)):
  s[i] = int(s[i])
c = 0
for i in range(1,len(s)):
  if s[i-1] == s[i]:
    s[i] += 1
    s[i] %= 2
    c += 1
if c > len(s) // 2:
  print(len(s)-c)
else:
  print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
count=0
s=list(input())
x=int(s[0])
for i in range(len(s)):
    if s[i]!=str(x):
        count+=1
    x=(x+1)%2
print(count)
exit()

Submission status: Accepted

Solution code:
S=input()
N=len(S)
tile=['0' if i&1==0 else '1' for i in range(N)]
ans=0
for i in range(N):
  if S[i]!=tile[i]:
    ans+=1
print(ans if ans<=N//2 else N-ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """000"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10010010"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """0"""
        output = """0"""
        self.assertIO(input, output)
def resolve():
    S=[int(i) for i in input()]
    X=sum([1 if i%2 != S[i] else 0 for i in range(len(S))])
    Y=sum([1 if S[i] != (i+1)%2 else 0 for i in range(len(S))])
    print(min(X,Y))
if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def f_c():
    s = input()
    co, ce = 0, 0
    for i in range(len(s)):
        if i%2!=0:
            co = co+1 if s[i]!="1" else co
            ce = ce+1 if s[i]!="0" else ce
        else:
            co = co+1 if s[i]!="0" else co
            ce = ce+1 if s[i]!="1" else ce
    print(min(co, ce))

if __name__ == "__main__":
    f_c()

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
S=input()

a=[S[::2].count(l) for l in "01"]
b=[S[1:][::2].count(k) for k in "01"]

print(min(a[0]+b[1],a[1]+b[0]))

Submission status: Accepted

Solution code:
S = input()

size = len(S)
n = "".join("1" if i % 2 == 0 else "0" for i in range(size))

nc, mc = 0, 0
for i in range(size):
    if S[i] == n[i]:
        nc += 1
    else:
        mc += 1

print(min(nc, mc))

Submission status: Accepted

Solution code:
#C
s=input()
n=len(s)
count1=0
for i in range(n):
    if i%2==0:
        if s[i]=="1":
            count1+=1
    else:
        if s[i]=="0":
            count1+=1
count2=0
for i in range(n):
    if i%2==0:
        if s[i]=="0":
            count2+=1
    else:
        if s[i]=="1":
            count2+=1
print(min(count1,count2))

Submission status: Accepted

Solution code:
s = input()
l = len(s)
counter = 0
if s[0] == '1':
    for i in range(1, l):
        if i % 2 == 1 and s[i] == '1':
            counter += 1
        elif i % 2 == 0 and s[i] == '0':
            counter += 1
else:
    for i in range(1, l):
        if i % 2 == 1 and s[i] == '0':
            counter += 1
        elif i % 2 == 0 and s[i] == '1':
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
S = input()

#0101
tmp=0
cntA=0
for i in range(len(S)):
    if tmp!=int(S[i]):
        cntA+=1
    if tmp==0:
        tmp=1
    else:
        tmp=0

#1010
tmp=1
cntB=0
for i in range(len(S)):
    if tmp!=int(S[i]):
        cntB+=1
    if tmp==0:
        tmp=1
    else:
        tmp=0
#print(cntA,cntB)
print(min(cntA,cntB))

Submission status: Accepted

Solution code:
s1=[1,0]*5*10**4
s0=[0,1]*5*10**4
s=list(input())
a1,a0=0,0
for i in range(len(s)):
    a1+=abs(int(s[i])-s1[i])
    a0+=abs(int(s[i])-s0[i])
print(min(a0,a1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
list=[]
lhst=[]
for i in range(len(s)):
  list.append(0)
  lhst.append(0)
for j in range(len(s)):
  if j%2==0:
    list[j]=1
  else:
    lhst[j]=1
d=0
e=0
for l in range(len(s)):
  f=int(s[l])
  if list[l]==f:
    d+=1
  else:
    e+=1
print(min(d,e))

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()
tmp1 = '01' * (len(S) // 2 + 1)
tmp2 = '10' * (len(S) // 2 + 1)
C = {0 : 0, 1 : 0}
for i, s in enumerate(S):
    if s != tmp1[i] : C[0] += 1
    if s != tmp2[i] : C[1] += 1
print(min(C.values()))

Submission status: Accepted

Solution code:
s = list(input())
ini = int(s[0])
count = 0
for i in range(1, len(s)):
    if i % 2 == 1:
        if int(s[i]) == ini:
            s[i] = -ini + 1
            count += 1
    else:
      if int(s[i]) != ini:
            s[i] = ini
            count += 1
print(count)

Submission status: Accepted

Solution code:
S=str(input())

c=0
for i, s in enumerate(S):
  c += (ord(s) - ord('0')) ^ (i % 2)
print(min(c, len(S) - c))

Submission status: Accepted

Solution code:
n=input()
s=""
a=""
sd,ad=0,0
for i in range(len(n)):
  if i%2:
    s+="1"
    a+="0"
  else:
    s+="0"
    a+="1"
for i in range(len(n)):
  if n[i]!=a[i]:ad+=1
  if n[i]!=s[i]:sd+=1
print(min(ad,sd))

Submission status: Accepted

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

for i in range(1,len(S)):
    if right_str[i-1] == '0':
        right_str+="1"
    else:
        right_str+="0"
ans = 0
for i in range(len(S)):
    if not right_str[i] == S[i]:
        ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
res = 0
rez = 0
if len(s) %2 ==0:
    hs = len(s) // 2
    for i in range(0,hs):
        if s[2*i] == "0":
            res += 1
        else:
            rez += 1
        if s[2*i+1] =="1":
            res += 1
        else:
            rez += 1
else:
    hs = len(s) // 2
    if s[0] == "0":
        res += 1
    else:
        rez += 1
    for i in range(0,hs):
        if s[2*i+2] == "0":
            res += 1
        else:
            rez += 1
        if s[2*i+1] =="1":
            res += 1
        else:
            rez += 1


print(min(res,rez))

Submission status: Accepted

Solution code:
s = input()
From0 = False
From1 = True
cntF0 = 0
cntF1 = 0
for i in range(len(s)):
    if s[i]!=str(int(From0)):
        cntF0 +=1
    if s[i]!=str(int(From1)):
        cntF1 +=1
    From0 = not(From0)
    From1 = not(From1)
print(min(cntF0,cntF1))

Submission status: Accepted

Solution code:
S = input()

start_0_count = 0
for i in range(len(S)):
    if i%2 == 0 and S[i] != "0":
        start_0_count += 1
    elif i%2 == 1 and S[i] != "1":
        start_0_count += 1
    else:
        pass
    
start_1_count = 0
for i in range(len(S)):
    if i%2 == 0 and S[i] != "1":
        start_1_count += 1
    elif i%2 == 1 and S[i] != "0":
        start_1_count += 1
    else:
        pass

print(min(start_0_count, start_1_count))

Submission status: Accepted

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

count = 0
ans = 0
for i in range(n):
	if i % 2 == 0 and target1[i] == "1":
		count += 1
	elif i % 2 and target1[i] == "0":
		count += 1
	
	if i % 2 == 0 and target2[i] == "0":
		ans += 1
	elif i % 2 and target2[i] == "1":
		ans += 1
		
print(min(count, ans))

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))
count = 0
for i in range(1, len(s)):
  if s[i]==s[i-1]:
    count+=1
    if s[i]==0:
      s[i]=1
    elif s[i]==1:
      s[i]=0
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = len(S)
a = b = ''
for i in range(n):
    if i % 2 == 0:
        a += '0'
        b += '1'
    else:
        a += '1'
        b += '0'

diff_a = diff_b = 0
for i in range(n):
    if S[i] != a[i]:
        diff_a += 1
    if S[i] != b[i]:
        diff_b += 1

print(min(diff_a, diff_b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

n = len(s)
a = "10" * (n // 2) + "1" * (n % 2)
b = "01" * (n // 2) + "0" * (n % 2)

print(min(bin(int(s, 2) ^ int(a, 2)).count("1"), bin(int(s, 2) ^ int(b, 2)).count("1")))

Submission status: Accepted

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

cnt_1 = 0
cnt_2 = 0

#左端のタイルの色が黒
for i in range(n):
  if i % 2 != int(s[i]):
    cnt_1 += 1

#左端のタイルの色が白    
for i in range(n):
  if i % 2 == int(s[i]):
    cnt_2 += 1
      
print(min(cnt_1, cnt_2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
count_odd = 0
count_even = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "0":
            count_even += 1
        else:
            count_odd += 1
    else:
        if s[i] == "1":
            count_even += 1
        else:
            count_odd += 1
print(min(count_even, count_odd))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lst = list(input())
p = -1
ans = 0
s = set(['0','1'])
for e in lst:
    if e == p:
        ans += 1
        p = (s - set(e)).pop()
    else:
        p = e
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def swap(ch):
    if ch == '0':
        return '1'
    else:
        return '0'


s = list(input())
ct = 0

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        s[i+1] = swap(s[i+1])
        ct += 1

print(ct)

Submission status: Accepted

Solution code:
S = input()

def paint(str_num, S):
    cnt = 0
    temp = int(str_num)
    for i in range(len(S)):
        if int(S[-1-i]) == temp:
            temp = (temp+1)%2
        else:
            cnt += 1
            temp = (temp+1)%2
    return cnt
            
print(min(paint("0", S),paint("1", S)))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
V = []
for i in range(N):
    V.append(int(S[i]))

A = []
B = []
for i in range(N):
    if i%2 == 0:
        A.append(0)
        B.append(1)
    else:
        A.append(1)
        B.append(0)

def count_dif(X,Y):
    p = 0
    for i in range(len(X)):
        if X[i] != Y[i]:
            p += 1
    return(p)

print(min(count_dif(V,A), count_dif(V,B)))

Submission status: Accepted

Solution code:
S = input()

tmp1 = 0
f = '0'
for s in S:
    if s != f:
        tmp1 += 1
    if f == '0':
        f = '1'
    else:
        f = '0'
tmp2 = 0
f = '1'
for s in S:
    if s != f:
        tmp2 += 1
    if f == '0':
        f = '1'
    else:
        f = '0'
print(min(tmp1, tmp2))

Submission status: Accepted

Solution code:
def main():
    s = list(input())

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
if(len(s)==1):
    print(0)
else:
    a=s[:]
    fir,sec=0,0
    for i in range(len(s)-1):
        if(s[i]==s[i+1]):
            s[i+1] = str(1 - (ord(s[i])-48))
            fir+=1
    print(fir)

Submission status: Accepted

Solution code:
s=list(input())
if(len(s)==1):
    print(0)
else:
    a=s[:]
    fir,sec=0,0
    for i in range(len(s)-1):
        if(s[i]==s[i+1]):
            s[i+1] = str(1 - (ord(s[i])-48))
            fir+=1
    for i in range(len(s)-1,0,-1):
        if(a[i]==a[i-1]):
            a[i-1] = str(1 - (ord(a[i])-48))
            sec+=1
    print(min(fir,sec))

Submission status: Accepted

Solution code:
S = input()

zero_start_cnt = 0
one_start_cnt = 0

for i in range(len(S)):
    if i % 2 == 0:
        zero_color = '0'
        one_color = '1'
    else:
        zero_color = '1'
        one_color = '0'

    if S[i] != one_color:
        one_start_cnt += 1
    else:
        zero_start_cnt += 1

print(min(one_start_cnt, zero_start_cnt))

Submission status: Accepted

Solution code:
a=input()

if len(a)==1:
  print(0)
  exit()
  
b=a[::2]
c=a[1::2]

b0=b.count("0")
b1=b.count("1")
c0=c.count("0")
c1=c.count("1")

print(min(b0+c1,b1+c0))

Submission status: Accepted

Solution code:
def test():
    s = list(map(int,list(input())))
    count = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] ^= 1
            count += 1
    print(count)


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

S = list(map(int, list(input().rstrip())))

# 先頭を0, 1 で二回走査すればいい

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

ans = count

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

ans = min(ans, count)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
even_list = S[::2]
odd_list =  S[1::2]

even_black = even_list.count('0')
even_white = even_list.count('1')
odd_black = odd_list.count('0')
odd_white = odd_list.count('1')

if even_white + odd_black < even_black + odd_white:
    print(even_white + odd_black)
else:
    print(even_black + odd_white)

Submission status: Accepted

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

#開始が0の場合の回数
kaishi0=0
for i in range(n):
  kaishi0+=abs(int(s[i])-i%2)

#開始が1の場合の回数
kaishi1=0
for i in range(n):
  kaishi1+=abs(int(s[i])-((i+1)%2))

print(min(kaishi0,kaishi1))

Submission status: Accepted

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

S1=[i%2 for i in range(N)]
S2=[(i+1)%2 for i in range(N)]

counter1=0
for i in range(N):
  if S[i]!=S1[i]:
    counter1+=1
    
counter2=0
for i in range(N):
  if S[i]!=S2[i]:
    counter2+=1
    
print(min(counter1, counter2))

Submission status: Accepted

Solution code:
string = input()
n  = len(string)
a  = '10'*(n//2+1)
b  = '01'*(n//2+1)
a = a[:n]
b = b[:n]

x = int(a,2) ^ int(string,2)
y = int(b,2) ^ int(string,2)
l ="{0:b}".format(x)
k ="{0:b}".format(y)

print(min(l.count('1'),k.count('1')))

Submission status: Accepted

Solution code:
S=list(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

if count2 >= count1:
    print(count1)
else:
    print(count2)

Submission status: Accepted

Solution code:
S = list(input())

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

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

print(min(cnt, cnt1))

Submission status: Accepted

Solution code:
S=str(input())
s=len(S)
Sk=[]
Sg=[]
for i in range(0,s,2):
    Sk.append(S[i])
for i in range(1,s,2):
    Sg.append(S[i])
Sk0=Sk.count('0')
Sk1=Sk.count('1')
Sg0=Sg.count('0')
Sg1=Sg.count('1')
Stotal=[Sk0,Sk1,Sg0,Sg1]
if Sk0+Sg1<Sk1+Sg0:
    print(Sk0+Sg1)
else:
    print(Sk1+Sg0)

Submission status: Accepted

Solution code:
S=input()

temp=0
for i in range(len(S)):
  if i%2==1:
    if S[i]=='0':
      temp+=1
  else:
    if S[i]=='1':
      temp+=1
#print(temp)
ans=len(S)-temp

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

print(ans)

Submission status: Accepted

Solution code:
s = list(int(x) for x in input())
n = len(s)
ans = []
#s[0]固定
count = 0
if n >= 3:
  if s[0] == s[1]:
    count += 1
for i in range(2, n):
  if i%2 == 0 and s[i] != s[0]:
    count += 1
  elif i%2 == 1 and s[i] == s[0]:
    count += 1
ans.append(count)
#s[0]変更
count = 1
if n >= 3:
  if s[0] != s[1]:
    count += 1
for i in range(2, n):
  if i%2 == 0 and s[i] == s[0]:
    count += 1
  elif i%2 == 1 and s[i] != s[0]:
    count += 1
ans.append(count)

if n == 1:
  print(0)
elif n == 2:
  if s[0] == s[1]:
    print(1)
  else:
    print(0)
else:
  print(min(ans))

Submission status: Accepted

Solution code:
s = list(input())
t1 = []
t2 = []
for i in range(len(s)):
  if i % 2 == 0:
    t1.append('0')
    t2.append('1')
  else:
    t1.append('1')
    t2.append('0')

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))
e = [i % 2 for i in range(len(s))]
o = [(i+1) % 2 for i in range(len(s))]
print(min(sum(x != y for x, y in zip(s, e)), sum(x != y for x, y in zip(s, o))))

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:
import copy

S = list(map(int, list(input()))) # str型だと書き換えの方法がスライスしかなくて面倒
N = len(S)
#print(S)
T = copy.copy(S)

ans1 = 0
ans2 = 0

for i in range(N-1):
    if S[i] == S[i+1]:
        S[i+1] = 1 ^ S[i+1]
        ans1 += 1
        #print(S)

T[0] = 1 ^ T[0]
ans2 += 1
for i in range(N-1):
    if T[i] == T[i+1]:
        T[i+1] = 1 ^ T[i+1]
        ans2 += 1
        #print(T)

ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


s = S()


str1 = '10' * (len(s) // 2) + (len(s) % 2) * '1'
str2 = '01' * (len(s) // 2) + (len(s) % 2) * '0'



cnt1 = 0

for i in range(len(s)):
    if s[i] != str1[i]:
        cnt1 += 1


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



print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
s = input()

s1 = ''.join(['1' if i%2 == 0 else '0' for i in range(len(s))])
s2 = ''.join(['0' if i%2 == 0 else '1' for i in range(len(s))])

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

Submission status: Accepted

Solution code:
S = list(input())
S = list(map(int,S))
N = len(S)
S1 = []
S2 = []
for i in range(N):
    if i%2==0:
        S1.append(0)
        S2.append(1)
    else:
        S1.append(1)
        S2.append(0)
d1 = 0
d2 = 0
for i in range(N):
    d1 += (S[i]+S1[i])%2
    d2 += (S[i]+S2[i])%2
print(min(d1,d2))

Submission status: Accepted

Solution code:
s = input()

cand1, cand2 = "", ""
if len(s) % 2 == 0:
  cand1 = "10" * (len(s) // 2)
  cand2 = "01" * (len(s) // 2)
else:
  cand1 = "0" + "10" * ((len(s) - 1) // 2)
  cand2 = "1" + "01" * ((len(s) - 1) // 2)

counter_cand1 = [s[i] == cand1[i] for i in range(len(s))]
counter_cand2 = [s[i] == cand2[i] for i in range(len(s))]

print(min(counter_cand1.count(False), counter_cand2.count(False)))

Submission status: Accepted

Solution code:
S = input()

As = []
Bs = []
count = 0
a = False
for i in range(len(S) - 1):
    count += 1
    if S[i] == S[i+1]:
        if a:
            As.append(count)
        else:
            Bs.append(count)
        a = not a
        count = 0
count += 1
if a:
    As.append(count)
else:
    Bs.append(count)

ans = sum(As) if sum(As) < sum(Bs) else sum(Bs)

print(ans)

Submission status: Accepted

Solution code:
S = list(input())

p1 = ['0' if i % 2 == 0 else '1' for i in range(len(S))]
p2 = ['0' if i % 2 == 0 else '1' for i in range(1, len(S) + 1)]

d1, d2 = 0, 0
for k in range(len(S)):
    if S[k] == p1[k]:
        d1 += 1
    if S[k] == p2[k]:
        d2 += 1

res = min(d1, d2)
print(res)

Submission status: Accepted

Solution code:
s = input()
W = 0
B = 0
for i in range(len(s)):
  if i%2==0 and s[i]=="0":
    W +=1
  if i%2!=0 and s[i]!="0":
    W +=1

for i in range(len(s)):
  if i%2==0 and s[i]=="1":
    B +=1
  if i%2!=0 and s[i]!="1":
    B +=1
    
print(min(W,B))

Submission status: Accepted

Solution code:
def change(a):
    if a == 0:
        return 1
    if a == 1:
        return 0

s = list(map(int,input()))
ans = 0
if len(s) == 0:
    print(0)
else:
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            s[i+1] = change(s[i+1])
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
a = input("")
b = list(a)
j = 0;
k = 0;
for m in b:
    if int(m) == 0 or int(m) == 1:
        k = k+1;
if k == len(b):
    if (int(b[0])==1 or int(b[0])==0) and len(b) == 1:
        j = 0
    else:
        for i in range(len(b)-1):
            if(b[i]==b[i+1]):
                if int(b[i]) == 0:
                    b[i+1] = "1"
                else:
                    b[i+1] = "0"
                j = j + 1;
            
print(j)

Submission status: Accepted

Solution code:
S=input()

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

case_w=count('1',S)
case_b=count('0',S)

print(min(case_b,case_w))

Submission status: Accepted

Solution code:
x = list(str(input()))
i = 0
counter =0
while i<len(x)-1 :
    if(x[i]==x[i+1]):
        if x[i+1]=="0":
            x[i+1]="1"
        else:
            x[i+1]="0"
       # x[i+1]=x[i-1]
        counter+=1
    i+=1
print(counter)

Submission status: Accepted

Solution code:
x=input()
x=[i for i in x]
n=len(x)
y=['1']
a=0
b=0
for i in range(n-1):
    if i%2==0:
        y.append('0')
    else:
        y.append('1')
z=['0']
for i in range(n-1):
    if i%2==0:
        z.append('1')
    else:
        z.append('0')
for i in range(n):
    if x[i]!=y[i]:
        a+=1
    if x[i]!=z[i]:
        b+=1
print(min(a,b))

Submission status: Accepted

Solution code:
c = input()
sum = 0;
cc = c[0]
if len(c)!=1:
    for i in range(1,len(c)):
        if (c[i]==cc[i-1]):
            sum+=1
            if (c[i]=='1'):
                cc+='0'
            else:
                cc+='1'
        else:
            cc+=c[i]
print(sum)