Problem:


Score : 300 points

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Sample Input 1

000

Sample Output 1

1

The condition can be satisfied by repainting the middle tile white.

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

Solution code:
S = input()

cnt_init_0 = 0
cnt_init_1 = 0

for i, s in enumerate(S):
    if s == "0":
        if i % 2 == 0:
            cnt_init_1 += 1
        else:
            cnt_init_0 += 1
    else:
        if i % 2 == 0:
            cnt_init_0 += 1
        else:
            cnt_init_1 += 1
print(min(cnt_init_0, cnt_init_1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce
from queue import Queue
from operator import mul
from functools import reduce
from functools import lru_cache

input = sys.stdin.readline

# N個整数
# a, b, c = list(map(int, input().split()))

# 1整数
# n = int(input())

# 空白区切りリスト整数
# b = list(map(int, input().split()))

# 空白区切り文字列
# t, d = input().split()


s = input()
l = len(s) - 1
r1 = 0
r2 = 0
for i in range(l):
    if i % 2 == 0:
        if s[i] != '0':
            r1 += 1
        else:
            r2 += 1
    if i % 2 == 1:
        if s[i] != '1':
            r1 += 1
        else:
            r2 += 1
print(min(r1, r2))

Submission status: Accepted

Solution code:
S = input()
T1 = "01"*int(len(S)/2+1)
T2 = "10"*int(len(S)/2+1)
count1 = 0
count2 = 0
for s,t1,t2 in zip(S,T1,T2):
    if s != t1:
        count1 += 1
    if s != t2:
        count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
S = input()

ans = len(S)+1
# 010...
cnt = 0
for i in range(len(S)):
    if i%2 == 0:
        color = '0'
    else:
        color = '1'
    if S[i] != color:
        cnt += 1
if cnt < ans:
    ans = cnt

# 101...
cnt = 0
for i in range(len(S)):
    if i%2 == 0:
        color = '1'
    else:
        color = '0'
    if S[i] != color:
        cnt += 1
if cnt < ans:
    ans = cnt

print(ans)

Submission status: Accepted

Solution code:
S = input()

n = 0
o = 0
for s in S:
    if o == 0:
        if s == '0':
            pass
        else:
            n = n + 1
    else:
        if s == '0':
            n = n + 1
        else:
            pass

    o = 1 - o
n = min(n, len(S) - n)
print(n)

Submission status: Accepted

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

s0=''
s1=''
for i in range(n):
    if (i%2==0):
        s0+='0'
        s1+='1'
    else:
        s0+='1'
        s1+='0'

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

Submission status: Accepted

Solution code:
S = input()
length = len(S)
zo = ['0', '1'] * (length//2) + ['0']*(length % 2)
oz = ['1', '0'] * (length//2) + ['1']*(length % 2)
c1 = 0
c2 = 0
for i in range(length):
    if S[i] != zo[i]:
        c1 += 1
    if S[i] != oz[i]:
        c2 += 1
print(min(c1, c2))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
lis1=['0' for i in range(n)]
lis2=['1' for i in range(n)]
for i in range(0,n,2):
    lis1[i]='1'
    lis2[i]='0'
ans1=0
ans2=0
for i in range(n):
    if lis1[i]!=s[i]:
        ans1+=1
    if lis2[i]!=s[i]:
        ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()
s1=''
s2=''
for i in range(len(s)//2):
    s1+='01'
    s2+='10'
if len(s)%2==1:
    s1+='0'
    s2+='1'
ans1=0
ans2=0
for i in range(len(s)):
    if s[i]!=s1[i]:
        ans1+=1
    if s[i]!=s2[i]:
        ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

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

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator

S = input()
N = len(S)

b1 = S[0::2].count('0')
w1 = (N // 2 + (N & 1)) - b1
b2 = S[1::2].count('0')
w2 = (N // 2) - b2

print(min(b1 + w2, w1 + b2))

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())

#################
s = input()
c0 = [0,0]
for n,i in enumerate(s):
    if n%2==0 and i=='0':
        c0[0] += 1
    elif n%2==1 and i=='1':
        c0[1] += 1
    
length = len(s)
print(min([sum(c0),length-sum(c0)]))

Submission status: Accepted

Solution code:
S = input()
c1, c2 = '0', '1'
n1 = 0
n2 = 0
for s in S:
    n1 += int(s != c1)
    n2 += int(s != c2)
    c1, c2 = c2, c1
print(min(n1, n2))

Submission status: Accepted

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


def main():
  tiles = list(map(int, input()))
  color = 0
  count = 0

  for tile in tiles:
    if tile == color:
      count += 1

    color = 1 - color

  if count > len(tiles) // 2:
    count = len(tiles) - count

  print(count)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

def solve():
    S= input()
    S = list(S)

    # 010101...のとき
    ans1 = 0
    for i in range(0, len(S)):
        if i%2==0 and S[i] == "1":
            ans1 += 1
        elif i%2==1 and S[i] == "0":
            ans1 += 1
    
    # 1010101...のとき
    ans2 = 0
    for i in range(0, len(S)):
        if i%2==0 and S[i] == "0":
            ans2 += 1
        elif i%2==1 and S[i] == "1":
            ans2 += 1

    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
tiles = list(input())
before = '-1'
c = 0
for tile in tiles:
	if before != tile:
		before = tile
	else:
		c += 1
		before = '0' if tile == '1' else '1'
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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
print(min(ans1, ans2))

Submission status: Accepted

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

N = len(S)

ans = 0
for i in range(N-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()

count1 = count2 = 0
for i in range(len(s)):
    after = str(i % 2)
    if s[i] != after:
        count1 += 1

for i in range(len(s)):
    after = str((i+1) % 2)
    if s[i] != after:
        count2 += 1
print(min(count1,count2))

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

print(
    min(
        sum(
            s==str(i%2) for i, s in enumerate(S)
        ),
        sum(
            s==str((i+1)%2) for i, s in enumerate(S)
        ),
    )
)

Submission status: Accepted

Solution code:
def main():
    s = input()
    diff1 = 0
    diff2 = 0
    for i, c in enumerate(s):
        if i % 2 == 0:
            if c == "0":
                diff1 += 1
            else:
                diff2 += 1
        else:
            if c == "1":
                diff1 += 1
            else:
                diff2 += 1
    print(min(diff1, diff2))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    input = sys.stdin.readline
    try:
        S = input()
        before = S[0]
        cnt = 0
        for s in S[1:]:
            if s == before:
                cnt += 1
                if s == "0":
                    before = "1"
                else:
                    before = "0"
            else:
                before = s
        print(cnt)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S=list(input())
le=len(S)
bl=0
for i,c in enumerate(S):
    if i%2==0:
        if c=='1':
            bl+=1
    else:
        if c=='0':
            bl+=1

if bl < le-bl:
    print(bl)
else:
    print(le-bl)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
s = input()
cnt1 = 0
cnt2 = 0
flag = '0'
for i in s[:-1]:
    if flag == '0':
        if i == flag:
            flag = '1'
        else:
            cnt1 += 1
            flag = '1'
    else:
        if i == flag:
            flag = '0'
        else:
            cnt1 += 1
            flag = '0'
flag = '1'
for i in s[:-1]:
    if flag == '0':
        if i == flag:
            flag = '1'
        else:
            cnt2 += 1
            flag = '1'
    else:
        if i == flag:
            flag = '0'
        else:
            cnt2 += 1
            flag = '0'
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S=input()

O=0
E=0

for i in range(len(S)):
    if i%2==0:
        if S[i]=="0":
            O+=1
        else:
            E+=1
    else:
        if S[i]=="0":
            E+=1
        else:
            O+=1
print(min(O,E))

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 permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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

ans1 = 0
for i in range(len(S)): # 偶数を0に
	if i%2 == 0 and S[i] == "1":
		ans1 += 1
	elif i%2 == 1 and S[i] == "0":
		ans1 += 1

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

print(min(ans1, ans2))

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] == '1'):
            ans1 += 1
        else:
            ans2 += 1
print(min(ans2, ans1))

Submission status: Accepted

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

cnt = [0] * 2
for i in range(n):
	m = i % 2
	if s[i] == 1:
		cnt[m] = cnt[m] + 1

ans = min((n // 2 + n % 2 - cnt[0]) + cnt[1], cnt[0] + (n // 2 - cnt[1]))
print(ans)

Submission status: Accepted

Solution code:
S = input()
A = [str(i%2) for i in range(len(S))]
B = [str(1-i%2) for i in range(len(S))]
a = b = 0
for i in range(len(S)):
    if S[i] != A[i]:
        a += 1
    if S[i] != B[i]:
        b += 1

print(min(a, b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
S=raw_input()

# start:0
s="0"
A0=0
for c in S:
    if s!=c:A0+=1
    if(s=="0"):s="1"
    else: s="0"
# start:1
s="1"
A1=0
for c in S:
    if s!=c:A1+=1
    if(s=="0"):s="1"
    else: s="0"
print(min(A0,A1))

Submission status: Accepted

Solution code:
s = input()

if(len(s) == 1):
    print(0)
    exit()

ans = 0

tmp = s[0]

for i in s[1:]:
    if(tmp == i):
        ans += 1
        if(i == "0"): tmp = "1"
        else: tmp = "0"
    else:
        tmp = i

print(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
  if i%2==1 and s[i]=="1":
    ans1 += 1
  if i%2==0 and s[i]=="1":
    ans2 += 1
  if i%2==1 and s[i]=="0":
    ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = input()

form = -1
ans = 0
for s in S:
    s = int(s)
    if form == -1:
        form = s
    elif form+s == 1:
        form = s
    else:
        if s == 1:
            form = 0
        else:
            form = 1
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
ans1, ans2 = 0, 0

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

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print(min(n1, n2))

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


s = list(str(input()))
ret1 = 0
ret2 = 0

for i in range(len(s)):
  t = int(s[i])
  if i&1 == t:
    ret1 += 1
  if i&1 != t:
    ret2 += 1

print(min(ret1, ret2))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
s1=""
for i in range(n//2):
  s1+="01"
if n%2>0:
  s1+="0"
ans1=0
for i in range(n):
  if s[i]!=s1[i]:
    ans1+=1
s2=""
for i in range(n//2):
  s2+="10"
if n%2>0:
  s2+="1"
ans2=0
for i in range(n):
  if s[i]!=s2[i]:
    ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  S = input()
  ans1 = 0
  ans2 = 0
  for i, c in enumerate(S):
    d = '0' if i % 2 == 0 else '1'
    d2 = '1' if i % 2 == 0 else '0'
    if c != d:
      ans1 += 1
    if c != d2:
      ans2 += 1
  print(min(ans1, ans2))

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

S = input()

# pattern that S start 0
v1 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s != "0":
            v1 += 1
    else:
        if s != "1":
            v1 += 1

# pattern that S start 1
v2 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s != "1":
            v2 += 1
    else:
        if s != "0":
            v2 += 1
            
print(min(v1, v2))

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())

    cnt_01 = 0
    cnt_10 = 0
    for i in range(len(S)):
        s = S[i]

        if i % 2 == 0:
            if s != '0':
                cnt_01 += 1
            else:
                cnt_10 += 1
        else:
            if s != '0':
                cnt_10 += 1
            else:
                cnt_01 += 1

    return min(cnt_01, cnt_10)


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

Submission status: Accepted

Solution code:
s=input()
st0=0
st1=1
ans0=0
ans1=0
for i in s:
    if(int(i)==st0):
        ans1+=1
    else:
        ans0+=1
    st0,st1=st1,st0
print(min(ans0,ans1))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
zeroStart = 0
oneStart = 0
for i in range(N):
    if i%2 == 0:
        if S[i] == "1":
            zeroStart += 1
        else:
            oneStart += 1
    else:
        if S[i] == "1":
            oneStart += 1
        else:
            zeroStart += 1

print(min(zeroStart,oneStart))

Submission status: Accepted

Solution code:
def main():
    s = input()
    target = 0
    cost0 = 0
    cost1 = 0
    
    for c in s:
        if int(c) != target:
            cost0 += 1
        else:
            pass
        target = 0 if target == 1 else 1
    target = 1
    for c in s:
        if int(c) != target:
            cost1 += 1
        else:
            pass
        target = 0 if target == 1 else 1
    print(min(cost0, cost1))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=list(input())	

ans1 = 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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
ct1=0;ct2=0
for i in range(len(s)):
  if i%2==0:
    if s[i]=='0':
      ct1+=1
  else:
    if s[i]=='1':
      ct1+=1
for i in range(len(s)):
  if i%2==0:
    if s[i]=='1':
      ct2+=1
  else:
    if s[i]=='0':
      ct2+=1
print(len(s)-max(ct1,ct2))

Submission status: Accepted

Solution code:
s=input()
flip='0'
a=0
for c in s:
    if c==flip:
        a+=1
    if flip=='0':
        flip='1'
    else:
        flip='0'
print(min(a,len(s)-a))

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    s = SI()

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

    return min(r, t)


print(main())

Submission status: Accepted

Solution code:
S=input()
ans0=0
ans1=0

for i in range(len(S)):
    if int(S[i])!=i%2:
        ans0+=1
    if int(S[i])!=(i+1)%2:
        ans1+=1

print(min(ans0,ans1))

Submission status: Accepted

Solution code:
s = input().strip()
p = [['0', '1'], ['1', '0']]
ans = [0, 0]
for i, v in enumerate(s):
    for j in range(2):
        ans[j] = ans[j]+1 if p[j][i % 2] == v else ans[j]
print(min(ans))

Submission status: Accepted

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

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

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

count1 = 0
count2 = 0

for i in range(len(s)):
  if s[i] != ideal1[i]:
    count1 += 1
  elif s[i] != ideal2[i]:
    count2 += 1

print(min(count1, count2))

Submission status: Accepted

Solution code:
s = list(input())
e = s[0::2]
o = s[1::2]
e_0 = e.count("0")
e_1 = e.count("1")
o_0 = o.count("0")
o_1 = o.count("1")
ans_a = e_1 + o_0
ans_b = e_0 + o_1
ans = min(ans_a, ans_b)
print(ans)

Submission status: Accepted

Solution code:
s=input()
p="10"*len(s)
q="01"*len(s)
r=0
t=0
for i in range(len(s)):
    if p[i]!=s[i]:
        r+=1
    if q[i]!=s[i]:
        t+=1  
print(min(r,t))

Submission status: Accepted

Solution code:
S=input()
N=len(S)
A="01"*(N//2)
A+="0" if N%2==1 else ""
B="10"*(N//2)
B+="1" if N%2==1 else ""
ansA=0
ansB=0
for i in range(N):
  if S[i]!=A[i]:
    ansA+=1
  if S[i]!=B[i]:
    ansB+=1
print(min(ansA,ansB))

Submission status: Accepted

Solution code:
s=input()
c1=c2=0
f1='0'
f2='1'
for x in s:
  if f1==x:
    pass
  else:
    c1+=1
  if f1=='0':
    f1='1'
  else:
    f1='0'
for x in s:
  if f2==x:
    pass
  else:
    c2+=1
  if f2=='0':
    f2='1'
  else:
    f2='0'
print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()

c1 = 0
cur = 0
for s in S:
  if cur != int(s):
    c1 += 1
  cur = (cur + 1) % 2

c2 = 0
cur = 1
for s in S:
  if cur != int(s):
    c2 += 1
  cur = (cur + 1) % 2
print(min(c1, c2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
x=[i%2 for i in range(len(s))]
y=[~i%2 for i in range(len(s))]
#print(x,y)
c=0
e=0
for i in range(len(s)):
    #print(s[i],x[i],y[i])
    if int(s[i])!=x[i]:
        c+=1
    if int(s[i])!=y[i]:
        e+=1
print(min(c,e))

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()
N=len(S)

T1=''
for i in range(N):
    if i%2==0:
        T1+='0'
    else:
        T1+='1'
T2=''
for i in range(N):
    if i%2==0:
        T2+='1'
    else:
        T2+='0'

cnt1=0
for i in range(N):
    if S[i]!=T1[i]:
        cnt1+=1
cnt2=0
for i in range(N):
    if S[i]!=T2[i]:
        cnt2+=1
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S = input()
p1,p2=0,0
for i,s in enumerate(S):
    if i%2==0:
        if s=="0":
            p1+=1
        else:
            p2+=1
    else:
        if s=="0":
            p2+=1
        else:
            p1+=1
print(min(p1,p2))

Submission status: Accepted

Solution code:
S = list(input())
cou_0s = 0
cou_1s = 0
i = -1

for s in S:
    i += 1
    if i % 2 == 0 and s == "0":
        cou_1s += 1
    elif i % 2 == 0:
        cou_0s += 1
    elif s == "1":
        cou_1s += 1
    else:
        cou_0s += 1

print(min(cou_0s, cou_1s))

Submission status: Accepted

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

S = input()
l = len(S) - 1
cnt1, cnt2 = 0, 0
for i in range(l):
    if i % 2:
        if S[i] != '0':
            cnt1 += 1
    else:
        if S[i] != '1':
            cnt1 += 1
for i in range(l):
    if i % 2:
        if S[i] != '1':
            cnt2 += 1
    else:
        if S[i] != '0':
            cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit
# a = [int(input()) for _ in range(N)]
S = str(input())
L = len(S)
# T = str(input())
# exit()
st0 = 0
st1 = 0
pari = True
for i in range(L):
    if(S[i] == "0" and i%2 == 0):#1,3,5
        st1+=1
    elif(S[i] == "1" and i%2 == 0):
        st0+=1
    elif(S[i] == "0" and i%2 == 1):#0,2,4
        st0+=1
    elif(S[i] == "1" and i%2 == 1):
        st1+=1
# print(st0,st1)
print(min(st0,st1))

Submission status: Accepted

Solution code:
s = input()
count = 0
for k,i in enumerate(s):
    if k % 2 == 0:
        if i == '0':
            count += 1
    if k % 2 == 1:
        if i == '1':
            count += 1

count1 = 0
for k, i in enumerate(s):
    if k % 2 == 0:
        if i == '1':
            count1 += 1
    if k % 2 == 1:
        if i == '0':
            count1 += 1

print(min(count, count1))

Submission status: Accepted

Solution code:
import numpy as np
# import copy


s = np.array([int(a) for a in input()])
n = len(s)
ans1 = np.zeros(n)
ans2 = np.zeros(n)
ans1[::2] = 1
ans2[1::2] = 1
print(min(np.sum(ans1 == s),np.sum(ans2 == s)))

Submission status: Accepted

Solution code:
S = list(input())
M = len(S)
k1 = ['0']*M
k2 = ['1']*M

for i in range(1, M, 2):
    k1[i] = '1'
    k2[i] = '0'

cnt1 = 0
cnt2 = 0

for i in range(M):
    if k1[i] != S[i]:
        cnt1 += 1
    if k2[i] != S[i]:
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
S = input()
ch = '0'
ans = 0
for s in S:
	if s == ch:
		ans += 1
	if ch == '0':
		ch = '1'
	else:
		ch = '0'

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

Submission status: Accepted

Solution code:
def coloring_colorfully(S: str)->int:
    # 黒から始まるように変更した場合の操作と
    # 白から始まるように変更した場合の操作数。
    black, white = 0, 0

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

    return min(black, white)


if __name__ == "__main__":
    S = input()
    ans = coloring_colorfully(S)
    print(ans)

Submission status: Accepted

Solution code:
S = list(input())

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

print(min(cnt0, cnt1))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
now = S[0]

a = 0
b = 0
for i in range(1,N):
    if S[i] == now:
        a += 1
        now = str((int(now)+1)%2)
    else:
        now = S[i]

for i in reversed(range(N)):
    if S[i] == now:
        b += 1
        now = str((int(now)+1)%2)
    else:
        now = S[i]
print(min(a,b))

Submission status: Accepted

Solution code:
S = input()

#01010...
bw = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '1':
            bw += 1
    else:
        if S[i] == '0':
            bw += 1

#10101...
wb = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            wb += 1
    else:
        if S[i] == '1':
            wb += 1

print(min(bw,wb))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template #


S = li()
N = len(S)
bw = []
for i in range(N):
    if i % 2 == 0:
        bw.append(1)
    else:
        bw.append(0)

# print(bw)
cnt = 0
for i in range(N):
    if S[i] != str(bw[i]):
        cnt += 1

# print(cnt)
if cnt >= N // 2 + 1:
    print(N - cnt)
else:
    print(cnt)

Submission status: Accepted

Solution code:
from heapq import heappush,heappop

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

S = input()
S = list(S)
def ans():
    ans =0

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

print(ans())

Submission status: Accepted

Solution code:
def main():
    s = input()
    n = len(s)
    a = 0
    b = 0
    for i in range(n):
        if i & 1:
            if s[i] == '1':
                a += 1
            else:
                b += 1
        else:
            if s[i] == '1':
                b += 1
            else:
                a += 1
    print(min(a, b))
    return 0
main()

Submission status: Accepted

Solution code:
import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff


@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())

s = raw_input()
cnt1 = 0
cnt2 = 0
l1 = []
l2 = []
for i in xrange(len(s)):
	if i%2 == 0:
		l1.append('1')
		l2.append('0')
	else:
		l1.append('0')
		l2.append('1')
for i in xrange(len(s)):
	if l1[i] != s[i]:
		cnt1 += 1
	if l2[i] != s[i]:
		cnt2 += 1
print min(cnt1, cnt2)

Submission status: Accepted

Solution code:
s = str(input())
w1,w2,b1,b2 = 0,0,0,0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == "0":
      w1 += 1
    else:
      b1 += 1
  else:
    if s[i] == "0":
      w2 += 1
    else:
      b2 += 1
print(min(w1+b2,w2+b1))

Submission status: Accepted

Solution code:
ans = [0, 0]

S = input()

colorA = ['0', '1']
colorB = ['1', '0']
idx = 0

for s in S:
    if colorA[idx] != s:
        ans[0] += 1
    if colorB[idx] != s:
        ans[1] += 1
    idx = (idx+1) % 2

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n = input()
    #h = [int(i) for i in input().split()]
    n1 = ""
    n2 = ""
    for i in range(len(n)):
        if i % 2 == 0:
            n1 += n[i]
        else:
            n2 += n[i]

    a0 = n1.count("0")
    a1 = n1.count("1")
    b0 = n2.count("0")
    b1 = n2.count("1")

    print(min ( a1 + b0, a0 + b1))
main()