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:
from itertools import zip_longest

S = input()
ans = 0

for curr, next in list(zip_longest(S, S[1:]))[::2]:
  if curr == '0': ans += 1
  if next == '1': ans += 1

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

Submission status: Accepted

Solution code:
S = input()

n = len(S)

ans = 0

for i in range(0,n,2):
    if S[i] == '0':
        ans +=1
    if i+1 < n:
        if S[i+1] == '1':
            ans +=1

print(min(ans, n - ans))

Submission status: Accepted

Solution code:
def diff(s1, s2):
  count = 0
  for (c1, c2) in zip(s1, s2):
    if c1 != c2:
      count += 1
  return count


def main():
  arr = list(input())
  t01 = (['0', '1'] * len(arr))[:len(arr)]
  t10 = (['1', '0'] * len(arr))[:len(arr)]
  print(min(diff(arr, t01), diff(arr, t10)))


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
tile = input()
ans = 0
for i in range(len(tile) - 1):
  if tile[i+1] != tile[i]:
    continue
  else:
    ans += 1
    if tile[i+1] == "0":
      tile = tile[:i+1] + "1" + tile[i+2:]
    else: 
      tile = tile[:i+1] + "0" + tile[i+2:]
print(ans)

Submission status: Accepted

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


def main():
    s = input()
    start_0_invalid = 0
    start_1_invalid = 0
    for i, si in enumerate(s):
        if i % 2 == 0:
            if si == '0':
                start_1_invalid += 1
            else:
                start_0_invalid += 1
        else:
            if si == '0':
                start_0_invalid += 1
            else:
                start_1_invalid += 1
    print(min([start_0_invalid, start_1_invalid]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = input()

odd_list = N[0:len(N):2]
even_list = N[1:len(N):2]


def a():
    if len(even_list) == 0:
        print(0)
        return


def calc_one_and_zero(arr):
    zero_count = arr.count('0')
    one_count = arr.count('1')
    return zero_count, one_count


odd_zero,  odd_one = calc_one_and_zero(odd_list)
even_zero, even_one = calc_one_and_zero(even_list)

if odd_zero + even_one > odd_one + even_zero:
    print(odd_one + even_zero)
else:
    print(odd_zero + even_one)

Submission status: Accepted

Solution code:
S = input()
first = S[0]
inverse = str(1-int(first))
unit = first+inverse
if len(S) % 2 == 0:
  sample = unit*(len(S)//2)
else:
  sample = unit*(len(S)//2)+first

count = 0
for k in range(len(S)):
  if S[k] != sample[k]:
    count += 1

print(count)

Submission status: Accepted

Solution code:
S = input()
bs = 0
ws = 0
count = 0
for i in range(len(S)):
  s = int(S[i])
  if s != i%2:
    bs += 1
  if s != (i+1)%2:
    ws += 1
print(min(bs,ws))

Submission status: Accepted

Solution code:
def main(input_str):
    input_list = list(input_str)
    count = 0
    if input_list[0] == "0":
        ans = []
        for i, _ in enumerate(input_list):
            if i % 2 == 0:
                ans.append("0")
            else:
                ans.append("1")
        for i, _ in enumerate(input_list):
            if input_list[i] != ans[i]:
                count += 1

    else:
        ans = []
        for i, _ in enumerate(input_list):
            if i % 2 == 0:
                ans.append("1")
            else:
                ans.append("0")
        for i, _ in enumerate(input_list):
            if input_list[i] != ans[i]:
                count += 1

    return count


if __name__ == "__main__":
    input_str = input()
    print(main(input_str))

Submission status: Accepted

Solution code:
s = input()

# p1は0101...p2は1010...との比較をカウントする
p1 = 0
p2 = 0

for i in range(len(s)):
  # 偶数番目が0のとき、p2(1010...)では塗り替えが必要なのでp2+1、1のときはp1+1
  if i % 2 == 0:
    if int(s[i]) == 0:
      p2 += 1
    else:
      p1 += 1
  
  # 奇数番目が0のときはp1(0101...)では塗り替えが必要なのでp1+1、1のときはp2+1
  if i % 2 == 1:
    if int(s[i]) == 0:
      p1 += 1
    else:
      p2 += 1

if p1 <= p2:
  print(p1)
else:
  print(p2)

Submission status: Accepted

Solution code:
s = input()
length  = len(s)
s = '0b'+s
s = int(s, 0)

c1 = '0b'+'01'*100000
c1 = int(c1, 0)
c2 = '0b'+'10'*100000
c2 = int(c2, 0)

a1 = bin(s^c1)
a2 = bin(s^c2)

a1 = a1[-length:]
a2 = a2[-length:]

print(min(a1.count('1'),a2.count('1')))

Submission status: Accepted

Solution code:
S = input()

counter = 0
diff1 = 0
diff2 = 0
    
for i in range(len(S)):
    # 0スタートの場合
    if i % 2 == 0:
        if S[i] == '1':
            diff1 += 1
    else:
        if S[i] == '0':
            diff1 += 1
    # 1スタートの場合
    if i % 2 == 0:
        if S[i] == '0':
            diff2 += 1
    else:
        if S[i] == '1':
            diff2 += 1

# print(diff1)
# print(diff2)

if diff1 > diff2:
    print(diff2)
else:
    print(diff1)

Submission status: Accepted

Solution code:
BLACK = '0'
WHITE = '1'

original_tile = input()
tile_length = len(original_tile)

bwbw_tile = (BLACK+WHITE) * (tile_length//2)
if tile_length % 2 == 1:
    bwbw_tile += BLACK

repaint_times = 0
for i in range(tile_length):
    if original_tile[i] != bwbw_tile[i]:
        repaint_times += 1

if repaint_times < tile_length - repaint_times:
    print(repaint_times)
else:
    print(tile_length - repaint_times)

Submission status: Accepted

Solution code:
ss = input()
s1, s2 = [], []
for i, s in enumerate(ss):
  if i % 2 == 0:
    s2.append(int(s))
  else:
    s1.append(int(s))

s1_0, s1_1 = len(s1) - sum(s1), sum(s1)
s2_0, s2_1 = len(s2) - sum(s2), sum(s2)

print(min(s1_0 + s2_1, s1_1 + s2_0))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = [int(x) for x in input()]

if len(s) == 1:
    print(0)
else:
    # case: s[0] = 0
    cnt1 = 0
    for idx in range(0, len(s) - 1, 2):
        if s[idx] != 0:
            cnt1 += 1
        if s[idx + 1] != 1:
            cnt1 += 1
    if len(s) % 2 == 1 and s[-1] != 0:
        cnt1 += 1

    # case: s[0] = 1
    cnt2 = 0
    for idx in range(0, len(s) - 1, 2):
        if s[idx] != 1:
            cnt2 += 1
        if s[idx + 1] != 0:
            cnt2 += 1
    if len(s) % 2 == 1 and s[-1] != 1:
        cnt2 += 1

    print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
s = [int(c) for c in input()]
a = 0
b = 0
for i in range(len(s)):
  if i % 2 == 0 and s[i] == 0:
    a = a
    b = b + 1
  elif i % 2 == 1 and s[i] == 0:
    a = a + 1
    b = b
  elif i % 2 == 0 and s[i] == 1:
    a = a + 1
    b = b
  else:
    a = a
    b = b + 1
p = [a,b]
print(min(p))

Submission status: Accepted

Solution code:
string = input()
ls = list(map(int, string))

count1, count2 = 0, 0

for i in range(len(ls)):
    ck = (i + 1) % 2
    if ls[i] != ck:
        count1 += 1

for j in range(len(ls)):
    ck = (j + 2) % 2
    if ls[j] != ck:
        count2 += 1

print(min(count1, count2))

Submission status: Accepted

Solution code:
n=[int(i) for i in input()]
p1=[1 if i%2==0 else 0 for i in range(len(n))]
p2=[0 if i%2==0 else 1 for i in range(len(n))]
p1_n=[p1[i]-n[i] for i in range(len(n))]
ans1=sum(x==0 for x in p1_n)
p2_n=[p2[i]-n[i] for i in range(len(n))]
ans2=sum(x==0 for x in p2_n)
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
# 整数の入力
a = input()
result = -500000

privious_list = ["0", "1"]
#print(len(a))

if len(a) == 1 or 0:
    print(0)
else:
    for x in privious_list:
        new_result = 0
        privious = x
        for i in a:
            if i == "0":
                if privious == "0":
                    new_result += 1
                    privious = "1"
                else:
                    privious = "0"
            else:
                if privious == "0":
                    privious = "1"
                else:
                    new_result += 1
                    privious = "0"
        #print(result, new_result)
        if result == -500000:
            result = new_result
        elif new_result < result:
            result = new_result
    
    if result == -500000:
        result = 0
    print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
c0 = 0
c1 = 0

for i in range(len(s)):
    if i % 2 == 0 and s[i] != '0':
        c0 += 1
    if i % 2 != 0 and s[i] != '1':
        c0 += 1

for i in range(len(s)):
    if i % 2 == 0 and s[i] != '1':
        c1 += 1
    if i % 2 != 0 and s[i] != '0':
        c1 += 1

print(min(c0, c1))

Submission status: Accepted

Solution code:
S = list(input())

turn = 0
count_0 = 0
count_1 = 0

for char in S:
    if(turn % 2 == 0):
        if(char == '0'):
            count_0 += 1
        else:
            count_1 += 1
    else:
        if(char == '0'):
            count_1 += 1
        else:
            count_0 += 1
    turn += 1

if(count_0 < count_1):
    print(count_0)
else:
    print(count_1)

Submission status: Accepted

Solution code:
import numpy as np
S = input()
S = np.array([int(x) for x in S])

if len(S)%2 == 0:
  P1 = np.array([1, 0]*int(len(S)/2))
  P2 = np.array([0, 1]*int(len(S)/2))
else:
  P1 = np.array([1, 0]*int(len(S)/2) + [1])
  P2 = np.array([0, 1]*int(len(S)/2) + [0])

ans1 = np.abs(S - P1).sum()
ans2 = np.abs(S - P2).sum()

if ans1 < ans2:
  print(ans1)
else:
  print(ans2)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
from_zero_count = 0
from_one_count = 0
for i in range(N):
  if i%2 == 0 and S[i] == "0":
    from_one_count += 1
  elif i%2 == 0 and S[i] == "1":
    from_zero_count += 1
  elif i%2 == 1 and S[i] == "0":
    from_zero_count += 1
  elif i%2 == 1 and S[i] == "1":
    from_one_count += 1
print(min([from_one_count, from_zero_count]))

Submission status: Accepted

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

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

times = min(count, l - count)
print(times)

Submission status: Accepted

Solution code:
s = list(input())
s_len = len(s)
cnt_w = 0
cnt_b = 0

white = []
black = []

for i in range(len(s)):
    if i%2 == 0:
        white.append("1")
        black.append("0")
    else:
        white.append("0")
        black.append("1")
        
for i in range(len(s)):
    if white[i] != s[i]:
        cnt_w += 1
    if black[i] != s[i]:
        cnt_b += 1

print(min(cnt_w, cnt_b))

Submission status: Accepted

Solution code:
S = input()

le = len(S)
w_pattern = '10'
b_pattern = '01'

A = (w_pattern * int(le/2 + 1))[0:le]
B = (b_pattern * int(le/2 + 1))[0:le]

w_ans = sum([s != a for s,a in zip(S,A)])
b_ans = sum([s != b for s,b in zip(S,B)])
ans = w_ans if w_ans < b_ans else b_ans

print(ans)

Submission status: Accepted

Solution code:
S = input()

print(min(S[::2].count("0")+S[1::2].count("1"), S[::2].count("1")+S[1::2].count("0")))

Submission status: Accepted

Solution code:
def getWbStr(length, start):
    clr = ['0', '1']
    cstr = ''
    for i in range(0, length):
        cstr += '0' if i % 2 == start else '1'

    return cstr

s = input()

wstr = getWbStr(len(s), 0)
bstr = getWbStr(len(s), 1)
wcnt, bcnt = 0, 0

for i in range(0, len(s)):
    if s[i] != wstr[i]:
        wcnt += 1
    if s[i] != bstr[i]:
        bcnt += 1

print(min(wcnt, bcnt))

Submission status: Accepted

Solution code:
def case_1 (S,size):
    count=0
    for i in range(0,size):
        if (i%2==0):
            if(int(S[i])==0):
                count+=1
        else:
            if(int(S[i])==1):
                count+=1
    return count

def case_2 (S,size):
    count=0
    for i in range(0,size):
        if (i%2==1):
            if(int(S[i])==0):
                count+=1
        else:
            if(int(S[i])==1):
                count+=1
    return count

S=str(input())
size=len(S)
can_1=case_1(S,size)
can_2=case_2(S,size)
print(min(can_1,can_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
back = 0
n = 0
for i in S:
    if i == back:
        back = '0' if i=='1' else '1'
        n += 1
    else:
        back = i

print(n);

Submission status: Accepted

Solution code:
S=[2*int(s) for s in input()]
N=len(S)
dBW=[S[i]==(1+(-1)**i) for i in range(N)]
dWB=[S[i]==(1-(-1)**i) for i in range(N)]


print(min(sum(dBW),sum(dWB)))

Submission status: Accepted

Solution code:
s = input()
p = ''
t = 0

def change(x):
    if x == '1':
        return '0'
    else:
        return '1'

for x in s:
    if x == p:
        t += 1
        p = change(x)
    else:
        p = x

print(t)

Submission status: Accepted

Solution code:
s = input()
odd_i = []
even_i = []
for i in range(len(s)):
    if i % 2 == 0 :
        even_i.append(int(s[i]))
    else : odd_i.append(int(s[i]))

def counter(list):
    b_count = 0
    w_count = 0
    for i in range(len(list)):
        if list[i] == 0 : b_count += 1
        else : w_count += 1
    return b_count,w_count

b_odd , w_odd = counter(odd_i)
b_even , w_even = counter(even_i)

o_diff = b_odd - w_odd
e_diff = b_even - w_even

if o_diff >  e_diff : print(w_odd + b_even)
else : print(b_odd+w_even)

Submission status: Accepted

Solution code:
s = input()

#a1はs内の奇数番の1の個数と偶数番の0の個数を求める
a1 = s[::2].count("1") + s[1::2].count("0")
#a2はs内の奇数番の1の個数と偶数番の1の個数を求める
a2 = s[::2].count("0") + s[1::2].count("1")

print(min(a1,a2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
N = len(S)
d, r = divmod(N, 2)
ref = "01"*d + "0"*r
cnt = 0
for c1, c in zip(ref, S):
    if c1 != c: cnt+=1
print(min(cnt, N-cnt))

Submission status: Accepted

Solution code:
ss = list(input())
ss = [int(ii) for ii in ss]
nn = len(ss)
bw = list()
wb = list()
while True:
    if len(bw)+2<=nn:
        bw.append(0)
        bw.append(1)
        wb.append(1)
        wb.append(0)
        continue
    elif len(bw)+1==nn:
        bw.append(0)
        wb.append(1)
        continue
    else:
        break

counter_bw = 0
counter_wb = 0
for ii in range(nn):
    if ss[ii] == bw[ii]:
        counter_bw += 1
    if ss[ii] == wb[ii]:
        counter_wb += 1

answer = min(counter_bw, counter_wb)
print(answer)

Submission status: Accepted

Solution code:
S = [int(c) for c in input()]
black_started = [0 ^ (i % 2) for i in range(len(S))]
white_started = [1 ^ (i % 2) for i in range(len(S))]
black_diff = 0
white_diff = 0
for i in range(len(S)):
    if black_started[i] != S[i]:
        black_diff += 1
    if white_started[i] != S[i]:
        white_diff += 1
print(min(black_diff, white_diff))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

start_0 = 0
start_1 = 0

for i, S_i in enumerate(S):
    # print(i, S_i)
    if i % 2 == 0:
        if S_i == "0":
            start_1 += 1
            # print("a")
        else:
            start_0 += 1
            # print("b")
    else:
        if S_i == "0":
            start_0 += 1
            # print("c")
        else:
            start_1 += 1
            # print("d")

print(min(start_0, start_1))

Submission status: Accepted

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

    
apopcount=0
bpopcount=0
for i in range(0,l):
  if i%2==0:
    if int(S[i])==1:
   		apopcount+=1
    else:
      	bpopcount+=1
  else:
    if int(S[i])==1:
    	bpopcount+=1
    else:
      	apopcount+=1
if apopcount<bpopcount:print(apopcount)
else:print(bpopcount)

Submission status: Accepted

Solution code:
a  = input()
s = 0
t = 0
k = ["0","1"]
for n,i in enumerate(a):
  if i != k[(n%2)]:
    s+=1
  if i != k[(n+1)%2]:
    t+=1
print(min(s,t))

Submission status: Accepted

Solution code:
S = input()
bw = 0
wb = 0
for i in range(len(S)):
    if int(S[i]) == i % 2:
        wb += 1
    else:
        bw += 1

print(min(bw, wb))

Submission status: Accepted

Solution code:
# input
s = input()
bins = [b == '1' for b in s]

pattern_a = ([True, False] * ((len(s) // 2) + 1))[:len(s)]
pattern_b = ([False, True] * ((len(s) // 2) + 1))[:len(s)]

pat_a_min = [p ^ q for p, q in zip(bins, pattern_a)].count(True)
pat_b_min = [p ^ q for p, q in zip(bins, pattern_b)].count(True)

print(min(pat_a_min, pat_b_min))

Submission status: Accepted

Solution code:
from sys import stdin

S = [int(x) for x in list(stdin.readline().rstrip())]

even = len(S) // 2
odd = len(S) // 2 + (len(S) % 2)

evens = 0
odds = 0

for i in S[1::2]:
    evens += i

for i in S[::2]:
    odds += i

print(min(even - evens + odds, odd - odds + evens))

Submission status: Accepted

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

even_list = list()
odd_list = list()

even_list = n[0::2]
odd_list = n[1::2]

count_zero = 0
count_one = 0

#print(len(even_list))
for i in range(len(even_list)):
    if even_list[i] == 1:
        count_zero += 1
for j in range(len(odd_list)):
    if odd_list[j] == 0:
        count_zero += 1

for n in range(len(even_list)):
    if even_list[n] == 0:
        count_one += 1
for m in range(len(odd_list)):
    if odd_list[m] == 1:
        count_one += 1

print(min(count_zero, count_one))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
str_S = input()
len_S = len(str_S)
num_S = int(str_S, 2)
mask = 0B0

for i in range(len_S):
    mask = mask << 1
    if i % 2 == 0:
        mask += 1

cnt_one = bin(mask ^ num_S).count("1")

print(min(cnt_one, len_S - cnt_one))

Submission status: Accepted

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

import copy
s1 = copy.copy(s)
s2 = copy.copy(s)

cnt1,cnt2 = 1, 0

if s1[0] == 0:
    s1[0] = 1
else:
    s1[0] = 0
for i in range(1,l):
    if s1[i - 1] == s1[i]:
        cnt1 += 1
        if s1[i - 1] == 1:
            s1[i] = 0
        else:
            s1[i] = 1

for j in range(1,l):
    if s2[j - 1] == s2[j]:
        cnt2 += 1
        if s2[j - 1] == 1:
            s2[j] = 0
        else:
            s2[j] = 1

print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
# coding: utf-8

s = input()
n = len(s)
m = n // 2

if n%2 == 0:
    x = '01'*m
    y = '10'*m
else:
    x = '01'*m + '0'
    y = '10'*m + '1'

l = [0,0]
for i in range(n):
    if s[i] != x[i]:
        l[0] += 1
    if s[i] != y[i]:
        l[1] += 1

print(min(l))

Submission status: Accepted

Solution code:
s = input()

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

print(min(count1, count2))

Submission status: Accepted

Solution code:
s = input()

s_odd = s[::2]
s_even = s[1::2]

ans = min(s_odd.count("1")+s_even.count("0"),s_odd.count("0")+s_even.count("1"))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# あまりにもTLEになるから解説見ちゃった

from sys import stdin
import numpy as np

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

## 0から始まる数列
cnt_0 = 0
for i in range(len(a)):
  if a[i] == (i % 2):
    cnt_0 += 1
    
cnt_1 = 0
for i in range(len(a)):
  if a[i] == ((i+1) % 2):
    cnt_1 += 1
  
ans = min(cnt_0, cnt_1)  
print(ans)

Submission status: Accepted

Solution code:
# input
s = input()

# solve
n = len(s)

## a[i] minimum moves to arrange "s[0:i]" into "...0101"
## b[i] minimum moves to arrange "s[0:i]" into "...1010"
a = [0 for i in range(n)]
b = [0 for i in range(n)]

if s[0] == '0':
	a[0] = 1
	b[0] = 0
else:
  a[0] = 0
  b[0] = 1

for i in range(1, n):
	if s[i] == '0':
		a[i] = b[i-1] + 1
		b[i] = a[i-1]
	else:
		a[i] = b[i-1]
		b[i] = a[i-1] + 1

print(min(a[n-1], b[n-1]))

Submission status: Accepted

Solution code:
S=list(input())
N=len(S)
A=[]
B=[]
for i in range(N):
    A.append(str(i%2))
    B.append(str((i+1)%2))
countA=0
countB=0
for x in range(N):
    if A[x]!=S[x]:
        countA+=1
    else:
        countB+=1

print(min(countA,countB))

Submission status: Accepted

Solution code:
S=str(input())
sl=S[::2]
sr=S[1::2]
N=len(S)
n1=len(sl)
n2=len(sr)
num1=sl.count('0')
num2=sr.count('0')
ans1=num1+n2-num2
ans2=num2+n1-num1
a=min(ans1,ans2)
print(a)

Submission status: Accepted

Solution code:
s = input()

# print(s[::2])
# print(s[1::2])

a = s[::2].count('1')
b = s[1::2].count('0')
c = s[::2].count('0')
d = s[1::2].count('1')

# 10101010にする場合
# c + d
# 0101010にする場合
# a + b
# いずれか小さい方
ans = min(a+b, c+d)
print(ans)

Submission status: Accepted

Solution code:
n = input()

black = 0
white = 0

for i in range(len(n)):

    if i % 2 == 0:
        if n[i] == "0":
            white += 1
        else:
            black += 1

    else:
        if n[i] == "0":
            black += 1
        else:
            white += 1

if black <= white:
    print(black)
else:
    print(white)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = [int(i) for i in list(input())]
n = len(s)
patA = [i % 2 for i in range(n)]
patB = [i % 2 for i in range(1,n+1)]
diffA = [0]*n
diffB = [0]*n
for i in range(n):
  diffA[i] = s[i] - patA[i]
  diffB[i] = s[i] - patB[i]
ans = [0,0]
ans[0] = len([i for i in diffA if i == 0])
ans[1] = len([i for i in diffB if i == 0])
print(min(ans))

Submission status: Accepted

Solution code:
S = list(input())
 
count = 0
s1 = S[:]
for i in range(1, len(S)):
    if s1[i - 1] == s1[i]:
        s1[i] = '0' if s1[i-1] == '1' else '1'
        count += 1
 
count2 = 0
s2 = S[:]
for i in reversed(range(len(S)-1)):
    if s2[i] == s2[i +1]:
        s2[i] = '0' if s2[i+1] == '1' else '1'
        count2 += 1
 
print(min(count, count2))

Submission status: Accepted

Solution code:

S=str(input())
N=len(S)
str1=''
str2=''
for n in range(N//2):
    str1=str1+'01'
    str2=str2+'10'
if N%2:
    str1=str1+'0'
    str2=str2+'1'
min1=sum(str1[i]!=S[i] for i in range(N))
min2=sum(str2[i]!=S[i] for i in range(N))
print(min(min1,min2))

Submission status: Accepted

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

l = sum(s[0::2])
r = sum(s[1::2])

print(min(abs(l-r+len(s[1::2])), abs(r-l+len(s[0::2]))))

Submission status: Accepted

Solution code:
s = input()

odd = s[::2]
even = s[1::2]
ans = odd.count("0") + even.count("1")
ans = min(ans, len(s) - ans)
print(ans)

Submission status: Accepted

Solution code:
s=input()

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

print(min(ans))

Submission status: Accepted

Solution code:
S = input()

N = len(S)

S2 = S

# s[0] = '1'

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

print (min(count_1,count_2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
S = [int(s) for s in S]
T = []
for s in range(len(S)):
    if s % 2 == 0:
        T.append(S[s]==0)
    else:
        T.append(S[s]==1)
U = []
for s in range(len(S)):
    if s % 2 == 0:
        U.append(S[s]==1)
    else:
        U.append(S[s]==0)
M = max(sum(T), sum(U))
print(len(S)-M)

Submission status: Accepted

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

count_0 = 0
count_1 = 0

#0-start

for i in s[0::2]:
	if i != '0':
		count_0 += 1
for i in s[1::2]:
	if i != '1':
		count_0 += 1

for i in s[0::2]:
	if i != '1':
		count_1 += 1
for i in s[1::2]:
	if i != '0':
		count_1 += 1

if count_1 > count_0:
	print(count_0)
else:
	print(count_1)

Submission status: Accepted

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

odd = 0
even = 0

for i in range(n):
    if i % 2 == 0:
        if s[i] == "1":
            odd += 1
        else:
            even += 1
    else:
        if s[i] == "0":
            odd += 1
        else:
            even += 1

ans = min(odd, even)

print(ans)

Submission status: Accepted

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

ans0, ans1 = 0, 0
n0_even, n0_odd = 0, 0
for i in range(n):
    if s[i] == "0":
        if i%2 == 0:
            n0_even += 1
        else:
            n0_odd += 1
n1_even = (n+1)//2 - n0_even
n1_odd = n//2 - n0_odd
ans0 = n1_even+n0_odd
ans1 = n0_even+n1_odd
print(min(ans0, ans1))

Submission status: Accepted

Solution code:
S = input()


count_0 = 0
count_1 = 0

current_0 = 0
current_1 = 1 
for s in S:
    if int(s) != current_0:
        count_0 += 1

    if int(s) != current_1:
        count_1 += 1

    current_0 += 1
    current_0 %= 2 

    current_1 += 1
    current_1 %= 2 

print(min(count_0, count_1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

x = S[::2].count("0") + (S[1::2]).count("1")
print(min(x, len(S)-x))

Submission status: Accepted

Solution code:
S=input()

ls = len(S)
cnt1 = 0
for i in range(ls):
    if (i % 2 == 0):
        if(S[i] == '0'):
            cnt1 += 1
    if (i % 2 == 1):
        if(S[i] == '1'):
            cnt1 += 1
cnt2 = 0
for i in range(ls):
    if (i % 2 == 0):
        if(S[i] == '1'):
            cnt2 += 1
    if (i % 2 == 1):
        if(S[i] == '0'):
            cnt2 += 1

print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 124
# https://atcoder.jp/contests/abc124
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main(S):
    n1 = 0
    n2 = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == '0':
                n1 += 1
            else:
                n2 += 1
        if i % 2 == 1:
            if S[i] == '1':
                n1 += 1
            else:
                n2 += 1
    n = min(n1, n2)
    print(n)

S = i2s()
main(S)

Submission status: Accepted

Solution code:
s=input();e=s[::2];o=s[1::2]
print(min(e.count("1")+o.count("0"),e.count("0")+o.count("1")))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()
    case1 = 0
    isZero = True
    for ss in s:
        if (isZero and ss == "1") or (not isZero and ss == "0"):
            case1 += 1
        isZero = not isZero
    isZero = False
    case2 = 0
    for ss in s:
        if (isZero and ss == "1") or (not isZero and ss == "0"):
            case2 += 1
        isZero = not isZero
    print(min(case1, case2))

Submission status: Accepted

Solution code:
S = list(input())

ans0 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if int(S[i]) == 0:
            ans0 += 1
        else:
            pass
    else:
        if int(S[i]) == 1:
            ans0 += 1
        else:
            pass

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

print(min(ans0, ans1))

Submission status: Accepted

Solution code:
List=input()
s = len(List)
a = [0] * s
b = [0] * s
b[1::2] = [1] * (s//2)
if s % 2 == 0:
	a[0::2] = [1] * (s//2)
else:
	a[0::2] = [1] * (s//2 + 1)

c1 = 0
c2 = 0

for (i,j) in zip(List,a):
	if int(i) != int(j):
		c1 += 1

for (i,j) in zip(List,b):
	if int(i) != int(j):
		c2 += 1

if c1 >= c2:
	print(c2)
else:
    print(c1)

Submission status: Accepted

Solution code:
s = input()
l1 = s[::2]
l2 = s[1::2]
c1 = l1.count('0') + l2.count('1')
c2 = l1.count('1') + l2.count('0')
print(min(c1,c2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
N=len(s)
A=0
B=0
for i in range(0,N,2):
    if s[i]=='0':
        A+=1
    if i+1==N:
        break
    if s[i+1]=='1':
        B+=1
if A+B<=N/2:
    print(A+B)
else:
    print(N-(A+B))

Submission status: Accepted

Solution code:
s = input()
cnt0 = 0
cnt1 = 0
tile = ['0','1']
ans0 = ''
ans1 = ''
for i in range(len(s)):
    ans0 += tile[i%2]
    ans1 += tile[(i+1)%2]

for i,j,k in zip(s,ans0,ans1):
    if i != j:
        cnt0 += 1
    if i != k:
        cnt1 += 1
print(min(cnt0,cnt1))

Submission status: Accepted

Solution code:
S = input()
x = '0'
num = 0

for i in range(len(S)):
  if S[i] != x:
    num = num + 1
  if x == '0':
    x = '1'
  else:
    x = '0'

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