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:
#abc124 c
s=input()
ans1=0
ans2=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="1":
            ans1+=1
        else:
            ans2+=1
    else:
        if s[i]=="0":
            ans1+=1
        else:
            ans2+=1
ans=min(ans1,ans2)
print(ans)

Submission status: Accepted

Solution code:
#124
n=input()
def check(n,st_num):
    count=0
    dic={1:1,0:2}
    for i in range(1,-(-len(n)//2)):
        try:
            if n[2*i]+n[2*i+1]==st_num:
                count+=0
            else:
                count+=dic[abs(int(n[2*i])+int(n[2*i+1])-1)]
        except:
            if n[2*i]!=st_num[0]:
                count+=1
    
    return count
    
if '1' not in n:
    print(len(n)//2)
    exit()
if n[:2]=="10":
    print(check(n,"10"))
elif n[:2]=="01":
    print(check(n,"01"))
else:
    print(0 if len(n)==1 else min([check(n,"10")+1,check(n,"01")+1]))

Submission status: Accepted

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

def change():
    global kk
    if kk == "1":
        kk = "0"
    else:
        kk = "1"

# case 1
count_1 = 0
kk = "1"
for c in range(L):
    if kk == S[c]:
        pass
    else:
        count_1 += 1
    change()
    

# case 2
count_2 = 0
kk = "0"
for c in range(L):
    if kk == S[c]:
        pass
    else:
        count_2 += 1
    change()

if count_1 < count_2:
    print(count_1)
else:
    print(count_2)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    s=list(input())
    a,b=0,0
    x,y=0,0
    for i in range(len(s)):
        if i%2==0:
            a+=int(s[i])
            x+=1
        else:
            b+=int(s[i])
            y+=1
    print(min(x-a+b,y-b+a))
           

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_ls = [i for i in s]
count = 0
for i in range(len(s)-1):

    if s_ls[i] == s_ls[i+1]:
        count += 1
        if s_ls[i+1] == '1':
            s_ls[i+1] = '0'
        else:
            s_ls[i+1] = '1'
print(count)

Submission status: Accepted

Solution code:
#n=int(input())
#n,m=map(int,input().split())
#sl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

s=list(input())
n=len(s)

#最初が0のリスト
goal1=["1" if i%2==0 else "0" for i in range(n)]
count1=0
#最初が1のリスト
goal2=["0" if i%2==0 else "1" for i in range(n)]
count2=0
for i in range(n):
    if goal1[i]!=s[i]:
        count1+=1
    if goal2[i]!=s[i]:
        count2+=1

print(min(count1,count2))

Submission status: Accepted

Solution code:
# coding: utf-8

start_col = ["0", "1"]

s = input().rstrip()


def get_next(prev: str):
    if prev == "0":
        return "1"
    else:
        return "0"


ans = len(s)
for i in start_col:
    current = i
    cnt = 0
    for j in range(len(s)):
        if s[j] != current:
            cnt += 1
        current = get_next(current)
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
S = input()
res1 = res2 = 0
for i in range(len(S)):
    if (i%2 == 0 and S[i] == '0') or (i%2 == 1 and S[i] == '1'):
        res1 += 1
    if (i%2 == 0 and S[i] == '1') or (i%2 == 1 and S[i] == '0'):
        res2 += 1
print(min(res1, res2))

Submission status: Accepted

Solution code:
S = input()

n = len(S)
cnt = 0

for i in range(n):
  if int(S[i])%2 == i%2:
    cnt += 1
    
print(min(cnt, n-cnt))

Submission status: Accepted

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

print(min(ans,ans1))

Submission status: Accepted

Solution code:
s = input()

alt_01 = int('01' * (len(s)//2) + '0' * (len(s)%2), 2)
alt_10 = int('10' * (len(s)//2) + '1' * (len(s)%2), 2)

bin_s = int(s, 2)
xor_01 = bin_s ^ alt_01
xor_10 = bin_s ^ alt_10

print(min(format(xor_01, 'b').count('1'), format(xor_10, 'b').count('1')))

Submission status: Accepted

Solution code:
# coding: utf-8

s = input().rstrip()

default = ["0", "1"]

ans = len(s)
for i in default:
    current = i
    cnt = 0
    for j in s:
        if j == current:
            cnt += 1
        if current == "1":
            current = "0"
        else:
            current = "1"
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

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

def main():
  s = list(map(int, list(input().strip())))
  odd1, odd0, even1, even0 = 0, 0, 0, 0
  for i in range(len(s)):
    if i%2 == 0:
      if s[i] == 0:
        even0 += 1
      else: 
        even1 += 1
    else:
      if s[i] == 0:
        odd0 += 1
      else:
        odd1 += 1
  print(min(even0+odd1, even1+odd0))

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
S = str(input())

diff0, diff1 = 0, 0
for i, s in enumerate(S):
  if i%2 == 0:
    if s == '0':
      diff1 += 1
    else:
      diff0 += 1
  else:
    if s == '0':
      diff0 += 1
    else:
      diff1 += 1

ans = min(diff0, diff1)
print(ans)

Submission status: Accepted

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

ans = even.count('0') + odd.count('1')
if ans > even.count('1') + odd.count('0'):
    ans = even.count('1') + odd.count('0')

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
import copy
d=copy.copy(s)
x=0
y=1
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'
    x+=1
if d[0]=='1':
  d[0]='0'
else:d[0]='1'
for i in range(len(d)-1):
  if int(d[i])==int(d[i+1]):
    if d[i+1]=='1':
      d[i+1]='0'
    else:d[i+1]='1'
    y+=1
print(min(x,y))

Submission status: Accepted

Solution code:
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys
from collections import deque

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    s = input()
    l = len(s)
    odd = 0
    even =0

    for i in range(l):
        if (i + 1) % 2 == 0:
            even += int(s[i])
        else:
            odd += int(s[i])

    #even = 1
    a = (l // 2) - even + odd

    #odd = 1
    b = ((l+1) // 2) - odd + even

    print(min(a,b))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

#奇数が1
countA = 0
for i in range(len(s)):
    if i%2==0 and s[i]=="0":
        countA += 1
    elif i%2==1 and s[i]=="1":
        countA += 1

#偶数が1
countB = 0
for i in range(len(s)):
    if i%2==0 and s[i]=="1":
        countB += 1
    elif i%2==1 and s[i]=="0":
        countB += 1

print(min(countA,countB))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

if s[0] == '0':
  even = '0'
  odd = '1'
else:
  even = '1'
  odd = '0'

cnt = 0
for i in range(len(s)):
  if (i%2 == 0 and s[i]!= even) or (i%2 == 1 and s[i]!= odd):
    cnt += 1
print(cnt)

Submission status: Accepted

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

    full_even = (N + 1) // 2
    even = 0
    for i in range(0, N, 2):
        if S[i] == '0':
            even += 1

    full_odd = N // 2
    odd = 0
    for i in range(1, N, 2):
        if S[i] == '0':
            odd += 1

    # print(even, odd)
    case1 = even + full_odd - odd
    case2 = odd + full_even - even
    print(min(case1, case2))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

s = input().strip()


flag=0
ans=[]
for flag in [0,1]:
    
    calc=0
    for i in range(len(s)):
        if s[i] != str( (i%2 == flag)*1 ):
            calc += 1

    ans += [calc]
    
print(min(ans))

Submission status: Accepted

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

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()
sa = s[::2]
sb = s[1::2]

sa1, sb1 = sa.count('0'), sb.count('1')
ty1 = sa1 + sb1
ty2 = len(s) - sa1 - sb1
if ty1 > ty2:
  print(ty2)
else:
  print(ty1)

Submission status: Accepted

Solution code:
S = list(input())

ans = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:

        ans += 1

        if S[i+1] == "1":
            S[i+1] = "0"

        else:
            S[i+1] = "1"

print(ans)

Submission status: Accepted

Solution code:
S=input()
count10=0
count01=0
def c10(s,n,count10):
    if ((n%2==0)and(s=="1"))or((n%2==1)and(s=="0")):
        count10=count10+1
    return count10
def c01(s,n,count01):
    if ((n%2==0)and(s=="0"))or((n%2==1)and(s=="1")):
        count01=count01+1
    return count01

for i in range(len(S)):
    count10=c10(S[i],i,count10)
    count01=c01(S[i],i,count01)
print(min(len(S)-count10,len(S)-count01))

Submission status: Accepted

Solution code:
import sys
S = input()
S_list = list(S)

l = len(S)


if len(S) % 2 == 0:
  ideal1 = list('01' * int(l / 2))
  ideal2 = list('10' * int(l / 2))
else:
  ideal1 = list('01' * (l // 2) + '0')
  ideal2 = list('10' * (l // 2) + '1')

ans = 0
ans1 = 0

for base,compe1 in zip(S_list,ideal1):
    if base != compe1:
        ans = ans + 1

for base,compe2 in zip(S_list,ideal2):
    if base != compe2:
        ans1 = ans1 + 1

print(min(ans,ans1))

Submission status: Accepted

Solution code:
S = input()

dif1 = 0
dif2 = 0

for i in range(len(S)):
	if i%2 == 0 and S[i] == '0':
		dif1 += 1
	if i%2 == 1 and S[i] == '1':
		dif1 += 1
	if i%2 == 0 and S[i] == '1':
		dif2 += 1
	if i%2 == 1 and S[i] == '0':
		dif2 += 1

print(min([dif1, dif2]))

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()
white_cnt = black_cnt = 0
ans = 0
for i in range(len(S)):
    if S[i]=="0":
        black_cnt += 1
        white_cnt = 0
    else:
        white_cnt += 1
        black_cnt = 0
    if black_cnt==2:
        ans += 1
        black_cnt = 0
        white_cnt += 1
    elif white_cnt == 2:
        ans += 1
        white_cnt = 0
        black_cnt += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

start1 = []
start0 = []

ans1 = 0
ans0 = 0

for i in range(len(S)):
    if i%2 == 0:
        start1.append('1')
        start0.append('0')
    else:
        start1.append('0')
        start0.append('1')
        
for i in range(len(S)):
    if S[i] != start1[i]:
        ans1 +=1
    
    if S[i] != start0[i]:
        ans0 +=1
        
print(min(ans1,ans0))

Submission status: Accepted

Solution code:
#124_C
S=input()
def Count(S,x):
    res=0
    for i in range(len(S)):
        if i%2==x:
            if S[i]=='0':
                res+=1
        else:
            if S[i]=='1':
                res+=1
    return res

print(min(Count(S,0),Count(S,1)))

Submission status: Accepted

Solution code:
s = list(input())

pre_c = None
l_count = 0
for c in s:
  if c == pre_c:
    l_count += 1
    pre_c = '0' if c == '1' else '1'
  else:
    pre_c = c

pre_c = None
r_count = 0
s.reverse()
for c in s:
  if c == pre_c:
    r_count += 1
    pre_c = '0' if c == '1' else '1'
  else:
    pre_c = c
print(min(l_count, r_count))

Submission status: Accepted

Solution code:
s = list(input())
s = [int(i) for i in s] 
c = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    c += 1
    s[i+1] = abs(s[i]-1)
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

a = 0
b = 1
ans_a = 0
ans_b = 0

for i in range(len(s)):
    if int(s[i]) != a:
        ans_a += 1
    else:
        ans_b += 1
    if a == 0:
        a = 1
        b = 0
    else:
        a = 0
        b = 1

print(min(ans_a, ans_b))

Submission status: Accepted

Solution code:
S = input()
a = 0
b = 0

for i in range(len(S)):
  if (i + 1) % 2 == 0:
    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:
s = list(str(input()))
t = int(len(s))
ans = 0
for i in range(t-1):
    if s[i] == s[i + 1]:
        if s[i + 1] == "1":
            s[i + 1] = "0"
            ans += 1
        else:
            s[i + 1] = "1"
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
a=["1"]*n
b=["0"]*n
for i in range(1,n):
    if a[i-1]=="1":
        a[i]="0"
    else:
        a[i]="1"
for i in range(1,n):
    if b[i-1]=="1":
        b[i]="0"
    else:
        b[i]="1"
cnt=0
for i in range(n):
    if a[i]!=s[i]:
        cnt+=1
ans=cnt
cnt=0
for i in range(n):
    if b[i]!=s[i]:
        cnt+=1
ans=min(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
s=input()
s = list(s)
#print(s)
fcount0 = 0
fcount1 = 0

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

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

print(min(fcount0, fcount1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

def count1(str):
    count = 0
    for i in range(len(str)):
        x = str[i]
        if i%2==0:
            if x!='0':
                count += 1
        else:
            if x!='1':
                count += 1

    return count

def count2(str):
    count = 0
    for i in range(len(str)):
        x = str[i]
        if i%2==0:
            if x!='1':
                count += 1
        else:
            if x!='0':
                count += 1

    return count

answer = min(count1(s),count2(s))
print(answer)

Submission status: Accepted

Solution code:
import sys
s=sys.stdin.buffer.readline().rstrip()
n=len(s)
a=0
for i in range(n):
    a+=s[i]%2==i%2
print(min(a,n-a))

Submission status: Accepted

Solution code:
S = input()
ans = []
if len(S) % 2 == 0:
    k = 0
    for i in range(len(S)//2):
        if S[2*i] != '0':
            k += 1
        if S[2*i + 1] != '1':
            k += 1
    ans.append(k)
    l = 0
    for i in range(len(S)//2):
        if S[2*i] != '1':
            l += 1
        if S[2*i + 1] != '0':
            l += 1
    ans.append(l)
    print(min(ans))
elif len(S) > 1 and len(S) % 2 != 0:
    k = 0
    for i in range(len(S)//2):
        if S[2*i] != '0':
            k += 1
        if S[2*i + 1] != '1':
            k += 1
    if S[-1] != '0':
        k += 1
    ans.append(k)
    l = 0
    for i in range(len(S)//2):
        if S[2*i] != '1':
            l += 1
        if S[2*i + 1] != '0':
            l += 1
    if S[-1] != '1':
        l += 1
    ans.append(l)
    print(min(ans))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
s=list(map(int,s))
a=[0]*len(s)
b=[0]*len(s)
for i in range(0,len(s),2):
    a[i]=1
for i in range(1,len(s),2):
    b[i]=1
cnt1=0
cnt2=0

for i,j in zip(a,s):
    if i!=j:
        cnt1+=1
for i,j in zip(b,s):
    if i!=j:
        cnt2+=1 
print(min([cnt1,cnt2]))

Submission status: Accepted

Solution code:
s=list(map(int,list(input())))
ans=0
t=s[0]
for u in s[1:]:
  if u==t:
    ans+=1
    t= int(not bool(u))
  else:
    t=u
print(ans)

Submission status: Accepted

Solution code:
s=input()
c1=0
c2=0
for i in range(len(s)):
    if i%2==0:
        if s[i]!="0":
            c1+=1
    else:
        if s[i]!="1":
            c1+=1
for i in range(len(s)):
    if i%2==0:
        if s[i]!="1":
            c2+=1
    else:
        if s[i]!="0":
            c2+=1

print(min(c1,c2))

Submission status: Accepted

Solution code:
S = list(input())
lenS = len(S)

patternA = []
patternB = []
countA = 0
countB = 0

for x in range(lenS):
    if x % 2 == 0:
        if S[x] == "0":
            countA += 1
        else:
            countB += 1
    else:
        if S[x] == "1":
            countA += 1
        else:
            countB += 1

if countA < countB:
    print(countA)
else:
    print(countB)

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    s = input().strip()
    ans, ans2 = 0, 0
    tmp = 0
    for c in s:
        if c != str(tmp):
            ans += 1
        tmp = 1 - tmp
    tmp = 1
    for c in s:
        # print(tmp)
        if c != str(tmp):
            ans2 += 1
        tmp = 1 - tmp

    print(min(ans, ans2))
if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

s=list(ss())
lens=len(s)
cnt_odd=0
cnt_even=0
for i in range(lens):
    if i%2==0:
        if s[i]=="0":
            cnt_even+=1
        else:
            cnt_odd+=1
    else:
        if s[i]=="0":
            cnt_odd+=1
        else:
            cnt_even+=1
print(min(lens-cnt_even,lens-cnt_odd))

Submission status: Accepted

Solution code:
s = input()
s_lis = list(s)
l = len(s)
a = ['0' if i%2 == 0 else '1' for i in range(l)]
b = ['1' if i%2 == 0 else '0' for i in range(l)]
a_count = 0
b_count = 0
for si,ai,bi in zip(s_lis,a,b):
    if si != ai:
        a_count += 1
    if si != bi:
        b_count += 1
print(min(a_count,b_count))

Submission status: Accepted

Solution code:
S = input()
s = ''
s2 = ''
for i in range(len(S)):
    s += str(i % 2)
    s2 += str((i+1) % 2)
c = 0
c2 = 0
for i in range(len(S)):
    if S[i] != s[i]:
        c += 1
    if S[i] != s2[i]:
        c2 += 1
print(min(c, c2))

Submission status: Accepted

Solution code:
S = list(input())

N = len(S)
P = [str(i%2) for i in range(N)]
Q = [str((i+1)%2) for i in range(N)]

PC = 0
QC = 0
for i in range(N):
    if P[i] != S[i]:
        PC += 1
    else:
        QC += 1

print(min(PC,QC))

Submission status: Accepted

Solution code:
s = list(input())

print(min(s[::2].count('0')+s[1::2].count('1'), s[::2].count('1')+s[1::2].count('0')))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] != "0":
            a += 1
    else:
        if s[i] != "1":
            a += 1

b = 0
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))

Submission status: Accepted

Solution code:
S = list(input())

res = 0

for i in range(1, len(S)):
    if S[i] == S[i-1]:
        res += 1
        S[i] = "0" if int(S[i]) else "1"
print(res)

Submission status: Accepted

Solution code:
s = list(input())
s2 = s.copy()
s_cnt, s2_cnt = 0, 0
if s[0] == '1':
    s2[0] = '0'
    s2_cnt += 1
else:
    s2[0] = '1'
    s2_cnt += 1

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        s_cnt += 1
        if s[i-1] == '1':
            s[i] = '0'
        else:
            s[i] = '1'
    if s2[i] == s2[i-1]:
        s2_cnt += 1
        if s2[i-1] == '1':
            s2[i] = '0'
        else:
            s2[i] = '1'
print(min(s_cnt, s2_cnt))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

u = 0
ans = 0
for i in t:
    if u != i:
        ans += 1
    u = 1 if u == 0 else 0

print(min(ans, lt-ans))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

s = input()
snp = np.array(list(map(int,s)))

cand1 = (1 == snp[0::2]).sum() + (0 == snp[1::2]).sum()
cand2 = (0 == snp[0::2]).sum() + (1 == snp[1::2]).sum()

print(min(cand1,cand2))

Submission status: Accepted

Solution code:
s = [int(i) for i in list(input())]
n = len(s)

a,b = [],[]

for i in range(n):
    if i%2 == 0:
        a.append(0)
        b.append(1)
    else:
        a.append(1)
        b.append(0)

A,B = 0,0

for j in range(n):
    if s[j] != a[j]:
        A += 1
    if s[j] != b[j]:
        B += 1

print(min(A,B))

Submission status: Accepted

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

    ans1 = 0
    ans0 = 0

    s_len = len(s)

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

    print(min(ans0,ans1))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

ans1 = 0
ans2 = 0
for i, title in enumerate(s):
    if i % 2 == 0 and title != "0":
        ans1 += 1
    if i % 2 == 1 and title != "1":
        ans1 += 1
    if i % 2 == 1 and title != "0":
        ans2 += 1
    if i % 2 == 0 and title != "1":
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()

so=""
se=""
for i in range(1, len(s), 2):
  so += s[i]
for i in range(0, len(s), 2):
  se += s[i]

print(len(s) - max(so.count("1") + se.count("0"), so.count("0") + se.count("1")))

Submission status: Accepted

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

def check(x, y):
    count = 0
    for i in range(len(x)):
        if x[i] != y[i]:
            count += 1
    print(count)

if ls%2 == 0:
    if s[0] == '1':
        s1 = '10'*(ls//2)
        check(s, s1)
    if s[0] == '0':
        s2 = '01'*(ls//2)
        check(s, s2)
else:
    if s[0] == '1':
        s3 = '10'*(ls//2) + '1'
        check(s, s3)
    if s[0] == '0':
        s4 = '01'*(ls//2) + '0'
        check(s, s4)

Submission status: Accepted

Solution code:
import sys
s = list(sys.stdin.readline())
n = len(s)

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

S = readline().decode('utf8').rstrip()

f0 = S[::2].count('0') + S[1::2].count('1')
f1 = S[::2].count('1') + S[1::2].count('0')
print(min(f0, f1))

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9

S = readline().decode('utf8').rstrip()
L = len(S)


def odd(M):
    while len(M) != L:
        if len(M) % 2 == 0:
            M += '1'
        else:
            M += '0'
    return M


def even(M):
    while len(M) != L:
        if len(M) % 2 == 0:
            M += '0'
        else:
            M += '1'
    return M


temp = ''
A = odd(temp)
B = even(temp)
na = sum(i == j for i, j in zip(S, A))
nb = sum(i == j for i, j in zip(S, B))
print(min(na, nb))

Submission status: Accepted

Solution code:
s = list(input())
even_s = s[0::2]
odd_s = s[1::2]
cnt = 0
for i in range(len(even_s)):
    if even_s[i] != '0':
        cnt += 1

for i in range(len(odd_s)):
    if odd_s[i] != '1':
        cnt += 1

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

Submission status: Accepted

Solution code:
import copy
s = list(input())
c = copy.copy(s)
n = len(s)
cnt1 = cnt2 = 0
for i in range(n-1):
    if c[i+1]==c[i]:
        cnt1 += 1
        c[i+1] = '0' if c[i+1]=='1' else '1'
s[0] = '0' if s[0]=='1' else '1'
cnt2+=1
for i in range(1,n):
    if s[i-1]==s[i]:
        cnt2 += 1
        s[i] = '0' if s[i]=='1' else '1'
print(min(cnt1,cnt2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

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

print(cnt)

Submission status: Accepted

Solution code:
S = list(str(input()))
count = 0
if S[0] == "1":
    for i, j in enumerate(S):
        if i % 2 == 0 and j == "0":
            count += 1
        elif i % 2 == 1 and j == "1":
            count += 1
else:
    for i, j in enumerate(S):
        if i % 2 == 0 and j == "1":
            count += 1
        elif i % 2 == 1 and j == "0":
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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