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:
N = input()
S = [int(c) for c in N]

A = [0] * (len(S)+4)
B = [0] * (len(S)+4)

for i in range((len(S)//2)+1):
  A[i*2+1] = 1
  B[i*2] = 1
  
ca =0
cb =0
for i in range(len(S)):
  ca += abs(S[i]-A[i])
  cb += abs(S[i]-B[i])
print(min(ca, cb))

Submission status: Accepted

Solution code:
s=input()

BW=s[::2]
WB=s[1::2]

x=BW.count("0") + WB.count("1")
y=BW.count("1") + WB.count("0")

print(min(x,y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
bw, wb = 0, 0 #bwbwbw... と wbwbwb...
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == '0':
      wb += 1
    else:
      bw += 1
  else:
    if s[i] == '0':
      bw += 1
    else:
      wb += 1
print(min(bw, wb))

Submission status: Accepted

Solution code:
s=input()
a=0
if s=='0':
  print(0)
else:
  for i in s[0::2]:
    if i=='0':
      a+=1
  for j in s[1::2]:
    if j=='1':
      a+=1
  print(min(a,len(s)-a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
d,m = len(S)//2,len(S)%2
A = '01'*d+'0'*m
B = '10'*d+'1'*m
count_a = 0
count_b = 0
for s,a,b in zip(S,A,B):
    if s != a:
        count_a += 1
    if s != b:
        count_b += 1
print(min(count_a, count_b))

Submission status: Accepted

Solution code:
S = input()
d,m = len(S)//2,len(S)%2
A = '01'*d+'0'*m
B = '10'*d+'1'*m
count_a = 0
count_b = 0
for s,a,b in zip(S,A,B):
    if s != a:
        count_a += 1
    if s != b:
        count_b += 1
print(min(count_a, count_b))

Submission status: Accepted

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

a = []
b = []
counta = 0
countb = 0
for i in range(n):
    if i % 2 == 0:
        a.append("0")
        b.append("1")
    else:
        a.append("1")
        b.append("0")
    if s[i] != a[i]:
        counta += 1
    if s[i] != b[i]:
        countb += 1
print(min(counta,countb))

Submission status: Accepted

Solution code:
S=input()

one_start=["1","0"]
one_start_count=0

zero_start=["0","1"]
zero_start_count=0

for i,subs in enumerate(S):
    if subs !=one_start[i%2]:
        one_start_count+=1
    elif subs != zero_start[i%2]:
        zero_start_count+=1
        

print(min(one_start_count, zero_start_count))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    S = str(input())
    
    N = len(S)
    S_0 = '01'*N
    S_0 = S_0[:N]
    S_1 = '10'*N
    S_1 = S_1[:N]
    
    count_0 = 0
    count_1 = 0
    for i in range(N):
        if S[i] != S_0[i]:
            count_0 += 1
        if S[i] != S_1[i]:
            count_1 += 1
    print(min(count_0, count_1))

Submission status: Accepted

Solution code:
s = input()

targets = []
if len(s) % 2 == 0:
    tmp_1 = ''
    tmp_2 = ''
    for i in range(len(s)//2):
        tmp_1 += '10'
        tmp_2 += '01'
    targets.append(tmp_1)
    targets.append(tmp_2)
else:
    tmp_1 = ''
    tmp_2 = ''
    for i in range(len(s)//2):
        tmp_1 += '10'
        tmp_2 += '01'
    tmp_1 += '1'
    tmp_2 += '0'
    targets.append(tmp_1)
    targets.append(tmp_2)

res = len(s)
for target in targets:
    count = 0
    for i in range(len(target)):
        if target[i] != s[i]:
            count += 1
    res = min(res, count)

print(res)

Submission status: Accepted

Solution code:
S=input()
l=len(S)
A='01'*(l//2)+'0'*(l%2)
c=0
for i in range(l):
  if A[i]==S[i]:c+=1
print(min(c,l-c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

S = list(int(x) for x in input())

L1 = np.array([0 if x % 2 == 0 else 1 for x in range(len(S))] )
L2 = np.array([1 if x % 2 == 0 else 0 for x in range(len(S))])

print(min(sum(np.logical_xor(S, L2)), sum(np.logical_xor(S, L1))))

Submission status: Accepted

Solution code:
s = input()
c = 0

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "0":
            c += 1
    else:
        if s[i] == "1":
            c += 1
if len(s) - c < c:
    c = len(s) - c
print(c)

Submission status: Accepted

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
s = input().strip()
cs = list(map(int, list(s)))
n = len(cs)

a = [0 for _ in range(n)]
for i in range(n):
    if i % 2 == 0:
        a[i] = 1
b = [1 for _ in range(n)]
for i in range(n):
    if i % 2 == 0:
        b[i] = 0

res0 = 0
for x, y in zip(cs, a):
    res0 += abs(x - y)
res1 = 0
for x, y in zip(cs, b):
    res1 += abs(x - y)
print(min(res0, res1))

Submission status: Accepted

Solution code:
s = input()

import numpy as np

s = np.array(list(s))
ans1 = []
ans2 = []
for i in range(len(s)):
    if i%2:
        ans1.append("0")
        ans2.append("1")
    else:
        ans1.append("1")
        ans2.append("0")

print(min(sum(s==ans1), sum(s==ans2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

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

print(min(cnt_start0, cnt_start1))

Submission status: Accepted

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

    cnt1 = 0

    # 先頭を1にする場合
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == '0':
                cnt1 += 1
        else:
            if s == '1':
                cnt1 += 1

    cnt2 = 0
    # 先頭を0にする場合
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == '1':
                cnt2 += 1
        else:
            if s == '0':
                cnt2 += 1

    print(min(cnt1,cnt2))



main()

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()

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

answb,ansbw=0,0
for i in range(len(S)):
  if S[i]!=WB[i]:
    answb+=1
  else:
    ansbw+=1
print(min(answb,ansbw))

Submission status: Accepted

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

T = [(1 + (-1)**i) / 2 for i in range(len(S))]
U = [(1 + (-1)**(i-1)) / 2 for i in range(len(S))]

st = sum([abs(s-t) for s, t in zip(S, T)])
su = sum([abs(s-u) for s, u in zip(S, U)])

print(int(min(st, su)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
toBeList1 = []
toBeList2 = []
ans1 = 0
ans2 = 0
for i in range(len(s)):
  toBeList1.append(str(i%2))
  toBeList2.append(str((i+1)%2))
  if s[i] != toBeList1[i]:
    ans1 += 1
  if s[i] != toBeList2[i]:
    ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
E = ''
O = ''
for i in range(len(S)):
  if i % 2 == 0:
    E += '1'
    O += '0'
  else:
    E += '0'
    O += '1'
p, q = 0, 0
for i in range(len(S)):
  if E[i] != S[i]:
    p += 1
  if O[i] != S[i]:
    q += 1
print(min(p, q))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=[int(i) for i in input()]
c=0
l=len(s)
for i in range(l):
    if (i%2==0 and s[i]==0) or (i%2==1 and s[i]==1):
        pass
    else:
        c+=1
print(min([c,l-c]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s) // 2 + 1
l1 = "01" * n
l2 = "10" * n
a1 = 0
a2 = 0
for i in range(len(s)):
    if l1[i] != s[i]:
        a1 += 1
    if l2[i] != s[i]:
        a2 += 1
    
print(min(a1, a2))

Submission status: Accepted

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

def main():
    s = input().strip()
    S = [int(i) for i in s]
    n1 = 0
    n2 = 0
    for i,v in enumerate(S):
        if i%2 == 0:
            if v == 0:
                n1 += 1
            else:
                n2 += 1
        else:
            if v == 1:
                n1 += 1
            else:
                n2 += 1
    print(min(n1,n2))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
prev = S[0]
res = 0
for i in range(1, len(S)):
  if prev == S[i]:
    res += 1
  prev = ["1", "0"][int(prev == "1")]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
n = len(S)
templ1 = ""
templ2 = ""
if n&1:
    templ1 = "10" * (n//2) + "1"
    templ2 = "01" * (n//2) + "0"
else:
    templ1 = "10" * (n//2)
    templ2 = "01" * (n//2)

diff1 = 0
diff2 = 0
for s,t1,t2 in zip(S,templ1,templ2):
    if s != t1:
        diff1 += 1
    if s != t2:
        diff2 += 1
print(min(diff1,diff2))

Submission status: Accepted

Solution code:
S = input()
pattern1 = "".join([str(x%2) for x in range(len(S))])
pattern2 = "".join([str((x+1)%2) for x in range(len(S))])

def energy(st1, st2):
  ene = 0
  for i in range(len(st1)):
    ene += abs(int(st1[i])-int(st2[i]))
  return ene

print(min(energy(S, pattern1), energy(S, pattern2)))

Submission status: Accepted

Solution code:
S = list(input())
l = len(S)
if l%2 == 0:
    ans = ['0', '1']*int(l/2)
else:
    ans = ['0', '1']*int(l//2)
    ans.append('0')

cnt = 0
for i in range(l):
    if ans[i] != S[i]:
        cnt += 1

print(min(cnt, l-cnt))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = "10"*(n//2) + '1'*(n%2)
p = 0

for i in range(n):
    if s[i]!=a[i]: p+=1

print(min(p,n-p))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def dif(s, l):
    diff = 0
    for i, j in zip(s, l):
        if i != j:
            diff += 1
    return diff


S = list(input())
S = list(map(int, S))
L1 = [int(1) if i % 2 == 0 else int(0) for i in range(len(S))]
L2 = [int(0) if i % 2 == 0 else int(1) for i in range(len(S))]
print(min(dif(S, L1), dif(S, L2)))

Submission status: Accepted

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

A = [i%2 for i in range(n)]
B = [(i+1)%2 for i in range(n)]

ans0 = 0
ans1 = 0

for i in range(n):
    if int(s[i]) != A[i]:
        ans0 += 1
    if int(s[i]) != B[i]:
        ans1 += 1

print(min(ans0, ans1))

Submission status: Accepted

Solution code:
def MAP(): return map(int,input().split())
s = input()
ans_1, ans_2= 0,0
for i,v in enumerate(s):
    if (i%2==0) and (v!="0"):
        ans_1+=1
    elif (i%2==1) and (v!="1"):
        ans_1+=1

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

print(min(ans_1,ans_2))

Submission status: Accepted

Solution code:
import numpy as np
S = np.array(list(input()), dtype = int)
r = [0,0]
for ii in range(2):
    l = np.zeros(len(S), dtype = int)
    l[ii::2] = 1
    r[ii] = abs(S - l).sum()

print (min(r))

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))
x = [i % 2 for i in range(len(s))]
y = [i % 2 for i in range(1, len(s) + 1)]
cntx = cnty = 0
for i, j, k in zip(s, x, y):
    if i != j:
        cntx += 1
    if i != k:
        cnty += 1
print(min(cntx, cnty))

Submission status: Accepted

Solution code:
import math
S = input()



kzero = 0
kone = 0
gzero = 0
gone = 0


buff1 = [0 for i in range(2)]
buff2 = [0 for i in range(2)]

_len = len(S)
gu_kazu = math.ceil(_len/2)
ki_kazu = _len//2

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

    else:
        if S[i] == '0':
            buff2[0] += 1
        else:
            buff2[1] += 1

print(min(gu_kazu-buff1[0]+ki_kazu-buff2[1],gu_kazu-buff1[1]+ki_kazu-buff2[0]))

Submission status: Accepted

Solution code:
def dist(x, y):
    return sum([0 if x == y else 1 for x, y in zip(x, y)])


S = list(input())

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

print(min(dist(S, p1), dist(S, p2)))

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
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()
ans1,ans2 = 0,0
for i in range(len(s)):
    if i % 2:
        if s[i] == '0':
            ans1 += 1
        else:
            ans2 += 1
    else:
        if s[i] == '1':
            ans1 += 1
        else:
            ans2 += 1
ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

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

a = [abs(s[i]-1) if i%2==0 else s[i] for i in range(len(s))]
b = [abs(s[i]-1) if i%2==1 else s[i] for i in range(len(s))]
print(min(sum(a),sum(b)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n % 2 == 1:
    pattern1 = '01' * (n // 2) + '0'
    pattern2 = '10' * (n // 2) + '1'
else:
    pattern1 = '01' * (n // 2)
    pattern2 = '10' * (n // 2)

diff1 = 0
diff2 = 0
for i in range(n):
    if pattern1[i] != s[i]:
        diff1 += 1
    if pattern2[i] != s[i]:
        diff2 += 1
print(min(diff1, diff2))

Submission status: Accepted

Solution code:
s = input()
cnt_01 = 0
cnt_10 = 0

for i in range(len(s)):
    if (i % 2 == 0 and s[i] == "0") or (i % 2 == 1 and s[i] == "1"):
        cnt_01 += 1
    if (i % 2 == 0 and s[i] == "1") or (i % 2 == 1 and s[i] == "0"):
        cnt_10 += 1

print(min(cnt_01, cnt_10))

Submission status: Accepted

Solution code:
s = input()


def count(a):
    global s
    cnt = 0
    for i in range(len(s)):
        if (i % 2 == 0 and s[i] == a[0]) or (i % 2 == 1 and s[i] == a[1]):
            cnt += 1
    return cnt


print(min(count("10"), count("01")))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
inputlist = list(n)

ansZero = 0
ansOne = 0

flg = False
for i in range(len(n)):
    if flg:
        if inputlist[i]=="0":
            ansZero+=1
    else:
        if inputlist[i]=="1":
            ansZero+=1
    flg = not flg

flg = True
for i in range(len(n)):
    if flg:
        if inputlist[i]=="0":
            ansOne+=1
    else:
        if inputlist[i]=="1":
            ansOne+=1
    flg = not flg

ans = min(ansZero, ansOne)

print(ans)

Submission status: Accepted

Solution code:
N = list(input())

ans1 = 0
expected = N[0]
for n in N[1:]:
    if expected == n:
        ans1 += 1
        if n == '0':
            expected = '1'
        else:
            expected = '0'
    else:
        expected = n

N.reverse()
ans2 = 0
expected = N[0]
for n in N[1:]:
    if expected == n:
        ans2 += 1
        if n == '0':
            expected = '1'
        else:
            expected = '0'
    else:
        expected = n


print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s=input()

d={'0':'1','1':'0'}

s1='1'
s2='0'
cnt1=0
cnt2=0
for a in s:
	if s1!=a:cnt1+=1
	if s2!=a:cnt2+=1
	s1=d[s1]
	s2=d[s2]
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
S = int(S, 2)

A = '0b'
B = '0b'
for i in range(n):
    if i % 2 == 0:
        A += '0'
        B += '1'
    else:
        A += '1'
        B += '0'

ans = min(bin(S ^ int(A, 0)).count('1'), bin(S ^ int(B, 0)).count('1'))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

per0 = str('0')
for i in range(l-1):
    if (i+1)%2 == 0:
        per0 = per0 + str('0')
    else:
        per0 = per0 + str('1')

per1 = str('1')
for i in range(l-1):
    if (i+1)%2 == 0:
        per1 = per1 + str('1')
    else:
        per1 = per1 + str('0')

count0 = 0
count1 = 0
for i in range(l):
    if n[i] == per0[i]:
        count0 = count0 + 1
    elif n[i] == per1[i]:
        count1 = count1 + 1
    else:
        count0 = count0
        count1 = count1

print(min(count0,count1))

Submission status: Accepted

Solution code:
text=input()
N=len(text)
count0=0
count1=0
sgn=0
for i in range(N):
  if(int(text[i])==sgn):
    count1=count1+1
  else:
    count0=count0+1
  sgn=1-sgn
print(min([count0,count1]))

Submission status: Accepted

Solution code:
import numpy as np

S = input()
N = len(S)
s = np.array([int(i) for i in list(S)])
s1 = np.array([i % 2 for i in range(N)])
s2 = abs(s1 - np.array([1] * N))

print(min(np.sum(np.abs(s - s1)), np.sum(np.abs(s - s2))))

Submission status: Accepted

Solution code:
import numpy as np

S = input()
N = len(S)
s = np.array([int(i) for i in list(S)])
s1 = np.array([i % 2 for i in range(N)])
s2 = np.array([(i + 1) % 2 for i in range(N)])

print(min(np.sum(np.abs(s - s1)), np.sum(np.abs(s - s2))))

Submission status: Accepted

Solution code:
s = input()
a = 0
b = 1
x = 0
y = 0
for i in range(len(s)):
  t = ord(s[i]) - 48
  if t != a:
    x += 1
  if t != b:
    y += 1
  a ^= 1
  b ^= 1
print(min(x, y))

Submission status: Accepted

Solution code:
import numpy as np

S = list(int(x) for x in input())
L1 = [0 if x%2 == 0 else 1 for x in range(len(S))]
L2 = [0 if x%2 == 1 else 1 for x in range(len(S))]

print(min(sum(np.logical_xor(S, L1)), sum(np.logical_xor(S,L2))))

Submission status: Accepted

Solution code:
O = input()
N = len(O)
total0=0
total1=0

for i in range(N):
    if(int(O[i])==i%2):
        total0+=1
    else:
        total1+=1

print(min(total0,total1))

Submission status: Accepted

Solution code:
import sys
input = list(input())
s = [int(i) for i in input]

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

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

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()
a = [int(c) for c in s]
b = a[:]
ans1 = 0
ans0 = 0

#最初が1
if a[0] == 0:
    a[0] = 1
    ans1 += 1
for i in range(1,len(s)):
    if a[i] == a[i-1]:
        a[i] = (a[i-1]+1)%2
        ans1 += 1
#最初が0
if b[0] == 1:
    b[0] = 0
    ans0 += 1
for i in range(1,len(s)):
    if b[i] == b[i-1]:
        b[i] = (b[i-1]+1)%2
        ans0 += 1
print(min(ans1,ans0))

Submission status: Accepted

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

import copy

def main(): 

    row = list(input().split())
    row = list(map(int,row[0]))

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

    S = copy.deepcopy(row)
    count2 = 1
    if S[0] == 1: 
        S[0] = 0
    else: 
        S[0] = 1
    for i in range(1,len(S)):
        if S[i-1] == S[i]:
            if S[i-1] == 1: S[i] = 0
            else: S[i] = 1
            count2+=1
    print(min(count,count2))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
odd0 = 0
odd = 0
even0 = 0
even = 0
for i in range(len(S)):
    if i%2==0:
        even += 1
        if S[i] == "0":
            even0 += 1
    if i%2==1:
        odd += 1
        if S[i] == "0":
            odd0 += 1
print(min(even - even0 + odd0, odd - odd0 + even0))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
even0 = s[1::2].count("0")
even1 = n // 2 - even0
odd0 = s[::2].count("0")
odd1 = n - even0 - even1 - odd0
print(n - max(even0 + odd1, even1 + odd0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

a = sum([1 for i in range(len(S)) if S[i] == "0" and i % 2 == 0 or  
                                     S[i] == "1" and i % 2 == 1])
b = sum([1 for i in range(len(S)) if S[i] == "1" and i % 2 == 0 or  
                                     S[i] == "0" and i % 2 == 1])
print (min(a,b))

Submission status: Accepted

Solution code:
s = input()
c = 0
nums = ["0", "1"]
for i,v in enumerate(s):
  if v == nums[i % 2]:
    c += 1
print(min(c, len(s)-c))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n == 1:
  print(0)
  exit()

cnt_e = 0
cnt_o = 0
for i in range(0,n,2):
  if s[i] == '1':
    cnt_o += 1
for i in range(1,n,2):
  if s[i] == '1':
    cnt_e += 1
print(min((n+1)//2 - cnt_o + cnt_e, n//2 - cnt_e + cnt_o))

Submission status: Accepted

Solution code:
def main(s):
    pattern1 = ["0" if i % 2 == 0 else "1" for i in range(len(s))]
    pattern2 = ["1" if i % 2 == 0 else "0" for i in range(len(s))]
    dist1 = 0
    dist2 = 0
    for i in range(len(s)):
        if s[i] != pattern1[i]:
            dist1 += 1
        if s[i] != pattern2[i]:
            dist2 += 1

    return min(dist1, dist2)


s = input()
# s = "000"  # 1
# s = "10010010"  # 3
# s = "0"  # 0
print(main(s))

Submission status: Accepted

Solution code:
s = input()

ev = s[0::2]
od = s[1::2]

print(min(ev.count('1')+od.count('0'), ev.count('0')+od.count('1')))

Submission status: Accepted

Solution code:
def main():
    S = input()
    N = len(S)
    count1 = 0
    count2 = 0
    for i in range(N):
        count1 += (str(i%2) != S[i])
        count2 += (str((i+1)%2) != S[i])
    return min(count1, count2) 

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:

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

before = S[0]
count = 0
for c in S[1:]:
    if before == c:
        before = (c ^ 1)
        count += 1
    else:
        before = c

print(count)

Submission status: Accepted

Solution code:
s = input()
m1 = {0 : 0, 1 : 0}
m2 = {0 : 0, 1 : 0}
for c in s[::2]:
    m1[int(c)] += 1
for c in s[1::2]:
    m2[int(c)] += 1
print(min(m1[0] + m2[1], m1[1] + m2[0]))

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

S = str(input())
n = len(S)

count1 = 0
count2 = 0

for i in range(n):
    if i%2==0:
        if S[i]=='0':
            count1 += 1
        else:
            count2 += 1
    else:
        if S[i]=='1':
            count1 += 1
        else:
            count2 += 1

print(min(count1,count2))

Submission status: Accepted

Solution code:
*S, = map(int, list(input()))
n = len(S)
T = [0, 1]*(n//2)+[0]*(n%2)
A = [s^t for s, t in zip(S, T)]
a = sum(A)
print(min(a, n-a))

Submission status: Accepted

Solution code:
s = list(input())
count1 = 0
count2 = 0

if s[0] == '0':
    for i in range(len(s)):
        if i % 2 == 0:
            if s[i] == '0':
                continue
            else:
                count1 +=1
        else:
            if s[i] == '1':
                continue
            else:
                count1 += 1
            
else:
    for i in range(len(s)):
        if i % 2 == 0:
            if s[i] == '1':
                continue
            else:
                count2 += 1
        else:
            if s[i] == '0':
                continue
            else:
                count2 += 1
            
print(max(count1,count2))

Submission status: Accepted

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

p = "0"
ans_1 = 0
for i in range(len_s):
    if s[i] != p:
        ans_1 += 1
    if p == "0":
        p = "1"
    else:
        p = "0"
        
q = "1"
ans_2 = 0
for j in range(len_s):
    if s[j] != q:
        ans_2 += 1
    if q == "0":
        q = "1"
    else:
        q = "0"

ans = min(ans_1, ans_2)
print(ans)

Submission status: Accepted

Solution code:
s=input()
l=len(s)
sum1=0
sum2=0

a=[0 for i in range(l)]
c=[0 for i in range(l)]
d=[0 for i in range(l)]

for i in range(l):
  a[i]=int(s[i])

for i in range(l):
  if i%2==0:
    c[i]=1

for i in range(l):
  if i%2==1:
    d[i]=1
    
for i in range(l):
  sum1+=abs(a[i]-c[i])
  sum2+=abs(a[i]-d[i])
  

print(min(sum1,sum2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

# 定数
INF = float("inf")
MOD = int(1e9 + 7)

# エントリーポイント
def main():
    S = input()
    N = len(S)

    class solve:
        def __init__(self):
            self.v = [0, 0]
    count = dd(solve)
    for i, s in enumerate(S):
        count[i % 2].v[int(s)] += 1
    # for k, v in count.items():
    #     print(k, v.v)
    print(min(count[0].v[0] + count[1].v[1], count[0].v[1] + count[1].v[0]))

main()

Submission status: Accepted

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

ans1 = 0
for i in range(n):
    if i % 2 != int(s[i]):
        ans1 += 1

ans2 = 0
for i in range(n):
    if (i+1) % 2 != int(s[i]):
        ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()

count1 = 0
count2 = 0

n = 0
#10101010...にする
for c in S:
    if n % 2 == 0 and c == '0':
        count1 += 1
    if n % 2 == 1 and c == '1':
        count1 += 1
    n += 1

n = 0
#010101010...にする
for c in S:
    if n % 2 == 0 and c == '1':
        count2 += 1
    if n % 2 == 1 and c == '0':
        count2 += 1
    n += 1
print(min(count1,count2))

Submission status: Accepted

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

n = len(s)
anses = [[], []]
for i in range(n):
  anses[0].append(i % 2)
  anses[1].append((i + 1) % 2)

draw = [0, 0]
for i in range(n):
  if s[i] != anses[0][i]:
    draw[0] += 1
  if s[i] != anses[1][i]:
    draw[1] += 1

print(min(draw))

Submission status: Accepted

Solution code:
s = list(map(int,input()))
sp = s.copy()
count = 0
counta = 0
if sp[0] == 0:
  for i in range(len(sp)):
    if sp[i] != i%2:
      count += 1
      sp[i] = i%2
    
  for i in range(len(sp)):
    if sp[i] != (i+1)%2:
      counta += 1
      sp[i] = (i+1)%2
    
if s[0] == 1 :
  for i in range(len(s)):
    if s[i] != (i+1)%2:
      counta += 1
      s[i] = (i+1)%2
  for i in range(len(s)):
    if s[i] != i%2:
      count += 1
      s[i] = i%2

#print(count)
#print(counta)
print(min(count,counta))

Submission status: Accepted

Solution code:
S = list(input())

l = len(S)
c1 = 0 
c2 = 0

for i in range(l):
  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))