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

Solution (Python):




def getOptimumPattern(tiles):
	n = len(tiles)
	zero = [ "0" if i%2 == 0 else "1" for i in range(n)]
	one = [ "1" if i%2 == 0 else "0" for i in range(n)]
	zero_count = 0
	one_count = 0
	for l,z in zip(tiles,zero):
		if l != z:
			zero_count = zero_count + 1

	for l,o in zip(tiles,one):
		if l != o:
			one_count = one_count + 1

	if zero_count <= one_count:
		return zero_count
	else:
		return one_count

tiles= list(input())
result = getOptimumPattern(tiles)
print(result)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    length = len(s)
    o = "10" * (length // 2 + (length % 2))
    o_len = len([i for i, j in zip(s, o) if i == j])
    z_len = len([i for i, j in zip(s, o[::-1]) if i == j])
    print(length - max([z_len, o_len]))


if __name__ == "__main__":
    main()

Solution (Python):
S = input()



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

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

Solution (Python):


S = input()

list_a = S[0::2]
list_b = S[1::2]



result_a, result_b = 0,0

for l in list_a:
  black = l.count("0")
  white = l.count("1")
  result_a += white
  result_b += black

for l in list_b:
  black = l.count("0")
  white = l.count("1")
  result_a += black
  result_b += white

result = min([result_a, result_b])
print(result)

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

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
S=S()
fb,fw=0,0
for i in range(len(S)):
    if i%2==0:
        if S[i]=='0':
            fw+=1
        else:
            fb+=1
    else:
        if S[i]=='0':
            fb+=1
        else:
            fw+=1
print(min(fb,fw))

Solution (Python):
s = input()
a = []

for i in range(len(s)):
  a.append(s[i])
  
a = list(map(int, a))

if len(a) == 1:
  print('0')
elif len(a) == 2:
  if a[0] == a[1]:
    print('1')
  else:
    print('0')
else:
  cnt = 0
  i = 0
  while True:
    if a[i] == a[i+1] and a[i+1] == a[i+2]:
      if a[i+1] == 0:
        a[i+1] = 1
      else:
        a[i+1] = 0
      i += 1
      cnt += 1
    elif a[i] == a[i+1]:
      if a[i+1] == 0:
        a[i+1] = 1
      else:
        a[i+1] = 0
      i += 1
      cnt += 1
    else:
      i += 1
      
    if i + 2 > len(a) - 1:
      break
      
  if a[i] == a[i+1]:
    if a[i+1] == 0:
      a[i+1] = 1
    else:
      a[i+1] = 0
    cnt += 1

  print(cnt)

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()

even0 = 0
even1 = 0
odd0 = 0
odd1 = 0

for i in range(len(s)):
    if (i % 2 == 0):
        if int(s[i]) == 0:
            even0 += 1
        else:
            even1 += 1
    else:
        if int(s[i]) == 0:
            odd0 += 1
        else:
            odd1 += 1

max = max(even0, even1, odd0, odd1)

if max == even0 or max == odd1:
    cnt = even1 + odd0
elif max == even1 or max == odd0:
    cnt = even0 + odd1

print(cnt)

Solution (Python):
tiles = input()

even_0 = 0
even_1 = 0
odd_0 = 0
odd_1 = 0

for i, t in enumerate(tiles):
    if i % 2 == 0:
        if t == '0':
            even_0 += 1
        else:
            even_1 += 1
    else:
        if t == '0':
            odd_0 += 1
        else:
            odd_1 += 1



if even_0 + odd_1 >= even_1 + odd_0:
    print(even_1 + odd_0)
else:
    print(even_0 + odd_1)

Solution (Python):
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

print(min(ans,n-ans))

Solution (Python):


S = [int(x) for x in input()]

ans1 = [x%2 for x in range(len(S))]
ans2 = [x%2 for x in range(1,len(S)+1)]
count1 = 0
count2 = 0
for i in range(len(S)):
    if S[i] != ans1[i]:
        count1 += 1

for i in range(len(S)):
    if S[i] != ans2[i]:
        count2 += 1
 
print(min(count1,count2))

Solution (Python):
c=list(input())
a=c[::2]
b=c[1::2]
print(min(a.count('0')+b.count('1'),a.count('1')+b.count('0')))

Solution (Python):
N = list(map(int,list(input())))
l = len(N)
start1 =0
start0 =0

for i in range(l):
    if(N[i] != 0 and i%2 == 0):
        start0 += 1
    elif(N[i] != 1 and i%2 == 1):
        start0 += 1
    
    if(N[i] != 1 and i%2 == 0):
        start1 += 1
    elif(N[i] != 0 and i%2 == 1):
        start1 += 1

print(min((start0,start1)))

Solution (Python):
li=list(input())
odd_0 = li[0::2].count("0")
even_0 = li[1::2].count("0")
odd_1 = li[0::2].count("1")
even_1 = li[1::2].count("1")








if odd_0 > even_0:
    print(odd_1+even_0)
elif odd_0 < even_0:
    print(odd_0+even_1)
else:
    print(min(odd_1+even_0,odd_0+even_1))

Solution (Python):
s = list(input())
n = len(s)
t = list("10"*((n+1)//2))
if len(t) != n : t = t[:-1]
a = len(list(filter(lambda x: x[0] != x[1], [(s[i],t[i]) for i in range(n)])))
print(min(a, n-a))

Solution (Python):


S = input()

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

Solution (Python):
n = input()
no = len(n)

num1 = 0
num2 = 0

i = 0
while(i < no):
    if(n[i] == '0'):
        num1 += 1
    if(n[i] == '1'):
        num2 += 1
    i += 1
    if(i < no):
        if(n[i] == '1'):
            num1 += 1
        if(n[i] == '0'):
            num2 += 1
    i += 1
    

if(num1 < num2):
    ans = num1
else:
    ans = num2

print(ans)

Solution (Python):
s = list(input())

last = s[0]

c = 1

ans = 0

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

Solution (Python):


import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    t = [int(c) for c in lines[0]]

    return (t, )


def solve(t, ):

    if debug:
        log("t=%s" % t)
    
    tmp = []
    for e in t:
        if e == 0:
            tmp.append(False)
        else:
            tmp.append(True)
    
    result = 0
    if len(t) == 1:
        pass
    else:
        for i in range(1, len(tmp)):
            if tmp[i-1] == tmp[i]:
                tmp[i] = not tmp[i-1]
                result = result + 1
        
        
        
        
        
        
        
        
        
        
        
                

    return result


def main():
    

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Solution (Python):
s = input()
l = len(s)
t = 0
for i in range(l):
  t = t + (int(s[i])*2-1)*(-1)**i
if t < 0:
  t = -t
print(int((l-t)/2))

Solution (Python):
S = list(input())
N = len(S)
count=0
count_10=0
count_00=0
num=0
if (N%2)!=0:
    NS=N-1
    a=1
else:
    NS =N
    a=0
    
count=0
for i in range(0,NS,2):
    num=int(S[i]+S[i+1])
    if num==10:
        count=count+1
        
    elif num==1:
        count_10=count_10 + 1
        
    else:
        count_00=count_00+1

count=min(count,count_10)
count=count*2
count=count+count_00
if a==1:
   if S[0]!=S[N-1]:
       count=count+1

print(count)

Solution (Python):
s_in = list(input())
S = [int(i) for i in s_in]
count = 0
Ans=[i % 2 for i in range(len(S))]
for i in range(len(S)):
    if S[i] != Ans[i]:
        count = count + 1
if count <= (len(S)//2):
    print(count)
else:
    print(len(S) - count)

Solution (Python):
str=input()
N=len(str)
s=list(str)
tehon=[]
if N%2==0:
    kai=N/2
    i=0
    while i<kai:
        tehon.append(1)
        tehon.append(0)
        i=i+1
else:
    kai=(N-1)/2
    i=0
    while i<kai:
        tehon.append(1)
        tehon.append(0)
        i=i+1
    tehon.append(1)
ss=0
cc=0
while cc<N:
    a=int(s[cc])
    b=int(tehon[cc])
    if a==b:
        ss=ss+1
    cc=cc+1
nn=N-ss
if nn<=ss:
    print(nn)
else:
    print(ss)

Solution (Python):
S = list(input())
cnt = 0
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        cnt += 1
        if S[i] == "1":
            S[i] = "0"
        else:
            S[i] = "1"
print(cnt)

Solution (Python):
S = input()

N = len(S)

count = 0

for n in range(N-1):
	if S[n] == S[n+1]:
		count += 1
		if S[n+1] == "0":
			S = S[:n+1] + "1" + S[n+2:]
		else:
			S = S[:n+1] + "0" + S[n+2:]

ccount = N - count

print(min(count, ccount))

Solution (Python):
s=str(input())
cnt=0
temp=[]
temp2=[]
nagasa=len(s)
lis=[]
cnt2=0
for p in s:
    lis.append(p)

if nagasa%2==0:
    for i in range(nagasa//2):
        temp.append("1")
        temp.append("0")
    for i in range(nagasa//2):
        temp2.append("0")
        temp2.append("1")
    
    for i in range(nagasa):
        if lis[i]!=temp[i]:
            cnt+=1
        elif lis[i]!=temp2[i]:
            cnt2+=1
        
else:
    for i in range(nagasa//2):
        temp.append("1")
        temp.append("0")
    temp.append("1")
    for i in range(nagasa//2):
        temp2.append("0")
        temp2.append("1")
    temp2.append("0")
    
    for i in range(nagasa):
        if lis[i]!=temp[i]:
            cnt+=1
        elif lis[i]!=temp2[i]:
            cnt2+=1
    

print(min(cnt,cnt2))

Solution (Python):
import copy

S = input()
s = list(S)
l = len(s)
t = copy.copy(s)

count_0 = 0
count_1 = 0


for i in range(0,l-1):
    if s[i] == "0":
        if s[i+1] != "1":
            s[i+1] = "1"
            count_0 += 1
    else:
        if s[i+1] != "0":
            s[i+1] = "0"
            count_0 += 1

if s[0] == "0":
    count_1 += 1
    t[0] = "1"
else:
    count_1 += 1
    t[0] = "0"

for j in range(0,l-1):
    if t[j] == "0":
        if t[j+1] != "1":
            t[j+1] = "1"
            count_1 += 1
    else:
        if t[j+1] != "0":
            t[j+1] = "0"
            count_1 += 1

n = min(count_0,count_1)
print(n)

Solution (Python):
S = str(input())
s0=0
s1=0
for i in range(len(S)):
    if i%2==0 and S[i]=="0":
        s1+=1
    elif i%2==0 and S[i]=="1" :
        s0+=1
    elif i%2==1 and S[i]=="0":
        s0+=1

    elif i%2==1 and S[i]=="1":
        s1+=1

print(min(s0,s1))

Solution (Python):
s = list(map(int,input()))
s1 = s
ans1,ans2 = 0,0
for i in range(1,len(s)):
  if s[i] != s[i-1]:
    continue
  elif s[i]==0:
    s[i]=1
    ans1+=1
  else:
    s[i]=0
    ans1+=1

if s1[0] == 0:
  s1[0] = 1
else:
  s1[0] = 0
  
for i in range(1,len(s)):
  if s1[i] != s1[i-1]:
    continue
  elif s1[i]==0:
    s1[i]=1
    ans2+=1
  else:
    s1[i]=0
    ans2+=1

print(min(ans1,ans2))

Solution (Python):
li = list(input())
sums = 0
leng = int(len(li))

for i in range(leng):
    now = i
    if (now + 1) >= leng:
        break
    if(li[now] == li[now + 1]):
        if(li[now + 1] == '0'):
            li[now + 1] = '1'
        else:
            li[now + 1] = '0'
        sums += 1
print(sums)

Solution (Python):
mozi = input()

front = mozi[0]
result = 0
for temp in mozi[1:]:
    if temp == front:
        result += 1
        if front == '1':
            front = '0'
        else:
            front = '1'
    else:
        front = temp
        

    
print(result)

Solution (Python):
S = input()
pre = ""
count = 0
for i, s in enumerate(S): 
  if i == 0:
    pre = s
  else:
    if s == pre:
      if pre == "1":
        pre = "0"
        count += 1
      else:
        pre = "1"
        count += 1
    else:
      if pre == "1":
        pre = "0"
      else:
        pre = "1"
print(count)

Solution (Python):
S = input()
kuro1 = 0
siro1 = 0
kuro2 = 0
siro2 = 0

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

print(min(siro2+kuro1, kuro2+siro1))

Solution (Python):
s = input()

changes = len([i for i, tile in enumerate(s) if (i%2) != int(tile)])

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

Solution (Python):
n=input()
l=list(n)
L=[]
for i in l:
    t=int(i)
    L.append(t)
m=len(L)
kisu=0
gusu=0
for i,k in enumerate(L):
    if(i%2==k):
        kisu+=1
    if(i%2!=k):
        gusu+=1
print(min(kisu,gusu))

Solution (Python):
def f(s,a):
    ans=0
    for i in range(len(s)):
        if i%2==0:
            if s[i]!=a:
                ans+=1
        else:
            if s[i]==a:
                ans+=1
    return ans


s=list(input())
print(min(f(s,'0'),f(s,'1')))

Solution (Python):
s = input()
chars = len(s)
if chars % 2 != 0:
    s += 'X'
chars = len(s)
ans1, ans2 = 0, 0
for i in range(1, chars, 2):
    if s[i-1] != '0':
        ans1 += 1
    if s[i] != '1' and s[i] != 'X':
        ans1 += 1
for i in range(1, chars, 2):
    if s[i-1] != '1':
        ans2 += 1
    if s[i] != '0' and s[i] != 'X':
        ans2 += 1
print(min(ans1, ans2))

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

s = [int(n) for n in s]
s1 = [0, 1] * int(n/2)
s2 = [1, 0] * int(n/2)

if(n%2 == 1):
    s1.append(0)
    s2.append(1)

c1, c2 = 0, 0

for i in range(n):
    if(s[i] != s1[i]):
        c1 += 1
    if(s[i] != s2[i]):
        c2 += 1

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

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

b = 0
w = 1

bw = []
for i in range(int(N / 2)):
    bw.append(b)
    bw.append(w)
if len(bw) < N:
    bw.append(b)
bw = ''.join(map(str, bw))

bin_bw = int(bw, 2)


wb = []
for i in range(int(N / 2)):
    wb.append(w)
    wb.append(b)
if len(wb) < N:
    wb.append(w)
wb = ''.join(map(str, wb))

bin_wb = int(wb, 2)

bw_xor_S = format(bin_bw ^ bin_S, 'b')
wb_xor_S = format(bin_wb ^ bin_S, 'b')
bwcout = 0
wbcout = 0
for i in range(len(bw_xor_S)):
    if bw_xor_S[i] == '1':
        bwcout += 1

for i in range(len(wb_xor_S)):
    if wb_xor_S[i] == '1':
        wbcout += 1

print(min(bwcout,wbcout))

Solution (Python):


s=input()

can1=""
can2=""

match1=0
match2=0

for i in range(len(s)):
    if i%2:
        can1=can1+"0"
        can2=can2+"1"
    else:
        can1=can1+"1"
        can2=can2+"0"
    if can1[i]==s[i]:
        match1=match1+1
    else:
        match2=match2+1

if match1>match2:
    print(match2)
else:
    print(match1)

Solution (Python):

def read_input():
    s = list(map(int, list(str(input()))))
    n = len(s)

    return n, s



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



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)

Solution (Python):
S = list(raw_input())

array=[]

if len(S) == 1:
    print 0
else:
    cnt = 0
    for i in range(len(S)):

        if i == 0:
            cnt = 1
        else:
            if S[i-1] == S[i]:
                array.append(cnt)
                cnt = 1
            else:
                cnt += 1
    array.append(cnt)

    even = [n for i,n in enumerate(array) if i % 2 == 0]
    odd  = [n for i,n in enumerate(array) if i % 2 == 1]



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

Solution (Python):

x=input()
round = len(x)

ans = 0

for i in range(round):
    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)

Solution (Python):
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)

Solution (Python):
a = input()
b = list(a)
num = 0
for i in range(len(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)

Solution (Python):
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]))

Solution (Python):
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

Solution (Python):
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])
      
     
    elif S[i-1]!=S[i]:
      continue
      
print(count)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
s = input()

count0 = 0
count1 = 0

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


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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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]))
    
    
    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))

Solution (Python):
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]))

Solution (Python):
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))

Solution (Python):
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()]))

Solution (Python):
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






    prev = 2 + ~cur
  else:
    prev = cur

print(ans)

Solution (Python):
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]))

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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()

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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"))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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]))))

Solution (Python):






import numpy as np
import numpy.matlib





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





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





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





print(min(ans1,ans2))

Solution (Python):

s = input()

with_zero, with_one = 0, 0
for i, c in enumerate(s):
    if i % 2 == 1:
        
        
        if c == "0":
            with_zero += 1
        elif c == "1":
            with_one += 1
    else:
        
        
        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)

Solution (Python):
S = input()

N = len(S)


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))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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)
  )
)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)