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 copy

s = list(map(int,list(input())))
n = len(s)
temp_1 = copy.deepcopy(s)
temp_0 = copy.deepcopy(s)
count_0 = 0
count_1 = 0

if s[0] == 0:
  temp_1[0] = 1
  count_1 = 1
elif s[0] == 1:
  temp_0[0] = 0
  count_0 = 1

for i in range(1,n):
  if temp_1[i-1] == temp_1[i]:
    count_1 = count_1 + 1
    temp_1[i] = not(temp_1[i-1]) 
  
  if temp_0[i-1] == temp_0[i]:
    count_0 = count_0 + 1
    temp_0[i] = not(temp_0[i-1])

print(min(count_0,count_1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def count(s, start):
    cnt = 0
    n = len(s)
    e = str(start) # 偶数番目はstartの文字
    o = str((1,0)[start]) # 奇数番目はstartでない文字（0,1を逆にする）
    for i in range(n):
        if i%2==0 and s[i] != e: cnt += 1
        elif i%2==1 and s[i] != o: cnt += 1
    return cnt

def main():
    S = input()
    cnt_0 = count(S, 0)
    cnt_1 = count(S, 1)
    print(min(cnt_0, cnt_1))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
x = sum([c=='0' for c in S[::2]]) + sum([c=='1' for c in S[1::2]])
y = sum([c=='1' for c in S[::2]]) + sum([c=='0' for c in S[1::2]])
print(min(x, y))

Submission status: Accepted

Solution code:
s = input()

ans=0
slist= [int(i) for i in s]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
ans1 = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] == '0':
            ans1 += 1
    else:
        if s[i] == '1':
            ans1 += 1
ans2 = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] == '1':
            ans2 += 1
    else:
        if s[i] == '0':
            ans2 += 1
ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

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

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

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

print(min(res, res2))

Submission status: Accepted

Solution code:
import numpy as np
s = input()
n = len(s)
ans = 0
for i in range(n // 2 + 1):
	if 2 * i == n:
		break
	if s[2 * i] == "0":
		ans += 1
	if 2 * i + 1 == n:
		break
	if s[2 * i + 1] == "1":
		ans += 1
print(min(ans, n - ans))

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  s = input()
  count_01 = 0
  count_10 = 0
  n = len(s)
  for i in range(n):
    if i%2==0:
      if s[i] == '0':
        count_01 += 1
      else:
        count_10 +=1
    else:
      if s[i] == '1':
        count_01 += 1
      else:
        count_10 += 1
  print(min(n-count_01,n-count_10))
        
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        if S[i] == "0":
            S[i+1] = "1"
        else:
            S[i+1] = "0"
        count += 1
print(count)

Submission status: Accepted

Solution code:
S = input()

n_01 = 0
S_0 = S[0::2]
S_1 = S[1::2]
n_01 = S_0.count("1") + S_1.count("0")
n_10 = S_0.count("0") + S_1.count("1")
print(min(n_01, n_10))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
s1=[]
s2=[]
a=0
b=0
for i in range(len(s)):
    if i%2==0:
        s1.append("0")
    else:
        s1.append("1")
for i in range(len(s)):
    if i%2==0:
        s2.append("1")
    else:
        s2.append("0")
for i in range(len(s)):
    if s[i]==s1[i]:
        a+=1
    if s[i]==s2[i]:
        b+=1
print(min(a,b))

Submission status: Accepted

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

Submission status: Accepted

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

    c0, c1 = 0, 0
    for i, c in enumerate(s):
        if i % 2 == 0:
            if c == '0':
                c1 += 1

            else:
                c0 += 1

        else:
            if c == '0':
                c0 += 1

            else:
                c1 += 1

    print(min(c0, c1))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
ans = 0
t = "01" * len(s)

for i in range(len(s)):
  if s[i] != t[i]:
    ans = ans + 1  
  
print(min(ans, abs(len(s)-ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

S = input()

if len(S) == 1:
    goal_1 = '1'
    goal_2 = '0'

elif len(S) % 2 == 1:
    goal_1 = "10" * (len(S) // 2) + "1"
    goal_2 = "01" * (len(S) // 2) + "0"

else:
    goal_1 = "10" * (len(S) // 2)
    goal_2 = "01" * (len(S) // 2)

ans_1 = 0
ans_2 = 0
for i in range(len(S)):
    if S[i] != goal_1[i]:
        ans_1 += 1
    if S[i] != goal_2[i]:
        ans_2 += 1

print(min(ans_1, ans_2))

Submission status: Accepted

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

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

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S=input()
cnt=0
for i in range(len(S)):
    if i%2==0 and S[i]=="0":
        cnt+=1
    if i%2==1 and S[i]=="1":
        cnt+=1  

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

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect,copy
s=list(input())
s2=copy.deepcopy(s)
ans=0
if len(s)=="1":
    print(0)
    exit()
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        if s[i]=="0":
            s[i+1]="1"
        else:
            s[i+1]="0"
        ans+=1
if s2[0]=="0":
    s2[0]="1"
    ans2=1
else:
    s2[0]="0"
    ans2=1
for i in range(len(s2)-1):
    if s2[i]==s2[i+1]:
        if s2[i]=="0":
            s2[i+1]="1"
        else:
            s2[i+1]="0"
        ans2+=1
print(min(ans,ans2))

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    s = input()
    # 奇数番目を黒くするか，偶数番目を黒くするかを考えればよく，片方を調べるともう片方も求めることができる
    n = len(s)
    # odd
    cnt = 0
    for i in range(n):
        if i%2 == 1 and s[i] == '1':
            cnt += 1
        if i%2 == 0 and s[i] == '0':
            cnt += 1
    print(min(cnt, n-cnt))
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
L = len(S)
oioi =""
ioio =""
Aoi = 0
Aio = 0
for i in range(L):
  if i%2 == 0:
    oioi = oioi+"0"
    ioio = ioio+"1"
  else:
    oioi = oioi + "1"
    ioio = ioio + "0"

for j in range(L):
  if S[j] != oioi[j]:
    Aoi = Aoi+1
  
  if S[j] != ioio[j]:
    Aio = Aio+1

print(min(Aoi,Aio))

Submission status: Accepted

Solution code:
color = [int(i) for i in input()]
n = len(color)
ans = 0

if n%2==1:
    arfa = [1,0]*(n//2) + [1]
    beta = [0,1]*(n//2) + [0]
else:
    arfa = [1,0]*(n//2)
    beta = [0,1]*(n//2)

ansa=0;ansb=0
for i in range(n):
    if color[i]!=arfa[i]:
        ansa += 1
    if color[i]!=beta[i]:
        ansb += 1
print(min([ansa,ansb]))

Submission status: Accepted

Solution code:
s = input()

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

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

if ct1 <= ct2:
    print(ct1)
else:
    print(ct2)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    n = len(s)
    a,b = 0,0
    for i in range(n):
        if i%2==0:
            if s[i]=='0':
                a += 1
        else:
            if s[i]=='1':
                a += 1

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

    print(min(a,b))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

change_a=0
for i in range(length):
    if i%2==0 and S[i]=='1':
        change_a+=1
    if i%2==1 and S[i]=='0':
        change_a+=1

change_b=0
for i in range(length):
    if i%2==0 and S[i]=='0':
        change_b+=1
    if i%2==1 and S[i]=='1':
        change_b+=1

print(min(change_a, change_b))

Submission status: Accepted

Solution code:
S = input()
nS = len(S)
white = ("01"*100000)[:nS]
black = ("10"*100000)[:nS]
sa_white = len([1 for x,y in zip(S, white) if x!=y])
sa_black = len([1 for x,y in zip(S, black) if x!=y])
print(min(sa_white, sa_black))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    cnt = 0
    if(S[0] == "0"):
        if(len(S)%2 == 0):
            ans = "01"*(len(S)//2)
        else:
            ans = "01"*(len(S)//2)+"0"
    else:
        if(len(S)%2 == 0):
            ans = "10"*(len(S)//2)
        else:
            ans = "10"*(len(S)//2)+"1"
    
    for i in range(len(S)):
        if(S[i] != ans[i]):
            cnt += 1
    print(cnt)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s_list1 = list(input())
n = len(s_list1)
s_list2 = s_list1.copy()
dic = {"0": "1", "1": "0"}
# first0
ans1 = 0
for i in range(n):
    if i == 0:
        if s_list1[i] == 1:
            s_list1[i] = 0
            ans1 += 1
    else:
        if s_list1[i - 1] == s_list1[i]:
            s_list1[i] = dic[s_list1[i - 1]]
            ans1 += 1

# first1
ans2 = 0
for i in range(n):
    if i == 0:
        if s_list2[i] == 0:
            s_list2[i] = 1
            ans2 += 1
    else:
        if s_list2[i - 1] == s_list2[i]:
            s_list2[i] = dic[s_list2[i - 1]]
            ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
for i in range(n):
    if (i & 1) ^ int(s[i]):
        count += 1
print(min(count,n-count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input();z=sum([int(s[i])==i%2 for i in range(len(s))]);print(min(z,len(s)-z))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

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

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

print(min(count, count2))

Submission status: Accepted

Solution code:
s = input()
first_white = 0
first_brack = 0
for si in s[::2]:
    if si == '0':
        first_brack += 1
    else:
        first_white += 1
for si in s[1::2]:
    if si == '0':
        first_white += 1
    else:
        first_brack += 1
print(min(first_brack, first_white))

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

S = input()

cnt1, cnt2 = 0, 0
for i, c in enumerate(S):
    if i % 2 == 0:
        if c == '1':
            cnt1 += 1
        else:
            cnt2 += 1
    else:
        if c == '1':
            cnt2 += 1
        else:
            cnt1 += 1
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
a = input()
l1 = a[::2]
l2 = a[1::2]
x, y = 0, 0
for i in range(len(l1)):
  if l1[i] =='1':
    x +=1
for i in range(len(l2)):
  if l2[i] =='0':
    y +=1
print(min(x +y,len(l1)-x + len(l2)-y))

Submission status: Accepted

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

x1 = 0
x2 = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] == '1':
            x1 += 1
        else:
            x2 += 1
    elif i % 2 == 1:
        if s[i] == '0':
            x1 += 1
        else:
            x2 += 1

print(min(x1, x2))

Submission status: Accepted

Solution code:
s = input()

s_01 = ''
s_10 = ''

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

for i in range(1,len(s)+1):
    if i % 2 == 1:
        s_10 += '1'
    
    else:
        s_10 += '0'
    
c_01 = 0
c_10 = 0

for i in range(len(s)):
    if s[i] != s_01[i]:
        c_01 += 1
    
    if s[i] != s_10[i]:
        c_10 += 1

print(min(c_10,c_01))

Submission status: Accepted

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

N = len(S)
if N % 2 == 0:
  op1 = [0, 1] * int(N//2)
  op2 = [1, 0] * int(N//2)
else:
  op1 = [0, 1] * int(N//2) + [0]
  op2 = [1, 0] * int(N//2) + [1]
  
cnt_op1 = 0
cnt_op2 = 0
for i in range(N):
  if list_S[i] != op1[i]:
    cnt_op1 += 1
  if list_S[i] != op2[i]:
    cnt_op2 += 1

print(min(cnt_op1, cnt_op2))

Submission status: Accepted

Solution code:
s = 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(len(s)-count, count))

Submission status: Accepted

Solution code:
A = list(input())
count = 0
if int(A[0]) == 1:
    flg = 1
else:
    flg = 0
for i in A:
    if int(i) == flg:
        if flg == 0:
            flg = 1
        else:
            flg = 0
    else:
        count += 1
        if flg == 0:
            flg = 1
        else:
            flg = 0
print(count)

Submission status: Accepted

Solution code:
s=input()
if s.count('01')>s.count('10') or (s.count('01')==s.count('10') and s[0]=='0'):
    cvf='0'
    cvb='1'
else:
    cvf='1'
    cvb='0'
c=0
for i in range(0,len(s),2):
    if s[i] != cvf:
        c+=1
    try:
        if s[i+1] != cvb:
            c+=1
    except IndexError:
        break
print(c)

Submission status: Accepted

Solution code:
S = list(map(int,(input())))
N = len(S)
pa = [None]*N
pb = [None]*N

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

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

ca = 0
cb = 0
for i in range(N):
    ca += abs(pa[i] - S[i])
    cb += abs(pb[i] - S[i])

print(min(ca,cb))

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    S = input()
    A = [int(c) for c in S]

    temp1=[0]*len(S)
    for i in range(0,len(S),2):
        temp1[i]=1

    temp2=[0]*len(S)
    for i in range(1,len(S),2):
        temp2[i]=1

    cnt1=0
    cnt2=0
    for i in range(len(S)):
        if A[i]!=temp1[i]:
            cnt1+=1
        if A[i]!=temp2[i]:
            cnt2+=1

    print(min(cnt1,cnt2))





resolve()

Submission status: Accepted

Solution code:
s = input()
# 偶数番目, 奇数番目を取り出すならスライス使おう!
c = s[::2].count('0') + s[1::2].count('1')
print(min(c, len(s)-c))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
ans1, ans2 = 0, 0
for i, s in enumerate(S):
    m = int(s)
    if i % 2:
        ans1 += 1 - m
        ans2 += m
    else:
        ans1 += m
        ans2 += 1 - m
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    N=len(S)

    #S[0]=="1"
    count0=0
    count1=0
    for i in range(N):
        if i%2==0:
            if S[i]=="0":
                count0+=1
            elif S[i]=="1":
                count1+=1
        else:
            if S[i]=="1":
                count0+=1
            elif S[i]=="0":
                count1+=1

    print(min(count0,count1))
        
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
l = len(S)
ideal1 = '10' * (l // 2)
ideal2 = '01' * (l // 2)
if l % 2 == 1:
    ideal1 += '1'
    ideal2 += '0'
cnt1 = 0
cnt2 = 0

for i in range(l):
    if ideal1[i] != S[i]:
        cnt1 += 1
    if ideal2[i] != S[i]:
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S = input()

pat0 = 0  # 010101010...
pat1 = 0  # 101010101...

for i, c in enumerate(S):
    if i % 2 == 0:
        if c == '0':
            pat0 += 1
        else:
            pat1 += 1
    else:
        if c == '0':
            pat1 += 1
        else:
            pat0 += 1

N = len(S)
print(min(N - pat0, N - pat1))

Submission status: Accepted

Solution code:
s = input()

ans = 10 ** 9
a = 0
for i, j in enumerate(s):
    if i % 2 != int(j):
        a += 1
ans = min(ans, a)

a = 0
for i, j in enumerate(s):
    if i % 2 == int(j):
        a += 1
ans = min(ans, a)

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
count_f1 = 0
count_f0 = 0
#101010
for i in range(N):
    if i % 2 == 0 and S[i] != "1":
        count_f1 += 1
    elif i % 2 == 1 and S[i] != "0":
        count_f1 += 1

for i in range(N):
    if i % 2 == 0 and S[i] != "0":
        count_f0 += 1
    elif i % 2 == 1 and S[i] != "1":
        count_f0 += 1

print(min(count_f1,count_f0))

Submission status: Accepted

Solution code:
s = input()
if len(s)%2 == 0:
    ans = "10"*(len(s)//2)
    ans2 = "01"*(len(s)//2)
    cnt = 0
    cnt2 = 0
    for i in range(len(s)):
        if ans[i] != s[i]:
            cnt+=1
        if ans2[i] != s[i]:
            cnt2+=1
else:
    ans = "10"*(len(s)//2)+"1"
    ans2 = "01"*(len(s)//2) + "0"
    cnt = 0
    cnt2 = 0
    for i in range(len(s)):
        if ans[i] != s[i]:
            cnt+=1
        if ans2[i] != s[i]:
            cnt2+=1
ans = min(cnt,cnt2)
print(ans)

Submission status: Accepted

Solution code:
s = input()
a = 0
b = 0
for i in range(len(s)):
    if i & 1:
        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:
s = list(input())
ans = 0
for i in range(1,len(s)):
    if s[i-1] == '1' and s[i] == '1':
        s[i] = '0'
        ans += 1
    elif s[i-1] == '0' and s[i] == '0':
        s[i] = '1'
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
pattern_1 = []
pattern_2 = []
cnt_1 = 0
cnt_2 = 0

for i in range(len(S)):
    if i % 2 == 0:
        pattern_1.append('1')
        pattern_2.append('0')
    else:
        pattern_1.append('0')
        pattern_2.append('1')

for (s, a, b) in zip(S, pattern_1, pattern_2):
    if s != a:
        cnt_1 += 1
    if s != b:
        cnt_2 += 1

print(min(cnt_1, cnt_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

res1, res2 = len(s), len(s)
for i in range(len(s)):
    if i % 2 == 0:
        if int(s[i]) == 0:
            res1 -= 1
        if int(s[i]) == 1:
            res2 -= 1
    else:
        if int(s[i]) == 1:
            res1 -= 1
        if int(s[i]) == 0:
            res2 -= 1

ans = min(res1, res2)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
S = [int(s) for s in input()]
p1 = [1 if i % 2 == 0 else 0 for i in range(len(S))]
p2 = [0 if i % 2 == 0 else 1 for i in range(len(S))]
print(min(np.count_nonzero(np.logical_xor(p1, S)), np.count_nonzero(np.logical_xor(p2, S))))

Submission status: Accepted

Solution code:
s = input()

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

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

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
n = input()
list_n = list(n)
c = len(list_n)
ans_a = 0
ans_b = 0

for i in range(c):
    if i % 2 == 0:
        if list_n[i] == "0":
            ans_a += 1
    if i % 2 == 1:
        if list_n[i] == "1":
            ans_a += 1

for i in range(c):
    if i % 2 == 0:
        if list_n[i] == "1":
            ans_b += 1
    if i % 2 == 1:
        if list_n[i] == "0":
            ans_b += 1

print(min(ans_a, ans_b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(str(input()))

arr = list(map(int, s))

ref1 = [0] * len(s)
for i in range(len(ref1)):
    if i % 2 == 0:
        ref1[i] = 1

ref2 = [0] * len(s)
for i in range(len(ref2)):
    if i % 2 == 1:
        ref2[i] = 1

score1 = 0
for i in range(len(s)):
    if ref1[i] != arr[i]:
        score1 += 1


score2 = 0
for i in range(len(s)):
    if ref2[i] != arr[i]:
        score2 += 1
    
print(min(score1,score2))

Submission status: Accepted

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

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

print(min(count, L-count))

Submission status: Accepted

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


def main():

    S = input()

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

    result = min(bin(int(S, 2) ^ int(a, 2)).count("1"),
                 bin(int(S, 2) ^ int(b, 2)).count("1"))

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def main():
    S = list(map(int, list(input())))

    result = 0
    for i in range(1, len(S)):

        if S[i - 1] == S[i]:
            if S[i] == 1:
                S[i] = 0
            else:
                S[i] = 1
            result += 1

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

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

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

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
e_cnt, o_cnt = 0, 0
for i in range(len(S)):
  if S[i] != str(i % 2):
    e_cnt += 1
  elif S[i] != str((i+1) % 2):
    o_cnt += 1
print(min(e_cnt, o_cnt))

Submission status: Accepted

Solution code:
S=input()

A="01"*(len(S)//2)+"0"*(len(S)%2)
count_A=0

B="10"*(len(S)//2)+"1"*(len(S)%2)
count_B=0

for i in range(len(S)):
    if S[i]!=A[i]:
        count_A+=1
    if S[i]!=B[i]:
        count_B+=1

print(min(count_A,count_B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

S = input()
odd = [0,0]
even = [0,0]
for i,s in enumerate(S):
  if i % 2 == 0:
    even[int(s)]+=1
  else:
    odd[int(s)]+=1
o0e1 = odd[1]+even[0]
o1e0 = odd[0]+even[1]
print(min(o0e1,o1e0))

Submission status: Accepted

Solution code:

s = input()

ans1 = 0
ans2 = 0

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

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s=input()
t='01'*(len(s))
d1=0
#0101...と違う個数
d2=0
#1010...と違う個数
for i in range(len(s)):
    if s[i]!=t[i]:
        d1+=1
    if s[i]!=t[i+1]:
        d2+=1
print(min(d1,d2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

for i in range(len(S)) :
    if i%2 == 0 and S[i] == "1" :
        ans2 += 1
    elif i%2 == 1 and S[i] == "0" :
        ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
l = len(S)
tmp0 = ''
tmp1 = ''
for i in range(l):
    if i&1:
        tmp0 += '0'
        tmp1 += '1'
    else:
        tmp0 += '1'
        tmp1 += '0'

cnt0 = 0
cnt1 = 0
for i in range(l):
    if S[i]==tmp0[i]:
        cnt0 += 1
    if S[i]==tmp1[i]:
        cnt1 += 1
print(min(cnt0,cnt1))

Submission status: Accepted

Solution code:
def main():
  s=list(input())
  count1,count2,l=0,0,len(s)
  for i in range(l):
    count1=count1+1 if (i%2==0 and int(s[i])==1) or (i%2==1 and int(s[i])==0) else count1
    count2=count2+1 if (i%2==1 and int(s[i])==1) or (i%2==0 and int(s[i])==0) else count2
  print(min(count1,count2))

if __name__=='__main__':
  main()