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: Time Limit Exceeded

Solution code:
s = input()
oddone = ''
evenone = ''

for i in range(len(s)):
    if i % 2 == 1:
        oddone += '1'
        evenone += '0'
    else:
        oddone += '0'
        evenone += '1'

def diffCount(s1, s2):
    count = 0
    if len(s1) != len(s2):
        print('error')
        return

    for i in range(len(s1)):
        if s1[i] != s2[i]:
            count += 1

    return count

print(min(diffCount(s, oddone), diffCount(s, evenone)))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
S = int(S, 2)

a = 0
two = 2
b = 2**N -1
for n in range(N//2):
	a += two
	two *= 4
b = b^a
a = a ^ S
b = b ^ S
at = 0
bt = 0
for n in range(N):
	at += a%2
	bt += b%2
	a //= 2
	b //= 2
print(min(at, bt))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
S = int(S, 2)
a = ""
b = ""
for n in range(N):
	if n%2 ==0:
		a += '1'
		b += '0'
	else:
		a += '0'
		b += '1'
a = int(a, 2)
b = int(b, 2)
a = a ^ S
b = b ^ S
at = 0
bt = 0
for n in range(N):
	at += a%2
	bt += b%2
	a //= 2
	b //= 2
print(min(at, bt))

Submission status: Time Limit Exceeded

Solution code:
S = input()
Slen = len(S)
s = int(S, 2)
x = 0
for n in range(Slen) :
    if n%2 == 0 :
        x += 2**n
nuri = s^x
ans = 0
while nuri > 0 :
    if nuri&1 == 1 :
        ans += 1
    nuri >>= 1
print(min(ans, Slen-ans))

Submission status: Time Limit Exceeded

Solution code:
import sys

def judge(string):
    mem = ""
    for char in string:
        if mem == char:
            return False
        mem = char

    return True


def main():
    sinputl = sys.stdin.readline

    input = sinputl().strip()
    length = len(input)
    input = int(input, base=2)

    paint = [length]

    for i in range(2 ** length):
        status = input ^ i
        if judge(bin(status)[2:].zfill(length)):
            paint.append(bin(i).count('1'))

        
    print(min(paint))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = int(a)
s = []
while b > 0:
  t = b % 10
  s.append(t)
  b = b // 10
i = 0
while(a[i:i+1] == '0'):
  s.append(0)
  i += 1
s.reverse()
cnt = 0
if(len(s) == 1):
	cnt = 0
else:
	for i in range(len(s)-1):
		if(s[i] == s[i+1]):
			if(s[i] == 0):
				s[i+1] = 1
			else:
				s[i+1] = 0
			cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
binary_s = int(s,2)

zeros = 0
ones = 0
for i in range(len(s)):
  if i % 2 == 1:
    zeros += 2**i
  else:
    ones += 2**i

zero_sum = sum([int(x) for x in list( str( bin( binary_s ^ zeros ) )[2:]) ])
one_sum  = sum([int(x) for x in list( str( bin( binary_s ^ ones  ) )[2:]) ])

if zero_sum < one_sum:
  print(zero_sum)
else:
  print(one_sum)

Submission status: Time Limit Exceeded

Solution code:
S =input()
l=len(S)
N=int(S,2)

    
apopcount=0
bpopcount=0
for i in range(0,l):
  if i%2==0:
    if (N & 0b10**i)!=0:
   		apopcount+=1
    else:
      	bpopcount+=1
  else:
    if (N & 0b10**i)!=0:
    	bpopcount+=1
    else:
      	apopcount+=1
if apopcount<bpopcount:print(apopcount)
else:print(bpopcount)

Submission status: Time Limit Exceeded

Solution code:
S =input()
l=len(S)
N=int(S,2)
a=0b1
b=0b0
for i in range(1,l):
  if i%2==0:
    a=a+0b10**i
  else:
  	b=b+0b10**i
aN=a ^ N
bN=b ^ N
apopcount=0
bpopcount=0
for i in range(0,l):
  if (aN & 0b10**i)!=0:
    apopcount+=1
  if (bN & 0b10**i)!=0:
    bpopcount+=1
if apopcount<bpopcount:print(apopcount)
else:print(bpopcount)

Submission status: Time Limit Exceeded

Solution code:
S  = str(input())
lst_even = []
lst_odd = []
for i in range(len(S)):
    if i % 2 == 0:
        lst_even = lst_even + [S[i]]
    else:
        lst_odd =  lst_odd + [S[i]]
even_white = lst_even.count('1')
even_black = lst_even.count('0')
odd_white = lst_odd.count('1')
odd_black = lst_odd.count('0')
bw = even_white + odd_black
wb = even_black + odd_white
print (min(wb, bw))

Submission status: Time Limit Exceeded

Solution code:
a = str(input())
ref1 = 0
ref2 = 0
for i in range(len(a)):
    if i % 2 ==0:
        ref1 = ref1 + 10**i
    else:
        ref2 = ref2 + 10**i

count1 = 0
count2 = 0
for i in range(len(str(ref1))):
    if str(ref1)[i] != a[i]:
        count1 = count1 + 1
for i in range(len(str(ref2))):
   if str(ref2)[i] != a[i]:
        count2 = count2 + 1


if count1 <count2:
    print(count1)
else:
    print(count2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

s_val = int(s, 2)


s1 = 0
s2 = 0
for i in range(len(s)):
    if i%2==0:
        s1 += 2**i
    elif i%2==1:
        s2 += 2**i

num = min(str(bin(s_val^s1)).count('1'), str(bin(s_val^s2)).count('1'))
print(num)

Submission status: Time Limit Exceeded

Solution code:
s = input()


a =[ int(i) for i in list(s)]
s_val = 0
for n_bit, bit in enumerate(a[::-1]):
    s_val += bit *(2**n_bit)


s1 = 0
for i in range(len(s)):
    if i%2==0:
        s1 += 2**i
        
s2 = 0
for i in range(len(s)):
    if i%2==1:
        s2 += 2**i

num = min(str(bin(s_val^s1)).count('1'), str(bin(s_val^s2)).count('1'))
print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = str(input())
s_list = np.array([int(list(s)[i]) for i in range(len(s))])

if len(s_list) % 2 == 0:
    s01 = np.array([0,1]*(len(s_list)//2))
    s10 = np.array([1,0]*(len(s_list)//2))
else:
    s01 = np.array([0,1]*(len(s_list)//2))
    s01 = np.append(s01, 0)
    s10 = np.array([1,0]*(len(s_list)//2))
    s10 = np.append(s10, 1)

ans = min(np.sum(s_list == s01), np.sum(s_list == s10))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h=0
a=list(input())
for i in range(1,len(a)):
  r=int(a[i])
  if int(a[i-1])==r:
    if r==0:
      b=1
    else:
      b=0
    a.pop(i)
    a.insert(i,b)
    h+=1
print(h)

Submission status: Time Limit Exceeded

Solution code:
h=0
a=list(input())
for i in range(1,len(a)):
  if int(a[i-1])==int(a[i]):
    if int(a[i])==0:
      b=1
    else:
      b=0
    a.pop(i)
    a.insert(i,b)
    h+=1
print(h)

Submission status: Time Limit Exceeded

Solution code:
h=0
a=list(input())
if len(a)==1:
  print(0)
else:
  for i in range(1,len(a)):
    if int(a[i-1])==int(a[i]):
      if int(a[i])==0:
        b=1
      else:
        b=0
      a.pop(i)
      a.insert(i,b)
      h+=1
  print(h)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
num=int(S)
# print(l,num,S)
count=0
for _ in reversed(range(l)):
    # print(_,(_%2==1)*1,num//(10**_))
    if num//(10**_)!=(_%2==1)*1:
        count+=1
    num=num%(10**_)
    # print(count)

print(min(count,l-count))

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
a = 0
for i in range(l):
  if i&1 == 1:
    a += 2**i
b = ((2**l)-1) ^ a

S = int(s, 2)
A = bin(S^a).count('1')
B = bin(S^b).count('1')
print(min(A, B))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()

value = int(S, 2)

eval = 0
length = len(S)
if length % 2 == 0: val = 1
else: val = 0
for i in xrange(length):
    if i % 2 == val:
        eval += 2 ** i

count = bin(value ^ eval).count('1')

if count <= 0.5 * length: print count
else: print (length - count)

Submission status: Time Limit Exceeded

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

s = input()
count = 0
while(1):
    while(1):
        key = "1001001"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "1010101" + s[index+len(key):]
            count += 3
            s = s_temp
        else:
            break


    
    while(1):
        key = "0110110"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "0101010" + s[index+len(key):]
            count += 3
            s = s_temp
        else:
            break

        
    while(1):
        key = "111"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "101" + s[index+len(key):]
            count += 1
            s = s_temp
        else:
            break

        
    while(1):
        key = "000"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "010" + s[index+len(key):]
            count += 1
            s = s_temp
        else:
            break

        
    while(1):
        key = "100"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "010" + s[index+len(key):]
            count += 1
            s = s_temp
        else:
            break
        
    while(1):
        key = "001"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "101" + s[index+len(key):]
            count += 1
            s = s_temp
        else:
            break
    
        
    while(1):
        key = "110"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "010" + s[index+len(key):]
            count += 1
            s = s_temp
        else:
            break
        
    while(1):
        key = "011"
        index = s.find(key)
        if index!=-1 :
            s_temp = s[:index] + "001" + s[index+len(key):]
            count += 1
            s = s_temp
        else:
            break
        
    if s.find("11")==-1 and s.find("00")==-1:
        break

print(count)

Submission status: Time Limit Exceeded

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

for i in range(len(S) - 1):
    if (S[0] == 0 and S[1] == 0):
        S[1] = 1
        S = S[1:]
        times += 1
    elif (S[0] == 1 and S[1] == 1):
        S[1] = 0
        S = S[1:]
        times += 1
    else:
        S = S[1:]
        
print(times)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
r = 0

def rec(a, b, s):
    global r
    if len(s) == 0:
        return [a] + [b]
    if a == '0' and b == '0':
        b = '1'
        r += 1
    elif a == '1' and b == '1':
        b = '0'
        r += 1
    return [a] + [b] + rec(b, s[0], s[1:])

if len(s) == 1:
    print(0)
else:
    rec(s[0], s[1], s[2:])
    print(r)

Submission status: Time Limit Exceeded

Solution code:
def even_bit_maker(number_length):
    bit = 0
    for i in range(number_length):
        if i % 2 == 0:
            bit += 2 ** i
    return bit


def odd_bit_maker(number_length):
    bit = 0
    for i in range(number_length):
        if i % 2 == 1:
            bit += 2 ** i
    return bit


if __name__ == '__main__':
    init_tile = input()
    init_tile_bit = int(init_tile, 2)
    tile_len = len(init_tile)
    even_bit = init_tile_bit ^ even_bit_maker(tile_len)
    odd_bit = init_tile_bit ^ odd_bit_maker(tile_len)
    even_change_count = bin(even_bit).count('1')
    odd_change_count = bin(odd_bit).count('1')
    print(min(even_change_count, odd_change_count))

Submission status: Time Limit Exceeded

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

S = [s for s in str(input())]

ans = 0


for i in range(len(S)):
    if i == 0:
        continue

    if S[i] == S[i-1]:
        if S[i] == "0":
            del S[i]
            S.insert(i, "1")
        else:
            del S[i]
            S.insert(i, "0")
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
l_index = 0
cnt = 0

if len(s) == 1:
  print(cnt)
else:
  while True:
    for k, v in enumerate(s):
      l_index = k
      if k == 0:
        next
      elif v == s[k - 1]:
        cnt += 1
        s[k] = str((int(v) + 1) % 2)
        break

    if l_index == len(s) - 1:
      break

  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()

value = int(S, 2)

zero = 0
one = 0
for i in xrange(len(S)):
    if i % 2 == 0:
        zero += 2 ** i
    else:
        one += 2 ** i

count = bin(value ^ zero).count('1')
count_1 = bin(value ^ one).count('1')

if count <= count_1: print count
else: print count_1

Submission status: Time Limit Exceeded

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 = ''
    temp_ans_1 = ''
    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
    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: Time Limit Exceeded

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 = ''
    temp_ans_1 = ''
    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'
    for i in range(len(S)):
        S_num += int(S[i]) * 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
            
    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: Time Limit Exceeded

Solution code:
import numpy as np
a = input()
l = len(a)
a = int(a,2)
b1 = 0
b2 = 0
for i in range(l):
    if i%2==0:
        b1+=2**i
    else:
        b2+=2**i

# print(str(bin(a))[2:])
# print(str(bin(b1))[2:])
# print(str(bin(b2))[2:])

# bb1=str(bin(a^b1))[2:]
# bb2=str(bin(a^b2))[2:]

# print(bb1,bb2)

# bs1 = 0
# for b in bb1:
#     if b=="1":
#         bs1+=1

# bs2 = 0
# for b in bb2:
#     if b=="1":
#         bs2+=1


bs1=bin(a^b1).count("1")
bs2=bin(a^b2).count("1")

print(min(bs1,bs2))

Submission status: Time Limit Exceeded

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 = ''
    temp_ans_1 = ''
    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'
    for i in range(len(S)):
        S_num += int(S[i]) * 2**i
        num_temp_ans_0 += int(temp_ans_0[i]) * 2**i
        num_temp_ans_1 += int(temp_ans_1[i]) * 2**i
    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: Time Limit Exceeded

Solution code:
import numpy as np
a = input()
l = len(a)
a = int(a,2)
b1 = 0
b2 = 0
for i in range(l):
    if i%2==0:
        b1+=2**i
    else:
        b2+=2**i

# print(str(bin(a))[2:])
# print(str(bin(b1))[2:])
# print(str(bin(b2))[2:])

bb1=str(bin(a^b1))[2:]
bb2=str(bin(a^b2))[2:]

# print(bb1,bb2)

bs1 = 0
for b in bb1:
    if b=="1":
        bs1+=1

bs2 = 0
for b in bb2:
    if b=="1":
        bs2+=1

print(min(bs1,bs2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
L = [int(i) for i in S]
b = 1
B = 0
for i in L:
  if i != b:
    B += 1
  b = 1 - b
l = len(L)
print(min(B, l - B))

Submission status: Accepted

Solution code:
S = input()
b = 1
B = 0
l = 0
for i in S:
  if int(i) != b:
    B += 1
  b = 1 - b
  l += 1
print(min(B, l - B))

Submission status: Accepted

Solution code:
S = input()
b = 1
B = 0
for i in S:
  if i != str(b):
    B += 1
  b = 1 - b
l = len(S)
print(min(B, l - B))

Submission status: Accepted

Solution code:
S = input()
b = 1
B = 0
for i in S:
  if int(i) != b:
    B += 1
  b = 1 - b
l = len(S)
print(min(B, l - B))

Submission status: Accepted

Solution code:
S = input()
b = 1
B = 0
for i in S:
  if int(i) != int(b):
    B += 1
  b = not b
l = len(S)
print(min(B, l - B))

Submission status: Accepted

Solution code:
from collections import Counter
moji = str(input())
guall = len(moji)//2
kiall = guall + len(moji) % 2
gucount=dict(Counter(moji[1::2]))
kicount=dict(Counter(moji[0::2]))
if len(moji) == 1:
    ans = 0
elif max(gucount, key=gucount.get) != max(kicount, key=kicount.get):
    ans = guall - max(gucount.values()) + kiall - max(kicount.values())
else:
    if kiall - max(kicount.values()) > guall - max(gucount.values()):
        ans = max(kicount.values()) + guall - max(gucount.values())
    else:
        ans = max(gucount.values()) + kiall - max(kicount.values())
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
cnt = 0
for i, ss in enumerate(s):
  if ss == str(i % 2):
    cnt += 1
print(min(cnt, len(s) - cnt))

Submission status: Accepted

Solution code:
S = [int(x) for x in list(input())]
bw = [0, 1]
wb = [1, 0]
ans1 = 0
ans2 = 0
for i in range(len(S)):
  if(S[i]!=bw[i%2]):
    ans1 += 1
  if(S[i]!=wb[i%2]):
    ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

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

diff0 = 0
diff1 = 0

for i in range(n):
    m = int(s[i])
    if i % 2 != m:
        diff0 += 1
    else:
        diff1 += 1
print(min(diff0, diff1))

Submission status: Accepted

Solution code:
import math


def main():
    # n = int(input())
    # a, b = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

    s = list(input())
    # 1010...
    count1 = 0
    # 0101...
    count2 = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != "1":
            count1 += 1
        if i % 2 != 0 and s[i] != "0":
            count1 += 1
        if i % 2 == 0 and s[i] == "1":
            count2 += 1
        if i % 2 != 0 and s[i] == "0":
            count2 += 1

    print(min(count1, count2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(str(input()))
cnt = 0

if len(s)>1 and s[0]==s[1]:
    if s[0] == '1':
        s[1] = '0'
    else:
        s[1] = '1'
    cnt += 1

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = list(map(int, list(input())))
p1 = 0
p2 = 0
flag = 0
for i in N:
  if i == flag:
    p1 += 1
  else:
    p2 += 1
  flag = 1 - flag
print(min(p1, p2))

Submission status: Accepted

Solution code:
S = input()

A = [1 if i % 2 == 0 else 0 for i in range(len(S))]
B = [1 if i % 2 != 0 else 0 for i in range(len(S))]

A_cost = 0
B_cost = 0

i = 0

for i in range(len(S)):
    if int(S[i]) != A[i]:
        A_cost += 1
    if int(S[i]) != B[i]:
        B_cost += 1

print(min(A_cost,B_cost))

Submission status: Accepted

Solution code:
s = list(input())

count = 0

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

        if s[i] == '1':
            s[i] = '0'
        else:
            s[i] = '1'

print(count)

Submission status: Accepted

Solution code:
S = input()
count = 0

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

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

Submission status: Accepted

Solution code:
S = list(input())


L = []
M = []

for i in range(len(S)//2):
    L.append("0")
    L.append("1")
    M.append("1")
    M.append("0")

if (len(S)) % 2 != 0:
    
    L.append("0")
    M.append("1")
    

cn_1 = 0
cn_2 = 0

for i in range(len(S)):
    if S[i] != L[i]:
        cn_1 = cn_1 + 1
    else:
        cn_2 = cn_2 + 1
        
print(min(cn_1, cn_2))

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

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

for i in range(len(s)):
    if i % 2 == 0:
        s[i] = bool(s[i])
    else:
        s[i] = not s[i]

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

Submission status: Accepted

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

res1 = 0
res2 = 0

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

print(min(res1,res2))

Submission status: Accepted

Solution code:
S=input()
temp=0

for i in range(len(S)):
    if S[i]!="0" and i%2==0:
        temp+=1
    if S[i]!="1" and i%2==1:
        temp+=1
ans=temp

temp=0
for i in range(len(S)):
    if S[i]!="0" and i%2==1:
        temp+=1
    if S[i]!="1" and i%2==0:
        temp+=1
if temp<ans:
    ans=temp

print(ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import numpy as np

def main():
    S = np.array(list(map(int,input().rstrip())))
    L = len(S)
    A = np.arange(L) & 1
    B = 1 - A
    x1 = (A!=S).sum()
    x2 = (B!=S).sum()
    print(min(x1,x2))

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
b=int(len(a))
c=0
d=0
if b%2==0:
  for i in range(b//2):
    if a[2*i]=="1":
      c=c+1
    if a[2*i+1]=="0":
      c=c+1
  for i in range(b//2):
    if a[2*i]=="0":
      d=d+1
    if a[2*i+1]=="1":
      d=d+1
  if c>d:
    print(d)
  else:
    print(c)
if b%2==1:
  for i in range(b//2):
    if a[2*i]=="1":
      c=c+1
    if a[2*i+1]=="0":
      c=c+1
  if a[-1]=="1":
    c=c+1
  for i in range(b//2):
    if a[2*i]=="0":
      d=d+1
    if a[2*i+1]=="1":
      d=d+1
  if a[-1]=="0":
    d=d+1
  if c>d:
    print(d)
  else:
    print(c)

Submission status: Accepted

Solution code:
s = input()

t, u = '', ''
for i in range(len(s)):
    t += '1' if i%2 == 0 else '0'
    u += '0' if i%2 == 0 else '1'

s = int(s, 2)
t = int(t, 2)
u = int(u, 2)
print(min(bin(s^t).count('1'), bin(s^u).count('1')))

Submission status: Accepted

Solution code:
s = str(input())
con = 0
con2 = 0
ans = 0
ans2 = 0
for i in range(len(s)):
  if i % 2 == 0:
    ans += 1
    if s[i] == '0':
      con += 1
  else:
    ans2 += 1
    if s[i] == '1':
      con2 += 1
L = [con + con2, (ans - con) + (ans2 - con2)]
print(min(L))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
if len(s) == 1:
    ans = 0
else:
    ans_w = sum([ 1 for i in s[::2] if i != '1']) + sum([ 1 for i in s[1::2] if i != '0'])
    ans_b = sum([ 1 for i in s[::2] if i != '0']) + sum([ 1 for i in s[1::2] if i != '1'])
    ans = min([ans_w, ans_b])
print(ans)

Submission status: Accepted

Solution code:
import sys
import copy
import math
import itertools
import numpy as np
S = input()
#010101...との比較
cnt = [0,0]
for i in range(len(S)):
    if i%2==0 and int(S[i]) == 1:
        cnt[0]+=1
    elif i%2 == 1 and int(S[i]) == 0:
        cnt[0]+=1
    
    if i%2==0 and int(S[i]) == 0:
        cnt[1]+=1
    elif i%2 == 1 and int(S[i]) == 1:
        cnt[1]+=1
    
if cnt[0]<=cnt[1]:
    print(cnt[0])
else:
    print(cnt[1])

Submission status: Accepted

Solution code:
a = list(input())
b = list(reversed(a))
ans_f = 0
ans_r = 0
for i in range(len(a)-1):
  if a[i] == a[i+1]:
    a[i+1] = str(abs(int(a[i]) - 1))
    ans_f += 1
for i in range(len(a)-1):
  if b[i] == b[i+1]:
    b[i+1] = str(abs(int(b[i]) - 1))
    ans_r += 1
print(min(ans_f,ans_r))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 01:37:10 2020

@author: liang
"""

S = input()
N = len(S)
ans = 0
for i in range(N):
    if i%2 == 0 and S[i] == "0":
        ans += 1
    if i%2 == 1 and S[i] == "1":
        ans += 1
ans = min(ans, N - ans)
print(ans)

Submission status: Accepted

Solution code:
S = input()

N = len(S)
O,E = 0,0
for i,s in enumerate(S):
  O +=(i%2)^int(s)
  E +=(i%2)^(not int(s))
print(min(O,E))

Submission status: Accepted

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

ans_1 = 0
ct = 0
for i in range(N):
  if int(S[i]) != ct:
    ans_1 += 1
  ct += 1
  ct %= 2
  
ans_2 = 0
ct = 1
for i in range(N):
  if int(S[i]) != ct:
    ans_2 += 1
  ct += 1
  ct %= 2
  
print(min(ans_1, ans_2))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans1 = 0
ans2 = 0
for i, v in enumerate(s):
    if v != (i % 2):
        ans1 += 1
    else:
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

count = 0
for i in range(len(s)-1):
  if s[i] == s[i+1] and s[i] == "0":
    s[i+1] = "1"
    count += 1
  elif s[i] == s[i+1] and s[i] == "1":
    s[i+1] = "0"
    count += 1
  else:
    pass
  
print(count)

Submission status: Accepted

Solution code:
S = input()

cnt1 = 0
cnt2 = 0
for i in range(len(S)):
    if i%2:
        if S[i] != "1":
            cnt1 += 1
        if S[i] != "0":
            cnt2 += 1
    else:
        if S[i] != "0":
            cnt1 += 1
        if S[i] != "1":
            cnt2 += 1
            
ans = min(cnt1, cnt2)
print(ans)

Submission status: Accepted

Solution code:
S = input()
checker = '01'*100001
keep1 = checker[:len(S)]
keep2 = checker[1:len(S)+1]
ans_1 = 0
ans_2 = 0
for i in range(len(S)):
    if S[i] != keep1[i]:
        ans_1 += 1
    else:
        ans_2 += 1
print(min(ans_1, ans_2))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = input()
cnt1 = 0
for i, j in enumerate(s):
    if (i+1)&1:
        if j=='1':
            cnt1 += 1
    else:
        if j=='0':
            cnt1 += 1

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

Submission status: Accepted

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

keep = '01' * 100000
keep_1 = keep[:s_length]
keep_2 = keep[1:s_length + 1]


ans_1 = 0
ans_2 = 0
for i in range(s_length):
    if s[i] != keep_1[i]:
        ans_1 += 1
    else:
        ans_2 += 1
print(min(ans_1, ans_2))

Submission status: Accepted

Solution code:
S=input()
s=[]
total=0
for i in range(len(S)):
    s.append(int(S[i]))
for i in range(0,len(s)-1):
    if s[i]==s[i+1]:
        total+=1
        s[i+1]=abs(1-s[i])
print(total)

Submission status: Accepted

Solution code:
s=input()
s1 = []
s2 = []
ans1 = 0
ans2 = 0
for i in range(len(s)):
    if i%2 != 0:
        s1.append('0')
    else:
        s1.append('1')
for i in range(len(s)):
    if i%2 == 0:
        s2.append('0')
    else:
        s2.append('1')

for x, y in zip(s, s1):
    if x != y:
        ans1 +=1
for x, y in zip(s, s2):
    if x != y:
        ans2 +=1

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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