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: Runtime Error

Solution code:
l = len(colors)
count1 = 0
for i in range(l):
	if colors[i] == i % 2:
		count1 += int(colors[i])
print(min(count1, l-count1))

Submission status: Runtime Error

Solution code:
s = list(int(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: Runtime Error

Solution code:
s=list(input())
count1=0
count2=0
for i in range(len(s)):
  if s[i]==s[i+1]:
    count1=count1+1
for i in range(1,len(s)):
  if s[i]==s[i+1]:
    count2=count2+1
if count1>=count2:
  print(count1)
else:
  print(count2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
string=list(input())
c=0
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: Runtime Error

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: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
t1 = ['0', '1'] * 25000
t2 = ['1', '0'] * 25000

s = input()
sl = list(s)

a1 = 0
a2 = 0

for i in range(len(sl)):
    if sl[i] != t1[i]:
        a1 += 1
    if sl[i] != t2[i]:
        a2 += 1

print(min(a1, a2))

Submission status: Runtime Error

Solution code:
s = list(input())
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] = str(abs(int(s[i]) - 1))
print(r)

Submission status: Runtime Error

Solution code:
S = list(input())
stlen = len(S) 
if len(S)%2 == 0:
    a = '10'*(stlen/2)
    b = '01'*(stlen/2)
    counta = countb = 0
    for i in range(stlen):
        if a[i] != S[i]:
            counta += 1
        if b[i] != S[i]:
            countb += 1
    print(min(counta,countb))
else:
    a = '10'*(int(stlen/2))+'1'
    b = '01'*(int(stlen/2))+'0'
    counta = countb = 0
    for i in range(stlen):
        if a[i] != S[i]:
            counta += 1
        if b[i] != S[i]:
            countb += 1
    print(min(counta,countb))

Submission status: Runtime Error

Solution code:
s = input() 
answer1 = '10'*5000 
answer2 = '01'*5000 

count1 = 0
for i in range(len(s)):
    if s[i] != answer1[i]:
        count1 += 1

count2 = 0
for i in range(len(s)):
    if s[i] != answer2[i]:
        count2 += 1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
colors = input()
l = len(colors)
count1 = 0
for i in range(l):
  count1 += int(colors[i])
 print(min(count1, l-count1))

Submission status: Runtime Error

Solution code:
S = list(input())
stlen = len(S) 
if len(S)%2 == 0:
    a = '10'*(stlen/2)
    b = '01'*(stlen/2)
    counta = countb = 0
    for i in range(stlen):
        if a[i] != S[i]:
            counta += 1
        if b[i] != S[i]:
            countb += 1
    print(min(counta,countb))
else:
    a = '10'*(int(stlen/2))+'1'
    b = '01'*int((stlen/2))+'0'
    counta = countb = 0
    for i in range(stlen):
        if a[i] != S[i]:
            counta += 1
        if b[i] != S[i]:
            countb += 1
    print(min(counta,countb))

Submission status: Runtime Error

Solution code:
S = input()

if len(S) <= 2:
    print(0)

else:
    ans1 = 0
    ans2 = 0
    flag1 = 0
    flag2 = 1
    for i in S:
        if flag1 % 2 == int(i):
            pass
        else:
            ans1 += 1
        flag1 += 1
    for i in S:
        if flag2 % 2 == int(i):
            pass
        else:
            ans2 += 1
        flag2 += 1

print(min(ans1,ans2))

Submission status: Runtime Error

Solution code:
li = list(map(input().split()))
sum = 0;
for i in li:
  if(li[i] != li[i + 1]):
    sum += 1
  if((i+1) >= len(li)):
    break;
print(sum)

Submission status: Runtime Error

Solution code:
S = list(input())

res_10 = 0
res_01 = 0

for i in range(N):
    if i % 2 == 0:
        if S[i] == "0":
            res_10 += 1
        else:
            res_01 += 1
    else:
        if S[i] == "1":
            res_10 += 1
        else:
            res_01 += 1
print(min(res_10, res_01))

Submission status: Runtime Error

Solution code:
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 + = 1
  x = hen(x)
print(min(c1,c2))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = str(input())
w1,w2,b1,b2 = 0,0,0,0
for i in range(len(s)):
  if i % 2 == 0:
  	if s[i] == "0":
      w1 += 1
    else:
      b1 += 1
  else:
    if s[i] == "0":
      w2 += 1
    else:
      b2 += 1
print(min(w1+b2,w2+b1))

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    n = len(s)
    a = 0
    b = 0
    for i in range(n):
        if i & 1:
            if arr[i] == '1':
                a += 1
            else:
                b += 1
        else:
            if arr[i] == '1':
                b += 1
            else:
                a += 1
        print(min(a, b))
    return 0
main()

Submission status: Runtime Error

Solution code:
def d201(a):
    count=0
    N=len(a)
    for i in range(N):
        if(i%2==0):
            if(a[i]=='0'):
                count+=1
        else:
            if(a[i]=='1'):
                count+=1
    return count

                
def d210(a):
    count=0
    N=len(a)
    for i in range(N):
        if(i%2==0):
            if(a[i]=='1'):
                count+=1
        else:
            if(a[i]=='0'):
                count+=1
    return count

a=input()
print(min(d210(a),d201(a))