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:
# -*- coding: utf-8 -*-
import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたらFalse
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

def main():

    w=1
    j=0
    k=0
    #n=int(input())
    #r=int(input())
    s=input()
    even=0
    odd=0
    a=[int(i) for i in s]#int取るとstrでも行ける
    #if len(s)%2==0:
    N=len(s)
    for i in range(N):
        #print(a[i],(i%2))
        if i%2==0 and a[i]==0 :
            even=even+1
        elif i%2==1 and a[i]==1 :
            even=even+1
        else:# a[i%2==0]==1 or a[i%2==1]==0:
            odd=odd+1
    print(min(N-even,N-odd))
    #print(min(N-even,N-odd))
    '''
    if len(s)%2==1:
     for i in range(N//2):
         if a[2*i]==0 or a[2*i+1]==1:
             even=even+1
         if a[2*i]==1 or a[2*i+1]==0:
             odd=odd+1
     if a[-1]==0 :
         even=even+1
     if a[-1]==1 :
         odd=odd+1

        #if a[2*i]==0:
        #    even=even+1
        #else if a[2*1]==0:
        #    odd=odd+1
    '''
    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    "1行1つの整数を入力を取得し、整数と取得する"
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(number_list)
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)


    #s=input()
    #a=[int(i) for i in s]#int取るとstrでも行ける
    #print(a)
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

    ls = ["a", "b", "c", "d", "e"]


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    S=input()
    N=len(S)
    s1="01"*(N//2)+"0"*(N%2)
    s2="10"*(N//2)+"1"*(N%2)
    #print(s1,s2)
    ans1,ans2=0,0
    for s in range(N):
        if S[s]!=s1[s]:ans1+=1
        if S[s]!=s2[s]:ans2+=1
    print(min(ans1,ans2))
#%%submit!    
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

s_ = S()
n = len(s_)
s = [int(s_[i]) for i in range(n)]
ans = 0
for i in range(1, n):
    if s[i-1] == s[i]:
        ans += 1
        s[i] ^= 1

ans = min(ans, n-ans)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
S = list(input())

N=len(S)
dammy1=0
dammy2=0
count=[]
#0101010101
for i in range(N):
    if i%2==0:
        if S[i] != '0':
            dammy1 += 1
    else:
        if S[i] != '1':
            dammy1 += 1
count.append(dammy1)

#1010101010
for i in range(N):
    if i%2==0:
        if S[i] != '1':
            dammy2 += 1
    else:
        if S[i] != '0':
            dammy2 += 1
count.append(dammy2)

print(min(count))

Submission status: Accepted

Solution code:
s = list(input())

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

print(ans)

Submission status: Accepted

Solution code:
S=input()
cnt=0
pre_s=""
if len(S)==1:
  print(0)
  exit(0)
for i in S:
  if pre_s == "":
    pre_s = "1" if i=="1" else "0"
  elif pre_s == i:
    pre_s = "1" if i=="0" else "0"
    cnt +=1
  else:
    pre_s = i
print(cnt)

Submission status: Accepted

Solution code:
S = input()

a = 0
b = 0

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

print(min(a, b))

Submission status: Accepted

Solution code:
Sin = input()
S = list(Sin)
S2 = list(Sin)
N = len(S)

if S[0] == "0":
    S[0] = "1"
else:
    S[0] = "0"

ans1 = 1    
for i in range(1, N):
    if S[i] == S[i-1]:
        if S[i-1] == "0":
            S[i] = "1"
        else:
            S[i] = "0"
        ans1 += 1

ans2 = 0
for i in range(1, N):
    if S2[i] == S2[i-1]:
        if S2[i-1] == "0":
            S2[i] = "1"
        else:
            S2[i] = "0"
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

S = input()

count = 0
for i in range(len(S)):
    t = int(S[i])
    if i==0:
        b = int(t)
    else:
        if b==0 and t==0:
            count += 1
            b = 1
        elif b==1 and t==1:
            count += 1
            b = 0
        else:
            b = t
print(count)

Submission status: Accepted

Solution code:
s = list(input())
s1 = s.copy()
s2 = s.copy()
c1 = 0
c2 = 0
for i in range(len(s1)-1):
    if s1[i] == s1[i+1]:
        c1 += 1
        s1[i+1] = '0' if s1[i] == '1' else '1'
for j in range(len(s2)-1, 0, -1):
    if s2[j] == s2[j-1]:
        c2 += 1
        s2[j-1] = '0' if s2[j] == '1' else '1'
print(min(c1, c2))

Submission status: Accepted

Solution code:
s = input()
l = len(s)
x = 0
y = 0
if (l/2)%2==0:
  a="01"*(l//2)
  b="10"*(l//2)
else:
  a="01"*(l//2)+"0"
  b="10"*(l//2)+"1"
for i in range(l):
  if s[i]!=a[i]:
    x+=1
  if s[i]!=b[i]:
    y+=1
print(min(x,y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    # 0から始まる文字列
    s1 = list(map(lambda x: str(x % 2), range(len(S))))
    ans1 = 0
    ans2 = 0
    for i, s in enumerate(S):
        if s1[i] != s:
            ans1 += 1
        else:
            ans2 += 1
    print(min([ans1, ans2]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

A1 = [0]*N#0から始まる
A2 = [0]*N#1から始まる
for i in range(N):
  if i%2==0:
    A2[i]=1
  else:A1[i]=1
count1=0
count2=0
for i in range(N):
  if S_int[i]!=A1[i]:
    count1 += 1
  if S_int[i]!=A2[i]:
    count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
import itertools
import math

s = input()
n = []
for i in range(len(s)):
    n.append(s[i])

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

print(count)

Submission status: Accepted

Solution code:
s = input()

ans = 0
temp = s[0]
for i in range(1,len(s)):
    if temp == s[i]:
        ans += 1
        if temp == "1":
            temp = "0"
        else:
            temp = "1" 
    else:
        temp = s[i]


ans2 = 1
if s[0] == "0":
    temp = "1"
else:
    temp = "0"
for i in range(1,len(s)):
    if temp == s[i]:
        ans2 += 1
        if temp == "1":
            temp = "0"
        else:
            temp = "1" 
    else:
        temp = s[i]

print(min(ans,ans2))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
if n==1:
  kouho1=[1]
  kouho2=[0]
else:
  kouho1=[0,1]*(n//2)
  kouho2=[1,0]*(n//2)
if n%2==1:
  kouho1.append(0)
  kouho2.append(1)

count1=0
count2=0
for i in range(0,n):
  ss=int(s[i])
  count1+=abs(kouho1[i]-ss)
  count2+=abs(kouho2[i]-ss)
  
print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
case0=0
case1=0

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

print(min(case0,case1))

Submission status: Accepted

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

res0=0
res1=0

for i in range(0,l,2):
	if s[i]=="0":
		res0+=1
	else:
		res1+=1
		
for i in range(1,l,2):
	if s[i]=="1":
		res0+=1
	else:
		res1+=1

print(min(res0,res1))

Submission status: Accepted

Solution code:
s = input()
ans_ptn1 = ""
ans_ptn2 = ""

for i in range(len(s)):
    if i % 2 == 0:
        ans_ptn1 += "0"
        ans_ptn2 += "1"
    else:
        ans_ptn1 += "1"
        ans_ptn2 += "0"

ans1 = 0
ans2 = 0
for i in range(len(s)):
    if s[i] == ans_ptn1[i]:
        ans1 += 1
    if s[i] == ans_ptn2[i]:
        ans2 += 1
        
print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

pre = S[0]
ans = 0

for s in S[1:]:
  if pre == s:
    ans += 1
  if pre == "0":
    pre = "1"
  else:
    pre = "0"
print(ans)

Submission status: Accepted

Solution code:
def main():
    S = input()
    before_c = None
    cnt = 0
    for c in S:
        c = int(c)
        if before_c == c:
            before_c = 1 - c
            cnt += 1
        else:
            before_c = c
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

a = ["0", "1"]
b = ["1", "0"]

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

print(min(acount, bcount))

Submission status: Accepted

Solution code:
sss = list(map(int, input()))
cnt2 = 0
cnt3 = 0
for i, s in enumerate(sss):
    if i % 2 == 0:
        if s == 1:
            cnt2 += 1
    else:
        if s == 0:
            cnt2 += 1

    if i % 2 == 0:
        if s == 0:
            cnt3 += 1
    else:
        if s == 1:
            cnt3 += 1

print(min(cnt2, cnt3))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
n=len(s)
ones=""
zers=""
counto,countz=0,0
for i in range(n):
    if i%2==0:
        ones+="1"
        zers+="0"
    else:
        ones+="0"
        zers+="1"
for i in range(n):
    if ones[i]!=s[i]:
        counto+=1
    if zers[i]!=s[i]:
        countz+=1
print(min(countz,counto))

Submission status: Accepted

Solution code:
moji = list(str(input()))
cnt =0
if moji[0]=="0":
  for i in range(len(moji)):
    if i%2==0:
      if moji[i]!="0":
        cnt+=1
    else:
      if moji[i]!="1":
        cnt+=1
else:
  for j in range(len(moji)):
    if j%2==0:
      if moji[j]!="1":
        cnt+=1
    else:
      if moji[j]!="0":
        cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    x=len(s)//2
    l1='10'*x+'1'
    l2='01'*x+'0'
    cnt1=0
    cnt2=0
    for i in range(len(s)):
        if s[i]!=l1[i]:
            cnt1+=1
        if s[i]!=l2[i]:
            cnt2+=1
    print(min(cnt1,cnt2))
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    x=len(s)//2
    l1=[1,0]*x+[1]
    l2=[0,1]*x+[0]
    cnt1=0
    cnt2=0
    for i in range(len(s)):
        if s[i]!=str(l1[i]):
            cnt1+=1
        if s[i]!=str(l2[i]):
            cnt2+=1
    print(min(cnt1,cnt2))
resolve()

Submission status: Accepted

Solution code:
S=input()
S0=S[::2]
S1=S[1::2]
S01=S0.count('1')
S00=S0.count('0')
S11=S1.count('1')
S10=S1.count('0')
change=min(S00+S11,S10+S01)
print(change)

Submission status: Accepted

Solution code:
s=input()
a1=0
a2=0
for i,v in enumerate(s):
    if i%2==0:
        if v=="1":
            a1+=1
        else:
            a2+=1
    else:
        if v=="1":
            a2+=1
        else:
            a1+=1
print(min(a1,a2))

Submission status: Accepted

Solution code:
n = str(input())
a = "10" * int(len(n)/2) 
b = "01" * int(len(n)/2) 
if int(len(n)) % 2 !=0:
    a +="1"
    b +="0"
s = int(n) + int(a)
t = int(n) + int(b)
p = str(s)
q = str(t)
print(min(p.count("1"),q.count("1")))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()
l = len(S)
s1 = ''.join(['0' if i % 2 == 0 else '1' for i in range(l)])
s2 = ''.join(['1' if i % 2 == 0 else '0' for i in range(l)])

t1 = 0
t2 = 0
for i, j, s in zip(s1, s2, S):
    if i != s:
        t1 += 1
    if j != s:
        t2 += 1
print(min(t1, t2))

Submission status: Accepted

Solution code:
# ABC124C

s = input()
s = [int(t) for t in list(s)]
repaint = 0
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        repaint += 1
        s[i] = 1 - s[i]
print(repaint)

Submission status: Accepted

Solution code:
s = input()
w = b = 0
for i, c in enumerate(s):
    if (int(c)+i)%2==0:
        w += 1
    else:
        b += 1
print(min(w, b))

Submission status: Accepted

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

Submission status: Accepted

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

    else:
        if s[i] == '1':
            ans += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
n = len(s)
res0 = "01"*(n//2) + "0"*(n % 2)
res1 = "10"*(n//2) + "1"*(n % 2)
ans0 = 0
ans1 = 0
for i in range(n):
    ans0 += abs(int(res0[i]) - int(s[i]))
    ans1 += abs(int(res1[i]) - int(s[i]))
print(min(ans1, ans0))

Submission status: Accepted

Solution code:
import numpy as np

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

a01 = np.tile([0,1], len(s)//2)
a10 = np.tile([1,0], len(s)//2)

if len(s)%2 != 0:
    a01 = np.append(a01, 0)
    a10 = np.append(a10, 1)

ans01 = np.abs(s -a01)
ans10 = np.abs(s -a10)

if sum(ans01) >= sum(ans10):
    print(sum(ans10))
else:
    print(sum(ans01))

Submission status: Accepted

Solution code:
import numpy as np

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

a01 = np.tile([0,1], len(s)//2+1)
a10 = np.tile([1,0], len(s)//2+1)

if len(s)%2 != 0:
    a01 = np.delete(a01, len(s))
    a10 = np.delete(a10, len(s))
else:
    a01 = np.delete(a01, [len(s)-1,len(s)])
    a10 = np.delete(a10, [len(s)-1,len(s)])

ans01 = np.abs(s -a01)
ans10 = np.abs(s -a10)

if sum(ans01) >= sum(ans10):
    print(sum(ans10))
else:
    print(sum(ans01))

Submission status: Accepted

Solution code:
s=input()

sodd=0
sevn=0

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

print(min(sodd,sevn))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
s1 = []
s2 = []
for i in range(len(s)):
    if i % 2 == 0:
        s1.append('0')
        s2.append('1')
    else:
        s1.append('1')
        s2.append('0')
min_1 = 0
#for i in range(2):
for i in range(len(s)):
    if s[i] != s1[i]:
        min_1 += 1
        
min_2 = 0
for i in range(len(s)):
    if s[i] != s2[i]:
        min_2 += 1
print(min(min_1, min_2))

Submission status: Accepted

Solution code:
s=list(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
    if i%2 != 0:
        if s[i] == '0':
            c2 += 1
    else:
        if s[i] == '1':
            c2 += 1
print(min(c1,c2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
tile1 = ""
tile2 = ""

for i in range(n):
  if i % 2 == 0:
    tile1 += "0"
    tile2 += "1"
  else:
    tile1 += "1"
    tile2 += "0"

ans1 = 0
ans2 = 0

for i in range(n):
  if s[i] == tile1[i]:
    ans1 += 1
  if s[i] == tile2[i]:
    ans2 += 1
    
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
def coloring_colorfully(s):

    ans = 0
    color = {"0":"1", "1":"0"}

    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            ans += 1
            s[i] = color[s[i]]

    return ans

def main():
    s = list(str(input()))
    print(coloring_colorfully(s))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

s = list(map(int, input()))
cnt = 0
# print(s)
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if s[i] == 0:
            s[i+1] = 1
            cnt += 1
        if s[i] == 1:
            s[i+1] = 0
            cnt += 1
print(cnt)

Submission status: Accepted

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

ans=0

if s[0]=="0":
    for i in range(1,l):
        if i%2 != 0:
            if s[i] != "1":
                ans+=1
        
        if i%2 == 0:
            if s[i] != "0":
                ans+=1

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

print(ans)