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:
def main():
    s = input().rstrip()

    black_first = '0'
    white_first = '1'
    black_first_count = 0
    white_first_count = 0

    for c in s:
        if c == black_first:
            white_first_count += 1
        else:
            black_first_count += 1

        temp = black_first
        black_first = white_first
        white_first = temp
    
    print(min(black_first_count, white_first_count))
             


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def check(s, ans):
    cnt = 0
    for i, v in enumerate(s):
        if v == ans[i]:
            cnt += 1
    return cnt

ans01 = ([0, 1] * (len(s) // 2 + 1))[:len(s)]
ans10 = ([1, 0] * (len(s) // 2 + 1))[:len(s)]
print(min(check(s, ans01), check(s, ans10)))

Submission status: Accepted

Solution code:
s = list(input())
a = []
b = []

for i in range(1, len(s)+1):
  a.append(i%2)     # 101010
  b.append((i+1)%2) # 010101

c = 0
d = 0

s = list(map(int, s))

for i in range(len(s)):
  if a[i] != s[i]:
    c += 1
  if b[i] != s[i]:
    d += 1

if c > d:
  print(d)
else:
  print(c)

Submission status: Accepted

Solution code:
zero = "01" * 10**5
one = "10" * 10**5
s = str(input())
ans1 = 0
ans2 = 0
for i, j in zip(s, zero):
    if i != j:
        ans1 += 1
for i, j in zip(s, one):
    if i != j:
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

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

A = '01' * (N//2) + '01'[(N-1)%2]
B = '10' * (N//2) + '10'[(N-1)%2]
ans_A = 0
for i in range(N):
    if S[i] != A[i]:
        ans_A += 1

ans_B = 0
for i in range(N):
    if S[i] != B[i]:
        ans_B += 1

print(min(ans_A, ans_B))

Submission status: Accepted

Solution code:
S = input()
lenS = len(S)
firstis0 = 0
firstis1 = 0

for i in range(len(S)):
    if i % 2 == 0 and S[i] == "1":
        firstis0 += 1
    elif i % 2 == 0 and S[i] == "0":
        firstis1 += 1
    elif i % 2 == 1 and S[i] == "0":
        firstis0 += 1
    else:
        firstis1 += 1
print(str(min(firstis0, firstis1)))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(s)):
    if len(s) == 1:
        sum = 0
        break
    if i % 2 == 0:
        if s[i] != s[0]:
            sum += 1
    else:
        if s[i] == s[0]:
            sum += 1
print(sum)

Submission status: Accepted

Solution code:

s = input().strip()
n = len(s)
cnt = 0

odd, even = 1, 0
flag = 0  # 0 for odd and 1 for even

for i in range(1, n):
    if s[i] == s[i-1]:
        flag = 1 - flag

    if flag == 0:
         odd += 1
    else:
        even += 1

print(min(odd, even))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
li = []
for s in S:
    li.append(int(s))

count = 0
first = li[0]
for i in range(len(li)):
    if i % 2 == 0:
        if li[i] != first:
            count += 1
    else:
        if li[i] == first:
            count += 1

count2 = 1
for i in range(len(li)):
    if i % 2 == 0:
        if li[i] == first:
            count2 += 1
    else:
        if li[i] != first:
            count2 += 1

print(min(count, count2))

Submission status: Accepted

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

Submission status: Accepted

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

s = input()
l = []
l.append(s[0])
count = 0
for i in range(1, len(s)):
    if l[i-1] == s[i]:
        count += 1
        if s[i] == "0":
            l.append("1")
        else:
            l.append("0")
    else:
        l.append(s[i])
print(count)

Submission status: Accepted

Solution code:
S = list(input())
#2パターン考える
ans1 = 0#0101010101010101
ans2 = 0#1010101010101010
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":#ans1の方は直さなくていいans2を直す
            ans2 += 1
        elif S[i] == "1":#ans2の方は直さなくていいans1を直す
            ans1 += 1
    else:
        if S[i] == "1":#ans1の方は直さなくていいans2を直す
            ans2 += 1
        elif S[i] == "0":#ans2の方は直さなくていいans1を直す
            ans1 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
from sys import stdin
s = list(map(int, list(stdin.readline().rstrip())))
ans_list = [0, 1] * (len(s) // 2)
if len(s) % 2 == 1: ans_list.append(0)
count = 0
for i, ans in zip(s, ans_list):
    if i != ans:
        count += 1
print("{}".format(min(count, len(s) - count)))

Submission status: Accepted

Solution code:
def calc_replace_n(str, start) :
    n = 0
    for i in range(len(str)) :
        if i%2==0 :
            if str[i] == start :
                n = n+1
        else :
            if str[i] != start :
                n = n+1
    return n

s = input()

replace_n_zero = calc_replace_n(s,"0")
replace_n_one = calc_replace_n(s,"1")

out = replace_n_zero if replace_n_zero < replace_n_one else replace_n_one
print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy


def count_num_flip(S):
    num_flip = 0
    S_prev = S[0]
    for S_next in S[1:]:
        if S_prev == S_next:
            num_flip += 1
            S_prev = not S_next
        else:
            S_prev = S_next
    return num_flip


if __name__ == '__main__':
    S = [bool(int(x)) for x in input()]
    S_prime = copy.copy(S)
    S_prime[0] = not S_prime[0]
    print(min(count_num_flip(S), count_num_flip(S_prime) + 1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def Main():
    S = input()
    a, b = 0, 0
    for s in S:
        a += (s == '0')
        b += (s == '1')
        a, b = b, a
        
    print(min(a, b))

if __name__ == "__main__":
    Main()

Submission status: Accepted

Solution code:
s=list(input())
a=[]
b=[]
for i in range(1,len(s)+1):
    a.append(i%2)
    b.append((i+1)%2)
c=0
d=0
s=list(map(int,s))
for i in range(len(s)):
    if a[i] != s[i]:
        c+=1
    if b[i] != s[i]:
        d+=1
if c>d:
    print(d)
else:
    print(c)

Submission status: Accepted

Solution code:
n = str(input())
n_arr = list(str(n))
arr = list(map(int, n_arr))
zero = []
one = []
for i in range(len(arr)):
    if i % 2 == 0:
        zero.append(0)
        one.append(1)
    else:
        zero.append(1)
        one.append(0)
zero_diff = 0
one_diff = 0
for i in range(len(arr)):
    if arr[i] != zero[i]:
        zero_diff += 1
for i in range(len(arr)):
    if arr[i] != one[i]:
        one_diff += 1
print(min([one_diff,zero_diff]))

Submission status: Accepted

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

for i in range(len(S)):
    if S[i] == str(i%2):
        a += 1
    else:
        b += 1

print(min(a, b))

Submission status: Accepted

Solution code:
s=input()
ce=co=0
for i in range(len(s)):
    if i%2==0 and s[i]=='0':
        ce+=1 
    elif i%2==1 and s[i]=='1':
        ce+=1 
for i in range(len(s)):
    if i%2==1 and s[i]=='0':
        co+=1 
    elif i%2==0 and s[i]=='1':
        co+=1
if ce<co:
    print(ce)
else:
    print(co)

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_b -d test-b
oj test -d test-c -c "python abc116c.py"
oj test -d test-b -c "python abc116b.py" test-b/sample-3.in
"""

from collections import defaultdict
import sys
import math
import time
import itertools

#累積和
def deco(func):
    def wrapper(*args, **kwargs):
        s = time.time()
        #print('--start--')
        ret = func(*args, **kwargs)
        logging.debug('--end in %f --' % (time.time() - s) )
        return ret
    return wrapper


@deco
def sol(S):
    zeroFirst= 0
    oneFirst = 0
    for i, s in enumerate(S):
        expected = '0' if i % 2 else '1'
        # 0 -> 0, 1 -> 1, 2 -> 0, 3-> 1
        logging.debug("expected {} and s {} zeroFirst {}, oneFirst {}".format(
            expected, s, zeroFirst, oneFirst
        ))
        if s == expected:
            oneFirst+=1
        else:
            zeroFirst+=1

    logging.debug("zeroFirst {}, oneFirst {}".format(zeroFirst, oneFirst))
    return min(oneFirst, zeroFirst)






import logging

do_submit = False
do_submit = True

if do_submit:
    logging.basicConfig(level=logging.ERROR, format="%(message)s")
else:
    logging.basicConfig(level=logging.DEBUG, format="%(message)s")
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(line.split()) for line in lines]
    (S) = parsed_lines[0][0]
    return (S)



if not do_submit:
    (S) = input_parse("""
    10010010
    """)
    print (sol(S))

    (S) = input_parse("""
    000
    """)
    print (sol(S))

else:
    str = ""
    str = input().strip()
    (S) = input_parse(str)
    print (sol(S))

Submission status: Accepted

Solution code:
s = input()

lgh = len(s)
s = int(s,2)

result = [0,0]

counter = 0

for i in range(lgh):
    result[0] = result[0] + (((s>>i)&1) ^ counter)
    counter = 1 - counter
    result[1] = result[1] + (((s>>i)&1) ^ counter)

print(min(result))

Submission status: Accepted

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

ans1 = 0
ans2 = 1

for i in range(1, len(s)):
    if (s[i-1] + s[i]) % 2 == 0:
        s[i] = abs(s[i]-1)
        ans1 += 1

if s2[0] == 0:
    s2[0] = 1
else:
    s2[0] = 0

for i in range(1, len(s)):
    if (s2[i-1] + s2[i]) % 2 == 0:
        s2[i] = abs(s2[i]-1)
        ans2 += 1

print(ans1 if ans1 <= ans2 else ans2)

Submission status: Accepted

Solution code:
S = input()

# case 01010101...
count01 = 0
pattern = False
for i in list(S):
  if bool(int(i)) is pattern:
    count01 += 1
  pattern = not(pattern)
# case 10101010...
count10 = 0
pattern = True
for i in list(S):
  if bool(int(i)) is pattern:
    count10 += 1
  pattern = not(pattern)

print(min(count01, count10))

Submission status: Accepted

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

A1 = '0'
A2 = '1'
for i in range(1, N):
  if i % 2 == 0:
    A1 = A1 + '0'
    A2 = A2 + '1'
  else:
    A1 = A1 + '1'
    A2 = A2 + '0'
S = int(S, 2)
A1 = int(A1, 2)
A2 = int(A2, 2)
n1 = bin(S ^ A1).count('1')
n2 = bin(S ^ A2).count('1')
print(min(n1, n2))

Submission status: Accepted

Solution code:
# C - Coloring Colorfully
# https://atcoder.jp/contests/abc124/tasks/abc124_c

S = raw_input()

num0 = 0
num1 = 0
beg0 = '0'
beg1 = '1'

for s in S:
    if s != beg0:
        num0 += 1
    else:
        num1 += 1
    beg0 = '0' if beg0 == '1' else '1'
    beg1 = '0' if beg1 == '1' else '1'

print '{}'.format(min(num0, num1))

Submission status: Accepted

Solution code:
from sys import stdin
S = list(str(stdin.readline().rstrip()))
ans = 0
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        ans+=1
        if S[i-1] == "0":
            S[i] = "1"
        if S[i-1] == "1":
            S[i] = "0"
print(ans)

Submission status: Accepted

Solution code:
#C - Coloring Colorfully
S = list(input())
a = []
b = []
aans = 0
bans = 0

for i in range(len(S)):
    if i%2 == 0:
        a.append('0')
        b.append('1')
    else:
        a.append('1')
        b.append('0')
        
for i in range(len(S)):
    if S[i] != a[i]:
        aans += 1
    if S[i] != b[i]:
        bans += 1
if aans >= bans:
    print(bans)
else:
    print(aans)

Submission status: Accepted

Solution code:
s = input()
i = a = b = 0
for j in s:
    a += int(j) == i
    i = 1 - i
i = 1
for j in s:
    b += int(j) == i
    i = 1 - i
print(len(s) - max(a, b))

Submission status: Accepted

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

i=0
c=0
count=0

while len(li) > i :
    if int(li[i]) == c :
        count = count + 1
    c = c + 1
    c = c % 2
    i = i + 1
    
if len(li) / 2 < count : 
    ans = len(li) - count
else :
    ans = count

print(ans)

Submission status: Accepted

Solution code:
# 正解パターンは2種類しか絶対にない
# それの小さいほうをとればよい

s = list(input())

N = len(s)

for i in range(N) : 
    s[i] = int(s[i])
    
s0 = []
s1 = []
    
for i in range(N) : 
    if i%2 == 0 : 
        s0.append(0)
    else : 
        s0.append(1)
        
for i in range(N) : 
    if i%2 == 1 : 
        s1.append(0)
    else : 
        s1.append(1)

# print(s)        
# print(s0)
# print(s1)

cnt0 = 0
cnt1 = 0

for i in range(N) : 
    if s[i] != s0[i] : 
        cnt0 += 1
    if s[i] != s1[i] : 
        cnt1 += 1
        
# print(cnt0)
# print(cnt1)

print(min(cnt0, cnt1))

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
ans = float('inf')
# 10101....
cnt = 0
T = ["0"]*N
for i in range(N):
    if i%2==0: T[i] = "1"
# print(T)
for si,ti in zip(S, T):
    if si != ti:
        cnt += 1
ans = min(cnt, ans)

# 01010....
cnt = 0
T = ["0"]*N
for i in range(N):
    if i%2==1: T[i] = "1"
# print(T)
for si,ti in zip(S, T):
    if si != ti:
        cnt += 1
ans = min(cnt, ans)
print(ans)

Submission status: Accepted

Solution code:
c2,c3 = 0,0
def ret(a,b,c):
  global c2,c3
  if a == b:
    if c == 2:
      c2 += 1
    else:
      c3 += 1
    if b == "0":
      return "1"
    else:
      return "0"
  else:
    return b
S = input()
S2,S3 = list(S),list(S)
default = S2[0]
for j,k in enumerate(S2):
  if j == 0:
    continue
  S2[j] = ret(S2[j-1],k,2)
for j,k in enumerate(S3):
  if j == 0:
    S3[0] = ret(default,S3[0],3)
  S3[j] = ret(S3[j-1],k,3)
print(c2 if c2 <= c3 else c3)

Submission status: Accepted

Solution code:
tile = list(int(x) for x in input())
#print(tile)
tile1 = []
tile2 = []
for i in range(len(tile)):
    if i%2 == 1:
        tile1.append(1)
        tile2.append(0)
    else:
        tile1.append(0)
        tile2.append(1)
#print(tile1)
#print(tile2)
import numpy as np
tile = np.array(tile)
tile1 = np.array(tile1)
tile2 = np.array(tile2)
sum1 = sum(abs(tile-tile1))
sum2 = sum(abs(tile-tile2))
print(min(sum1,sum2))

Submission status: Accepted

Solution code:
S = str(input())
S_list = [i for i in S]
target = ["0", "1"]

an1 = []
an2 = []

an1_suu = 0
an2_suu = 0

for j in range(len(S_list)):
    if j % 2 == 0:
        an1.append(target[0])
        an2.append(target[1])
    else:
        an1.append(target[1])
        an2.append(target[0])
    if S_list[j] == an1[j]:
        an1_suu += 1
    elif S_list[j] == an2[j]:
        an2_suu += 1
        
print(min(an1_suu, an2_suu))

Submission status: Accepted

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

s1 = [ ((-1)**i + 1)//2 for i in range(l)]
s2 = [ ((-1)**(i+1) + 1)//2 for i in range(l)]

m = 0
n = 0
for i in range(l):
  m += (int(s[i]) - s1[i])**2
  n += (int(s[i]) - s2[i])**2

print(min([m,n]))

Submission status: Accepted

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

Submission status: Accepted

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

# 文字列の入力
s = str(input())

# 配列に一文字ずつ格納
colors = list(s)

prev = int(colors[0])
changeCnt = 0

for i in range(1,len(colors)):

    if prev == int(colors[i]):
        colors[i] = abs(int(colors[i])-1)
        changeCnt += 1
    
    prev = int(colors[i])

# 出力
print(str(changeCnt))

Submission status: Accepted

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

convertor = {'1': '0', '0': '1'}

prev = s[0]
ans = 0

for i in range(1, n):
    if s[i] == prev:
        s[i] = convertor[s[i]]
        ans += 1
    prev = s[i]

print(ans)

Submission status: Accepted

Solution code:
from itertools import cycle
S = input()
cnt = sum(x if s=='0' else 1-x for s,x in zip(S, cycle((0,1))))

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

Submission status: Accepted

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


# 0101…にする場合
cnt1 = sum([1 for i in range(N) if i%2==0 and S[i]=="0"])
cnt2 = sum([1 for i in range(N) if i%2!=0 and S[i]=="1"])
cnt_S01 = cnt1 + cnt2
# 1010…にする場合
cnt3 = sum([1 for i in range(N) if i%2==0 and S[i]=="1"])
cnt4 = sum([1 for i in range(N) if i%2!=0 and S[i]=="0"])
cnt_S10 = cnt3 + cnt4

ans = min(cnt_S01, cnt_S10)
print(ans)

Submission status: Accepted

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

cnt1 = sum([1 for i in range(N) if i%2==0 and S[i]=="0"])
cnt2 = sum([1 for i in range(N) if i%2!=0 and S[i]=="1"])

cnt3 = sum([1 for i in range(N) if i%2==0 and S[i]=="1"])
cnt4 = sum([1 for i in range(N) if i%2!=0 and S[i]=="0"])

ans = min(cnt1 + cnt2, cnt3 + cnt4)
print(ans)

Submission status: Accepted

Solution code:
a = list(str(input()))

empty = []

empty.append([i for i in a[0::2]])
empty.append([i for i in a[1::2]])

aa = empty[0].count('0') + empty[1].count('1')
bb = empty[0].count('1') + empty[1].count('0')

if aa >= bb:
    print(bb)
else:
    print(aa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
s = int(s, 2)
s_10 = '1' * (n % 2) + '01' * (n // 2)
s_01 = '0' * (n % 2) + '10' * (n // 2)
s_10 = int(s_10, 2)
s_01 = int(s_01, 2)
r = bin(s ^ s_01)
l = bin(s ^ s_10)
print(min(r.count('1'), l.count('1')))

Submission status: Accepted

Solution code:
S = input()
ans = []
for i in range(2):
    pre_ans = 0
    _S = [s for s in S]
    if _S[0] == '0':
        if i == 1:
            _S[0] = '1'
            pre_ans += 1
    else:
        if i == 0:
            _S[0] = '0'
            pre_ans += 1
    for j in range(1,len(S)):
        if _S[j-1] == '0':
            if _S[j-1] == _S[j]:
                _S[j] = '1'
                pre_ans += 1
        else:
            if _S[j-1] == _S[j]:
                _S[j] = '0'
                pre_ans += 1
    ans.append(pre_ans)
print(min(ans))

Submission status: Accepted

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

S = input()
Se, So = S[0::2], S[1::2]

Se0, Se1, So0, So1 = Se.count('0'), Se.count('1'), So.count('0'), So.count('1')

print(min(Se0 + So1, Se1 + So0))

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
sub = 0
(pop) = 0

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

        elif S[i-1] == "1":
            S[i] = "0"
            sub += 1

    elif S[i] == "0":
        if S[i-1] == "1":
            (pop) += 1

        elif S[i-1] == "0":
            S[i] = "1"
            sub += 1

print(sub)

Submission status: Accepted

Solution code:
s=input()
count_1=0
count_2=0
p=0
for i in range(0,len(s)):
    if (s[i]=='0' and p==0) or (s[i]=='1' and p==1):
        if(p==0):
            p=1
        elif(p==1):
            p=0
        continue
    else:
        if(p==0):
            p=1
        elif(p==1):
            p=0
        count_1=count_1+1
p=1
for i in range(0,len(s)):
    if (s[i]=='0' and p==0) or (s[i]=='1' and p==1):
        if(p==0):
            p=1
        elif(p==1):
            p=0
        continue
    else:
        if(p==0):
            p=1
        elif(p==1):
            p=0
        count_2=count_2+1
print(min(count_1,count_2))

Submission status: Accepted

Solution code:
s=input()
count_1=0
count_2=0
for i in range(len(s)):
  if i%2 == 0 and s[i] == '0':
    count_1+=1
  if i%2 == 1 and s[i] == '1':
    count_1+=1
for i in range(len(s)):
  if i%2 == 0 and s[i] == '1':
    count_2+=1
  if i%2 == 1 and s[i] == '0':
    count_2+=1
if count_1 < count_2:
  print(count_1)
else:
  print(count_2)

Submission status: Accepted

Solution code:
s = str(input())

cnt = 0
new = s[0]
for idx in range(len(s[1:])):
    idx += 1
    if new[idx-1]==s[idx]:
        if s[idx] == '0':
            new+='1'
        else:
            new+='0'
        cnt += 1
    else:
        new+=s[idx]
print(cnt)

Submission status: Accepted

Solution code:
tiles = list(input())
dic = {'0':'1', '1':'0'}
cnt = 0
for i in range(1,len(tiles)):
    if tiles[i] == tiles[i-1]:
        tiles[i] = dic[tiles[i]]
        cnt += 1
    else:
        continue
print(cnt)

Submission status: Accepted

Solution code:
S = list(input())

s = S[::2].count('1') + S[1::2].count('0')
u = S[::2].count('0') + S[1::2].count('1')

print(min(s, u))

Submission status: Accepted

Solution code:
S = list(input())

c = 0
if S[0] == '0':
    for i in S[::2]:
        if i == '1':
            c += 1
    for j in S[1::2]:
        if j == '0':
            c += 1
        
d = 0
if S[0] == '1':
    for i in S[::2]:
        if i == '0':
            d += 1
    for j in S[1::2]:
        if j == '1':
            d += 1
            
print(max(c,d))

Submission status: Accepted

Solution code:
import copy
S = [s for s in input()]
A, B = copy.deepcopy(S), copy.deepcopy(S)
li = [A, B]
count = [0, 1]

if S[0] == '0':
    B[0] = '1'
else:
    B[0] = '0'

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

print(min(count))

Submission status: Accepted

Solution code:
s = [int(x) for x in input()]
s1 = s[::2]
s0 = s[1::2]
print(min(len(s1)-sum(s1)+sum(s0) , len(s0)-sum(s0)+sum(s1)))

Submission status: Accepted

Solution code:
s = input()

count = 0
try:
    for i in range(0,len(s),2):
        if s[i] == '0':
            count += 1 
        if s[i+1] == '1':
            count +=1
except :
    pass
if count <= int(len(s)/2):
    print(count)
else:
    print(len(s)-count)

Submission status: Accepted

Solution code:
s = input()
last = int(s[0])
count = 0

for c in s[1:]:
	c = int(c)
	if(last == c):
		count += 1
		last = (c+1)%2
	else:
		last = c

s = s[::-1]
last = int(s[0])
count2 = 0

for c in s[1:]:
	c = int(c)
	if(last == c):
		count2 += 1
		last = (c+1)%2
	else:
		last = c


print(min(count,count2))

Submission status: Accepted

Solution code:
s=list(input())
b=[]
w=[]
n=len(s)
for i in range(n):
    if i%2==0:
        b+=s[i]
    else:
        w+=s[i]
bc=b.count('1')
wc=w.count('0')
print(min(bc+wc,n-bc-wc))

Submission status: Accepted

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

wb = ''
bw = ''
for i in range(0,length):
  if i % 2 == 0:
    wb += '0'
    bw += '1'
  else:
    wb += '1'
    bw += '0'

pat1 = 0
pat2 = 0
for i in range(0, length):
  if s[i] != wb[i]:
    pat1 += 1
  elif s[i] != bw[i]:
    pat2 += 1

if pat1 > pat2:
  print(pat2)
else:
  print(pat1)

Submission status: Accepted

Solution code:
S=input()
a=1
b=0
ct1,ct0=0,0
#print(type(S))
for i in range(len(S)):
    a=a^1
    b=b^1
    #print(a,b)
    if(a!=int(S[i])):
        ct1+=1
    if(b!=int(S[i])):
        ct0+=1
print(min(ct1,ct0))

Submission status: Accepted

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

l =[0,1] * (len(S)//2) + ([0] if len(S)%2 == 1 else [])

l = [x + y for (x,y) in zip(S,l)]

print(min(l.count(1),(l.count(0)+l.count(2))))

Submission status: Accepted

Solution code:
S = input()

l = "01" * (len(S)//2) + ("0" if len(S)%2 == 1 else "")

l = [int(x) + int(y) for (x,y) in zip(S,l)]

print(min(l.count(1),(l.count(0)+l.count(2))))

Submission status: Accepted

Solution code:
s = input()
last = int(s[0])
count = 0

for c in s[1:]:
	c = int(c)
	if(last == c):
		count += 1
		last = (c+1)%2
	else:
		last = c
print(count)

Submission status: Accepted

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

l =[0,1] * (len(S)//2) + ([0] if len(S)%2 == 1 else [])

l = [x + y for (x,y) in zip(S,l)]

print(min(l.count(1),(l.count(0)+l.count(2))))

Submission status: Accepted

Solution code:
s = input()

n = len(s)
a = "10" * (n // 2) + "1" * (n % 2)
b = "01" * (n // 2) + "0" * (n % 2)

print(min(bin(int(s, 2) ^ int(a, 2)).count("1"), bin(int(s, 2) ^ int(b, 2)).count("1")))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
head = s[0:1]
tail = ''.join(['10' for _ in range(len(s))])
ss = (head + tail if head == '0' else tail)[0:len(s)]
print(bin(int(s, 2) ^ int(ss, 2)).count("1"))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s1 = '01' * 50000
s2 = '10' * 50000

ans1 = 0
ans2 = 0

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

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import math, itertools, operator
from math import *
from math import factorial as fact
from functools import reduce
from statistics import mean, median, median_low, median_high, mode
# Before Python 3.5
from fractions import gcd
#import numpy
#import scipy, scipy.special
#from sympy import isprime, nextprime
#from sympy.ntheory import factorint

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################

S = input()

cnt1 = 0  # Black first
cnt2 = 0  # White first
BLACK = '0'
WHITE = '1'
for i in range(len(S)):
    if i & 1:
        if S[i] != WHITE:
            cnt1 += 1
        if S[i] != BLACK:
            cnt2 += 1
    else:
        if S[i] != BLACK:
            cnt1 += 1
        if S[i] != WHITE:
            cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
S = input()
bf = '01' * (len(S) // 2) + '0' * (len(S) & 1)
wf = '10' * (len(S) // 2) + '1' * (len(S) & 1)
ans = 10**5
ans = min(ans, [x != y for x, y in zip(S, bf)].count(True))
ans = min(ans, [x != y for x, y in zip(S, wf)].count(True))
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
S = input()
lis = []
for t in range(len(S)):
    lis.append(S[t])
evencount0 = 0
unevencount0 = 0
evencount1 = 0
unevencount1 = 0
if len(S)%2 == 0:
    for t in range(int(len(S)/2)):
        if S[2*t + 1] == "0":
            evencount0 += 1
    evencount1 = int(len(S)/2) - evencount0
    for t in range(int(len(S)/2)):
        if S[2*t] == "0":
            unevencount0 += 1
    unevencount1 = int(len(S)/2) - unevencount0

else:
    for t in range(int((len(S) - 1)/2)):
        if S[2*t + 1] == "0":
            evencount0 += 1
    evencount1 = int((len(S) - 1)/2) - evencount0        

    for t in range(int((len(S)+1)/2)):
        if S[2*t] == "0":
            unevencount0 += 1
    unevencount1 = int((len(S)+1)/2) - unevencount0

elist = [evencount0 , evencount1 , unevencount0 , unevencount1 ]
if evencount1 + unevencount0 > evencount0 + unevencount1:
    k = evencount0 + unevencount1
else:
    k =evencount1 + unevencount0
print(k)

Submission status: Accepted

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

ans = 0
last_str = ''
for s in S:
  if (last_str == s) and s == '0':
    ans += 1
    last_str = '1'
  elif (last_str == s) and s == '1':
    ans += 1
    last_str = '0'
  else:
    last_str = s
print(ans)

Submission status: Accepted

Solution code:
S = input()
def func():
    from collections import Counter as c
    ev,od = [],[]
    for i in range(len(S)):
        ev.append(S[i]) if i%2 == 0 else 0
        od.append(S[i]) if i%2 == 1 else 0
    ev = c(ev).most_common()
    od = c(od).most_common()
    if len(od) == 0:
        return 0
    if ev[0][0] != od[0][0]:
        return len(S)-ev[0][1]-od[0][1]
    else:
        if len(ev) == len(od) == 1:
            return len(S)//2
        else:
            return min(len(S)-ev[0][1]-od[-1][1],len(S)-ev[-1][1]-od[0][1])
print(func())

Submission status: Accepted

Solution code:
tile = input()
total_0 = 0
total_1 = 0

for i in range(len(tile)):
    if i % 2 == 0:
        if int(tile[i]) == 0:
            total_1 += 1
        else:
            total_0 += 1
    else:
        if int(tile[i]) == 0:
            total_0 += 1
        else:
            total_1 += 1
print(total_0 if total_0 <= total_1 else total_1)

Submission status: Accepted

Solution code:
s = input()
a = ''
b = ''
for i in range(len(s)):
  if i%2 == 0:
    a += '0'
    b += '1'
  else:
    a += '1'
    b += '0'
def distance(s, a):
  return format(int(s, 2) ^ int(a, 2), 'b').count('1')
print(min(distance(s, a),distance(s, b)))

Submission status: Accepted

Solution code:
def countStr(x,S):
    c = 0
    for i, s in enumerate(S):
        if i % 2 == x:
            if s == "0":
                c += 1
        else:
            if s == "1":
                c += 1
    return c

S = input()
print(min(countStr(0,S),countStr(1,S)))

Submission status: Accepted

Solution code:
S = input()
#複数の定義はまとめられる
cntA, cntB = 0, 0

for i, t in enumerate(S):
    if i%2 == 0:
        if t == '0': #標準入力Sはstr型だから0ではなく'0'のようにする
            cntA += 1
        else:
            cntB += 1
    else:
        if t == '1':
            cntA += 1
        else:
            cntB += 1
print (min(cntA, cntB))

Submission status: Accepted

Solution code:
t = input()
c1, c2 = 0, 0
for i, s in enumerate(t):
  if i % 2 == 0:
    if s == '0':
      c1 += 1
    else:
      c2 += 1
  else:
    if s == '1':
      c1 += 1
    else:
      c2 += 1
print(min(c1, c2))

Submission status: Accepted

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