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 read_input():
    s = list(map(int, list(str(input()))))
    n = len(s)

    return n, s


# 桁数nでtスタートの数列を作成する
def make_answers(n, t):
    curr  = t

    result = []
    for i in range(n):
        result.append(curr)

        if curr == 1:
            curr = 0
        else:
            curr = 1

    return result


# aとbを要素比較して異なる部分を数える
def diff_num_seq(a, b):
    return sum([1 for ae, be in zip(a, b) if ae != be])


if __name__ == '__main__':
    n, s = read_input()

    answer0 = make_answers(n, 0)
    answer1 = make_answers(n, 1)

    diff0 = diff_num_seq(s, answer0)
    diff1 = diff_num_seq(s, answer1)

    answer = min(diff0, diff1)

    print(answer)

Submission status: Accepted

Solution code:
S = list(raw_input())

array=[]

if len(S) == 1:
    print 0
else:
    cnt = 0
    for i in range(len(S)):
#        print "--", i
        if i == 0:
            cnt = 1
        else:
            if S[i-1] == S[i]:
                array.append(cnt)
                cnt = 1
            else:
                cnt += 1
    array.append(cnt)
#    print "array:",array
    even = [n for i,n in enumerate(array) if i % 2 == 0]
    odd  = [n for i,n in enumerate(array) if i % 2 == 1]

#    print even
#    print odd
    
    if sum(even) > sum(odd):
        print sum(odd)
    else:
        print sum(even)

Submission status: Accepted

Solution code:

x=input()
round = len(x)

ans = 0

for i in range(round):#10101...
    if i % 2 == 0:
        if x[i] == '0':
            ans = ans+1
            
    else:
        if x[i] =='1':
            
            ans = ans+1

if ans>round/2:
    print(round-ans)
else:
    print(ans)

Submission status: Accepted

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

count1 = 0
count2 = 0

for i, num in enumerate(s):
    if i % 2 == 1 and num == '0':
        count1 += 1
    elif i % 2 != 1 and num == '1':
        count1 += 1

for i, num in enumerate(s):
    if i % 2 == 1 and num == '1':
        count2 += 1
    elif i % 2 != 1 and num == '0':
        count2 += 1

result = min(count1, count2)
print(result)

Submission status: Accepted

Solution code:
a = input()
b = list(a)
num = 0
for i in range(len(b)):
  #print(b)
  if 1 <= i <= len(b)-1:
    if b[i-1] == "1" and b[i] == "1":
      b[i] = "0"
      num += 1
    elif b[i-1] == "0" and b[i] == "0":
      b[i] = "1"
      num += 1
    else:
      pass
  elif i == 0:
    pass
  elif i == 0 and len(b) == 1:
    pass
    
print(num)

Submission status: Accepted

Solution code:
number = input()
le = len(number)
wst = [0] * le
bst = [0] * le
for k in range(le):
  if k % 2 == 0:
    wst[k] = 1
  else:
    bst[k] = 1
wsc = 0
bsc = 0
for k in range(le):
  if int(number[k]) != wst[k]:
    wsc += 1
  if int(number[k]) != bst[k]:
    bsc += 1
print(min([wsc,bsc]))

Submission status: Accepted

Solution code:
S = raw_input()

lenS = len(S)
intS = int(S)
binS = "0b" + S

start0 = ""
start1 = ""
flag = True

for _ in xrange(lenS):
    if flag:
        start0 += "0"
        start1 += "1"
        flag = False
    else :
        start0 += "1"
        start1 += "0"
        flag = True

bin0 = "0b" + start0
bin1 = "0b" + start1



bin0dif = str(bin(int(bin0, 2) ^ int(binS, 2))).count("1")
bin1dif = str(bin(int(bin1, 2) ^ int(binS, 2))).count("1")

if bin0dif > bin1dif:
    print bin1dif
else:
    print bin0dif

Submission status: Accepted

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

count=0
def change_string(S):

  if S=="0":
    S="1"
  elif S=="1":
    S="0"
  return S
    
if N!=1:
  for i in range(1,N):
    if S[i-1]==S[i]:
      count=count+1
      S[i]=change_string(S[i])
      #print(i)
     # print(S)
    elif S[i-1]!=S[i]:
      continue
      
print(count)

Submission status: Accepted

Solution code:
def distance(a, b, n):
    count = 0
    for i in range(n):
        if a[i] != b[i]:
            count += 1
    return count

def main():
    array = [int(x) for x in input()]
    n = len(array)
    a0 = [1 if i % 2 == 1 else 0 for i in range(n)]
    a1 = [1 if i % 2 == 0 else 0 for i in range(n)]
    print(min(distance(array, a0, n), distance(array, a1, n)))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A=[int(x) for x in list(input())]
B=list(reversed(A))
N=len(A)

if N ==0:
  out=0
else:
  out_1=0
  for i in range(1,N):
    if A[i-1] == A[i] :
      A[i] = 1 - A[i] 
      out_1+=1

  out_2=0
  for i in range(1,N):
    if B[i-1] == B[i] :
      B[i] = 1 - B[i] 
      out_2+=1
      
  out=min(out_1,out_2)
print(out)

Submission status: Accepted

Solution code:
a = input()
N = len(a)
old_a = a
count1 = 0
count2 = 0
for i in range(N):
    if i%2:
        if a[i:i+1] != "0":
            a = a[:i] + "0" + a[i+1:]
            count1 += 1
    else:
        if a[i:i+1] != "1":
            a = a[:i] + "1" + a[i+1:]
            count1 += 1
a = old_a
for i in range(N):
    if i % 2:
        if a[i:i+1] != "1":
            a = a[:i] + "1" + a[i+1:]
            count2 += 1
    else:
        if a[i:i+1] != "0":
            a = a[:i] + "0" + a[i+1:]
            count2 += 1
if count1 > count2:
    print(count2)
else :
    print(count1)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
s = input()

count0 = 0
count1 = 0
# 0101…の場合
for i in range(len(s)):
    if i % 2 == 0 and s[i] == '1':
        count0 = count0 + 1
    if i % 2 == 1 and s[i] == '0':
        count0 = count0 + 1

#1010…の場合
for i in range(len(s)):
    if i % 2 == 0 and s[i] == '0':
        count1 = count1 + 1
    if i % 2 == 1 and s[i] == '1':
        count1 = count1 + 1

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

Submission status: Accepted

Solution code:
nums = list(map(int,list(input())))
SUM = 0
for i in range(len(nums)-1):
  if not nums[i] ^ nums[i+1]:
    nums[i+1] = nums[i+1] ^ 1
    SUM += 1
    
print(SUM)

Submission status: Accepted

Solution code:
l = [x for x in input()]

r = len(l)

l1 = []
l2 = []

c1 = 0
c2 = 0

for i in range(r):
	if i % 2 == 0:
		l1.append('0')
		l2.append('1')
	else:
		l1.append('1')
		l2.append('0')

for i in range(r):
	if l[i] != l1[i]:
		c1 += 1
	if l[i] != l2[i]:
		c2 += 1

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
odds = []
even = []

if N == 1:
    print(0)
#奇数番目と偶数番目で別にリスト化する
else:
    for i in range(N):
        if i % 2 == 1:
            odds.append(int(S[i]))
        else:
            even.append(int(S[i]))
    #print(odds)
    #print(even)
    n1 = len(odds)
    n2 = len(even)
    ans1 = 0
    ans2 = 0
    for j in range(n1):
        if odds[j] == 1:
            ans1 += 1
    for k in range(n2):
        if even[k] == 0:
            ans1 += 1

    for n in range(n1):
        if odds[n] == 0:
            ans2 += 1
    for m in range(n2):
        if even[m] == 1:
            ans2 +=1

    print(min(ans1, ans2))

Submission status: Accepted

Solution code:
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

s = input()
bef = ""
ct = 0
for i in range(len(s)):
    if i == 0:
        bef = s[i]
        continue
    else:
        if bef != s[i]:
            bef = s[i]
        else:
            ct +=1
            if s[i] == "0":
                bef = "1"
            else:
                bef = "0"

ct1 = ct

s = s[::-1]

bef = ""
ct = 0
for i in range(len(s)):
    if i == 0:
        bef = s[i]
        continue
    else:
        if bef != s[i]:
            bef = s[i]
        else:
            ct +=1
            if s[i] == "0":
                bef = "1"
            else:
                bef = "0"

ct2 = ct
print(min([ct1,ct2]))

Submission status: Accepted

Solution code:
import copy
l = [int(x) for x in input()]
l1 = copy.copy(l)
l2 = copy.copy(l)
c = 0
c1 = 0
for i in range(len(l1)-1):
  if l1[i] == l1[i+1]:
    if l1[i] == 0:
      l1[i+1] = 1
    else:
      l1[i+1] = 0
    c += 1
for i in range(len(l2)-1,0,-1):
  if l2[i] == l2[i-1]:
    if l2[i] == 0:
      l2[i-1] = 1
    else:
      l2[i-1] = 0
    c1 += 1
print(min(c,c1))

Submission status: Accepted

Solution code:
import math
import numpy as np
N = list(input())
lenN = len(N)

a = list(('10'*math.ceil(lenN/2))[:lenN])
b = list(('01'*math.ceil(lenN/2))[:lenN])

N, a ,b = np.array(N).astype(int), np.array(a).astype(int), np.array(b).astype(int)
print(min([(N != a).sum(), (N != b).sum()]))

Submission status: Accepted

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

S = list(input().replace('\n',''))
S = list(map(int, S))
prev = S[0]
ans = 0
for i in range(1, len(S)):
  cur = S[i]
  if prev ^ cur == 0:
    ans += 1
#     if i == 1:
#       if cur ^ S[i+1] == 1:
#         prev = cur
#       else:
#         prev = 2 + ~cur
#     else:
    prev = 2 + ~cur
  else:
    prev = cur

print(ans)

Submission status: Accepted

Solution code:
s = input()
li = [s[i] for i in range(len(s))]
li2 = [s[i] for i in range(len(s))]
count1 = 0
count2 = 0
l = len(s) - 1
if len(s) >= 2:
    for j in range(len(s) - 1):
        if li[j + 1] == "0" and li[j] == "0":
            li[j + 1] = "1"
            count1 += 1
        elif li[j + 1] == "1" and li[j] == "1":
            li[j + 1] = "0"
            count1 += 1
    while l >= 1:
        if li2[l - 1] == "0" and li2[l] == "0":
            li2[l - 1] = "1"
            count2 += 1
        elif li2[l - 1] == "1" and li2[l] == "1":
            li2[l - 1] = "0"
            count2 += 1
        l -= 1
print(min([count1, count2]))

Submission status: Accepted

Solution code:
s = list(str(input()))
ans = 0
x = ""
for i in range(len(s)):
    if i % 2 == 0:
        x = x + "0"
    else:
        x = x + "1"
xx = ""
for i in range(len(s)):
    if i % 2 == 0:
        xx = xx + "1"
    else:
        xx = xx + "0"
ans1 = 0
for i in range(len(s)):
    if s[i] != x[i]:
        ans1 += 1
ans2 = 0
for i in range(len(s)):
    if s[i] != xx[i]:
        ans2 += 1
if ans1 > ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a =list(input())


def saisyo1(a):
    kisuu = a[1::2]
    guusuu = a[0::2]
    count = 0
    for i in kisuu:
        if i != "1":
            count += 1
    for i in guusuu:
        if i != "0":
            count += 1
    return count

def saisyo0(a):
    kisuu = a[1::2]
    guusuu = a[0::2]
    count = 0
    for i in kisuu:
        if i != "0":
            count += 1
    for i in guusuu:
        if i != "1":
            count += 1
    return count

def main():
    print(min(saisyo0(a),saisyo1(a)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = list(input())
flag = 0
ans_1 = 0
ans_2 = 0
# 最初を変える
S1 = S[0]
if (S1 == "0"):
    flag_a = 1
else:
    flag_a = 0
for i in range(1, len(S)):
    if (flag_a == 0):
        if (S[i] == "1"):
            ans_1 += 1
        flag_a = 1
    else:
        if (S[i] == "0"):
            ans_1 += 1
        flag_a = 0
if (len(S) != 1):
    if (S[0] != S[1]):
        ans_1 = 1000000

# 最初を変えない
S1 = S[0]
if (S1 == "1"):
    flag_b = 1
else:
    flag_b = 0
for i in range(1, len(S)):
    if (flag_b == 0):
        if (S[i] == "0"):
            ans_2 += 1
        flag_b = 1
    else:
        if (S[i] == "1"):
            ans_2 += 1
        flag_b = 0
if (len(S) != 1):
    if (S[0] == S[1]):
        ans_2 = 1000000

print(min(ans_1, ans_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t = "0"
u = "1"
a = 0
b = 0

for i in range(len(s)-1):
    if i%2 == 0:
        t = t + "1"
        u = u + "0"
    else:
        t = t + "0"
        u = u + "1"
x = 0
        
for i in range(len(s)):
    if s[i] != t[i]:
        a = a + 1
    if s[i] != u[i]:
        b = b + 1

print(min(a,b))

Submission status: Accepted

Solution code:
S = input()

a = "0b"
for i in range(len(S)):
    if i % 2 == 0:
        a += "0"
    else:
        a += "1"
a = int(a, 2)
b = "0b"
for i in range(len(S)):
    if i % 2 == 0:
        b += "1"
    else:
        b += "0"
b = int(b, 2)
S = int("0b"+S, 2)
S_a = S ^ a
S_b = S ^ b
print(bin(S_a).count("1") if bin(S_a).count("1") < bin(S_b).count("1") else bin(S_b).count("1"))

Submission status: Accepted

Solution code:
s=input()
a=[]
for i in range(len(s)):
  if i%2==0:
    a.append('0')
  else:
    a.append('1')
b=[]
for j in range(len(s)):
  if j%2==0:
    b.append('1')
  else:
    b.append('0')
cnt=0
for k in range(len(s)):
  if s[k]!=a[k]:
    cnt+=1
ans=0
for l in range(len(s)):
  if s[l]!=b[l]:
    ans+=1
print(min(cnt,ans))

Submission status: Accepted

Solution code:
S = input()

odd = 1
even = 0
odd_flag = True

for i in range(1, len(S)):
    if not S[i-1] == S[i]:
        if odd_flag:
            odd += 1
        else:
            even += 1
    else:
        odd_flag = not odd_flag
        if odd_flag:
            odd += 1
        else:
            even += 1

print(min(odd, even))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s0 = 0
s1 = 0
kis=s[1::2].count('0')
gus=s[0::2].count('0')
print(min(abs(kis-len(s[1::2]))+abs(gus),abs(kis)+abs(gus-len(s[0::2]))))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[121]:


import numpy as np
import numpy.matlib


# In[126]:


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


# In[127]:


pattern = np.matlib.repmat((0, 1),1, len(S)).flatten()


# In[128]:


ans1 = np.sum(np.array(Slist) == pattern[1:len(Slist)+1])
ans2 = np.sum(np.array(Slist) == pattern[:len(Slist)])


# In[129]:


print(min(ans1,ans2))


# In[ ]:

Submission status: Accepted

Solution code:
# coding: utf-8
s = input()
# 0始まりと1始まりのどちらに近いか？を調べて、より近いものにする際の差分を取る
with_zero, with_one = 0, 0
for i, c in enumerate(s):
    if i % 2 == 1:
        # 奇数桁: 0 -> 0始まりのものとマッチしているので+1
        #         1 -> 1始まりのものとマッチしているので+1
        if c == "0":
            with_zero += 1
        elif c == "1":
            with_one += 1
    else:
        # 偶数桁: 1 -> 0始まりのものとマッチしているので+1
        #         0 -> 1始まりのものとマッチしているので+1
        if c == "1":
            with_zero += 1
        elif c == "0":
            with_one += 1

min_diff = len(s) - (with_zero if with_zero > with_one else with_one)
print(min_diff)

Submission status: Accepted

Solution code:
S = input()

N = len(S)
#ODD = 0
#EVEN = 1
cnt = [[0, 0], [0, 0]]
for i in range(N):
    cnt[int(S[i])][(i % 2)] += 1
ans = 0
cnt0o1e = cnt[0][0] + cnt[1][1]
cnt0e1o = cnt[0][1] + cnt[1][0]

print(min(cnt0o1e, cnt0e1o))

Submission status: Accepted

Solution code:
list1 = []
list1 = [int(i) for i in input()]
len1 = len(list1)
list2 = [0 if i%2==0 else 1 for i in range(len1)]
list3 = [1 if i%2==0 else 0 for i in range(len1)]
dif1 = [(x1 - x2)**2 for (x1, x2) in zip(list1, list2)] 
dif2 = [(x1 - x2)**2 for (x1, x2) in zip(list1, list3)] 
ans1 = sum(dif1)
ans2 = sum(dif2)
if ans1 <= ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
end1 = "0"
end2 = "1"
for i in range(l-1):
    if i%2==0:
        end1 = end1 + "1"
        end2 = end2 + "0"
    else:
        end1 = end1 + "0"
        end2 = end2 + "1"
start_bin = int("0b"+s,0)
end1_bin = int("0b"+end1,0)
end2_bin = int("0b"+end2,0)

a = start_bin^end1_bin
b = start_bin^end2_bin

a_1 = bin(a).count("1")
b_1 = bin(b).count("1")

if a_1<b_1:
    print(a_1)
else:
    print(b_1)

Submission status: Accepted

Solution code:
import numpy as np
S = input()
N = len(S)

answer0 = np.zeros(N, int)
answer1 = np.ones(N, int)
for i in range(N):
    if i % 2 == 1:
        answer0[i] = 1
        answer1[i] = 0

num0 = 0
num1 = 0
for i in range(N):
    if int(S[i]) != answer0[i]:
        num0 += 1
    if int(S[i]) != answer1[i]:
        num1 += 1
if num0 > num1:
    num = num1
else:
    num = num0
print(int(num))

Submission status: Accepted

Solution code:
co = input()

c1 = 0
c2 = 0
for i in range(len(co)):
  if i%2 == 0:
    if co[i] == '0':
      c1 += 1
    else:
      c2 += 1
  else:
    if co[i] == '1':
      c1 += 1
    else:
      c2 += 1
print(c1 if c1<=c2 else c2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
pre_word = s[0]
counter = 0
for word in s[1:]:
  if word == pre_word:
    counter += 1
    pre_word = "1" if pre_word == "0" else "0"
  else:
    pre_word = word
print(counter)

Submission status: Accepted

Solution code:
S = input()
T = []
kai = len(S)
for A in range(2):
  if A == 1:
    AA = ["1"]
  else:
    AA = ["0"]
  for AAA in range(1,len(S)):
    if AA[AAA - 1] == "1":
      AA += "0"
    else:
      AA += "1"
  T += [AA]

for B in range(2):
  KK = 0
  BS = T[B]
  for BBS in range(len(BS)):
    C = BS[BBS]
    if S[BBS] != C:
      KK += 1
  if kai > KK:
    kai = KK
print(kai)

Submission status: Accepted

Solution code:
import math
s = list(input())
kaha = math.ceil(len(s) / 2)
t = "10" * kaha
t1 = list(t)
n = 0
for i in range(len(s)):
	if(s[i]!=t1[i]):
		n = n + 1
if(n >= kaha):
	n= len(s)-n
print(n)

Submission status: Accepted

Solution code:
s = input()
spl = ""
cnt1 = 0
cnt2 = 0

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

cnt2 = len(s) - cnt1

if cnt1 < cnt2: print(cnt1)
else: print(cnt2)

Submission status: Accepted

Solution code:
s=input()
hi=5
ans=0
for i in range(len(s)):
    if(hi==s[i]):
        ans+=1
        if(s[i]=='0'):
            s=s[:i]+'1'+s[i+1:]

        else:
            s=s[:i]+'0'+s[i+1:]
    hi=s[i]
print(str(ans))

Submission status: Accepted

Solution code:
a=input()
l=len(a)
x=[int(a[i:i+1]) for i in range(l)]
counta=0
for i in range(l):
  if i%2==1:
    if x[i]==0:
      counta +=1
  else:
    if x[i]==1:
      counta +=1
countb=0
for i in range(l):
  if i%2==1:
    if x[i]==1:
      countb +=1
  else:
    if x[i]==0:
      countb +=1
c=int(min(counta,countb))
print(c)

Submission status: Accepted

Solution code:
print((lambda a: min(sum([abs(int(a[i])-(i+1)%2) for i in range(len(a))]),sum([abs(int(a[i])-i%2) for i in range(len(a))])))(list(input())))

Submission status: Accepted

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


def get_diff(str_a, str_b):
    res = ''
    for i in range(len(str_a)):
        if str_a[i] == str_b[i]:
            res = res + '-'
        else:
            res = res + '+'
    return res


def get_mixed_a(ml):
    return ('01' * (1 + int(ml / 2)))[0:ml]


def get_mixed_b(ml):
    return ('10' * (1 + int(ml / 2)))[0:ml]


zba = get_mixed_a(len_s)
zbb = get_mixed_b(len_s)
res_a = get_diff(zba, S)
res_b = get_diff(zbb, S)
ma = res_a.count('+')
mb = res_b.count('+')
print(min(ma, mb))

Submission status: Accepted

Solution code:
import numpy as np

S = list(map(int,input()))
S_len = len(S)
Tmp_S =[]
First_S = S[0]
for _ in range(S_len):
    Tmp_S.append(First_S)
    First_S = First_S ^ 1

S_np = np.array(S)
Tmp_S_np = np.array(Tmp_S)

TF_S = np.array(S_np == Tmp_S_np)
print(np.sum(TF_S == False))

Submission status: Accepted

Solution code:
S=input()
ans=0
if len(S)==1:
    print(0)
else:
    tmp=S[0]
    for s in S[1:]:
        if s==tmp:
            ans+=1
            if s=="0":
                tmp="1"
            else:
                tmp="0"
        else:
            tmp=s
    print(ans)

Submission status: Accepted

Solution code:
def even_bit_maker(number_length):
    bit = ['0'] * number_length
    for i in range(number_length):
        if i % 2 == 0:
            bit[i] = '1'
    return int(''.join(bit), 2)


def odd_bit_maker(number_length):
    bit = ['0'] * number_length
    for i in range(number_length):
        if i % 2 == 1:
            bit[i] = '1'
    return int(''.join(bit), 2)


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: Accepted

Solution code:
s_str = input()
s = list(map(int,s_str))
a = 0
for i in range(len(s)):
    if s[i] == i % 2:
        a = a + 1
if a < len(s) - a:
    print(a)
else:
    print(len(s)-a)

Submission status: Accepted

Solution code:
s = str(input())
l = len(s)
first = "01"*(int(l/2))
result1 = 0
result2 = 0
if l%2!=0:
	first += "0"
for i in range(l):
	if first[i] == s[i]:
		result2+=1
	else:
		result1+=1
print(min(result1,result2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 21:30:35 2019

@author: yuta
"""
from collections import Counter
S = input()

def main(s):
    moji = list(s)
    first = moji[0:len(moji):2]
    second = moji[1:len(moji):2]
    
    x = Counter(first)
    y = Counter(second)
    
    x_count0 = x['0']
    x_count1 = x['1']
    y_count0 = y['0']
    y_count1 = y['1']
    
    count = min(x_count0 + y_count1,x_count1 + y_count0)
    print(count)
main(S)

Submission status: Accepted

Solution code:
s = list(input())
len = len(s)
a =["0"]*len
b =["0"]*len

for i in range(len):
    if i % 2 == 0:
        a[i] = "1"

for i in range(len):
    if i % 2 == 1:
        b[i] = "1"


len_a = 0
len_b = 0

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

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

ans = min(len_a,len_b)
print(ans)

Submission status: Accepted

Solution code:
N=str(input())

X=0
Y=0
n=0
for i in N:
  if n %2==0:
    if i =="0":
      X+=1
    
  else:
    if i =="1":
      X+=1
  n+=1
n=0
for i in N:
  if n %2==0:
    if i =="1":
      Y+=1
    
  else:
    if i =="0":
      Y+=1
  n+=1


ans=min(X,Y)
print(ans)

Submission status: Accepted

Solution code:
S=list(input())

now=S[0]
n=0#数え
X=0
for i in S:

    if n==0:
        n+=1
        continue
    if now==i:
        if now=='1':
            S[n]='0'
        else:
            S[n]='1'
        X+=1
    now=S[n]
    n+=1

print(X)

Submission status: Accepted

Solution code:
s = input()

len_s = len(s)

cnt01_0 = 0
cnt01_1 = 0
cnt10_0 = 0
cnt10_1 = 0

for i in range(len_s):
    if (i%2 == 0)and(s[i]=='0'):
        cnt01_0 += 1
    elif(i%2 == 1)and(s[i]=='1'):
        cnt01_1 += 1

for i in range(len_s):
    if (i%2 == 0)and(s[i]=='1'):
        cnt10_0 += 1
    elif(i%2 == 1)and(s[i]=='0'):
        cnt10_1 += 1

out01 = len_s - cnt01_0 - cnt01_1
out10 = len_s - cnt10_0 - cnt10_1


print(min(out01,out10))

Submission status: Accepted

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

s1=[0 for __ in range(len(s))]
s2=[0 for __ in range(len(s))]

for i in range(len(s)):
    if i%2 == 0:
        s1[i]=1
    else:
        s2[i]=1

ans1=0
ans2=0
for i in range(len(s)):
    if s1[i] != s[i]:
        ans1=ans1 + 1
    else:
        ans2=ans2 + 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input()
s_g = list(map(int, (s[0::2])))
s_k = list(map(int, (s[1::2])))
ans = [len(s_g) - sum(s_g) + sum(s_k),len(s_k) - sum(s_k) + sum(s_g)]

print(min(ans))

Submission status: Accepted

Solution code:
S = str(input())
N = len(S)
c_K = 0
c_H = 0
for i in range(N):
  K = str(i%2)
  if(S[i]==K):
    c_K+=1
  else:
    c_H+=1
M = max(c_K,c_H)
G = N-M
print(G)

Submission status: Accepted

Solution code:
char_list = list(input())
count1 = 0
count2 = 0
if len(char_list) == 1:
    print(0)
else:
    for i in range(len(char_list)):
        if i % 2 == 0:
            if char_list[i] is "0":
                continue
            else:
                count1 += 1
        else:
            if char_list[i] is "1":
                continue
            else:
                count1 += 1
    for i in range(len(char_list)):
        if i % 2 == 0:
            if char_list[i] is "1":
                continue
            else:
                count2 += 1
        else:
            if char_list[i] is "0":
                continue
            else:
                count2 += 1
    print(min(count1,count2))

Submission status: Accepted

Solution code:
S = list(input())
answer = 0
for i in range(len(S)):
    if i == 0:
        continue
    elif S[i] == S[i-1]:
        if S[i] == '1':
            S[i] = '0'
        else:
            S[i] = '1'
        answer += 1

print(answer)

Submission status: Accepted

Solution code:
S = list(input())
g_list = S[0::2]
k_list = S[1::2]

print(
  min(
    g_list.count("0")+k_list.count("1"),
    g_list.count("1")+k_list.count("0")
  )
)

Submission status: Accepted

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

ac = 0
bc = 0

for idx, s in enumerate(n):
    if(idx % 2 == 0):
        if(s == '0'):
            ac += 1
        else:
            bc += 1
    else:
        if(s == '0'):
            bc += 1
        else:
            ac += 1

if(ac < bc):
    print(ac)
else:
    print(bc)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
color_list = [int(_) for _ in input()]

zero_start = 0
one_start = 0

for i in range(len(color_list)):
    if i % 2 == 0: #偶数番目の時
        if color_list[i] == 0:
            one_start += 1
        else:
            zero_start += 1
    else: # 奇数番目の時
        if color_list[i] == 0:
            zero_start += 1
        else:
            one_start += 1

if zero_start < one_start:
    print(zero_start)
else:
    print(one_start)

Submission status: Accepted

Solution code:
S = input()

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

count1 = 0
for i in range(len(S)):
    if S[i] != H[i]:
        count1 += 1
count2 = 0
for i in range(len(S)):
    if S[i] != M[i]:
        count2 += 1

ans = min(count1,count2)
print(ans)

Submission status: Accepted

Solution code:
s = input()

cnt0 = 0                 # 010101...にする場合に必要な塗る回数
for i in range(len(s)):
    if s[i] != str(i%2):
        cnt0 = cnt0 + 1


cnt1 = 0                # 10101010..にする場合に必要な塗る回数
for i in range(len(s)):
    if s[i] == str(i%2):
        cnt1 = cnt1 + 1


if cnt0 < cnt1:
    print(cnt0)
else:
    print(cnt1)

Submission status: Accepted

Solution code:
S = list(input())

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

fill_1_g = int(len(S)/2) - g
fill_1_k = int(len(S)/2) - k
if len(S) % 2 == 1:
  fill_1_g += 1

print(min([fill_1_g + k, fill_1_k + g]))

Submission status: Accepted

Solution code:
s=input()
even=s[1::2]
odd=s[::2]
ez=eo=oz=oo=cnt1=cnt2=0
#print(even,odd)

for i in range(len(odd)):
  if odd[i]!='1':
    cnt1+=1
for i in range(len(even)):
  if even[i]!='0':
    cnt1+=1
for i in range(len(odd)):
  if odd[i]!='0':
    cnt2+=1
for i in range(len(even)):
  if even[i]!='1':
    cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()
m = len(s)
sl = [0]*m
for i in range(m):
    sl[i] = s[i]
pre = sl[0]
ans = 0

for i in range(m-1):
    if sl[i+1] == pre:
        ans += 1

        if sl[i+1] == "0":
            sl[i+1] = "1"
        else:
            sl[i+1] = "0"
            
        pre = sl[i+1]

    else:
        pre = sl[i+1]
    
print(ans)

Submission status: Accepted

Solution code:
s=input()
l=len(s)
odd=s[::2]
even=s[1::2]
o0=odd.count("0")
o1=odd.count("1")
e0=even.count("0")
e1=even.count("1")
if o0+e1>o1+e0:
    print(o1+e0)
else:
    print(o0+e1)

Submission status: Accepted

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

res = 0
for i in range(n):
    if i%2 == 0 and s[i] == '0':
        res += 1
    elif i%2 == 1 and s[i] == '1':
        res += 1

res2 = 0
for i in range(n):
    if i%2 == 0 and s[i] == '1':
        res2 += 1
    elif i%2 == 1 and s[i] == '0':
        res2 += 1
print(min(res,res2))

Submission status: Accepted

Solution code:
def hanten(tairu):
    if tairu == 0:
        return 1
    else:
        return 0

def main():
    l = list(map(int, list(input())))
    
    if len(l) <= 1:
        print(0)
    else:
        cnt = 0
        move_cnt = 1
        if l[0] == l[move_cnt]:
            l[move_cnt] = hanten(l[move_cnt])
            cnt = 1
        
        while move_cnt + 1 <= len(l) - 1:
            if l[move_cnt] == l[move_cnt + 1]:
                l[move_cnt + 1] = hanten(l[move_cnt + 1])
                cnt += 1
                
            move_cnt += 1
    
        print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=list(map(int,input()))
o=s[0::2]
e=s[1::2]
a=o.count(0)+e.count(1)
b=o.count(1)+e.count(0)
print(min(a,b))

Submission status: Accepted

Solution code:
S = input()
cnt = 0
s = S[0]
for i in range(1, len(S)):
    si = int(S[i])
    #print(s, si)
    if int(s) == int(si):
        #print("hit")
        s = 1 - si
        cnt += 1
    else:
        s = si

# reverse first
cnt2 = 1
s = 1 - int(S[0])
for i in range(1, len(S)):
    si = int(S[i])
    #print(s, si)
    if int(s) == int(si):
        #print("hit")
        s = 1 - si
        cnt2 += 1
    else:
        s = si

#print(cnt, cnt2)
print(min(cnt, cnt2))

Submission status: Accepted

Solution code:
import numpy as np
S=input()
ans=np.zeros(len(S))
s=np.zeros(len(S))
if S[0]=='1':
    ans[0]=1
    s[0]=1
else:
    ans[0]=0
    s[0]=0
    
for i in range(1,len(S)):
    ans[i]=(ans[i-1]+1)%2
    s[i]=int(S[i])
    
print(sum(ans!=s))