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()
c1 = 1 if s[0] == '0' else 0
a = []
a.append('1')
for i in range(1,len(s)):
  if s[i] == a[len(a)-1]:
    c1+=1
    a.append('0' if s[i]=='1' else '1')
  else:
    a.append(s[i])
    
a = []
a.append('0')
c2 = 1 if s[0]=='1' else 0
for i in range(1,len(s)):
  if s[i] == a[len(a)-1]:
    c2+=1
    a.append('0' if s[i]=='1' else '1')
  else:
    a.append(s[i])
    
    
print(min(c1,c2))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
c_list = [int(c) for c in input()]
n = len(c_list)

o_count = [0, 0]
for i in range(0, n, 2):
    o_count[int(c_list[i])] += 1

e_count = [0, 0]
for i in range(1, n, 2):
    e_count[c_list[i]] += 1

print(min(o_count[1] + e_count[0], o_count[0] + e_count[1]))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = list(input()[:-1])
n = len(s)

#0番目を1にする
res = 0
for i in range(n):
    if i%2 == 0 and s[i] == '0':
        res += 1
    elif i%2 == 1 and s[i] == '1':
        res += 1

#0番目を0にする
res2 = 0
for i in range(n):
    if i%2 == 0 and s[i] == '1':
        res2 += 1
    elif i%2 == 1 and s[i] == '0':
        res2 += 1
print(min(res,res2))

Submission status: Accepted

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

se = [0]*s
so = [0]*s

for i in range(s):
  if i%2 == 0:
    se[i] = 1
  else:
    so[i] = 1

ce = 0
co = 0

for j in range(s):
   x = int(S[j])
   if x != se[j]:
      ce += 1
   if x != so[j]:
      co += 1

print(min(ce,co))

Submission status: Accepted

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

    ans = 1000000000
    # 0, 1
    for iro in range(2):
        cnt = 0
        for idx, s in enumerate(S):
            if idx % 2 == 0 and str(iro) != s: cnt += 1
            elif idx % 2 != 0 and str(iro) == s: cnt += 1
        # print(cnt)
        ans = min(ans, cnt)

    print(ans)
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

    ans = len(S)
    # 0, 1
    for iro in range(2):
        cnt = 0
        for idx, s in enumerate(S):
            if idx % 2 == 0 and str(iro) != s: cnt += 1
            elif idx % 2 != 0 and str(iro) == s: cnt += 1
        # print(cnt)
        ans = min(ans, cnt)

    print(ans)
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

    ans = len(S)
    # 0, 1
    for iro in range(2):
        cnt = 0
        for idx, s in enumerate(S):
            if idx % 2 == 0 and str(iro) != s: cnt += 1
            if idx % 2 != 0 and str(iro) == s: cnt += 1
        # print(cnt)
        ans = min(ans, cnt)

    print(ans)
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

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

    # 最初を書き換えない
    iro = S[0]
    cnt1 = 0
    for idx, s in enumerate(S):
        if idx % 2 == 0 and s != iro:
            cnt1 += 1
        elif idx % 2 != 0 and s == iro:
            cnt1 += 1

    # 最初を書き換える
    cnt2 = 0
    for idx, s in enumerate(S):
        if idx % 2 == 0 and s == iro:
            cnt2 += 1
        elif idx % 2 != 0 and s != iro:
            cnt2 += 1

    print(min(cnt1, cnt2))



if __name__ == '__main__':
    solve()

Submission status: Accepted

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

s1 = "01" * (N // 2)
s2 = "10" * (N // 2)

if N % 2 == 1:
    s1 += "0"
    s2 += "1"

diff1 = 0
diff2 = 0

for i in range(N):
    if S[i] != s1[i]:
        diff1 += 1
    if S[i] != s2[i]:
        diff2 += 1

print(min(diff1, diff2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
start_1 = [0] * n
start_0 = [0] * n

for i in range(n):
    if i % 2 == 0:
        start_1[i] = 1
    else:
        start_0[i] = 1
        
d1 = 0
d2 = 0

for i in range(n):
    x = int(s[i])
    
    if x != start_1[i]:
        d1 += 1
        
    if x != start_0[i]:
        d2 += 1
        
print(min(d1,d2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
l=[]
for i in range(len(s)):
    l.append(s[i])

cnt=0
for i in range(1,len(l)):
    if l[i] != l[i-1]:
        continue
    else:
        cnt+=1
        if l[i-1]=="1":
            l[i]="0"
        else:
            l[i]="1"

print(cnt)

Submission status: Accepted

Solution code:
s = input()

count1=0
count2=0

for i, name in enumerate(s):  
  if i%2==0:
    if name=='0':
      count1+=1
    else:
      count2+=1
  else:
    if name!='0':
      count1+=1
    else:
      count2+=1
print(min(count1, count2))

Submission status: Accepted

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

def zo(a):
  if a==1:
    b=0
  else:
    b=1
  return b

vol = len(s)
klist = s
glist = s
nk = 1
ng = 0
k=0
g=0

for i in range(vol):
  if klist[i]!=nk:
    k=k+1
  if glist[i]!=ng:
    g=g+1
  nk = zo(nk)
  ng = zo(ng)

if k>=g:
  print(g)
else:
  print(k)

Submission status: Accepted

Solution code:
a=input()
ct1=0
ct2=0
for i in range(len(a)):
    if (i+1)%2==0:
        if a[i]!='0':
            ct1+=1
        else:
            ct2+=1
    else:
        if a[i]=='0':
            ct1+=1
        else:
            ct2+=1
if ct1>ct2:
    print(ct2)
else:
    print(ct1)

Submission status: Accepted

Solution code:
import math
import sys
def makestr(i):
    if (i % 2 == 0):
        return '0'
    else:
        return '1'
s = input()
candicate1 = ''
candicate2 = ''
for i in range(len(s)):
    candicate1 += makestr(i)
    candicate2 += makestr(i + 1)
ans1 = 0
ans2 = 0
for i in range(len(s)):
    if (candicate1[i] != s[i]):
        ans1 += 1
    else:
        ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Coloring Colorfully

s = str(input())

odd0 = 0
odd1 = 0
even0 = 0
even1 = 0

for i in range(len(s)):
    if i%2==0:
        if int(s[i])%2==0:
            even0 += 1
        else:
            even1 += 1
    else:
        if int(s[i])%2==0:
            odd0 += 1
        else:
            odd1 += 1

print(min(even0+odd1, even1+odd0))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
cnt_b=0
cnt_w=0
#黒白の順
for i in range(n):
  if i%2==1:
    if s[i]!="1":
      cnt_b+=1
  else:
    if s[i]!="0":
      cnt_b+=1

#白黒の順
for i in range(n):
  if i%2==1:
    if s[i]!="0":
      cnt_w+=1
  else:
    if s[i]!="1":
      cnt_w+=1
      
print(min(cnt_b,cnt_w))

Submission status: Accepted

Solution code:
from collections import Counter
n=input()
o=Counter(n[0::2])
e=Counter(n[1::2])
m=len(n)-max(o["0"]+e["1"],o["1"]+e["0"])
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
g=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=='0':
            g+=1
    else:
        if s[i]=='1':
            g+=1
c=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=='1':
            c+=1
    else:
        if s[i]=='0':
            c+=1
if g>c:
    print(c)
else:
    print(g)

Submission status: Accepted

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

Submission status: Accepted

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

black = ""

for i in range(l):
  if i%2 == 0:
    black = black + "0"
  else:
    black = black + "1"

bswap = 0
wswap = 0

for i in range(l):
  if s[i] != black[i]:
    bswap += 1
  else:
    wswap += 1
print(min(bswap,wswap))

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

S = input()

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

print(min(w, b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
b = s[0]
cnt = 0
for w in s[1:]:
    if w == b:
        cnt += 1
        if w == "0":
            b = "1"
        else:
            b = "0"
    else:
        b = w
print(cnt)

Submission status: Accepted

Solution code:
def compare(s1, s2):
    ans = 0
    for i in range(len(s1)):
        if s1[i] == s2[i]: ans += 1
    return ans

s = input()
n = len(s)
s1 = ('01' * n)[:n]
s2 = ('10' * n)[:n]
print(min(n - compare(s1, s), n - compare(s2, s)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
left = s[0]
ans = 0

if int(s[0]) % 2 == 0:
    num = 0
else:
    num = 1
    
for i in range(1, len(s)):
    if left == s[i]:
        ans += 1
    left = str((i + num) % 2)

print(ans)

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
even = [0]*2
odd = [0]*2
for i, s in enumerate(S):
  if i % 2 == 0:
    even[s] += 1
  else:
    odd[s] += 1
ans = min(even[0]+odd[1], even[1]+odd[0])
print(ans)

Submission status: Accepted

Solution code:
def diff(a,b):
    output = 0
    for i in range(N):
        if a[i] != b[i]:
            output += 1
    return output

S = input()
N = len(S)

S1,S2 = "",""
for i in range(N):
    if i % 2 == 0:
        S1 += "0"
        S2 += "1"
    else:
        S1 += "1"
        S2 += "0"

ans = min(diff(S,S1),diff(S,S2))
print(ans)

Submission status: Accepted

Solution code:
import sys
s = input()
n = len(s)
ans =0
ans += s[0::2].count("0")
ans += s[1::2].count("1")
if  n / 2 <= ans:
    print(n - ans)
else:
    print(ans )

Submission status: Accepted

Solution code:
s = input()

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

p1 = 0
t = ''.join(bw)
for i in range(len(s)):
    if s[i] != t[i]:
        p1 += 1

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

p2 = 0
t = ''.join(bw)
for i in range(len(s)):
    if s[i] != t[i]:
        p2 += 1
ans = min(p1, p2)
print(ans)

Submission status: Accepted

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

# 先頭を0にするか1にするかで全てがきまる！！！！
count1 = 0
for i in range(N - 1):
    if S[0] == '0':
        if (i + 1) % 2 == 1 and S[i + 1] != '1':
            count1 += 1
        elif (i + 1) % 2 == 1 and S[i + 1] != '0':
            continue
        elif (i + 1) % 2 == 0 and S[i + 1] != '1':
            continue
        elif (i + 1) % 2 == 0 and S[i + 1] != '0':
            count1 += 1
    else:
        if (i + 1) % 2 == 1 and S[i + 1] != '0':
            count1 += 1
        elif (i + 1) % 2 == 1 and S[i + 1] != '1':
            continue
        elif (i + 1) % 2 == 0 and S[i + 1] != '0':
            continue
        elif (i + 1) % 2 == 0 and S[i + 1] != '1':
            count1 += 1

print(count1)

Submission status: Accepted

Solution code:
a=str(input())
i=0
sw=0
cou1=0
cou2=0
while i<len(a):
  if sw==0:
    if a[i]!="0":
      cou1+=1
    sw=1
  else:
    if a[i]!="1":
      cou1+=1
    sw=0
  i+=1
sw=1
i=0

while i<len(a):
  if sw==0:
    if a[i]!="0":
      cou2+=1
    sw=1
  else:
    if a[i]!="1":
      cou2+=1
    sw=0
  i+=1

if cou2>=cou1:
  print(cou1)
else:
  print(cou2)

Submission status: Accepted

Solution code:
S = list(input())
Ski = S[0:len(S):2]
Sgu = S[1:len(S):2] 
p1 = Ski.count('1') + Sgu.count('0') 
p2 = Ski.count('0') + Sgu.count('1')
print(min(p1,p2))

Submission status: Accepted

Solution code:
S = list(input())
Ski = S[0:len(S):2]
Sgu = S[1:len(S):2] 
p1 = Ski.count('1') + Sgu.count('0') 
p2 = Ski.count('0') + Sgu.count('1')
if p1>p2:
    print(p2)
else:
    print(p1)

Submission status: Accepted

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

counter1 = 0
current_value = 0
for _ in S:
    if not _ == current_value:
        counter1 += 1
    if current_value == 0:
        current_value = 1
    else:
        current_value = 0

counter2 = 0
current_value = 1
for _ in S:
    if not _ == current_value:
        counter2 += 1
    if current_value == 0:
        current_value = 1
    else:
        current_value = 0

print(min([counter1, counter2]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
fbcnt = 0
fwcnt = 0

for i in range(len(S)):
    val = S[i]
    if i%2==0:
        if val == '1':
            fbcnt += 1
        else:
            fwcnt += 1
    else:
        if val == '1':
            fwcnt += 1
        else:
            fbcnt += 1
print(min(fbcnt, fwcnt))

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 accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

S = input()

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

S1 = []
S2 = []

cnt1 = 0
cnt2 = 0

for i in range(len(S)):
	if i%2 == 0:
		S1.append("0")
		S2.append("1") 
	else:
		S1.append("1")
		S2.append("0") 

	if S[i] == S1[i]:
		cnt1 += 1

	if S[i] == S2[i]:
		cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
# solution
import io
import math

data = input()
qwe = data[::2].count('0') + data[1::2].count('1')
print(min(qwe, len(data)-qwe))

Submission status: Accepted

Solution code:
s = str(input())

cnt_1 = 0
cnt_2 = 0

for i in range(len(s)):
    if i%2 == 0:
        if s[i] == "1":
            cnt_1 += 1
        else:
            cnt_2 += 1
    else:
        if s[i] == "0":
            cnt_1 += 1
        else:
            cnt_2 += 1
print(min(cnt_1, cnt_2))

Submission status: Accepted

Solution code:
# coding:utf-8
s = input()
n = len(s)
b = 0
w = 0

# 文字列パターンを作る
if n % 2 == 0:
    black = '01' * (n // 2)
    white = '10' * (n // 2)
else:
    black = '01' * (n // 2) + '0'
    white = '10' * (n // 2) + '1'

#print(black, white)

for i in range(n):
    if s[i] != black[i]:
        b += 1
    if s[i] != white[i]:
        w += 1

print(min(b, w))

Submission status: Accepted

Solution code:
def main():
    S = list(input())
    even = [ "0" if (i + 1) % 2 == 0 else "1" for i in range(len(S))]
    odd  = [ "0" if (i + 1) % 2 != 0 else "1" for i in range(len(S))]
    n_even = 0
    n_odd = 0
    for i in range(len(S)):
        if S[i] != even[i]:
            n_even += 1
        if S[i] != odd[i]:
            n_odd += 1
    print(min(n_odd, n_even))
main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    L = len(S)
    a, b = 0, 0
    for i in range(L):
        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))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

t1 = ["0" if i % 2 == 0 else "1" for i in range(len(s))]
t2 = ["1" if i % 2 == 0 else "0" for i in range(len(s))]

c1 = 0
c2 = 0

for i in range(len(s)):
    if s[i] != t1[i]:
        c1 += 1

for i in range(len(s)):
    if s[i] != t2[i]:
        c2 += 1

print(min(c1,c2))

Submission status: Accepted

Solution code:
from operator import sub
s = list(map(int,input()))
l0 = [0] * len(s)
l1 = [0] * len(s)
for i in range(len(s)):
    if (i & 1) == 1: l0[i] += 1
    else: l1[i] += 1
c0 = list(map(sub,s,l0))
c1 = list(map(sub,s,l1))
cnt0 = 0
cnt1 = 0
for i in range(len(s)):
    if c0[i] == 0: pass
    else: cnt0 += 1
    if c1[i] == 0: pass
    else: cnt1 += 1
print(min(cnt0,cnt1))

Submission status: Accepted

Solution code:
def main():
    S = list(map(int, list(input())))
    cnt1, cnt2 = 0, 0
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s:
                cnt1 += 1
            else:
                cnt2 += 1
        else:
            if s:
                cnt2 += 1
            else:
                cnt1 += 1
    print(min(cnt1, cnt2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(map(int,input()))
n = len(s)
cnt1 = 0
cnt0 = 0
s1 = s[:]
s2 = s[:]
if s1[0] == 0:
    for i in range(n-1):
        if s1[i] == 0:
            if s1[i+1] == 1:
                pass
            else:
                s1[i+1] = 1
                cnt0 += 1
        else:
            if s1[i+1] == 0:
                pass
            else:
                s1[i+1] = 0
                cnt0 += 1
else:# if s[0] == "1"
    s1[0] = 0
    cnt0 += 1
    for i in range(n-1):
        if s1[i] == 0:
            if s1[i+1] == 1:
                pass
            else:
                s1[i+1] = 1
                cnt0 += 1
        else:
            if s1[i+1] == 0:
                pass
            else:
                s1[i+1] = 0
                cnt0 += 1
if s2[0] == 1:
    for i in range(n-1):
        if s2[i] == 0:
            if s2[i+1] == 1:
                pass
            else:
                s2[i+1] = 1
                cnt1 += 1
        else:
            if s2[i+1] == 0:
                pass
            else:
                s2[i+1] = 0
                cnt1 += 1
else:
    s2[0] = 0
    cnt1 += 1
    for i in range(n-1):
        if s2[i] == 0:
            if s2[i+1] == 1:
                pass
            else:
                s2[i+1] = 1
                cnt1 += 1
        else:
            if s2[i+1] == 0:
                pass
            else:
                s2[i+1] = 0
                cnt1 += 1


l = [cnt0,cnt1]
print(min(l))

Submission status: Accepted

Solution code:
s = [-1 if s=='0' else 1 for s in list(input())]

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

Submission status: Accepted

Solution code:

s = list(input())

t1 = ["0" if i % 2 == 0 else "1" for i in range(len(s))]
t2 = ["1" if i % 2 == 0 else "0" for i in range(len(s))]

c1 = 0
c2 = 0

for i in range(len(s)):
    if s[i] != t1[i]:
        c1 += 1

for i in range(len(s)):
    if s[i] != t2[i]:
        c2 += 1

print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()
ans = 0
for i in range(len(S)):
  tmp = S[i]
  if(i == 0):
    tmp2 = tmp
  else:
    if(i % 2 == 0 and tmp2 != tmp):
      ans += 1
    elif(i % 2 != 0 and tmp2 == tmp):
      ans += 1
print(str(ans))

Submission status: Accepted

Solution code:
s = list(input())

sf = []
sb = []
for i in range(len(s)):
  if i % 2 == 0:
    sf.append("1")
    sb.append("0")
  else:
    sf.append("0")
    sb.append("1")
    
cntf = 0
cntb = 0
for i in range(len(s)):
  if sf[i] != s[i]:
    cntf += 1
  if sb[i] != s[i]:
    cntb += 1
print(min(cntf, cntb))

Submission status: Accepted

Solution code:
#C
s = list(input())
#0101010101…
count1 = 0
#1010101010…
count2 = 0

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

print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

s = load(str)

n = len(s)

s1 = ["0" for _ in range(n)]
s2 = ["1" for _ in range(n)]

def hanten(c):
    if c == "0":
        return "1"
    return "0"

for i in range(1, n):
    s1[i] = hanten(s1[i-1])
    s2[i] = hanten(s2[i-1])

ans1 = 0
ans2 = 0
for i in range(0, n):
    if s[i] != s1[i]:
        ans1 += 1
    if s[i] != s2[i]:
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s=list(input())
p=['1' if i%2==0 else "0" for i in range(len(s))]
q=['0' if i%2==0 else "1" for i in range(len(s))]
print(min(len([0 for i in range(len(s)) if s[i]!=p[i]]),len([0 for i in range(len(s)) if s[i]!=q[i]])))

Submission status: Accepted

Solution code:
s = input().rstrip()


def flip(c):
    return '1' if c == '0' else '0'


a, b = 0, 1
pre_a, pre_b = s[0], flip(s[0])

for i in range(1, len(s)):
    if pre_a == s[i]:
        a += 1
        pre_a = flip(s[i])
    else:
        pre_a = s[i]

    if pre_b == s[i]:
        b += 1
        pre_b = flip(s[i])
    else:
        pre_b = s[i]

print(min(a, b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

a=["0","1"]

one=0
two=0
for i,tail in enumerate(s):
    if a[i%2]!=tail:
        one+=1
    else:
        two+=1
print(min(one,two))

Submission status: Accepted

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

string = '0'
ans1 = 0
for i in range(n):
	if s[i] != string:
		ans1 += 1
	if string == '0':
		string = '1'
	else:
		string = '0'

string = '1'
ans2 = 0
for i in range(n):
	if s[i] != string:
		ans2 += 1
	if string == '0':
		string = '1'
	else:
		string = '0'

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
white_start = ["0" if i%2==0 else "1" for i in range(n)]
#black_start = ["1" if i%2==0 else "0" for i in range(n)]


Wcnt = 0
#Bcnt = 0

for i in range(n):
  if s[i]!=white_start[i]:
    Wcnt +=1
  #else:
    #Bcnt +=1
print(min(Wcnt,n-Wcnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

if len(S)%2 == 1:
    T = "10"*(len(S)//2) + "1"
    U = "01"*(len(S)//2) + "0"
else:
    T = "10"*(len(S)//2)
    U = "01"*(len(S)//2)

t_ans = 0
u_ans = 0
for i in range(len(S)):
    if S[i] != T[i]:
        t_ans += 1
    if S[i] != U[i]:
        u_ans += 1

print(min(t_ans, u_ans))

Submission status: Accepted

Solution code:
S = input()

is_even = lambda number: number % 2 == 0
is_odd = lambda number: not is_even(number)

even = S[0]
odd = '1' if even == '0' else '0'

answer = 0
for i, Si in enumerate(S):
    if is_even(i) and Si != even:
        answer += 1
    elif is_odd(i) and Si != odd:
        answer += 1

print(answer)

Submission status: Accepted

Solution code:
S = input()

if S[0::2].count('0') > S[1::2].count('0'):
    print(S[0::2].count('1') + S[1::2].count('0'))
else:
    print(S[0::2].count('0') + S[1::2].count('1'))

Submission status: Accepted

Solution code:
s = list(map(int,input()))
n = len(s)
count1 = 0
count2 = 0
if n == 1:
    print(0) 
else:
    for i in range(n):
        if i%2 == 0 and s[i] != 0:
            count1 += 1
        elif i%2 != 0 and s[i] != 1:
            count1 += 1
    for i in range(n):
        if i%2 == 0 and s[i] != 1:
            count2 += 1
        elif i%2 !=0 and s[i] != 0:
            count2 += 1
    print(min(count1,count2))

Submission status: Accepted

Solution code:
s=input()
l=len(s)
c1=-(-l//2)
c2=l//2
c1b=0
c2b=0

for i in range(l):
  if s[i]=='0':
    if i%2==0:
      c1b+=1
    else:
      c2b+=1
print(min(c1b+c2-c2b, c1-c1b+c2b))

Submission status: Accepted

Solution code:
S=input()
l=list(S)
N=len(S)
count=0
for i in range(1,N):
  if l[i]==l[i-1]:
    count+=1
    if l[i]=="0":
      l[i]="1"
    else:
      l[i]="0"

#T="".join(l)

#print(T)
print(count)

Submission status: Accepted

Solution code:
S = input()

if S[0::2].count('0') > S[1::2].count('0'):
    print(S[0::2].count('1') + S[1::2].count('0'))
else:
    print(S[0::2].count('0') + S[1::2].count('1'))

Submission status: Accepted

Solution code:
S = list(map(int, input()))
N = len(S)
count1 = 0
count2 = 0
if N == 1:
    print(0)
    exit()
for a in range(N):
    if a % 2 == 0:
        if S[a] != 0:
            count1 += 1
    else:
        if S[a] != 1:
            count1 += 1

for a in range(N):
    if a % 2 == 0:
        if S[a] != 1:
            count2 += 1
    else:
        if S[a] != 0:
            count2 += 1

print(min(count1, count2))