Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

000

Sample Output 1

1

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

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ans1 = 0
ans2 = 0
for i in range(N):
  if i % 2 == 0 and S[i] == "0":
    ans1 += 1
  if i % 2 == 1 and S[i] == "1":
    ans1 += 1
for i in range(N):
  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 = [int(i) for i in input()]
S1 = [i % 2 for i in range(len(S))]
S2 = [(i + 1) % 2  for i in range(len(S))]

s1 = 0
s2 = 0

for i in range(len(S)):
  if S[i] == S1[i]:
    s1 += 1
  if S[i] == S2[i]:
    s2 += 1
print(min(s1,s2))

Submission status: Accepted

Solution code:
s = input()
len = len(s)
min1,min2 = 0,0
moji1 = "10" * (len//2 +1)
moji2 = "01" * (len//2 +1)
for i in range(len) :
    if s[i] != moji1[i] :
        min1 += 1
    if s[i] != moji2[i] :
        min2 += 1
print(min(min1,min2))

Submission status: Accepted

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

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

tmp = 1
for i in range(k):
    if tmp != S[i]:
        ans2 += 1
    tmp = (tmp + 1) % 2

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()
length = len(s)
black_s = ["0" if x %2 == 0 else "1" for x in range(length) ]
white_s = ["0" if x %2 == 1 else "1"for x in range(length)]

black = 0
white = 0
for index, x in enumerate(s):
    if x != black_s[index]:
        black += 1

    if x!= white_s[index]:
        white += 1
else:
    print(min(black, white))

Submission status: Accepted

Solution code:
S = input()
ans = 10 ** 6
# 奇数番目が1のケース
temp = 0
for i in range(len(S)):
    if i & 1 :
        if S[i] == '0':
            temp += 1
    else:
        if S[i] != '0':
            temp += 1
ans = min(ans,temp)
# 奇数番目が0のケース
temp = 0
for i in range(len(S)):
    if i & 1 :
        if S[i] != '0':
            temp += 1
    else:
        if S[i] == '0':
            temp += 1
ans = min(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

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

S = input()

r1 = 0
r2 = 0
for i in range(len(S)):
    if int(S[i]) == (i % 2):
        r1 += 1
    else:
        r2 += 1
print(min(r1, r2))

Submission status: Accepted

Solution code:
S = input()

length = len(S)
counter = 0

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

    else:
        if S[i] == '1':
            counter += 1

print(length - counter if length // 2 < counter else counter)

Submission status: Accepted

Solution code:

TL = input()
TL = list(TL)
cnt1 = 0
cnt2 = 0
fg = True

for lop in range(0,len(TL)):
    if fg == True:
        if TL[lop] == "0":
            cnt1 += 1
    else:
        if TL[lop] == "1":
            cnt1 += 1
    fg = fg ^ 1

fg = True
for lop in range(0,len(TL)):
    if fg == True:
        if TL[lop] == "1":
            cnt2 += 1
    else:
        if TL[lop] == "0":
            cnt2 += 1
    fg = fg ^ 1
 
print( min(cnt1,cnt2) )

Submission status: Accepted

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

kouho0 = [i % 2 == 0 for i in range(len(tiles))]
kouho1 = [i % 2 != 0 for i in range(len(tiles))]

kekka0 = 0
kekka1 = 0
for i in range(len(tiles)):
    if tiles[i] != kouho0[i]:
        kekka0 += 1
    if tiles[i] != kouho1[i]:
        kekka1 += 1

if kekka0 < kekka1:
    print(kekka0)
else:
    print(kekka1)

Submission status: Accepted

Solution code:
s = input()

x = s[0::2].count("0") + s[1::2].count("1")
y = s[0::2].count("1") + s[1::2].count("0")

print(min(x, y))

Submission status: Accepted

Solution code:


# N = int(input())
# A, B = map(int, input().split())

S = input()
a, b = 0, 0
for i, c in enumerate(S):
    c = int(c)
    if i % 2 == c:
        a += 1
    else:
        b += 1
print(min(a, b))

Submission status: Accepted

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

length=len(s)
target_1=[]
target_2=[]
for i in range(length):
    if i%2==0:
        target_1.append(1)
        target_2.append(0)
    else:
        target_1.append(0)
        target_2.append(1)
sum_1=0
sum_2=0
for i in range(length):
    if target_1[i]!=s[i]:
        sum_1=sum_1+1
    if target_2[i]!=s[i]:
        sum_2=sum_2+1

print(min(sum_1, sum_2))

Submission status: Accepted

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

SA="01"*(int(N))
SB="10"*(int(N))
ma=0
mb=0
for i in range(N):
    if SA[i]!=S[i]:
        ma+=1
    else:
        mb+=1
print(min(ma,mb))

Submission status: Accepted

Solution code:
s = input()

cnt_1 = 0
cnt_2 = 0

pattern = "01"

for i in range(len(s)):
    if s[i] != pattern[i % 2]:
        cnt_1 += 1
    
    if s[i] != pattern[(i + 1) % 2]:
        cnt_2 += 1

print(min(cnt_1, cnt_2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a = []
b = []
for i, s in enumerate(S):
  if i%2==0:
    a.append(s)
  else:
    b.append(s)
a0 = a.count('0')
a1 = a.count('1')
b0 = b.count('0')
b1 = b.count('1')
if a0+b1>=a1+b0:
  print(a1+b0)
else:
  print(a0+b1)

Submission status: Accepted

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

ans1 = 0
ans2 = 0

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


print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()

cnt = 0
prev = S[0]
for i in range(1, len(S)):
    if S[i] == prev:
        cnt += 1
        prev = str(abs(int(S[i])-1))
    else:
        prev = S[i]
    
print(cnt)

Submission status: Accepted

Solution code:
# 初めが白か黒か

S = list(input())
N = len(S)
ans0 = 0
ans1 = 0
# 0 偶数
for i in range(N):
    if i % 2 == 0:
        if S[i] == '0':
            pass
        else:
            ans0 += 1
    else:
        if S[i] == '1':
            pass
        else:
            ans0 += 1


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

print(min(ans0, ans1))

Submission status: Accepted

Solution code:
def solve(s):
    side = 0
    count = [0,0]
    for c in s:
        if c != "0":
            count[side] += 1
        else:
            count[1-side] += 1
        side = 1 - side
    print(min(count))

s = input()
solve(s)

Submission status: Accepted

Solution code:
s = input()
zeroone = '01'* len(s)
onezero = '10' * len(s)
count_z = 0
count_o = 0
for i in range(len(s)):
    if s[i] == zeroone[i]:
        count_z += 1
    else:
        count_o += 1
print(min(count_o, count_z))

Submission status: Accepted

Solution code:
s=list(input())
a=s[::2].count("0")+s[1::2].count("1")
b=s[::2].count("1")+s[1::2].count("0")
print(len(s)-max(a,b))

Submission status: Accepted

Solution code:
S = input()

res = 0
tmp = ""

for i in S:
    if tmp != i:
        tmp = i
        continue
    if i == "0":
        tmp = "1"
        res += 1
    else:
        tmp = "0"
        res += 1

print(res)

Submission status: Accepted

Solution code:
s = input()

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


print(min(start_white, start_black))

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [S] = [(input_raw[0])]
    N = len(S)
    opt1 = "1"
    opt2 = "0"
    for i in range(1, N):
        opt1 += "1" if opt1[i - 1] == "0" else "0"
        opt2 += "1" if opt2[i - 1] == "0" else "0"
    count1 = 0
    count2 = 0
    for i in range(N):
        if S[i] != opt1[i]:
            count1 += 1
        if S[i] != opt2[i]:
            count2 += 1
    print min(count1, count2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def make_valid(leng):
    s0 = ''
    s1 = ''
    last0 = '0'
    last1 = '1'
    for i in range(leng):
        s0 = s0 + last0
        s1 = s1 + last1
        last0, last1 = last1, last0
    return (s0, s1)


def count_dif(s, s1):
    ret = 0
    for idx,c in enumerate(s):
        if c != s1[idx]:
            ret += 1
    return ret

v0,v1 = make_valid(leng)
min_dif = min(count_dif(S,v0), count_dif(S,v1))
print(min_dif)

Submission status: Accepted

Solution code:
s=input()
r1=0
r2=0
sw="0"
for z in s:
  if sw==z:
    r1+=1
  else:
    r2+=1
  if sw=="0":
    sw="1"
  else:
    sw="0"
print(min((r1,r2)))

Submission status: Accepted

Solution code:
S = input()

zero = 0
for i, e in enumerate(S):
    if i % 2 == 0 and e == '1':
        zero += 1
    elif i % 2 == 1 and e == '0':
        zero += 1
one = 0
for i, e in enumerate(S):
    if i % 2 == 0 and e == '0':
        one += 1
    elif i % 2 == 1 and e == '1':
        one += 1

print(min(zero, one))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
cur1 = 1
cur2 = 0
ans1,ans2 = 0,0
for i in range(n):
    if cur1 != int(s[i]):
        ans1 +=1
    if cur2  != int(s[i]):
        ans2 += 1
    if cur1 ==1:
        cur1 = 0
    else:
        cur1 = 1
    if cur2 == 0:
        cur2 = 1
    else:
        cur2 = 0
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
od = [0, 0]
ev = [0, 0]
for i, s in enumerate(S):
    if i % 2 == 0:
        if s == '0':
            ev[0] += 1
        else:
            ev[1] += 1        
    else:
        if s == '0':
            od[0] += 1
        else:
            od[1] += 1
print(min(od[0]+ev[1], od[1]+ev[0]))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
count = 0
for i, s in enumerate(S):
	if i % 2 == 0:
		if s == "0":
			count += 1
	else:
		if s == "1":
			count += 1

print(min(count, N - count))

Submission status: Accepted

Solution code:
S = input()
c = 0
x = 0
for i in S:
    if i == str(c):
        x+=1
    c = (c+1)%2
print(min(x,len(S)-x))

Submission status: Accepted

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

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    s = list(input())
    s.append("2")
    res = ans = i = 0
    while i < len(s) - 2:
        if s[i] != s[i + 1]:
            i += 1
        elif s[i] == s[i + 1] and s[i + 1] == s[i + 2]:
            i += 2
            ans += 1
        else:
            s[i + 1] = "1" if s[i + 1] == "0" else "0"
            ans += 1
            i += 1
    p(ans)


main()

Submission status: Accepted

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

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

d1 = len([1 for s,p in zip(S,p1) if not s == p])
d2 = len([1 for s,p in zip(S,p2) if not s == p])

print(min(d1,d2))

Submission status: Accepted

Solution code:
S = input()

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

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

print(len(S) - max(count, count2))

Submission status: Accepted

Solution code:
S=input()
e=[0,0]#全体、白の数
o=[0,0]
for i,s in enumerate(S):
    if i%2:#odd
        o[0]+=1
        o[1]+=int(s)
    else:
        e[0]+=1
        e[1]+=int(s)
eblack,ewhite=e[0]-e[1],e[1]
oblack,owhite=o[0]-o[1],o[1]
print(min(eblack+owhite,ewhite+oblack))

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input().strip()
    slen = len(s)

    ans1 = 0
    for i in range(slen):
        if s[i] != str(i%2):
            ans1 += 1
    ans2 = 0

    for i in range(slen):
        if s[i] != str((i+1)%2):
            ans2 += 1
    
    print(min(ans1, ans2))

solve()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
c1 = c2 = 0
for i in range(N):
    if (S[i] == '0') ^ (i % 2):
        c1 += 1
    elif (S[i] == '1') ^ (i % 2):
        c2 += 1
print(min([c1, c2]))

Submission status: Accepted

Solution code:
def solve():
  S = input()
  cnt = 0
  flag = False
  for s in S:
    flag = not flag
    if s == str(int(flag)): continue
    cnt = cnt + 1

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

print(solve())

Submission status: Accepted

Solution code:
s = input()
    
ans1, ans2 = 0, 0

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    if s[i] == str(i%2):
        ans += 1

print(min(ans, n-ans))

Submission status: Accepted

Solution code:
s = input()
a = [int(c) for c in s]

def ans1(a):
	c = 0
	for i in range(len(a)):
		if(i%2 == 0 and a[i]==1):
			c = c + 1
		elif(i%2 == 1 and a[i] == 0):
			c = c + 1
	return c
	
def ans2(a):
	c = 0
	for i in range(len(a)):
		if(i%2 == 0 and a[i]==0):
			c = c + 1
		elif(i%2 == 1 and a[i] == 1):
			c = c + 1
	return c

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S1 = S[::2]
S2 = S[1::2]
ans1 = S1.count('0') + S2.count('1')
ans2 = S1.count('1') + S2.count('0')
ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

str01 = "01" * (N // 2)
str10 = "10" * (N // 2)
if N % 2 == 1:
    str01 += "0"
    str10 += "1"

ans01 = 0
ans10 = 0
for i in range(N):
    if S[i] != str01[i]:
        ans01 += 1
    if S[i] != str10[i]:
        ans10 += 1

print(min(ans01, ans10))

Submission status: Accepted

Solution code:
S = input()

count1 = 0
count2 = 0
for s_i, s in enumerate(S):
    if s_i % 2 == 0:
        if s == "0":
            count1 += 1
        else:
            count2 += 1
    else:
        if s == "1":
            count1 += 1
        else:
            count2 += 1

out = min(count1, count2)
print(out)

Submission status: Accepted

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

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

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

print(min(a,b))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

a=0#0
b=0#1

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

print(min(a,b))

Submission status: Accepted

Solution code:
S = str(input())

S_10 = '10' * (len(S) // 2)
if len(S) % 2 == 1:
  S_10 += '1'
S_01 = '01' * (len(S) // 2)
if len(S) % 2 == 1:
  S_01 += '0'
  
s_10 = sum([x != y for (x, y) in zip(list(S), list(S_10))])
s_01 = sum([x != y for (x, y) in zip(list(S), list(S_01))])
print(min(s_10, s_01))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)

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

print(min(count, N - count))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools


# リストに入れる
s = [int(i) for i in input()] 

answer = [0,0]
for j in range(2):
    for i in range(len(s)):
        if (s[i]+i) % 2 == j:
            answer[j] += 1

print(min(answer[0],answer[1]))

Submission status: Accepted

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

if N % 2:
	A = '01'*(N//2)+'0'
	#B = '10'*(N//2)+'1'
else:
	A = '01'*(N//2)
	#B = '10'*(N//2)

c1 = 0
c2 = 0
for s,a in zip(S,A):
	if s!=a:
		c1+=1
	else:
		c2+=1

print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()
ans1 = 0
ans2 = 0
frag = True
for s in S:
  if s == '1' and frag:
    ans1 += 1
  elif frag:
    ans2 += 1
  elif s == '0':
    ans1 += 1
  else:
    ans2 += 1
  frag = not frag
print(min(ans1,ans2))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()

count = 0
for i, si in enumerate(S):
    if i % 2 == 0 and si != '0':
        count += 1
    if i % 2 == 1 and si != '1':
        count += 1

mi = count

count = 0
for i, si in enumerate(S):
    if i % 2 == 0 and si != '1':
        count += 1
    if i % 2 == 1 and si != '0':
        count += 1

print(min(mi, count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
tile = input()

head = tile[0]
tile = tile[1:]
tmp = head

counter = 0

for i in tile:
    if i == tmp and i == "1":
        i = "0"
        tmp = i
        counter += 1
    elif i == tmp and i == "0":
        i = "1"
        tmp = i
        counter += 1
    else:
        tmp = i

print(counter)

Submission status: Accepted

Solution code:
S=input()

def Diff(S,S2):
    r=0
    for i in range(len(S)):
        if S[i]!=S2[i]:
            r+=1
            
    return r


if len(S)%2==0:
    print(min(Diff(S,"01"*int(len(S)/2)),Diff(S,"10"*int(len(S)/2))))
else:
    print(min(Diff(S,"01"*int(len(S)/2)+"0"),Diff(S,"10"*int(len(S)/2)+"1")))

Submission status: Accepted

Solution code:
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 += 1
  x = hen(x)
print(min(c1,c2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 20:57:42 2019

@author: Yamazaki Kenichi
"""

S = input()

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

Submission status: Accepted

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

ans_0 = 0
tmp = 0
for i in s:
  if i != tmp:
    ans_0 += 1
  tmp = 1-tmp

ans_1 = 0
tmp = 1
for i in s:
  if i != tmp:
    ans_1 += 1
  tmp = 1-tmp
    
print(min(ans_0,ans_1))

Submission status: Accepted

Solution code:
str = input()
cnt = 0
num = 0
for i in str:
    if cnt % 2 == 0:
        if i == '0':
            num += 1
    else:
        if i == '1':
            num += 1
    cnt += 1

cnt2 = 0
num2 = 0
for i in str:
    if cnt2 % 2 == 0:
        if i == '1':
            num2 += 1
    else:
        if i == '0':
            num2 += 1
    cnt2 += 1

print(min(num,num2))

Submission status: Accepted

Solution code:
s = input()
# 01010...
pata = 0
# 10101...
patb = 0
for i, c in enumerate(s):
    val = i%2
    if val == 0:
        if c == "0":
            patb += 1
        if c == "1":
            pata += 1
    if val == 1:
        if c == "1":
            patb += 1
        if c == "0":
            pata += 1

print(min(pata, patb))

Submission status: Accepted

Solution code:
S = input()

a = len(S[::2]) - S[::2].count('1') + len(S[1::2]) - S[1::2].count('0')
b = len(S[::2]) - S[::2].count('0') + len(S[1::2]) - S[1::2].count('1')
print(min(a, b))

Submission status: Accepted

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

S = input()

a, b = 0, 0
for i in range(len(S)):
    if i % 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:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str):
    N = len(S)
    ptn1 = [1 if i & 1 else 0 for i in range(N)]
    # print(*ptn1, sep="")
    ans1 = 0
    for i, c in enumerate(S):
        if int(c) != ptn1[i]:
            ans1 += 1
    # print(ans1)
    ptn2 = [0 if i & 1 else 1 for i in range(N)]
    # print(*ptn2, sep="")
    ans2 = 0
    for i, c in enumerate(S):
        if int(c) != ptn2[i]:
            ans2 += 1
    # print(ans2)

    print(min(ans1, ans2))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
hoge=list(input())
hoge_a=[]
hoge_b=[]
for i in range(len(hoge)):
  if(i%2==0):
    hoge_a.append(hoge[i])
  else:
    hoge_b.append(hoge[i])
    
ans=min(len(hoge_a)-hoge_a.count("0")+
        len(hoge_b)-hoge_b.count("1"),
        len(hoge_a)-hoge_a.count("1")+
        len(hoge_b)-hoge_b.count("0"))

print(ans)

Submission status: Accepted

Solution code:
s = [int(t) for t in list(input())]
n = len(s)
a = sum(s[0::2])
b = sum(s[1::2])
# print(a,b,n)
x = ((n+1)//2 - a) + b
y = a + (n//2-b)
print(min(x,y))

Submission status: Accepted

Solution code:
s = input()
odd = s[0::2]
even = s[1::2]

oddone = odd.count('1')
oddzero = odd.count('0')
evenone = even.count('1')
evenzero = even.count('0')

ans = min(oddone+evenzero, oddzero+evenone)

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

reatInt = lambda: int(sys.stdin.readline())
reatIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]


ss = sys.stdin.readline()
e = 0
o = 0
for i, s in enumerate(ss):
    if i % 2 == 0:
        e += int(s == '0')
        o += int(s == '1')
    else:
        e += int(s == '1')
        o += int(s == '0')
ret = min(e, o)
print(ret)

Submission status: Accepted

Solution code:
S = input()

odd = S[::2]
even = S[1::2]

A = odd.count('0') + even.count('1')
B = odd.count('1') + even.count('0')
print(min(A, B))

Submission status: Accepted

Solution code:
s=input()
s1=s2=''

for i in range(len(s)):
    if i%2==0:
        s1+='1'
        s2+='0'
    else:
        s1+='0'
        s2+='1'
c1=c2=0
for i in range(len(s)):
    if s1[i]!=s[i]:
        c1+=1
    if s2[i]!=s[i]:
        c2+=1
print(min(c1,c2))

Submission status: Accepted

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