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 = input()
N = len(s)

ans = 0

goal1 = [0]*N
goal2 = [0]*N

for i in range(N):
    if i%2==0:
        goal1[i] = '0'
        goal2[i] = '1'
    else:
        goal1[i] = '1'
        goal2[i] = '0'

ans1 = 0
ans2 = 0

for i in range(N):
    if s[i] != goal1[i]:
        ans1 += 1
    if s[i] != goal2[i]:
        ans2 += 1
ans = min(ans1, ans2)

print(ans)

Submission status: Accepted

Solution code:
import sys
s = list(input())

sum0 = 0
sum1 = 0

len_s = len(s)

if len_s == 1:
    print(0)
    sys.exit()
else:
    for i in range(len_s):
        if (i % 2 == 0):
            if (s[i] == '0'):
                sum0 += 1
            else:
                sum1 += 1
        else:
            if (s[i] == '0'):
                sum1 += 1
            else:
                sum0 += 1


if (sum0 > sum1):
    print(sum1)
else:
    print(sum0)

Submission status: Accepted

Solution code:
S = input()

pattern1 = '0'
pattern2 = '1'

even = True
pattern1 = 0
pattern2 = 0
for s in S:
    if even:
        if s == '0':
            pattern1 += 1
        else:
            pattern2 += 1
    else:
        if s == '0':
            pattern2 += 1
        else:
            pattern1 += 1
    even = not even
print(str(min(pattern1, pattern2)))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
hikaku10 = ""
hikaku01 = ""
if n % 2 == 0:
    for i in range(int(n/2)):
        hikaku10 += "10"
        hikaku01 += "01"
else:
    for i in range(int((n-1)/2)):
        hikaku10 += "10"
        hikaku01 += "01"
    hikaku10 += "1"
    hikaku01 += "0"
#print(hikaku10)
#print(hikaku01)
#print(int(hikaku10,2)^int(s,2))
#print(int(hikaku01,2)^int(s,2))
#print(str(bin(int(hikaku10,2)^int(s,2)).count("1")))
#print(str(bin(int(hikaku01,2)^int(s,2))).count("1")))

print(min(str(bin(int(hikaku10,2)^int(s,2))).count("1"),str(bin(int(hikaku01,2)^int(s,2))).count("1")))

Submission status: Accepted

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

tmp = list(S)
for i in range(1, N):
    if tmp[i-1] == tmp[i]:
        if tmp[i] == '0':
            tmp[i] = '1'
        else:
            tmp[i] = '0'
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
S=input()
count=0
start=0
for i in S:
    if count%2==0:
        if i=="0":
            start+=1
    else:
        if i=="1":
            start+=1
    count+=1
if (len(S)-start)>start:
    print(start)
else:
    print(len(S)-start)

Submission status: Accepted

Solution code:
s = list(input())
cnt0 = 0
cnt1 = 0

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

print(min(cnt0, cnt1))

Submission status: Accepted

Solution code:
S = input()

first_zero_count=0
first_one_count=0

counter = '0'
for i in range (len(S)):
    if S[i] == counter:
        first_one_count += 1
    else:
        first_zero_count+=1
    if counter =='0':
        counter ='1'
    else:
        counter = '0'
    
print(min(first_one_count,first_zero_count))

Submission status: Accepted

Solution code:
S = [int(_) for _ in input()]

ptA = [_ % 2  for _ in range(len(S))]
ptB = [abs(_ - 1)  for _ in ptA]
cntA = 0
cntB = 0

for s, a, b in zip(S, ptA, ptB) :
    if s != a:
        cntA += 1

    if s != b:
        cntB += 1

ans = min(cntA, cntB)
print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
S=input()
count=0
for i in range(len(S)):
    """奇数番目を0,偶数番目を1にする"""
    if i%2==1:
        if S[i]=="1":
            count+=1
    else:
        if S[i]=="0":
            count+=1

if count<=len(S)/2:
    print(count)
else:
    print(len(S)-count)

Submission status: Accepted

Solution code:
s = [int(x) for x in list(input())]

n = len(s)

p = [s[i] == i % 2 for i in range(n)]
q = [s[i] == (i - 1) % 2 for i in range(n)]

result = min([sum(p), sum(q)])
print(result)

Submission status: Accepted

Solution code:
S=raw_input()
l=len(S)

p1=""
for i in range(l):
	p1+=str(i%2)

p2=""
for i in range(l):
	p2+=str( (i+1)%2 )

a1=0
for x,y in zip(S,p1):
	if x!=y:
		a1+=1

a2=0
for x,y in zip(S,p2):
	if x!=y:
		a2+=1

print min(a1,a2)

Submission status: Accepted

Solution code:
# coding: utf-8

colors_1 = [int(x) for x in input()]
colors_2 = colors_1.copy()

count_1 = 0
count_2 = 0

for (i, c) in enumerate(colors_1):
    if i == 0:
        continue
    else:
        if colors_1[i-1] == c:
            colors_1[i] = int(not c)
            count_1 += 1

for (i, c) in enumerate(colors_2):
    if i == 0:
        colors_2[i] = int(not c)
        count_2 += 1
    else:
        if colors_2[i-1] == c:
            colors_2[i] = int(not c)
            count_2 += 1

print(min(count_1, count_2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solv(s):
    sum0 = 0
    sum1 = 0
    b = 0
    for a in s:
        if b == a:
            sum0 += 1
        else:
            sum1 += 1
        b = 1 - b

    ans = min(sum0, sum1)
    return ans


if __name__ == '__main__':

    s = map(int, input())
    ans = solv(s)
    print(ans)

Submission status: Accepted

Solution code:
S = input()

ans1, ans2 = 0, 0

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

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s=input()
cnt=0

if s!='1': 
    for i in range(0,len(s),2):
        if s[i]=='0':
            cnt+=1
    for j in range(1,len(s),2):
        if s[j]=='1':
            cnt+=1
else:
    cnt=0

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

Submission status: Accepted

Solution code:
s = input()
odd = ''
even = ''
for i in range(len(s)):
    if i%2 == 0:
        odd = odd + s[i]
    else:
        even  = even + s[i]

odd_black_count = odd.count('0')
odd_white_count = odd.count('1')
even_black_count = even.count('0')
even_white_count = even.count('1')

print(min((odd_white_count + even_black_count),(odd_black_count + even_white_count)))

Submission status: Accepted

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

S = read()
len_s = len(S)-1
# print(S, len_s)
# ans0 = 0  # 0はじまり ->len_s-ans1で計算可能
ans1 = 0  # 1はじまり
for i, s in enumerate(S[:-1]):
    if i % 2:
        if s != '1':
            ans1 += 1
    else:
        if s != '0':
            ans1 += 1
    # print(i, ans1)

print(min(ans1, (len_s-ans1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
n=len(a)
b=[]
for i in range(n):
    if i%2==0:
        b.append('0')
    else:
        b.append('1')
res=0
for i in range(n):
    if a[i]!=b[i]:
        res+=1
if res<n/2:
    print(res)
else:
    print(n-res)

Submission status: Accepted

Solution code:
#!/snap/bin/pypy3

import operator

def main():
    S = input()

    count0 = 0
    count1 = 0

    for i, char in enumerate(S):
        bit = i % 2
        count0 += int(char) ^ bit
        count1 += int(char) ^ (not bit) 

    # print(count0, count1)
    print(min(count0, count1))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ss = input()

first_zero_count = 0
first_zero_last = '0'
first_one_count = 0
first_one_last = '1'
for s in ss:
    first_zero_count += 1 if s == first_zero_last else 0
    first_one_count += 1 if s == first_one_last else 0
    first_zero_last, first_one_last = first_one_last, first_zero_last
print(min(first_zero_count, first_one_count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
tmp = "0"
A = 0
B = 0

for ss in s:
    if tmp != ss:
        A += 1
    if tmp == "1":
        tmp = "0"
    elif tmp == "0":
        tmp = "1"

tmp = "1"
for ss in s:
    if tmp != ss:
        B += 1
    if tmp == "1":
        tmp = "0"
    elif tmp == "0":
        tmp = "1"
if A < B:
    print(A)
else:
    print(B)

Submission status: Accepted

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

Submission status: Accepted

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

S = input().rstrip()

if len(S) == 1:
    print(0)
else :
    S1 = S[0::2]
    S2 = S[1::2]

    p1 = len(S) - S1.count('1') - S2.count('0')
    p2 = len(S) - S1.count('0') - S2.count('1')

    if p1 > p2:
        print(p2)
    else:
        print(p1)

Submission status: Accepted

Solution code:
S = list(input())
 
res_10 = 0
res_01 = 0
 
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            res_10 += 1
        else:
            res_01 += 1
    else:
        if S[i] == "1":
            res_10 += 1
        else:
            res_01 += 1
print(min(res_10, res_01))

Submission status: Accepted

Solution code:
S=list(input())

# 最終形は、以下のいずれかでは？
# どちらか、近い方との差分を取る
# 1010101010...
# 0101010101...

N=len(S)

ans1=[]
ans2=[]

color=["0","1","0"]

for n in range(N):
	ans1.append(color[n%2])
	ans2.append(color[n%2+1])

# print(ans1)
# print(ans2)

diff1=0
diff2=0

for n in range(N):
	if S[n] != ans1[n]:
		diff1+=1
	if S[n] != ans2[n]:
		diff2+=1

print(min(diff1,diff2))

Submission status: Accepted

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

for i in range(1,n,2):
    if s[i:i+1] == "1":
        b += 1

print(min(a + b,n - a - b))

Submission status: Accepted

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

cnt1=0
cnt2=0
for i in range(n):
  if s[i]==a[i]:
    cnt1+=1
  if s[i]==b[i]:
    cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

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


def count_reverse(t):
    count = 0
    for i, s_i in enumerate(S):
        if s_i != t:
            count += 1
        if t == 0:
            t = 1
        else:
            t = 0
    return count


c_0 = count_reverse(0)
c_1 = count_reverse(1)
print(min(c_0, c_1))

Submission status: Accepted

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

from sys import stdin
    
def calc(s):
    ans0 = 0
    ans1 = 0
    num = 0

    for x in s:
        if num == 0:
            if x == '0':
                ans1 += 1
            else:
                ans0 += 1
        else:
            if x == '1':
                ans1 += 1
            else:
                ans0 += 1
        num = (num + 1) % 2

    return min(ans0,ans1)

def main():
    s = stdin.readline().rstrip()
    ans = calc(s)
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
n=len(s)
s1=''
s2=''
for i in range(n):
    if i%2==0:
        s1+='0'
        s2+='1'
    else:
        s1+='1'
        s2+='0'
dif1=sum(s1[i]!=s[i] for i in range(n))
dif2=sum(s2[i]!=s[i] for i in range(n))
print(min(dif1,dif2))

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
colors = [0, 1]
cnt_b, cnt_w = 0, 0
b_list = [colors[i % 2] for i in range(len(S))]

for i in range(len(S)):
    if S[i] == b_list[i]:
        cnt_w += 1
    else:
        cnt_b += 1
        
print(min([cnt_w, cnt_b]))

Submission status: Accepted

Solution code:
S = input()

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

print(min([ans1, ans2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
S = [int(t) for t in s]
N=len(S)
S_1 = [i%2 for i in range(N)]
S_2 = [(i+1)%2 for i in range(N)]


n_1 =0
n_2 =0

for i in range(N):
    if S[i]!=S_1[i]:
        n_1 += 1
    else:
        n_2 += 1
    
ans = min(n_1,n_2)
print(ans)

Submission status: Accepted

Solution code:
def solve(s):
    return min(solve_partial(s), solve_partial(s[::-1]))


def solve_partial(s):
    n = len(s)
    cs = [int(c) for c in s]
    res = 0
    for i in range(n - 1):
        if cs[i] == cs[i + 1]:
            cs[i + 1] = int(not cs[i])
            res += 1
    return res


def main():
    s = input()
    res = solve(s)
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

#先頭1からか0からのパターンで考える
next=1
count1=0
for s in ss:
    if s != next:
        count1+=1
    next = (next+1)%2

next=0
count2=0
for s in ss:
    if s != next:
        count2+=1
    next = (next+1)%2

print(min(count1,count2))

Submission status: Accepted

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

# 0101...
# 偶数：0, 奇数:1
ans1 = 0
for i, si in enumerate(s):
    if i % 2 == 0:
        if si != '0':
            ans1 += 1
    else:
        if si != '1':
            ans1 += 1

# 1010..
ans2 = 0
for i, si in enumerate(s):
    if i % 2 == 0:
        if si != '1':
            ans2 += 1
    else:
        if si != '0':
            ans2 += 1

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N = input()
countA = 0
countB = 0
for n,i in enumerate(list(N)):
    if (n % 2 == 0 and i == "1") or (n % 2 == 1 and i == "0") :# 010101 にしたいとき
        countA+=1
    if(n % 2 == 0 and i == "0") or (n % 2 == 1 and i == "1"):# 101010  にしたいとき
        countB+=1
#print(countB,countA)
print(min(countB,countA))

Submission status: Accepted

Solution code:
s=input()

n=len(s)
n1=n//2
n2=n%2

if n2==0:
    k1="01"*n1
    k2="10"*n1
else:
    k1="01"*(n1)+"0"
    k2="10"*(n1)+"1"

count1=0
count2=0

for i in range(n):
    if k1[i]==s[i]:
        count1+=1
    if k2[i]==s[i]:
        count2+=1
        
print(min(count1,count2))

Submission status: Accepted

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

evensum = 0
oddsum = 0
evenall = 0
oddall = 0

for i in range(0,n,2):
    evensum += int(s[i])
    evenall += 1
for i in range(1,n,2):
    oddsum += int(s[i])
    oddall += 1

#evenを1にするとき
evendiff = evenall-evensum
odddiff = oddsum
even1count = evendiff+odddiff 

#oddを1にするとき
evendiff = evensum
odddiff = oddall-oddsum
odd1count = evendiff+odddiff 

print(min(even1count,odd1count))

Submission status: Accepted

Solution code:
s = input()

if len(s) % 2 == 0:
    a = '01' * (len(s) // 2)
    b = '10' * (len(s) // 2)
else:
    a = '01' * (len(s) // 2) + '0'
    b = '10' * (len(s) // 2) + '1'

s_i = int(s, 2)
a_i = int(a, 2)
b_i = int(b, 2)

s1 = bin(s_i ^ a_i)[2:]
s2 = bin(s_i ^ b_i)[2:]

print(min(s1.count('1'), s2.count('1')))

Submission status: Accepted

Solution code:
S = list(input())
answer = 0
first = True
flag = ""
for i in range(len(S)):
    if(first):
        first = False
        flag = S[i]
    else:
        if(flag == S[i]):
            answer += 1
            if(S[i] == "0"):
                S[i] = "1"
            else:
                S[i] = "0"
            flag = S[i]
        else:
            flag = S[i]
print(answer)

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
# odd  = 0101010101...
# even = 1010101010
# 違ったら足す
odd = 0
even = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 0:
            even += 1
        if s[i] == 1:
            odd += 1
    else:
        if s[i] == 0:
            odd += 1
        if s[i] == 1:
            even += 1
    # print("i",i,"s[i]",s[i],"odd",odd,"even",even)
# print("odd",odd)
# print("even",even)
print(min(odd,even))

Submission status: Accepted

Solution code:
S = str(input())
Sarray = list(S)
for i in range(len(Sarray)):
    Sarray[i] = int(Sarray[i])

count = [0] * 2
for i in range(2):
    if i == 1:
        if Sarray[0] == 1:
            Sarray[0] = 0
        else:
            Sarray[0] = 1
    
    for j in range(1,len(Sarray)):
        if Sarray[j] == Sarray[j-1]:
            count[i] += 1
            if Sarray[j] == 1:
                Sarray[j] = 0
            else:
                Sarray[j] = 1

count.sort

print(count[0])

Submission status: Accepted

Solution code:
S = input()

G0 = 0
K1 = 0

total = len(S)

g = False
for i in S:
    if i == "0" and g:
        G0 += 1
    if i == "1" and not g:
        K1 += 1
    g = not g

res = total - (G0 +  K1)
res = min(res, (G0 +  K1))       
print(res)

Submission status: Accepted

Solution code:
import numpy as np

a=input()
arr_a = np.array([int(x) for x in list(a)])
arr_1 = np.array([0 if i%2 == 0 else 1 for i in range(len(a))])
arr_2 = np.array([1 if i%2 == 0 else 0 for i in range(len(a))])

print(min(np.abs(arr_1 - arr_a).sum(), np.abs(arr_2 - arr_a).sum()))

Submission status: Accepted

Solution code:
# C
s = str(input())

s = list(s)
s = list(map(lambda x: int(x), s))

count_odd = [0 for i in range(2)]
count_even = [0 for i in range(2)]

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 0:
            count_even[0] += 1
        else:
            count_even[1] += 1
    else:
        if s[i] == 0:
            count_odd[0] += 1
        else:
            count_odd[1] += 1

ans = 0
if max(count_even) > max(count_odd):
    if count_even[0] >= count_even[1]:
        ans = count_even[1] + count_odd[0]
    else:
        ans = count_even[0] + count_odd[1]
else:
    if count_odd[0] >= count_odd[1]:
        ans = count_odd[1] + count_even[0]
    else:
        ans = count_odd[0] + count_even[1]
    
print(ans)

Submission status: Accepted

Solution code:
S=input()
od0=0
ev0=0
odn=len(S)//2
for i,ch in enumerate(S):
	if i%2==0:
		if ch=="0":
			ev0+=1
	else:
		if ch=="0":
			od0+=1
print(min(ev0+odn-od0,od0+len(S)-odn-ev0))

Submission status: Accepted

Solution code:
S = input()

def count(s1, s2):
  n = len(s1)
  count = 0
  for i in range(n):
    if s1[i] != s2[i]:
      count += 1
  return count

N = len(S)
S = list(S)

final_odd = ["0"] * N
final_even = ["0"] * N

for i in range(N):
  if i % 2 == 0:
    final_odd[i] = "1"
  else:
    final_even[i] = "1"
    
print(min(count(S, final_odd), count(S, final_even)))

Submission status: Accepted

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

for i in range(len(S)):
    if (i % 2 == 0 and S[i] != '1') or (i % 2 == 1 and S[i] != '0'):
        ans[0] += 1
    if (i % 2 == 0 and S[i] != '0') or (i % 2 == 1 and S[i] != '1'):
        ans[1] += 1
    j = len(S) - i - 1
    if (j % 2 == 0 and S[j] != '1') or (j % 2 == 1 and S[j] != '0'):
        ans[2] += 1
    if (j % 2 == 0 and S[j] != '0') or (j % 2 == 1 and S[j] != '1'):
        ans[3] += 1
    
print(min(ans))

Submission status: Accepted

Solution code:
S = input()

# 理想の配置を定義
I = ''
J = ''
for i in range(len(S)):
    if i % 2 == 0:
        I += '0'
        J += '1'
    else:
        I += '1'
        J += '0'

i_c = 0
j_c = 0
for s, i, j in zip(S, I, J):
    if s != i:
        i_c += 1
    if s != j:
        j_c += 1

print(min(i_c, j_c))

Submission status: Accepted

Solution code:
s = str(input())
s = list(s)
cnt = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        cnt += 1
        if s[i] == "0":
            s[i+1] = "1"
        else:
            s[i+1] = "0"

print(cnt)

Submission status: Accepted

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

A = [ '0' if i%2 == 0 else '1' for i in range(L)]
ans = 0
for s, a in zip(S,A):
    if s == a: ans += 1
            
print(min(ans,L-ans))

Submission status: Accepted

Solution code:
S = input()

len_s = len(S)

import numpy as np
s_arr = np.array(list(map(int, list(S))))
s_arr[s_arr == 0] = -1

a_arr = np.ones(len_s)
a_arr[::2] = -1
b_arr = np.ones(len_s)
b_arr[1::2] = -1

num_a = sum((s_arr * a_arr) < 0)
num_b = sum((s_arr * b_arr) < 0)

print(min(num_a, num_b))

Submission status: Accepted

Solution code:
S = list(str(input()))
list = [int(s) for s in S]
cnta = 0
cntb = 0
for i, color in enumerate(list):
    if color == i % 2:
        cnta += 1
    else:
        cntb += 1
print(min(cnta, cntb))

Submission status: Accepted

Solution code:
S = str(input())

ans_one_start = ''
for i in range(len(S)):
    if i % 2 == 0:
        ans_one_start += '0'
    else:
        ans_one_start += '1'
        
ans_zero_start = ''
for i in range(len(S)):
    if i % 2 == 0:
        ans_zero_start += '1'
    else:
        ans_zero_start += '0'

diff_one = 0
diff_zero = 0

for i in range(len(S)):
    s_i = S[i]
    diff_i = ans_one_start[i]
    if s_i != diff_i:
        diff_one += 1
        
for i in range(len(S)):
    s_i = S[i]
    diff_i = ans_zero_start[i]
    if s_i != diff_i:
        diff_zero += 1
    
print(min(diff_one, diff_zero))

Submission status: Accepted

Solution code:
s = input()
ans1 = 0
ans2 = 0
for i in range(len(s)):
  if i % 2 == 0 and s[i] == "1":
    ans1 += 1
  elif i % 2 == 1 and s[i] == "0":
    ans1 += 1
for i in range(len(s)):
  if i % 2 == 0 and s[i] == "0":
    ans2 += 1
  elif i % 2 == 1 and s[i] == "1":
    ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = input()
even = 0
odd = 0
for i, s in enumerate(S):
    if (i + 1) % 2 == 0:
        even += int(s)
    else:
        odd += int(s)
N = len(S)
if even >= odd:
    ans = odd + N // 2 - even
else:
    if N % 2 == 0:
        ans = even + N // 2 - odd
    else:
        ans = even + N // 2 - odd + 1
print(ans)

Submission status: Accepted

Solution code:
inmap=input()

odd = {'0':0, '1':0}
ev = {'0':0, '1':0}
for i, tile in enumerate(inmap):
    if i % 2:
        odd[tile] += 1
    else:
        ev[tile] += 1

print(min( ev['0'] + odd['1'] , ev['1'] + odd['0'] ))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = [int(i) for i in input()]
s0 = [x for i,x in enumerate(S) if i % 2 == 0]
s1 = [x for i,x in enumerate(S) if i % 2 == 1]
# 0_1, 0_0, 1_1, 1_0
num01 = sum(s0)
num11 = sum(s1)
print(min(num01+len(s1)-num11, num11+len(s0)-num01))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
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 _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

S = input()
# 2通り試せばいい
# 最初を0にするか1にするか
current = '0'
ans1 = 0
for s in S:
    if s == current:
        if current == '0':
            current = '1'
        else:
            current = '0'
    else:
        # 塗り直し
        if current == '0':
            current = '1'
        else:
            current = '0'
        ans1 += 1

current = '1'
ans2 = 0

for s in S:
    if s == current:
        if current == '0':
            current = '1'
        else:
            current = '0'
    else:
        # 塗り直し
        if current == '0':
            current = '1'
        else:
            current = '0'
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

pat1 = 0
pat2 = 1
ans1 = 0
ans2 = 0

for s in S:

    if not s == str(pat1):
        ans1 += 1
    elif not s == str(pat2):
        ans2 += 1
    pat1 = abs(pat1-1)
    pat2 = abs(pat2-1)
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S=str(input())
s1=[0]
s2=[1]
for i in range(len(S)-1):
  if(s1[-1]==0): s1.append(1)
  else: s1.append(0)
for i in range(len(S)-1):
  if(s2[-1]==0): s2.append(1)
  else: s2.append(0)

d1=0
d2=0
for i,v in enumerate(S):
  d1 += abs(s1[i]-int(v))
  d2 += abs(s2[i]-int(v))

if(d1>d2): print(d2)
else: print(d1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
length=len(s)
s_list=[int(s[i]) for i in range(length)]
s_dimlist=[s[i+1]==s[i] for i in range(length-1)]
# print(s_dimlist)
pre=0
isDone=True
cnt=0
for i in range(length-1):
    if s_dimlist[i]:
        if isDone:
            pre=i
            isDone=False
        else:
            cnt+=i-pre
            isDone=True
if not isDone:
    cnt+=length-1-pre
    # print(pre,length)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
H = np.array([int(i) for i in input()])
p1 = np.array([1 if i %2==0 else 0 for i in range(len(H)) ])
p2 = np.array([0 if i %2==0 else 1 for i in range(len(H)) ])
print(min([np.sum(H!=p1),np.sum(H!=p2)]))

Submission status: Accepted

Solution code:
l = list(input())
count = 0
currStr = ""
nextStr = ""
if len(l) >= 2:    
    for i in range(len(l)-1):
        currStr = l[i]
        nextStr = l[i+1]
        if currStr == nextStr:
            count += 1
            if nextStr == "1":
                l[i+1] = "0"
            else:
                l[i+1] = "1"

print(count)

Submission status: Accepted

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

candidate_1 = "10" * (n // 2) + "1" * (n % 2)
candidate_2 = "01" * (n // 2) + "0" * (n % 2)

cnt_1 = 0
cnt_2 = 0
for elem, can1, can2 in zip(s, candidate_1, candidate_2):
    if elem != can1:
        cnt_1 += 1
    if elem != can2:
        cnt_2 += 1
print(min(cnt_1, cnt_2))

Submission status: Accepted

Solution code:
from collections import Counter
S = input()
even = Counter(S[::2])
odd = Counter(S[1::2])
ans = min(even['0']+odd['1'], even['1']+odd['0'])
print(ans)

Submission status: Accepted

Solution code:
S = input()
A = ''.join([str(i % 2) for i in range(len(S))])
B = ''.join([str((i + 1) % 2)  for i in range(len(S))])

ans1 = ans2 = 0

for a, b in zip(S, A):
    if a != b:
        ans1 += 1

for a, b in zip(S, B):
    if a != b:
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
"""
map(int,input().split())

"""
S = input()

a = S[::2]
b = S[1::2]

a0 = 0
a1 = 0
b0 = 0
b1 = 0

for i in a:
    if i == '0':
        a0+=1
    else:
        a1+=1

for j in b:
    if j == '0':
        b0+=1
    else:
        b1+=1

r = min(a0,a1,b0,b1)

if r == a0:
    print(r+b1)
elif r == a1:
    print(r+b0)
elif r == b0:
    print(r+a1)
else:
    print(r+a0)

Submission status: Accepted

Solution code:
s = input()

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

print(ans if ans < len(s)-ans else len(s)-ans)

Submission status: Accepted

Solution code:
s=input()
ans1=0
ans2=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="0":
            ans1+=1
    else:
        if s[i]=="1":
            ans1+=1
for k in range(len(s)):
    if k%2==0:
        if s[k]=="1":
            ans2+=1
    else:
        if s[k]=="0":
            ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = str(input())
S_len = len(S)

A = ('01' * 10**5)[:S_len]
B = ('10' * 10**5)[:S_len]
#print(B)

result_A = sum([a == s for a, s in zip(A, S)])
result_B = sum([b == s for b, s in zip(B, S)])
print(min([result_A, result_B]))

Submission status: Accepted

Solution code:

S = str(input())
s=len(S)
x=[0]*2
y=[0]*2

for i in range(s):
    if i%2==0 :
        if S[i]=="1":
            x[0]+=1
        else:
            x[1]+=1
    else:
        if S[i]=="1":
            y[0]+=1
        else:
            y[1]+=1
print(min(x[0]+y[1],x[1]+y[0]))

Submission status: Accepted

Solution code:
colors = input()

ans_1 = '01' * int(len(colors) / 2)
ans_2 = '10' * int(len(colors) / 2)
if len(colors) % 2 == 1:
    ans_1 = ans_1 + '0'
    ans_2 = ans_2 + '1'

replace_1 = 0
replace_2 = 0
for base, char_1, char_2 in zip(colors, ans_1, ans_2):
    if base != char_1:
        replace_1 += 1
    if base != char_2:
        replace_2 += 1
print(min(replace_1, replace_2))

Submission status: Accepted

Solution code:
import re
S = [int(item) for item in list(input())]

# 0 start
flip0 = sum(S[0::2]) + (len(S[1::2]) - sum(S[1::2]))

# 1 start
flip1 = sum(S[1::2]) + (len(S[0::2]) - sum(S[0::2]))

print(min(flip0, flip1))

Submission status: Accepted

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

Submission status: Accepted

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