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

import sys
import math

def solve(S: str):
    s0 = [0,1]*math.ceil(len(S)/2)
    s1 = [1,0]*math.ceil(len(S)/2)

    d0 = 0
    for i in range(len(S)):
        if(S[i] != str(s0[i])):
            
            d0 += 1

    d1 = 0
    for i in range(len(S)):
        if(S[i] != str(s1[i])):
            d1 += 1

    
    
    print(min(d1,d0))
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):

S = list(map(int, list(input())))
l = []
cnt = 0
state = [0]
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        S[i] = abs(S[i] - 1)
        cnt += 1
print(cnt)

Solution (Python):
S = input()
lo,ol = 0,0

if len(S)==0:
    print(0)
    exit()

for i in range(len(S)//2):
    
    
    if S[i*2:(i+1)*2]=="10":
        ol += 2
    elif S[i*2:(i+1)*2] =="01":
        lo += 2
    else:
        ol += 1
        lo += 1
else:
    
    if len(S)%2!=0:
        if S[-1] == "1":
            ol += 1
        else:
            lo += 1
    
    print(min(lo,ol))

Solution (Python):
read = input
s = read()
a = []
pc = '0' if s[0] == '1' else '1'
pcnt = 0
for c in s:
    if pc == c:
        a.append(pcnt)
        pcnt = 1
    else :
        pcnt = pcnt + 1
    pc = c
a.append(pcnt)

odd = sum(map(lambda tp:tp[1], filter(lambda tp:tp[0] % 2 != 0, enumerate(a))))
even = sum(map(lambda tp:tp[1], filter(lambda tp:tp[0] % 2 == 0, enumerate(a))))
print(min(odd, even))

Solution (Python):
s = list(map(int, list(input())))
n = len(s)

even = [(i+1)%2 for i in range(n)]



neven = 0
nodd = 0
for i in range(n):
    if s[i] == even[i]:
        neven += 1
    else:
        nodd += 1
        
if neven >= nodd:
    ans = n - neven
else:
    ans = n - nodd
    
print(ans)

Solution (Python):
import numpy as np

S = np.array(list(map(int, input())))
N = S.shape[0]

repeat_count = N // 2 + 1
a = np.tile(np.array([0, 1]), repeat_count)[:N]
b = np.tile(np.array([1, 0]), repeat_count)[:N]

result = min(np.sum(np.abs(S - a)), np.sum(np.abs(S - b)))

print(result)

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

s = ns()
o = 0
e = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            e += 1
    else:
        if s[i] == '0':
            o += 1
if len(s) % 2 == 0:
    half = len(s) // 2
    print(min((half - e) + o, e + (half - o)))
else:
    half = len(s) // 2
    print(min((half + 1 - e) + o, e + (half - o)))

Solution (Python):
s = input()

count_1 = 0
count_2 = 0

flag = True
n = 0
for i in range(len(s)):

    if s[i-1] == s[i]:
        if flag:
            count_1 += n
            flag = False
        else:
            count_2 += n
            flag = True
        n = 0
    n += 1

if flag:
    count_1 += n
    flag = False
else:
    count_2 += n
    flag = True

print(min(count_1, count_2))

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

ans = 0

a = ['1','0']

for i in range(1,len(s)):
    if s[i] == s[i-1]:
        b = int(float(s[i-1]))
        s[i] = str(a[b])
        ans += 1
    
print(ans)

Solution (Python):
import numpy as np

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

print(min(Ans1,Ans2))

Solution (Python):
s=input()
l=len(s)
c1=0
c2=0
for i in range(l):
  if i%2==0:
    if s[i]!='0':
      c1+=1
    else:
      c2+=1
  else:
    if s[i]!='1':
      c1+=1
    else:
      c2+=1
print(min(c1,c2))

Solution (Python):
S = input()

cnt0 = 0
prev = '1'
for s in S:
  if s == prev:
    cnt0 += 1
  prev = '1' if prev == '0' else '0'

cnt1 = 0
prev = '0'
for s in S:
  if s == prev:
    cnt1 += 1
  prev = '1' if prev == '0' else '0'

print(min(cnt0, cnt1))

Solution (Python):
S=input()
lens=len(S)
S=int(S, 2)
a=[]
b=[]

def popcnt0(n):
	global lens
	c = 0
	for i in range(lens):
		c += (n >> i) & 1
	return c

for i in range(lens):
	if i%2==0:
		a.append('0')
		b.append('1')
	if i%2==1:
		a.append('1')
		b.append('0')
aa=''.join(a)
bb=''.join(b)
aaa=int(aa,2)
bbb=int(bb,2)
c=S^aaa
d=S^bbb

print(min(popcnt0(c),popcnt0(d)))

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

if n % 2 == 0:
    S0 = "01" * (n//2)
    S1 = "10" * (n//2)
else:
    S0 = "0" + "10" * (n//2)
    S1 = "1" + "01" * (n//2)

c0 = sum(1 for s, s0 in zip(S, S0) if s != s0)
c1 = sum(1 for s, s1 in zip(S, S1) if s != s1)

print(min(c0, c1))

Solution (Python):
S = input()

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

odd_0_count = odd.count('0')
odd_1_count = odd.count('1')

even_0_count = even.count('0')
even_1_count = even.count('1')


pattern1 = odd_1_count + even_0_count

pattern2 = odd_0_count + even_1_count

print(min(pattern1,pattern2))

Solution (Python):
s = input()
z,o,x_z,y_o = 0,0,0,0
for i,k in enumerate(s):
  if (i+1)%2==0:
    if k =='0':
      z+=1
    else:
      o +=1
  else:
    if k =='0':
      x_z +=1
    else:
      y_o += 1
print(min(z,x_z)+min(o,y_o))

Solution (Python):
S=input()
So=S[0::2]
Se=S[1::2]
if So.count('0')+Se.count('1')>So.count('1')+Se.count('0'):
    print(len(S)-So.count('0')-Se.count('1'))
else:
    print(len(S)-So.count('1')-Se.count('0'))

Solution (Python):
s=list(input())
c1=0
c2=0
a="0"
d="1"
for i in range(len(s)):
  if a=="0":
    a="1"
    if s[i]=="0":
      c1+=1
  elif a=="1":
    a="0"
    if s[i]=="1":
      c1+=1
  if d=="0":
    d="1"
    if s[i]=="0":
      c2+=1
  elif d=="1":
    d="0"
    if s[i]=="1":
      c2+=1
print(min(c1,c2))

Solution (Python):

S = input()
N=len(S)
count_101 =0
count_100 =0
count_011 =0
count_010 =0

for i in range(0,N,2):
    if S[i]=='1':
        count_101 +=1
    else:
        count_010 +=1
for i in range(1,N,2):
    if S[i]=='1':
        count_011 +=1
    else:
        count_100 +=1

if (count_101 + count_100) >= (count_011 + count_010):
    print(N-(count_101 + count_100))
else:
    print(N-(count_011 + count_010))

Solution (Python):
s = input()

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

Solution (Python):
import sys

def i2s():
    return sys.stdin.readline()

def ii2ss(n):
    return [sys.stdin.readline() for _ in range(n)]

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def main(S):
    S = S.rstrip()
    c0 = 0
    c1 = 0
    for i, s in enumerate(S):
        if (i % 2) == int(s):
            c0 += 1
        else:
            c1 += 1
    cmin = min(c0, c1)
    print(cmin)

main(i2s())

Solution (Python):
s = input()

if len(s) == 1:
    print(0)
else:
    
    prev_char = s[0]
    cntr1 = 0
    for x in s[1:]:
        if x == prev_char:
            cntr1 += 1  
            prev_char = '0' if x == '1' else '1'
        else:
            prev_char = x
    
    
    prev_char = '0' if s[0] == '1' else '1'
    cntr2 = 1
    for x in s[1:]:
        if x == prev_char:
            cntr2 += 1
            prev_char = '0' if x == '1' else '1'
        else:
            prev_char = x
    
    print(min([cntr1, cntr2]))

Solution (Python):
s = [int(_) for _ in input()]
cnt = 0

for i, n in enumerate(s):
    if i%2 == n:
        cnt += 1

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

Solution (Python):
S = input()
n = int(S, 2)
L = len(S)

S2 = ""
for _ in range(L//2+1):
    S2+= "10"
S1 = S2[:L]
S0 = S2[1:L+1]
n1 = int(S1, 2)
n0 = int(S0, 2)

ans1 = str(bin(n^n1)).count("1")
ans2 = str(bin(n^n0)).count("1")

print(min(ans1, ans2))

Solution (Python):
s = input()
leng = len(s)
ans_a = 0
ans_b = 0

for i in range(leng):
  if (i % 2 == 0 and s[i] == '0') or (i % 2 == 1 and s[i] == '1'):
    ans_a += 1

for i in range(leng):
  if (i % 2 == 0 and s[i] == '1') or (i % 2 == 1 and s[i] == '0'):
    ans_b += 1

print(min(ans_a,ans_b))

Solution (Python):
S = list(map(int, input()))
start0 = [0, 1]*(len(S)//2+1)
start1 = [1, 0]*(len(S)//2+1)
ans = [0, 0]
for i, j, k in zip(S, start0, start1):
    if(i != j):
        ans[0] += 1
    if(i != k):
        ans[1] += 1
print(min(ans))

Solution (Python):
import math
S = input()
a = (['1'] + ['0']) * (len(S)//2)
if (len(S) % 2 == 1):
  a += ['1']
ans = 0
for i in range(len(S)):
  if (S[i] != a[i]):
    ans += 1

if (len(S) - ans <= ans):
  print(len(S) - ans)
else:
  print(ans)

Solution (Python):
import sys
S = input()
if len(S) == 1:
    print(0)
    sys.exit()
ans_1 = 0
ans_2 = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == "0":
        ans_1 += 1
    if i % 2 != 0 and S[i] == "1":
        ans_1 += 1

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

print(min(ans_1,ans_2))

Solution (Python):
s=input()
a=[]
b=[]
c=0
d=0
e=0
for i in range(len(s)):
    if int(s[i])==c%2:
        d+=1
    if int(s[i])==(c+1)%2:
        e+=1
    c+=1
print(min(d,e))

Solution (Python):
s = input()
last_word = ""
count = 0

for _ in s:

	if last_word == "":
		last_word = _
		
	elif last_word == _:
		if last_word == "1":
			_ = "0"
		else:
			_ = "1"
		count += 1
			
	last_word = _
	
print(count)

Solution (Python):
h = str(input())
r = 0
for i, x in enumerate(h):
  if (i % 2) != int(x):
    r += 1
print(min(r, len(h) - r))

Solution (Python):

def main():
	N = list(input())
	if len(N) == 1 :
		print(0)
		return 0
	
	count = 0
	for i,h in enumerate(N) :
		if i<=len(N)-2 :
			if h == N[i+1] :
				N[i+1] = "1" if N[i+1] == "0" else "0"
				count+=1
	print(count)

if __name__ == "__main__" :
	main()

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

bf = 0
wf = 0

for i in range(n):
    c = '0' if i % 2 == 0 else '1'
    if s[i] == c:
        wf += 1
    else:
        bf += 1

print(bf if bf < wf else wf)

Solution (Python):
S = input()

now_col = int(S[0])
ans = 0
if len(S)==1:
    print(ans)
if len(S)!=1:
    for i in range(1,len(S)):
        
        if now_col != int(S[i]):
            
            now_col = int(S[i])
            continue
        else:
            ans += 1
            if now_col == 1:
                now_col = 0
            else:
                now_col = 1
    print(ans)

Solution (Python):
*s,=map(int,input())
a=0
for i in range(1,len(s)):
    a+=s[i]==s[i-1]
    s[i]=1-s[i-1]
print(a)

Solution (Python):
S = input()

count = 0
pos = 0
for i in S:
    n = int(i)
    if pos % 2 == n:
        count += 1
    pos += 1

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

Solution (Python):
S = input()
N = len(S)
zero_start, one_start = '', ''
for i in range(N):
    if i % 2 == 0:
        zero_start += '0'
        one_start += '1'
    else:
        zero_start += '1'
        one_start += '0'
zero_ans = 0
for i in range(N):
    if S[i] != zero_start[i]:
        zero_ans += 1
print(min(zero_ans, N-zero_ans))

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

Solution (Python):
S = input()

flag = True
counter1 = 0
counter2 = 0

for s in S:
    if flag:
        if s == "0":
            counter1 = counter1 + 1
        else:
            counter2 = counter2 + 1
    else:
        if s == "1":
            counter1 = counter1 + 1
        else:
            counter2 = counter2 + 1

    flag = not flag

print(str(min(counter1, counter2)))

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

c1 = 0
c2 = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != 0:
            c1 += 1
        if s[i] != 1:
            c2 += 1
    else:
        if s[i] != 1:
            c1 += 1
        if s[i] != 0:
            c2 += 1

print(min(c1, c2))

Solution (Python):
s = input()

if s[0] == '0':
    b = False
else:
    b = True

s = s[1:]

ans = 0
for i in s:
    if i == '1':
        if b:
            ans += 1
            b = False
        else:
            b = True
    else:
        if not b:
            ans += 1
            b = True
        else:
            b = False

print(ans)

Solution (Python):
S = input()
n = len(S)
i = n%2
As = []
Bs = []
if i == 0:
    As = "01"*(n//2)
    Bs = "10"*(n//2)
elif i == 1:
    As = "01"*(n//2)+"0"
    Bs = "10"*(n//2)+"1"
count_A,count_B = 0,0
for A,B,s in zip(As,Bs,S):
    count_A += (int(A)+int(s))%2
    count_B += (int(B)+int(s))%2
print(min(count_A,count_B))

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

d = [0, 0]
for start in [0, 1]:
  target = start
  for i in range(n):
    if int(S[i]) != target:
      d[start] += 1
    target = (target + 1) % 2
print(min(d))

Solution (Python):
s = list(input())
count = 0
for i in range(0,len(s)):
    if s[i] == str(i%2):
        count += 1
print(min(len(s)-count,count))

Solution (Python):

S = list(input())
ans = 0
c = ['1', '0']
tmp = S[0]
for i in range(1, len(S)):
    if S[i] == tmp:
        ans += 1
        tmp = c[int(S[i])]
    else:
        tmp = S[i]
print(ans)

Solution (Python):
S = list(input())
lens = len(S)
if S[0]=='0':
  s = ['0' if i%2==0 else '1' for i in range(lens)]
else:
  s = ['1' if i%2==0 else '0' for i in range(lens)]
cnt = 0
for j in range(lens):
  if S[j]!=s[j]:
    cnt+=1
print(cnt)

Solution (Python):
S = input()
T = []
tmp = '1'
for i in range(len(S)-1):
    if tmp[-1] == '0':
        tmp += '1'
    else:
        tmp += '0'
T.append(tmp)
tmp = '0'
for i in range(len(S)-1):
    if tmp[-1] == '0':
        tmp += '1'
    else:
        tmp += '0'
T.append(tmp)
ans = float('inf')
for j in range(2):
    cnt = 0
    for i in range(len(S)):
        if S[i] != T[j][i]:
            cnt += 1
    if cnt < ans:
        ans = cnt
print(ans)

Solution (Python):
from numpy import zeros
s = list(map(int, list(input())))
ans1 = 0
ans2 = 0
sam1 = zeros(len(s))
sam2 = zeros(len(s))
for i in range(len(s)):
    if i%2: sam1[i] = 1
    else: sam2[i] = 1
for i in range(len(s)):
    if s[i] != sam1[i]: ans1 += 1
    elif s[i] != sam2[i]: ans2 += 1
print(min(ans1, ans2))

Solution (Python):
def load_input():
    s = [int(c) for c in list(input())]
    return s


def main():
    s = load_input()

    cand = []
    cand.append([0 if i % 2 == 0 else 1 for i in range(len(s))])
    cand.append([0 if i % 2 == 1 else 1 for i in range(len(s))])

    diff = [0, 0]
    for i in range(2):
        for j in range(len(s)):
            if s[j] != cand[i][j]:
                diff[i] += 1
    if diff[0] < diff[1]:
        print(diff[0])
    else:
        print(diff[1])


if __name__ == '__main__':
    main()

Solution (Python):
s = input()


x1 = 0
for i in range(len(s)):
    t1 = s[i]
    t2 = '0' if i % 2 == 0 else '1'
    if t1 != t2:
        x1 += 1


x2 = 0
for i in range(len(s)):
    t1 = s[i]
    t2 = '1' if i % 2 == 0 else '0'
    if t1 != t2:
        x2 += 1

print(min(x1, x2))

Solution (Python):
S = list(map(int,input()))
zero = [0 if i%2==0 else 1 for i in range(len(S))]
one = [0 if i%2==1 else 1 for i in range(len(S))]
diff_from_zero = 0
diff_from_one = 0
for i in range(len(S)):
    if one[i] != S[i]:
        diff_from_one += 1
    if zero[i] != S[i]:
        diff_from_zero += 1
print(min(diff_from_one,diff_from_zero))

Solution (Python):
s = list(input())
chk1 = 0
chk2 = 0

bk = []
for i in range(len(s)):
  if i%2 == 0:
    bk.append('1')
  else :
    bk.append('0')
    
    
for i in range(len(s)):
  if bk[i] == s[i]:
    chk1 += 1
  else :
    chk2 += 1
print(min(chk1,chk2))

Solution (Python):
S = str(input())
a = [0] * len(S)

for i in range(0, len(S), 2):
    a[i] = 1
    
count = 0
for j in range(0, len(S)):
    if int(S[j]) != a[j]:
        count += 1
        
print(min(count, len(S)-count))

Solution (Python):
from sys import stdin

s = stdin.readline().rstrip()
len_s = len(s)

count0 = 0
count1 = 0
for i in range(len_s):
  if (int(s[i]) == i%2):
    count0 += 1
  if (int(s[i]) != i%2):
    count1 += 1


if (count0 < count1):
  print("{0}".format(count0))
else:
  print("{0}".format(count1))

Solution (Python):
S = input()

flag = True
length = len(S)
count = 0
for c in S:
    if int(flag) == int(c):
        count += 1
    flag = not flag

if count > divmod(length, 2)[0]:
    count = length - count
print(count)

Solution (Python):
s = input()
N = len(s)
num = float('inf')
for i in range(2):
    tmp = 0
    for j in range(N):
        if j % 2 == i:
            if s[j] == '1':
                tmp += 1
        else:
            if s[j] == '0':
                tmp += 1
    num = min(tmp, num)
print(num)

Solution (Python):
s = input()
i = s[0::2]
j = s[1::2]
i0 ,i1 = i.count('0'), i.count('1')
j0, j1 = j.count('0'), j.count('1')

print(min((i0+j1), (i1+j0)))

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

n = len(s)

def count_flips(s0):
  ans = 0
  for i in range(n):
    si = (s0 + i) % 2
    if s[i] != si:
      ans += 1
  return ans

print(min(count_flips(0), count_flips(1)))

Solution (Python):
S = input()

score = 0
for i in range(len(S)):
    if (i % 2) != int(S[i]):
        score += 1

score2 = 0
for i in range(len(S)):
    if ((i+1) % 2) != int(S[i]):
        score2 += 1

print(min(score,score2))

Solution (Python):
S = [int(i) for i in input()]
if(len(S)%2==0):
    s_01 = [0,1]*int((len(S)/2))
    s_10 = [1,0]*int((len(S)/2))
    acc_01 = sum([i==j for i,j in zip(S,s_01)])
    acc_10 = sum([i==j for i,j in zip(S,s_10)])
    print(min(len(S)-acc_01, len(S)-acc_10))
else:
    s_01 = [0,1]*int((len(S)/2))
    s_01.append(0)
    s_10 = [1,0]*int((len(S)/2))
    s_10.append(1)
    acc_01 = sum([i==j for i,j in zip(S,s_01)])
    acc_10 = sum([i==j for i,j in zip(S,s_10)])
    print(min(len(S)-acc_01, len(S)-acc_10))

Solution (Python):
import numpy as np

S = np.array(list(input()))
N = len(S)

cnt1 = 0
cnt2 = 0

for i in range(0, N):
    if i % 2 == 0:
        if int(S[i]) != 0:
            cnt1 = cnt1 + 1
    else:
        if int(S[i]) != 1:
            cnt1 = cnt1 + 1

for i in range(0, N):
    if i % 2 == 0:
        if int(S[i]) != 1:
            cnt2 = cnt2 + 1
    else:
        if int(S[i]) != 0:
            cnt2 = cnt2 + 1

print(min(cnt1, cnt2))

Solution (Python):
s = input()

start_0 = 0
start_1 = 0

for i, l in enumerate(s):
  if i % 2 == 0:
    start_0 += int(l) 
    start_1 += 1-int(l)
  else:
    start_0 += 1-int(l)
    start_1 += int(l) 

print(min([start_0, start_1]))

Solution (Python):
S=input()
E=[]
O=[]
for i in range(len(S)):
  if i%2==0:
    E.append(int(S[i]))
  else:
    O.append(int(S[i]))
a=E.count(0)
b=E.count(1)
c=O.count(0)
d=O.count(1)
print(min(a+d,b+c))

Solution (Python):
st = input()
length = len(st)
pat1 = ['0' if i % 2 else '1' for i in range(length)]
pat2 = ['0'] + pat1[:-1] 
len1 = len([s for s, ss in zip(st, pat1) if s != ss])
len2 = len([s for s, ss in zip(st, pat2) if s != ss])
print(min(len1, len2))

Solution (Python):
S = list(input())
s = S[0]
r = 0
if(len(S) == 1):
  print(r)
  quit()
for i, l in enumerate(S):
  if(i+1 >= len(S)):
    break
  if(S[i+1] == l):
    r += 1
    if(l == '0'):
      S[i+1] = '1'
    else:
      S[i+1] = '0'
print(r)

Solution (Python):
S = input()
S0 ="01"
S1 ="10"
n0 = 0
n1 = 0
for i in range(len(S)):
    if(S[i]!=S0[i%2]):
        n0+=1
    if(S[i]!=S1[i%2]):
        n1+=1
print(min(n0,n1))

Solution (Python):
S = list(input())
L = len(S)
ob = 0
ow = 0
eb = 0
ew = 0
for i in range(L):
    if S[i] == '0' and i % 2 == 0:
        ob += 1
    elif S[i] == '0':
        eb += 1
ow = (L + 1) // 2 - ob
ew = L // 2 - eb

print(min(ob + ew, ow + eb))

Solution (Python):
t = input()
a1, a2 = 0, 0
for i in range(len(t)):
  if i % 2 == 0:
    if t[i] == '0':
      a1 += 1
    else:
      a2 += 1
  else:
    if t[i] == '1':
      a1 += 1
    else:
      a2 += 1
print(min(a1, a2))

Solution (Python):

s = input()
S = []
for c in s:
    S.append(int(c))
count = 0
l = len(S)
for i in range(0,l,2):
    if S[i] == 0:
        count += 1 
for i in range(1,l,2):
    if S[i] == 1:
        count += 1

print(min(count,l-count))

Solution (Python):
*s,=map(int,input())
t=s[::-1]
n=len(s)
a=b=0
for i in range(1,n):
    a+=s[i]==s[i-1]
    s[i]=1-s[i-1]
for i in range(1,n):
    b+=t[i]==t[i-1]
    t[i]=1-t[i-1]
print(min(a,b))

Solution (Python):
s = input()

ans_0 = 0

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

ans_1 = 0

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

print(min(ans_1,ans_0))

Solution (Python):
s=list(input())
n=len(s)
if n%2==0:
    n_e=n//2
    n_o=n//2
else:
    n_e=n//2+1
    n_o=n//2
s_e=s[0::2]
s_o=s[1::2]
s_e0=s_e.count("0")
s_o0=s_o.count("0")

ans=min(n_e-s_e0+s_o0,n_o-s_o0+s_e0)
print(ans)

Solution (Python):
str = input()
len = len(str)
count = 0
list = []
list.append(int(str[0]))
for i in range(len-1):
  if list[i] == int(str[i+1]):
    if list[i] == 0:
      list.append(1)
    else:
      list.append(0)
    count += 1
  else:
    list.append(int(str[i+1]))
print(count)

Solution (Python):
s = input()
t1 = 0
t2 = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != '0':
            t1 = t1 + 1
    if i % 2 == 1 and s[i] != '1':
        t1 = t1 + 1

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != '1':
            t2 = t2 + 1
    if i % 2 == 1 and s[i] != '0':
        t2 = t2 + 1

print(min(t1,t2))

Solution (Python):
S = input()
l = len(S)
c1 = ''.join(['0' if i %2 == 0 else '1' for i in range(l)])
c2 = ''.join(['1' if i %2 == 0 else '0' for i in range(l)])
x = sum(a == b for a, b in zip(S, c1))
y = sum(a == b for a, b in zip(S, c2))
if x > y :
    print(y)
else :
    print(x)

Solution (Python):
S = input()

o = S[::2]
p = S[1::2]

o1 = len([i for i in o if i == "1"])
o0 = len(o) - o1

p1 = len([i for i in p if i == "1"])
p0 = len(p) - p1

print(min(o1 + p0, o0 + p1))

Solution (Python):
s = input()
ans1 = 0
ans2 = 0

for i in range(len(s)):
    if s[i] != str(i%2):
        ans1 += 1

for i in range(len(s)):
    if s[i] != str((i+1)%2):
        ans2 += 1

print(min(ans1,ans2))

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

res0 = 0
res1 = 0

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

print(min(res0,res1))

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






res1=0
for i in range(N):
  if (int(S[i]) % 2) == (i % 2):
    res1+=1

res0=N-res1

print(min(res0,res1))

Solution (Python):
s = input()
tmp1 = ""
tmp2 = ""
for i in range(len(s)):
    if i %2 ==0:
        tmp1+=str(1)
    else:
        tmp1+=str(0)

for i in range(len(s)):
    if i %2 ==0:
        tmp2+=str(0)
    else:
        tmp2+=str(1)
        
count1=0
count2=0
for i in range(len(s)):
    if s[i] != tmp1[i]:
        count1+=1
        
for i in range(len(s)):
    if s[i] != tmp2[i]:
        count2+=1
        
print(min(count1, count2))

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

e = '0'
if (s[0] == '0'):
    e = '1'

s.pop(0)
count = 0
for c in s:
    if c != e:
        count += 1
    if e == '0':
        e = '1'
    else:
        e = '0'

print(count)

Solution (Python):
S =  input()

diff1 = 0
diff2 = 0

for i,s in enumerate(S):
    
    if i%2==0:
        
        if s!="0":
            diff1 +=1
    else:
        
        if s!="1":
            diff1 +=1


i=0
for i,s in enumerate(S):
    if i%2==0:
        if s!="1":
            diff2 +=1
    else:
        if s!="0":
            diff2 +=1

print(min(diff1, diff2))

Solution (Python):
S = input()

ans1 = 0
ans2 = 0

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

print(min(ans1, ans2))

Solution (Python):
S = input()

first_zero_count = 0
first_one_count = 0

i = 0

buf = '0'
while i < len(S):
    if S[i] == buf:
        first_zero_count += 1

    if buf == '0':
        buf_buf = '1'
    else:
        buf_buf = '0'

    if S[i] == buf_buf:
        first_one_count += 1
    if buf == '0':
        buf = '1'
    else:
        buf = '0'
    i += 1

print(min(first_zero_count, first_one_count))

Solution (Python):
s = input()

ret = 0
for i, it in enumerate(s):
    if i%2==0:
        if it == '0':
            ret += 1
    else:
        if it == '1':
            ret += 1
print(min(ret, len(s)-ret))

Solution (Python):
import numpy as np

s = np.array([int(i) for i in input()])

ans_0 = np.array(
  [int(i%2==0) for i in range(len(s))])
ans_1 = np.array(
  [int(i%2==1) for i in range(len(s))])

diff_0 = (s == ans_0).sum()
diff_1 = (s == ans_1).sum()

print(min(diff_0, diff_1))

Solution (Python):
S=input()
a=[]
b=[]
s=list(S)
flag=True
for i in range(len(S)):
   
    if flag:
        a.append('0')
        b.append('1')
        flag=False
    else:
        a.append('1')
        b.append('0')
        flag=True
    
a_count=0
b_count=0
for i in range(len(s)):
    if s[i]==a[i]:
        a_count+=1
    if s[i]==b[i]:
        b_count+=1
print(min(a_count,b_count))

Solution (Python):
s = input()
s0 = ""
s1 = ""
for i in range(len(s)):
    s0 += str(i % 2)
    s1 += str((i + 1) % 2)
br0 = br1 = 0
for i in range(len(s)):
    if s[i] != s0[i]:
        br0 += 1
    if s[i] != s1[i]:
        br1 += 1
print(min(br0, br1))

Solution (Python):
S = input()
count1 = 0
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "1":
      count1 += 1
  else:
    if S[i] == "0":
      count1 += 1
count2 = 0
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "0":
      count2 += 1
  else:
    if S[i] == "1":
      count2 += 1
print(min(count1, count2))

Solution (Python):
from sys import stdin

def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()



S = rs()
N = len(S)

mi = int(1e9)
for p in range(2):
    cnt = 0
    for i in range(N):
        if S[i] != chr(ord('0') + ((i % 2) ^ p)): cnt += 1
    mi = min(mi, cnt)

print(mi)

Solution (Python):



s = input()

s01 = "01"*((len(s)+1)//2)
s10 = "10"*((len(s)+1)//2)

c1 = sum([1 if i==j else 0 for i,j in zip(s,s01)])
c2 = sum([1 if i==j else 0 for i,j in zip(s,s10)])

print(min(c1,c2))

Solution (Python):
s = str(input())
sum=0
for i in range(len(s)):
    if(i%2==0 and int(s[i])==1):
        sum+=1
    if(i%2==1 and int(s[i])==0):
        sum+=1
if(sum > (len(s)-sum)):
    print(len(s)-sum)
else:
    print(sum)

Solution (Python):
s = list(input())
s = [int(i) for i in s]
ans1, ans2 = 0, 0
for i in range(len(s)):
    if i % 2 == 1:
        if s[i] == 1:
            ans1 += 1
        else:
            ans2 += 1
    else:
        if s[i] == 1:
            ans2 += 1
        else:
            ans1 += 1
print(min(ans1, ans2))

Solution (Python):
s = input()
res = 0
st = '0'
for c in s:
    if c !=st:
        res+=1
    if st=='0':
        st = '1'
    else:
        st = '0'
tmp = 0
st = '1'
for c in s:
    if c!=st:
        tmp+=1
    if st=='0':
        st='1'
    else:
        st='0'
res = min(tmp,res)
print(res)

Solution (Python):
S = list(input())
zeroone = 0
onezero = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == '1':
        zeroone += 1
    elif i % 2 == 1 and S[i] == '0':
        zeroone += 1
for i in range(len(S)):
    if i % 2 == 0 and S[i] == '0':
        onezero += 1
    elif i % 2 == 1 and S[i] == '1':
        onezero += 1

print(min(zeroone, onezero))

Solution (Python):
s=input()
a=0
b=0
c=0
d=0
for i in range(len(s)):
    if i%2==0 and s[i]=="0":
        a+=1
    elif i%2==1 and s[i]=="1":
        b+=1
    if i%2==0 and s[i]=="1":
        c+=1
    elif i%2==1 and s[i]=="0":
        d+=1
I=max(a+b,c+d)
ans=len(s)-I
print(ans)

Solution (Python):
def diff(u, v):
    res = 0
    for i in range(len(u)):
        if u[i] != v[i]:
            res += 1

    return res


s = [int(item) for item in list(input())]
print(min(diff(s, [1 if i % 2 else 0 for i in range(len(s))]),
          diff(s, [0 if i % 2 else 1 for i in range(len(s))])))

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

Solution (Python):
s = input()
N = len(s)

ans = 0

goal1 = [0]*N
goal2 = [0]*N

for i in range(N):
    if i%2==0:
        goal1[i] = '0'
        goal2[i] = '1'
    else:
        goal1[i] = '1'
        goal2[i] = '0'

ans1 = 0
ans2 = 0

for i in range(N):
    if s[i] != goal1[i]:
        ans1 += 1
    if s[i] != goal2[i]:
        ans2 += 1
ans = min(ans1, ans2)

print(ans)

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

sum0 = 0
sum1 = 0

len_s = len(s)

if len_s == 1:
    print(0)
    sys.exit()
else:
    for i in range(len_s):
        if (i % 2 == 0):
            if (s[i] == '0'):
                sum0 += 1
            else:
                sum1 += 1
        else:
            if (s[i] == '0'):
                sum1 += 1
            else:
                sum0 += 1


if (sum0 > sum1):
    print(sum1)
else:
    print(sum0)

Solution (Python):
S = input()

pattern1 = '0'
pattern2 = '1'

even = True
pattern1 = 0
pattern2 = 0
for s in S:
    if even:
        if s == '0':
            pattern1 += 1
        else:
            pattern2 += 1
    else:
        if s == '0':
            pattern2 += 1
        else:
            pattern1 += 1
    even = not even
print(str(min(pattern1, pattern2)))

Solution (Python):
s = input()
n = len(s)
hikaku10 = ""
hikaku01 = ""
if n % 2 == 0:
    for i in range(int(n/2)):
        hikaku10 += "10"
        hikaku01 += "01"
else:
    for i in range(int((n-1)/2)):
        hikaku10 += "10"
        hikaku01 += "01"
    hikaku10 += "1"
    hikaku01 += "0"







print(min(str(bin(int(hikaku10,2)^int(s,2))).count("1"),str(bin(int(hikaku01,2)^int(s,2))).count("1")))

Solution (Python):
S = input()
N = len(S)
ans = 0

tmp = list(S)
for i in range(1, N):
    if tmp[i-1] == tmp[i]:
        if tmp[i] == '0':
            tmp[i] = '1'
        else:
            tmp[i] = '0'
        ans += 1

print(ans)

Solution (Python):
S=input()
count=0
start=0
for i in S:
    if count%2==0:
        if i=="0":
            start+=1
    else:
        if i=="1":
            start+=1
    count+=1
if (len(S)-start)>start:
    print(start)
else:
    print(len(S)-start)