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():
    result = sub()
    print(result)


def sub():
    maskA = '10' * 10 ** 5
    maskB = '01' * 10 ** 5

    raw = input()
    length = len(raw)

    maskA = maskA[:length]
    maskB = maskB[:length]
    a = int(raw, 2) ^ int(maskA, 2)
    b = int(raw, 2) ^ int(maskB, 2)
    tmp = min(bin(a).count("1"), bin(b).count("1"))
    return min(tmp, length - tmp)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

S = input()
N = [0] * len(S)
for i in range(len(S)):
    N[i] = int(S[i])
arr = np.zeros((2,2))

for i in range(0, len(S), 2):
    if N[i] == 0:
        arr[0,0] += 1
    else:
        arr[0,1] += 1

for i in range(1, len(S), 2):
    if N[i] == 0:
        arr[1,0] += 1
    else:
        arr[1,1] += 1

ans = int(min(arr[0,0]+arr[1,1], arr[0,1]+arr[1,0]))

print(ans)

Submission status: Accepted

Solution code:
s = list(input())

result = 0
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    s[i+1] = str(int(s[i+1]) ^ 1)
    result = result +1

print(result)

Submission status: Accepted

Solution code:
S = str(input())
N = int(len(S))
cnt = 0
S_list = list(S)
for i in range(1,N):
    if S_list[i-1] == S_list[i]:
        if S_list[i-1] == "0":
            cnt += 1
            S_list[i] = "1"
        elif S_list[i-1] == "1":
            cnt += 1
            S_list[i] = "0"
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_c

# input
s = input()
# output
s0 = s[0::2]
s1 = s[1::2]
cost1 = s0.count('0') + s1.count('1')
cost2 = s0.count('1') + s1.count('0')
ans = min(cost1, cost2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S = list(S)
s1 = int(S[0])
count = 0
for i in S[1:]:
    i = int(i)
    if s1 == i:
        count += 1
        if i == 0:
            s1 = 1
        elif i == 1:
            s1 = 0
    else:
        s1 = i
print(count)

Submission status: Accepted

Solution code:
s=input()

hit = 0
for j in range(len(s)):
    if j%2 ==0:
        if s[j] == "0":
            hit = hit+1
        else:
            continue
    if j%2 ==1:
        if s[j] == "1":
            hit = hit+1
        else:
            continue
print(min(hit,len(s)-hit))

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    S = S[::-1]    
    S_num = 0
    temp_ans_0 = '0b'
    temp_ans_1 = '0b'
    num_temp_ans_0 = 0
    num_temp_ans_1 = 0
    for i in range(len(S)):
        if(i%2 ==0):
            temp_ans_0 += '0'
            temp_ans_1 += '1'
        else:
            temp_ans_0 += '1'
            temp_ans_1 += '0'
    # i = 0
    # for s in S:
    #     S_num += int(s) * 2**i
    #     if(i%2 ==0):
    #         num_temp_ans_0 += 0 * 2**i
    #         num_temp_ans_1 += 1 * 2**i
    #     else:
    #         num_temp_ans_0 += 1 * 2**i
    #         num_temp_ans_1 += 0 * 2**i
    #     i +=1
    S_str ='0b'+''.join(S)
    S_num = int(S_str,0)
    num_temp_ans_0 = int(temp_ans_0,0)
    num_temp_ans_1 = int(temp_ans_1,0) 
    c0 = bin(S_num ^ num_temp_ans_0).count('1')
    c1 = bin(S_num ^ num_temp_ans_1).count('1')
    
    print(min(c0,c1))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

s = input()
ans = 0

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()
S = [int(s[i]) for i in range(len(s))]
N = len(S)
 
dis1 = 0
dis2 = 0
start = 0
for i in range(N):
    if (S[i]!=1-start):
        dis1 += 1
    if (S[i]!=start):
        dis2 += 1
    start = 1-start
res = min(dis1, dis2)
print (res)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = n
for i in range(2):
    t = 0
    for j in range(n):
        v = (i+j)%2
        if v != int(s[j]):
            t += 1
    ans = min(ans, t)
print(ans)

Submission status: Accepted

Solution code:
#C
S = str(input())
N = len(S)
b1 = ''
b2 = ''
for i in range(N):
    if i % 2 == 0:
        b1 = b1 + '1'
        b2 = b2 + '0'
    else:
        b1 = b1 + '0'
        b2 = b2 + '1'
bnum1 = int(b1, 2)
bnum2 = int(b2, 2)
bS = int(S, 2)
num1 = bnum1 ^ bS
num2 = bnum2 ^ bS
num1 = (bin(num1).replace('-','').replace('0b','').count('1'))
num2 = (bin(num2).replace('-','').replace('0b','').count('1'))
ans = min(num1, num2)
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
l = len(s)
x = 0
y = 0
ans = 0

for i in range(l):
    if i % 2 == 0:
        if s[i] == '1':
            x += 1
    if i % 2 == 1:
        if s[i] == '0':
            x += 1

for i in range(l):
    if i % 2 == 0:
        if s[i] == '0':
            y += 1
    if i % 2 == 1:
        if s[i] == '1':
            y += 1

ans = min(x, y)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
string=list(input())
if int(string[0])==1:
    c=0
else:
    c=1
a=0
for s in string:
    if int(s)==0 and c==1:
        c-=1
    elif int(s)==0 and c==0:
        c+=1
        a+=1
    elif int(s)==1 and c==0:
        c+=1
    elif int(s)==1 and c==1:
        c-=1
        a+=1
print(a)

Submission status: Accepted

Solution code:
## ひとまず愚直に書いて、ダメだったら後で賢いやり方を探ろう！
S = str(input())
## 101010...
count_10 = 0 
for i in range(len(S)):
  s = int(S[i])
  if i % 2 == 0:
    if s != 1:
      count_10 += 1
  else:
    if s != 0:
      count_10 += 1

## 010101...
count_01 = 0 
for i in range(len(S)):
  s = int(S[i])
  if i % 2 == 0:
    if s != 0:
      count_01 += 1
  else:
    if s != 1:
      count_01 += 1
    
print(min(count_10,count_01))

Submission status: Accepted

Solution code:
S = input()
BW01 = '01' * (len(S) // 2)
if len(S) % 2 == 1:
    BW01 += '0'
WB10 = '10' * (len(S) // 2)
if len(S) % 2 == 1:
    WB10 += '1'

ans1 = ans2 = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == '1':
        ans1 += 1
    if i % 2 == 1 and S[i] == '0':
        ans1 += 1
    if i % 2 == 0 and S[i] == '0':
        ans2 += 1
    if i % 2 == 1 and S[i] == '1':
        ans2 += 1
# print(ans1, ans2)
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
A = input()

#print(A)

LENGTH = len(A)
S = int(A)
S_LIST = []

for i in A:
    S_LIST.append(i)

#print(S_LIST)

LIST = list(map(int,S_LIST))
#print(LIST)

PATTERN_A = []
for i in range(LENGTH):
    if i % 2 == 0:
        PATTERN_A.append(0)
    else:
        PATTERN_A.append(1)

#print(PATTERN_A)


COUNT = 0
for i in range(LENGTH):
    if PATTERN_A[i] == LIST[i]:
        COUNT += 1

if LENGTH - COUNT < COUNT:
    COUNT = LENGTH - COUNT

print(COUNT)

Submission status: Accepted

Solution code:
S = str(input())
S_len = int(len(S))
zero_start = '01'*int(S_len/2)
one_start = '10'*int(S_len/2)
if S_len % 2 == 1:
    # print(zero_start, one_start)
    zero_start = int(zero_start + '0', 2)
    one_start = int(one_start + '1', 2)
else:
    zero_start = int(zero_start, 2)
    one_start = int(one_start, 2)

# print(zero_start, one_start)
# 異なっている部分が １ になった文字列
tmp_z = format(int(S, 2) ^ zero_start, 'b')
z_count = 0
for i in tmp_z:
    if i == '1':
        z_count += 1

tmp_o = format(int(S, 2) ^ one_start, 'b')
o_count = 0
for i in tmp_o:
    if i == '1':
        o_count += 1
# print(z_count, o_count)
if z_count > o_count:
    print(o_count)
else:
    print(z_count)

Submission status: Accepted

Solution code:
s=list(input())
o = len(s)
j = 0
k = 0

for i in range(o):
    if i%2 == 1:
        if s[i] == str(1):
           j = j + 1
        else: k = k + 1
    if i%2 == 0:
        if s[i] == str(0):
           j = j + 1
        else: k = k + 1

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

Submission status: Accepted

Solution code:
import numpy as np

S = input()

S = [int(i) for i in S]
#print(s_zero[0])

count = 0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

v = 0


i = 1
while i<len(n):
    if(n[i-1] == n[i]):
        n[i] = (1-n[i])
        v+=1
    i+=1
print(v)

Submission status: Accepted

Solution code:
s = list(map(int, input()))
z = []
o = []
zj = 0
oj = 0
for i in range(len(s)):
    if i % 2 == 0:
        z.append(0)
        o.append(1)
        if s[i] == 0:
            oj += 1
        else:
            zj += 1
    else:
        z.append(1)
        o.append(0)
        if s[i] == 0:
            zj += 1
        else:
            oj += 1
print(min(zj, oj))

Submission status: Accepted

Solution code:
S = input()

len_S = len(S)
first = ("01" * (len_S//2+1))[:len_S]
second = ("10" * (len_S//2+1))[:len_S]

ans = min(bin(int(S,2) ^ int(first,2)).count('1'), bin(int(S,2) ^ int(second,2)).count('1'))
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
first_zero = []
first_one = []
s_size = len(s)
for i in range(s_size):
    if i % 2 == 0:
        first_zero.append("0")
        first_one.append("1")
    else:
        first_zero.append("1")
        first_one.append("0")

count_zero = 0
count_one = 0

for index,number in enumerate(s):
    if number == first_zero[index]:
        pass
    else:
        count_zero += 1

    if number == first_one[index]:
        pass
    else:
        count_one += 1

if count_one > count_zero:
    print(count_zero)
else:
    print(count_one)

Submission status: Accepted

Solution code:
s = input()
num_s = list(map(int,s))
odd = num_s[0::2]
even = num_s[1::2]

total_count = len(s)
odd_count = len(odd)
even_count = len(even)

odd_sum = sum(odd)
even_sum = sum(even)

rev = 0
rev += abs(odd_count-odd_sum)
rev += even_sum
rev = rev if (total_count // 2 >= rev) else total_count - rev

print(rev)

Submission status: Accepted

Solution code:
S = input()

white_counter = 0
tile_color = '1'
for tile in S:
    if tile_color == tile:
        pass
    else:
        white_counter += 1
    if tile_color == '1':
        tile_color = '0'
    else:
        tile_color = '1'

black_counter = 0
tile_color = '0'
for tile in S:
    if tile_color == tile:
        pass
    else:
        black_counter += 1
    if tile_color == '1':
        tile_color = '0'
    else:
        tile_color = '1'

print(min(white_counter, black_counter))

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
even_zero, even_one, odd_zero, odd_one = 0, 0, 0, 0

for i in range(len_s):

    if i % 2 == 0:
        if s[i] == "0":
            even_zero += 1
        else:
             even_one += 1
    else:
        if s[i] == "0":
            odd_zero += 1
        else:
             odd_one += 1

print(min(len_s - even_zero - odd_one, len_s - even_one - odd_zero))

Submission status: Accepted

Solution code:
n = input()
if len(n) == 1:
  print(0)
  exit()
cnt = 0
li = []
for i in n:
  li.append(int(i))
#print(li)
cnt = 0

for i in range(1, len(li)):
  if li[i] == li[i-1]:
    if li[i] == 1:
      li[i] = 0
    else:
      li[i] = 1
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
data=[]

for i in input():
  data.append(int(i))

  
A=data.count(0)+data.count(1)

a=0
b=0
c=0
d=0
if A%2==0:
  for j in range(0,A//2):
    s=2*j
    if data[s]==1:
      a=a+1
    else:
      b=b+1
    if data[s+1]==1:
      c=c+1
    else:
      d=d+1
      
if A%2==1:
  for j in range(0,A//2+1):
    s=2*j
    if data[s]==1:
      a=a+1
    else:
      b=b+1
  for j in range(0,A//2):
    s=2*j
    if data[s+1]==1:
      c=c+1
    else:
      d=d+1
      
      
e=max(a+d,b+c)

print(A-e)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
a = str(input())
lis_a = []
for i in a:
    lis_a.append(int(i))
    
sum = 0
for i in range(1,len(lis_a)):
    if lis_a[i-1] == lis_a[i]:
        sum += 1
        if lis_a[i] == 0:
            lis_a[i] = 1
        else:
            lis_a[i] = 0

print(sum)

Submission status: Accepted

Solution code:
s = list(input())
count1 = 0
s_copy = s.copy()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count1 += 1
        if s[i+1] == '0':
            s[i+1] = '1'
        else:
            s[i+1] = '0'
s = s_copy.copy()
s.reverse()
count2 = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        count2 += 1
        if s[i+1] == '0':
            s[i+1] = '1'
        else:
            s[i+1] = '0'
print(min(count1,count2))

Submission status: Accepted

Solution code:
s = input()
s_00 = 0
s_01 = 0 
s_10 = 0
s_11 = 0
count = 0

if s == "0" or s == "1":
    print(0)
    exit()


for i in s:
    count += 1
    if i == "0" and count % 2 == 1:
        s_00 += 1
    elif i == "1" and count % 2 == 1:
        s_01 += 1
    elif i == "0" and count % 2 == 0:
        s_10 += 1
    elif i == "1" and count % 2 == 0:
        s_11 += 1

if s_00 + s_11 <= s_01 + s_10:
    print(s_00 + s_11)
else:
    print(s_01 + s_10)

Submission status: Accepted

Solution code:
s = input()

fc = s[0]
nc = ""

count = 0

if fc == "0":
    nc = "1"
else:
    nc = "0"

for i in range(1,len(s)):
    if s[i] != nc :
        count += 1
        nc = s[i]
    else:
        if nc == "0":
            nc = "1"
        else:
            nc = "0"

print(count)

Submission status: Accepted

Solution code:
s = input()

s_list = list(s)
s_len = len(s)

s_pattern1 = ""
is_zero = False
for _ in range(s_len):
    if is_zero:
        s_pattern1 += "0"
    else:
        s_pattern1 += "1"
    is_zero = not is_zero
    
s_pattern2 = ""
is_zero = True
for _ in range(s_len):
    if is_zero:
        s_pattern2 += "0"
    else:
        s_pattern2 += "1"
    is_zero = not is_zero

count1 = 0
count2 = 0
for i, c in enumerate(s_list):
    if c != s_pattern1[i]:
        count1 += 1
    if c != s_pattern2[i]:
        count2 += 1
        
print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
listA = []
listB = []
ans1 = 0
ans2 = 0

for i in range(len(S)//2):
    listA.append(1)
    listA.append(0)
    listB.append(0)
    listB.append(1)

if len(S)%2 != 0:
    listA.append(1)
    listB.append(0)


for i in range(len(S)):
    if int(S[i]) != listA[i]:
        ans1 += 1
    if int(S[i]) != listB[i]:
        ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
# import math
S = str(input())
ans = 0

before = S[0]
for i in range(1, len(S)):
    # print(before)
    # print('')
    # print(S[i])
    # print(before==S[i])
    if before == S[i]:
        ans += 1
    if before == '0':
        before = '1'
    else:
        before = '0'

print(ans)

# zero = 0
# one = 0
# for i in range(len(S)):
#     if S[i] == '0':
#         zero += 1
#     else:
#         one += 1
#
# hoge = abs(zero - one) /2
#
# ans = int(hoge)
#
# print(ans)

Submission status: Accepted

Solution code:
a = [i for i in input()]
target1 = []
target2 = []
for i, n in enumerate(a):
    if i % 2 == 0:
        target1.append('1')
        target2.append('0')
    else:
        target1.append('0')
        target2.append('1')

result1 = 0
result2 = 0
for i, el in enumerate(a):
    if target1[i] != el:
        result1 += 1
    if target2[i] != el:
        result2 += 1

print(min(result1, result2))

Submission status: Accepted

Solution code:
S=list(input())
count_0 = 0
count_1 = 0

#101010
for (i,item) in enumerate(S):
    if i%2 != 0 and item=="0":
        count_1 +=1


    elif i%2==0 and item=="1":
        count_1 +=1

#010101
for (i,item) in enumerate(S):
    if i%2 != 0 and item =="1" :
        count_0 +=1

    elif i%2==0 and item=="0":
        count_0 +=1

print(min(count_0,count_1))

Submission status: Accepted

Solution code:
import sys
import io
import math
import re

datalist = input().split()
num_summit = list(str(datalist[0]))

num_match = 0
flag = 0

for num in range(len(num_summit)):
    check_num = int(num_summit[num])
    if check_num == flag % 2:
        num_match += 1
    flag += 1

if num_match * 2 < len(num_summit):
    print(num_match)
else:
    print(len(num_summit)- num_match)

Submission status: Accepted

Solution code:
# coding: utf-8
s = input()
strlen = len(s)
cnt = 0
for i in range(0, strlen, 2):
    if s[i] != '0':
        cnt += 1
for j in range(1, strlen, 2):
    if s[j] != '1':
        cnt += 1
print(min(cnt, strlen - cnt))

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc124
# -*- coding: utf-8 -*-

s = list(input())
cnt1=0
for i in range(len(s)):
        if int(s[i]) == i%2:
                cnt1 += 1

cnt2=0
for i in range(len(s)):
        if int(s[i]) == (i+1)%2:
                cnt2 += 1

print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
a=raw_input()
x=sum([a[i]=="01"[i%2] for i in range(len(a))])
ans=min([x,len(a)-x])
print ans

Submission status: Accepted

Solution code:
a = list(map(int,list(input())))
r =[1,0]
n = 0
def change(n):
  if n == 0 :
    return 1
  else :
    return 0
if len(a) == 1 :
  print(0)
else :
  for i in range(1,len(a)):
    if a[i-1] == a[i] :
      n = change(n)
    r[n] +=1
  print(min(r))

Submission status: Accepted

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

dp = {}

for i in range(length):
  for j in range(2):
    if i == 0:
      dp[(i,j)] = 0 if S[0] == j else 1
      continue

    # print('i,j:', i, j)
    inverse = 0 if S[i] == 1 else 1

    if S[i] == j: # 最后 S[i] 不动
      dp[(i, j)] = dp[(i-1, inverse)]
    else: # 最后 S[i] 变成inverse
      dp[(i, j)] = dp[(i-1, S[i])] + 1




# print('dp', dp)
print(min(dp[(length-1, 0)], dp[(length-1, 1)]))

Submission status: Accepted

Solution code:
ls = list(map(int, list(input().split()[0])))
N = len(ls)

cnt_0 = 0
cnt_1 = 0
ls_0 = ls.copy()
ls_1 = ls.copy()
for i in range(N):
    if i == 0:
        if ls_0[i] == 0:
            pass
        else:
            ls_0[i] = 0
            cnt_0 += 1
    else:
        if i % 2 == 0:
            if ls_0[i] == 0:
                pass
            else:
                ls_0[i] = 0
                cnt_0 += 1
        else:
            if ls_0[i] == 1:
                pass
            else:
                ls_0[i] = 1
                cnt_0 += 1

for i in range(N):
    if i == 0:
        if ls_1[i] == 1:
            pass
        else:
            ls_1[i] = 1
            cnt_1 += 1
    else:
        if i % 2 == 0:
            if ls_1[i] == 1:
                pass
            else:
                ls_1[i] = 1
                cnt_1 += 1
        else:
            if ls_1[i] == 0:
                pass
            else:
                ls_1[i] = 0
                cnt_1 += 1

print(min([cnt_0, cnt_1]))

Submission status: Accepted

Solution code:
s=input()
pre=bool(int(s[0]))
cnt=0
for i in range(1, len(s)):
    if pre == bool(int(s[i])):
        cnt+=1
        pre= not bool(int(s[i]))
    else:
        pre = bool(int(s[i]))
print(cnt)

Submission status: Accepted

Solution code:
S =input()
S_bin = int("0b"+S, 0)
if len(S)%2 == 0:
    a = int("0b"+"01"*int(len(S)/2),0)
    b = int("0b"+"10"*int(len(S)/2),0)
else:
    a = int("0b"+"1" + "01"*int(len(S)/2) ,0)
    b = int("0b"+"0" + "10"*int(len(S)/2) ,0)
print(min(bin(a^S_bin).count("1"),bin(b^S_bin).count("1")))

Submission status: Accepted

Solution code:
S = list(map(int, input()))
zero_one_cnt = 0
one_zero_cnt = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == 0:
            zero_one_cnt += 0
            one_zero_cnt += 1
        else:
            zero_one_cnt += 1
            one_zero_cnt += 0
    else:
        if S[i] == 0:
            zero_one_cnt += 1
            one_zero_cnt += 0
        else:
            zero_one_cnt += 0
            one_zero_cnt += 1

print(min(zero_one_cnt, one_zero_cnt))

Submission status: Accepted

Solution code:
S = input()
S += '_'
a = 0
cnt = 0
if S[0] == "0":
    for i in range(0, len(S), 2):
        if S[i] == '1':
            cnt += 1
    for i in range(1, len(S), 2):
        if S[i] == '0':
            cnt += 1
if S[0] == "1":
    for i in range(0, len(S), 2):
        if S[i] == '0':
            cnt += 1
    for i in range(1, len(S), 2):
        if S[i] == '1':
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def revS(x):
    if x == '0':
        return '1'
    return '0'

S = list(input().rstrip())

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t = input()
s = list(t)
a=0
if len(s)!=1:
    for i in range(len(s)-1):
        if s[i]==s[i+1] and s[i]=="1":
            s[i+1]="0"
            a=a+1
        elif s[i]==s[i+1] and s[i]=="0":
            s[i+1]="1"
            a=a+1
    print(a)
elif len(s)==1:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np

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

answer_option_A = np.array([0 if i%2 == 0 else 1 for i in range(len(S))])
answer_option_B = np.array([1 if i%2 == 0 else 0 for i in range(len(S))])

answer_option_A = np.logical_xor(S, answer_option_A)
answer_option_B = np.logical_xor(S, answer_option_B)

print(min(answer_option_A.sum(),answer_option_B.sum()))

Submission status: Accepted

Solution code:
S=input()
cnt=0
for i in range(len(S)):
    if S[i]==str(i%2):
        cnt+=1
print(min(cnt,len(S)-cnt))

Submission status: Accepted

Solution code:
def tairu(a):
    hoge=None
    ii=0
    if len(a)==1:
        return 0
    for i in range(len(a)-1):
        hoge=a[i:i+2]
        if hoge[0]==hoge[1]:
            ii+=1
            if a[i+1]=="0":
                a[i+1]="1"
            else:
                a[i+1]="0"
    else:
        if a[-1]==a[-2]:
            ii+=1
    return ii
  
a=list(input())
print(tairu(a))

Submission status: Accepted

Solution code:
def main():
    S = [int(i) for i in input()]

    counterOne = coloringColorful(0, S)
    counterZero = coloringColorful(1, S)

    print(counterOne if counterOne <= counterZero else counterZero)


def coloringColorful(preNumber, S):
    pre = preNumber
    counter = 0
    for s in S:
        if s != pre:
            pre = 1 if pre == 0 else 0
        else:
            pre = 1 if s == 0 else 0
            counter += 1

    return counter


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
mojiretu = input()
nagasa = len(mojiretu)

zero_ichi = ''
ichi_zero = ''

for i in range(nagasa):
    if i % 2 == 0:
        zero_ichi += '0'
        ichi_zero += '1'
    if i % 2 == 1:
        zero_ichi += '1'
        ichi_zero += '0'

counter_0 = 0
counter_1 = 0
for i in range(nagasa):
    if zero_ichi[i] != mojiretu[i]:
        counter_0 += 1
    if ichi_zero[i] != mojiretu[i]:
        counter_1 += 1

if counter_0 <= counter_1:
    print(counter_0)
else:
    print(counter_1)

Submission status: Accepted

Solution code:
l = input()
m = []
mx = []
for x in range(len(l)):
    m.append(str(int(x % 2)))
    mx.append(str(abs(int(x % 2) - 1)))
l = list(l)
mng = 0
mxng = 0
for i in range(len(l)):
    if m[i] != l[i]:
        mng += 1
    if mx[i] != l[i]:
        mxng += 1
print(mng if mng <= mxng else mxng)

Submission status: Accepted

Solution code:
S = input()

cnt1 = 0
cnt2 = 0

nc = '0'
for c in S :
    if c != nc :
        cnt1 += 1
    
    if nc == '0' :
        nc = '1'
    else :
        nc = '0'
        
nc = '1'
for c in S :
    if c != nc :
        cnt2 += 1
    
    if nc == '0' :
        nc = '1'
    else :
        nc = '0'
        
print(min(cnt1, cnt2))

Submission status: Accepted

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

to_z = [z for z in s[0::2] if z == '1']
to_o = [o for o in s[1::2] if o == '0']
a = len(to_z) + len(to_o)
to_z = [z for z in s[1::2] if z == '1']
to_o = [o for o in s[0::2] if o == '0']
b = len(to_z) + len(to_o)
if a < b:
    print(a)
else:
    print(b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    S = lines.pop(0)
    L = R = 0
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == '0':
                L += 1
            else:
                R += 1
        else:
            if s == '1':
                L += 1
            else:
                R += 1
    print(min(L,R))
    
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

Solution code:
add_flag = False
tiles = input()
if tiles.__len__() % 2 != 0:
    tiles += "0"
    add_flag = True
pair_tiles_list = [tiles[i: i + 2] for i in range(0, len(tiles), 2)]
base_pair = ""
count = 0
if pair_tiles_list.count("01") < pair_tiles_list.count("10"):
    base_pair = "10"
else:
    base_pair = "01"
if add_flag:
    pair_tiles_list[-1] = pair_tiles_list[-1][0]
for pair in pair_tiles_list:
    if pair != base_pair:
        if pair[0] != base_pair[0]:
            count += 1
        if pair.__len__() > 1:
            if pair[1] != base_pair[1]:
                count += 1
print(count)

Submission status: Accepted

Solution code:
color_str = input()
color_str_arr = list(color_str)

count_a = 0
count_b = 0

color_pattern = ['0', '1']

index_a = 0
index_b = 1

for color in color_str_arr:
    if color != color_pattern[index_a]:
        count_a += 1
    if color != color_pattern[index_b]:
        count_b += 1
    index_a = 1 - index_a
    index_b = 1 - index_b

min_count = count_a if count_a < count_b else count_b

print(min_count)

Submission status: Accepted

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

p1 = ""
p2 = ""
for i in range(N):
    if i % 2 == 0:
        p1+=str(0)
        p2+=str(1)
    else:
        p1+=str(1)
        p2+=str(0)
#print(p1)
#print(p2)

a1 = 0
a2 = 0
for i in range(N):
    if p1[i] != S[i]:
        a1 += 1
    if p2[i] != S[i]:
        a2 += 1
#print(a1,a2)
print(min(a1,a2))

Submission status: Accepted

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

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

even_1 = sum(even)
even_0 = len(even) - even_1
odd_1 = sum(odd)
odd_0 = len(odd) - odd_1

ans = 0
if even_0 + odd_1 <= even_1 + odd_0:
    ans = even_0 + odd_1
else:
    ans = even_1 + odd_0

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
for i in range(n):
  s[i]=int(s[i])
n=len(s)
a=[0]*n
b=[0]*n
cnta=0
cntb=0

for i in range(n):
  if i%2==1:
    a[i]=1
    if a[i]!=s[i]:
      cnta+=1
  else:
    if a[i]!=s[i]:
      cnta+=1

for j in range(n):
  if j%2==0:
    b[j]=1
    if b[j]!=s[j]:
      cntb+=1
  else:
    if b[j]!=s[j]:
      cntb+=1

if cnta<cntb:
  print(cnta)
else:
  print(cntb)

Submission status: Accepted

Solution code:
S = input()

count = 0
a = int(S[0])
b = 0 if a == 1 else 1

for i in range(1,len(S)):
    color = int(S[i])
    if i % 2 == 1 and color !=b:
        count += 1
    elif i % 2 == 0 and color != a:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
S = input()
N = len(S)
if N // 2 == 0:
  even = np.array([int(S[2*k]) for k in range(N // 2)])
  odd = np.array([int(S[2*k + 1]) for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 > odd_1:
    print(int(N//2 - even_1 + odd_1))
  else:
    print(int(N//2 + even_1 - odd_1))
else:
  even = np.array([int(S[2*k]) for k in range( (N+1) // 2)])
  odd = np.array([int(S[2*k + 1]) for k in range(N // 2)])
  even_1 = even.sum()
  odd_1 = odd.sum()
  if even_1 <= odd_1:
    print(int(even_1 + N//2 - odd_1))
  else:
    print(int(odd_1 + (N+1)//2 - even_1))

Submission status: Accepted

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