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

s = input()

firstTile = s[0]
lastTile = s[-1]

def isOneColor():
    t = None
    for c in s:
        if t is None:
            t = c
        else:
            if c is not t:
                return False
    return True

def reverse(tile):
    if tile is "0":
        return "1"
    else:
        return "0"

def shouldZeroStart():
    z = 0
    o = 0
    currentTile = "0"
    for tile in s:
        if tile is not currentTile:
            z = z + 1
        currentTile = reverse(currentTile)
    currentTile = "1"
    for tile in s:
        if tile is not currentTile:
            o = o + 1
        currentTile = reverse(currentTile)
    if z < o:
        return True
    else:
        return False

result = 0
currentTile = "1"
if isOneColor():
    if firstTile is "0":
        currentTile = "0"
else:
    if shouldZeroStart():
        currentTile = "0"
for i in range(len(s)):
    if s[i] is not currentTile:
        result = result + 1
    currentTile = reverse(currentTile)



print(result)

Solution (Python):
L=list(input())
if L[::2].count("0") > L[1::2].count("0") :
  print( L[::2].count("1")+L[1::2].count("0"))
else :
  print( L[::2].count("0")+L[1::2].count("1"))

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

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

evens = s[::2]
odds = s[1::2]

ans_0 = evens.count('0') + odds.count('1')
ans_1 = evens.count('1') + odds.count('0')

print(len_s - max(ans_0,ans_1))

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

Solution (Python):
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)



c = 0
count_start_0 = 0
for i in range(len(s)):
    if int(s[i]) == c:
        count_start_0 += 1
    c = 0 if c == 1 else 1

count_start_1 = len(s) - count_start_0

print(min([count_start_0, count_start_1]))

Solution (Python):




def problem(s):
    size = len(s)

    evens = s[::2]
    odds = s[1::2]

    p1 = size - (evens.count('0') + odds.count('1'))
    p2 = size - (evens.count('1') + odds.count('0'))

    return min(p1, p2)


def main():
    s = input()

    print(problem(s))


if __name__ == '__main__':
    main()

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

res = 0
for i in range(len(S)-1):
    if S[i] == '0' and S[i+1] == '0':
        S[i+1] = '1'
        res += 1
        
    if S[i] == '1' and S[i+1] == '1':
        S[i+1] = '0'
        res += 1
        
print(res)

Solution (Python):
s = input()
c = 0
for i, a in enumerate(s):
    if i % 2 == 0 and a == '0':
        c += 1
    if i % 2 == 1 and a == '1':
        c += 1
print(min(c, len(s)-c))

Solution (Python):
if __name__ == '__main__':
	
	S = input()
	N = len(S)
	BNum=0
	BNumEven=0
	for i in range(len(S)):
		if(S[i]=='0'):
			BNum+=1
		if(S[i]=='0' and i%2==1):
			BNumEven+=1
	NEven = N//2
	NOdd = N - NEven
	BNumOdd = BNum - BNumEven
	WNum=N-BNum
	WNumEven=N//2-BNumEven
	WNumOdd = WNum - WNumEven

	min_change = 100001
	
	if(WNumEven + BNumOdd<min_change):
		min_change = WNumEven + BNumOdd
	
	if(WNumOdd + BNumEven<min_change):
		min_change = WNumOdd + BNumEven

	print(min_change)

Solution (Python):
s = list(input())
n = len(s)
cnt1 = 0
cnt2 = 0
for i in range(n):
        if i%2 == 0:
                if s[i] == "1":
                        cnt1 += 1
                else:
                        cnt2 += 1
        else:
                if s[i] == "0":
                        cnt1 += 1
                else:
                        cnt2 += 1
print(min(cnt1,cnt2))

Solution (Python):
S = input()

bin_0 = "".join(["0" if i % 2 == 0 else "1" for i in range(len(S))])
bin_1 = "".join(["1" if i % 2 == 0 else "0" for i in range(len(S))])
lis_S = [ i for i in S]

if abs(int(S,2) - int(bin_0,2)) <= abs(int(S,2) - int(bin_1,2)):

	res = sum([ 1  for i in range(len(S)) if bin_0[i] != lis_S[i]])
else:

	res = sum([ 1  for i in range(len(S)) if bin_1[i] != lis_S[i]])
print(res)

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

Solution (Python):
BLACK = "0"
WHITE = "1"
S = input()
even_black = 0
even_white = 0
odd_black = 0
odd_white = 0

for i in range(len(S)):
  if i%2 == 0:
    even_black += S[i]==BLACK
    even_white += S[i]==WHITE
  else:
    odd_black += S[i]==BLACK
    odd_white += S[i]==WHITE
if even_black+odd_white < even_white+odd_black:
  print("{}" .format(even_black+odd_white))
else:
  print("{}" .format(even_white+odd_black))

Solution (Python):
list = list(map(int,list(input())))
odds =[list[i] for i in range(0,len(list),2)]
evens =[list[i] for i in range(1,len(list),2)]
a = odds.count(0)
b = len(odds) - a
c = evens.count(0)
d = len(evens) - c
print(min(a+d,b+c))

Solution (Python):
S = input()
N = len(S)
num = 0
i=0
X=num%2
while num<N:
  if S[num] == "0":
    i+=1
  if not num==X+N-1:
    if S[num+1] == "1":
      i+=1
  num+=2
if N-i>i:
  print(i)
else:
  print(N-i)

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

Solution (Python):


n = list(input())
n_size = len(n)
count = 0

new_list = []
new_list.append(int(n[0]))
for i in range(n_size-1):
  if new_list[i] == 0:
    new_list.append(1)
  else:
    new_list.append(0)


    
for i in range(n_size):
  if (int(n[i]) != int(new_list[i])):
    count+=1


if n_size == 1:
  print(0)
else:

  print(count)

Solution (Python):
S = input()
even = S[0::2].count('0') + S[1::2].count('1')
print(min([even,len(S)-even]))

Solution (Python):
l =[int(i) for i in list(str(input()))]
ans = 0
num =0
n = 0

if l[0] == 1:
    l=[abs(i-1) for i in l]

for i in l:
    if num%2 ==0:
        if i == 1:
            ans = ans +1
    else:
        if i == 0:
            ans =ans +1
    num = num +1
print(ans)

Solution (Python):
s=input()

oi=0
io=0
ctr=0

for c in str(s):
    if c == str(ctr):
        oi+=1
    else:
        io+=1
    if ctr:
        ctr=0
    else:
        ctr=1

print(min(oi,io))

Solution (Python):
ans = 0
str = list(input())

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

print(ans)

Solution (Python):
s = input()
ans = len(s)
for k in range(2):
    pen = 0
    for i in range(len(s)):
        if k == 0:
            if i % 2 == 0 and s[i] == '0':
                pen += 1
            if i % 2 == 1 and s[i] == '1':
                pen += 1
        if k == 1:
            if i % 2 == 0 and s[i] == '1':
                pen += 1
            if i % 2 == 1 and s[i] == '0':
                pen += 1
    ans = min(ans, pen)

print(ans)

Solution (Python):
n=input()
cnt1=len(n)
cnt2=0
cnt3=0

x="0"
for i in range(cnt1):
	if n[i] != x:
		cnt2+=1
	if x=="0":
		x="1"
	else:
		x="0"

x="1"
for i in range(cnt1):
	if n[i] != x:
		cnt3+=1
	if x=="0":
		x="1"
	else:
		x="0"

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

Solution (Python):
S = input()
c_odd, c_even = 0,0


for i in range(len(S)):
  if S[i] == '0':
    if i%2 == 0: 
      c_even += 1
    else:
      c_odd += 1
  else:
    if i%2 == 0: 
      c_odd += 1
    else:
      c_even += 1
      
print(min(c_odd, c_even))

Solution (Python):
tiles = str(input())
size = len(tiles)
one = 0
zero = 0

for i in range(size):
	one_i = (i+1) % 2
	zero_i = i % 2
	one += abs(one_i - int(tiles[i]))
	zero += abs(zero_i - int(tiles[i]))

print(min(one, zero))

Solution (Python):
s=input()
l=len(s)//2
s0="01"*l
if len(s)%2!=0:
    s0+="0"
s1="10"*l
if len(s)%2!=0:
    s1+="1"
ans0=0
ans1=0
for i in range(len(s)):
    if s[i]!=s0[i]:
        ans0+=1
    if s[i]!=s1[i]:
        ans1+=1
print(min(ans0,ans1))

Solution (Python):
s = input()
i = 0
ans = 0
while i < len(s):
    if int(s[i]) == i % 2:
        ans += 1
    i += 1
print(min(ans,i-ans))

Solution (Python):


S=input()

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

print(count)

Solution (Python):
s=input()
a=b=[]
ac=bc=0
for i in range(len(s)):
    a.append('0')
    b.append('1')
    if s[i]!=a[i]:
        ac+=1
    else: bc+=1
print(min(ac,bc))

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

Solution (Python):


S = input()

Se, So = S[0::2], S[1::2]
Se0, Se1, So0, So1 = Se.count('0'), Se.count('1'), So.count('0'), So.count('1')
print(min(Se0 + So1, Se1 + So0))

Solution (Python):
color = input()

even = color[::2]
odd = color[1::2]


count1 = even.count('0') + odd.count('1')


count2 = even.count('1') + odd.count('0')

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

Solution (Python):
ar = input()
c1 = 0
c2 = 0
for i in range(len(ar)):
    if i % 2 == 0:
        if ar[i] == "0":
            c1 += 1
        elif ar[i] == "1":
            c2 += 1
    elif i % 2 == 1:
        if ar[i] == "0":
            c2 += 1
        elif ar[i] == "1":
            c1 += 1
print(min(c1,c2))

Solution (Python):
S=input()
a=["0","1"]
count=0
n=len(S)
for i in range(n):
    if S[i] == a[i%2]:
        count+=1
print(min(count,n-count))

Solution (Python):
def get_distance(s1, s2):
    dis = 0
    for c1, c2 in zip(s1, s2):
        if c1 != c2:
            dis = dis + 1
    return dis

S = str(input())

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

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

ans = min(get_distance(S, S0), get_distance(S, S1))
print(ans)

Solution (Python):
S = input()

ans0 = 0
ans1 = 0
target = 0
for i in range(len(S)):
  if S[i] == str(target):
    ans0 += 1
  else:
    ans1 += 1
  target = 1 - target
print(min(ans0, ans1))

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

num = n[0]
total = 0
for i in range(1,len(n)):
    if n[i] == n[i-1]:
        total += 1
        if n[i] == 1:
            n[i] = 0
        else:
            n[i] = 1

print(total)

Solution (Python):
S = input()
ans1 = ''
ans2 = ''
for i in range(len(S)):
    ans1 += str(i % 2)
    ans2 += str((i+1)%2)
count1 = 0
count2 =0
for i in range(len(S)):
    if S[i] !=ans1[i]: count1 += 1
    if S[i] != ans2[i]: count2 += 1
print(min(count1,count2))

Solution (Python):
S = input()
count = [0,0]

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

print(min(count))

Solution (Python):
import numpy as np

S = list(map(int,input()))
S = np.array(S)
l = len(S)
ptnA = np.tile((1,0), l)
ptnA = ptnA[0:l]
ptnB = np.tile((0,1),l)
ptnB = ptnB[0:l]

xorsumA = sum(np.logical_xor(S, ptnA))
xorsumB = sum(np.logical_xor(S, ptnB))

print(min((xorsumA,xorsumB)))

Solution (Python):
s = input()
N = len(s)
count_w = 0
for i in range(N):
    if ((i%2) == 0 and int(s[i]) == 0) or ((i%2) == 1 and int(s[i]) == 1):
        count_w += 1
count_b = 0
for i in range(N):
    if ((i%2) == 0 and int(s[i]) == 1) or ((i%2) == 1 and int(s[i]) == 0):
        count_b += 1
print(min(count_b,count_w))

Solution (Python):
s = input()
N = len(s)
left_white=[]
for i in range(N):
    if (i%2) == 0:
        left_white.append(1)
    else:
        left_white.append(0)
left_black=[]
for i in range(N):
    if (i%2) == 0:
        left_black.append(0)
    else:
        left_black.append(1)
count_w = 0
for i in range(N):
    if int(s[i]) != left_white[i]:
        count_w = count_w+1
count_b = 0
for i in range(N):
    if int(s[i]) != left_black[i]:
        count_b += 1
print(min(count_w,count_b))

Solution (Python):
import sys
inp=[i.strip() for i in sys.stdin.readlines()]
if len(inp)==1:
    if len(inp[0].split())==2:
        A,B=map(int,inp[0].split())
        print(max(2*A-1,2*B-1,A+B))
    else:
        S=inp[0]
        N=len(S)
        X=""
        Y=""
        for i in range(N):
            if i%2==0:
                X=X+"0"
                Y=Y+"1"
            else:
                X=X+"1"
                Y=Y+"0"
        A=0
        B=0
        for i in range(N):
            if X[i]!=S[i]:
                A+=1
            if Y[i]!=S[i]:
                B+=1
        print(min(A,B))
else:
    if len(inp[0].split())==1:
        N=int(inp[0])
        H=[int(i) for i in inp[1].split()]
        ans=1
        for i in range(1,N):
            flag=1
            for j in range(i):
                if H[j]>H[i]:
                    flag=0
                    break
            if flag==1:
                ans+=1
        print(ans)
    else:
        N,K=map(int,inp[0].split())
        S=inp[1]
        L=[0]
        tmp="1"
        for i in range(N):
            if tmp!=S[i]:
                L.append(1)
            else:
                L[-1]+=1
            tmp=S[i]
        if tmp=="0":
            L.append(0)
        M=len(L)
        if M<=2*K+1:
            print(N)
            exit()
        X=[0 for i in range(M+1)]
        for i in range(M):
            X[i+1]=L[i]+X[i]
        ans=0
        for i in range(0,M-2*K,2):
            ans=max(ans,X[i+2*K+1]-X[i])
        print(ans)

Solution (Python):
s = input()
ans = 0

for i, v in enumerate(s):
    r = i % 2
    if int(v) != r:
        ans += 1

print(min([ans,len(s)-ans]))

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

list_0 = list()
list_1 = list()
for i in range(len(S)):
  if i % 2 ==0:
    list_0.append(int(S[i]))
  else:
    list_1.append(int(S[i]))

count_0_0 = list_0.count(0)
count_1_0 = list_1.count(1)

count_0_1 = list_0.count(1)
count_1_1 = list_1.count(0)

sum_0 = count_0_0 + count_1_0
sum_1 = count_0_1 + count_1_1

print(min(sum_0, sum_1))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter


_nprime = 10 ** 5 + 1
primes = list(range(int(_nprime) + 1))
primes[1] = 0
for i in range(2, int((_nprime + 1) ** 0.5) + 1):
    if primes[i]:
        for j in range(2 * i, _nprime + 1, i):
            primes[j] = 0

def main():
    S = SI()
    ans = [0, 0]
    i = 0
    for s in S:
        if int(s) == i:
            ans[0] += 1
        else:
            ans[1] += 1
        i = 1 - i
    ans = min(ans)
    return ans

print(main())

Solution (Python):


S = input()
N = len(S)
ans = 0
SR = []
if S[0] == '0':
	for i in range(N):
		SR.append('0')
		SR.append('1')
else:
	for i in range(N):
		SR.append('1')
		SR.append('0')

for i in range(N):
	if S[i] != SR[i]:
		ans += 1
		
print(ans)

Solution (Python):
S = input()
even_0,even_1 =0,0
odd_0 ,odd_1 = 0,0

for i,s in enumerate(S):
    if (i+1)%2==0:
        if s == "0":
            even_0 += 1
        elif s == "1":
            even_1 += 1
    else:
        if s == "0":
            odd_0 += 1
        elif s == "1":
            odd_1 += 1

print(min([odd_1+even_0,odd_0+even_1]))

Solution (Python):




def main():
    S = [(True if c == '1' else False) for c in input() ]

    min_ = float('inf')

    for c in (True, False):
        num = 0
        for s in S:
            if s != c:
                num += 1
            c = not c
        min_ = min(num, min_)

    print(min_)


if __name__ == '__main__':
    main()

Solution (Python):
S = input()

a = "01" * (len(S) // 2) 

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

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

Solution (Python):
s = input()

count1=0
count2=0

for i in range(len(s)):
	if int(s[i]) == i%2:
		count1 += 1
	else:
		count2 += 1
print(min(count1,count2))

Solution (Python):
s=input()
a,b=s[::2],s[1::2]
a_lst=[i for i in a]
a0=a_lst.count("0")
a1=a_lst.count("1")
b_lst=[i for i in b]
b0=b_lst.count("0")
b1=b_lst.count("1")
print(min(a0+b1,a1+b0))

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

Solution (Python):
import math
S = input()
a = "01"*math.ceil(len(S))
b = "10"*math.ceil(len(S))
a_diff = 0
b_diff = 0
for i in range(len(S)):
    a_diff += a[i] != S[i] 
    b_diff += b[i] != S[i]
print(min(a_diff, b_diff))

Solution (Python):
s=input()

h=""
if s[0]=="0":
    if len(s)%2==0:
        for i in range(int(len(s)/2)):
            h+="0"
            h+='1'
    else:
        for i in range(int(len(s)/2)):
            h+='0'
            h+='1'
        h+='0'
else:
    if len(s)%2==0:
        for i in range(int(len(s)/2)):
            h+="1"
            h+='0'
    else:
        for i in range(int(len(s)/2)):
            h+='1'
            h+='0'
        h+='1'

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

print(ans)

Solution (Python):

S = input()

def cnt_even(prev):
    global S
    cnt = 0

    for x, y in enumerate(list(S)):
        y = int(y)
        if prev == y:
            cnt += 1
            y = 1 if y == 0 else 0
        prev = y
    return cnt

A = cnt_even(0)
B = cnt_even(1)

print(min(A, B))

Solution (Python):
S = input()
even_black_num = 0
even_white_num = 0
odd_black_num = 0
odd_white_num = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s == "1":
            even_white_num += 1
        else:
            even_black_num += 1
    else:
        if s == "1":
            odd_white_num += 1
        else:
            odd_black_num += 1

print(min(even_black_num + odd_white_num, odd_black_num + even_white_num))

Solution (Python):


from sys import stdin






import numpy as np


data = stdin.readline().split()




data2 = str(data)[1:-1]


count1=0
count2=0
data = data[1:-1]

for i,a in enumerate(data2[1:-1]):
    a = int(a)
    if i %2 == 0:
        if a == 1:
            count1+=1
        else:
            count2+=1
    else:
        if a == 0:
            count1+=1
        else:
            count2+=1
    
if count1<count2:
    count=count1
else:
    count=count2
print(count)

Solution (Python):
def getInt(): return int(input())

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                w = cmt + ': ' + str(x)
            else:
                w = str(x)
            print(w)
        return x

def color(start, tiles):
    count = 0
    for i in range(len(tiles)):
        if i % 2 == 0 and tiles[i] != start:
            count += 1
        elif i % 2 == 1 and tiles[i] == start:
            count += 1
    return count


def prob():
    d = Debug()
    d.off()
    S = input()
    count1 = color('0', S)
    count2 = color('1', S)
    d.dmp((count1,count2),'count1,count2')
    return min(count1, count2)

ans = prob()
print(ans)

Solution (Python):
S = [int(c) for c in input()]
pairs = (len(S)+1) // 2

zeroone = 0
onezero = 0

for _ in range(pairs):

    last = S.pop()

    if last == 1:
        zeroone += 1
    else:
        onezero += 1

    if S:
        last = S.pop()
        if last == 0:
            zeroone += 1
        else:
            onezero += 1

print(min(zeroone, onezero))

Solution (Python):
S = input()
left0 = 0

left1 = 0


for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == '0':
      left1 += 1
    else:
      left0 += 1
  else:
    if S[i] == '0':
      left0 += 1
    else:
      left1 += 1
      
print(min(left1,left0))

Solution (Python):
S = str(input())
ans = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '1':
            ans += 1
    else:
        if S[i] == '0':
            ans += 1
print(min(ans, len(S)-ans))

Solution (Python):




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

Solution (Python):
s = str(input())
a = 0
b = 0


for i in range(len(s)):
    if i % 2 == 0 and int(s[i]) == 1:
        a += 1
    if i % 2 == 1 and int(s[i]) == 0:
        a += 1


for i in range(len(s)):
    if i % 2 == 0 and int(s[i]) == 0:
        b += 1
    if i % 2 == 1 and int(s[i]) == 1:
        b += 1
print(min(a, b))

Solution (Python):
S = input()
s1 = list(S)
s2 = list(S)

ans1 = 0
ans2 = 0
for i,t in enumerate(s1):
    if i%2 == 0:
        if t == "0":
            ans1 += 1
    else:
        if t == "1":
            ans1 += 1


for i,t in enumerate(s1):
    if i%2 == 0:
        if t == "1":
            ans2 += 1
    else:
        if t == "0":
            ans2 += 1
print(min (ans1,ans2))

Solution (Python):
S = input()

S_int = [int(S[i]) for i in range(len(S))]

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

print(count)

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

Solution (Python):
from collections import Counter

S = list(input())

N = len(S)
N1 = len(S[::2])
N2 = N - N1

c = Counter(S[::2])
cnt1 = abs(c['1'] - N1)
cnt2 = abs(c['0'] - N1)

c = Counter(S[1::2])
cnt1 += abs(c['0'] - N2)
cnt2 += abs(c['1'] - N2)

print(min(cnt1, cnt2))

Solution (Python):
s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))

Solution (Python):
import math
import os
import random
import re
import sys
from collections import defaultdict




def onezero(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 0:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 1:
			count += 1
	return count

def zeroone(a):
	count = 0
	for i in range(0, len(a), 2):
		if a[i] == 1:
			count += 1
	for i in range(1, len(a), 2):
		if a[i] == 0:
			count += 1
	return count


def count(n):
	return min(onezero(n),zeroone(n))

if __name__ == '__main__':
	N = [int(d) for d in input()]
	print(count(N))

Solution (Python):
s = input()
ifone = True
onecount = zerocount = 0
for i in s:
	if int(i) != int(ifone):
		onecount += 1
	else:
		zerocount += 1
	ifone = not ifone
print(min(onecount,zerocount))

Solution (Python):
S = input()

num_flip = 0 

if len(S) == 1:
    print(num_flip)


else:
    for i in range(1, len(S)):
        if S[i-1] == S[i] :
            num_flip += 1
            
            
            if S[i] == "0":
                S = S[:i] + "1" + S[i+1:]
            else:
                S = S[:i] + "0" + S[i+1:]

    print(num_flip)

Solution (Python):
def solve(n):
  cnt = 0
  for i in range(len(S)):
    if (i + n) % 2:
      if S[i] == '0':
        cnt += 1
    else:
      if S[i] == '1':
        cnt += 1
  return cnt

S = input()
print(min(solve(0), solve(1)))

Solution (Python):


















import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right



dy = [0, 0, 1, -1]
dx = [1, -1, 0, 0]
INF = float("inf")

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))

S = input()

s_one = "".join([ "0" if i % 2 == 1 else "1" for i in range(len(S))])
s_two = "".join([ "1" if i % 2 == 1 else "0" for i in range(len(S))])

ans = INF
tmp = 0
for si, oi in zip(S, s_one):
    if si != oi:
        tmp += 1

ans = min(ans, tmp)

tmp = 0
for si, oi in zip(S, s_two):
    if si != oi:
        tmp += 1

ans = min(ans, tmp)

print(ans)

Solution (Python):
S = "0b" + input()

N = len(S) - 2

A = "0b" + "10" * (N // 2) + "1" * (N % 2)
B = "0b" + "01" * (N // 2) + "0" * (N % 2)

s = int(S, 2)
a = int(A, 2)
b = int(B, 2)

num_a = bin(s ^ a).count("1")
num_b = bin(s ^ b).count("1")

print(min([num_a, num_b]))

Solution (Python):
s = input()
a = [int(b) for b in s]
c01, c10 = 0,0
for i in range(len(a)):
	d = i%2
	if a[i] != d:
		c01+=1
	else:
		c10+=1
print(c01 if c01<c10 else c10)

Solution (Python):
s = input()
len_s = len(s)
list_ans =[]
for i in range(2):
        ans = 0
        if i == 0:
                for j in range(len_s):
                                if j % 2 == 0:
                                        if s[j] == "0":
                                                ans += 1
                                else:
                                        if s[j] == "1":
                                                ans += 1
        else:
                for j in range(len_s):
                        if j % 2 == 0:
                                if s[j] == "1":
                                        ans += 1
                        else:
                                if s[j] == "0":
                                        ans += 1
        list_ans.append(ans)
print(min(list_ans))

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    S = input()

    ans = 0
    cs = int(S[0])

    for s in S[1:]:
        s = int(s)
        if s == cs:
            ans += 1
            cs = 1 - s
        else:
            cs = s

    print(ans)


main()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    S = input()
    
    l = []
    
    l.append([v for k, v in enumerate(S) if k % 2 == 0]) 
    
    l.append([v for k, v in enumerate(S) if k % 2 == 1])
    
    ans = []
    
    ans.append(l[0].count('0') + l[1].count('1'))
    
    ans.append(l[0].count('1') + l[1].count('0'))
    
    print(min(ans))
    
    
if __name__ == '__main__':
    main()

Solution (Python):
s=input()
S=list(s)
L=len(s)
s=0

if S[0]=='1':
    for i in range(0,L):
        if i%2==1:
            if S[i]=='1':
                s=s+1
            else:
                continue
        else:
            if S[i]=='0':
                s=s+1
            else:
                continue

else:
    for i in range(0,L):
        if i%2==1:
            if S[i]=='0':
                s=s+1
            else:
                continue
        else:
            if S[i]=='1':
                s=s+1
            else:
                continue

m=1
if S[0]=='1':
    for i in range(0,L):
        if i%2==1:
            if S[i]=='0':
                m=m+1
            else:
                continue
        else:
            if S[i]=='1':
                m=m+1
            else:
                continue

else:
    for i in range(0,L):
        if i%2==1:
            if S[i]=='1':
                m=m+1
            else:
                continue
        else:
            if S[i]=='0':
                m=m+1
            else:
                continue
if m>s:
    print(s)
else:
    print(m)

Solution (Python):
def main():
    s = input().rstrip()

    black_first = '0'
    white_first = '1'
    black_first_count = 0
    white_first_count = 0

    for c in s:
        if c == black_first:
            white_first_count += 1
        else:
            black_first_count += 1

        temp = black_first
        black_first = white_first
        white_first = temp
    
    print(min(black_first_count, white_first_count))
             


if __name__ == '__main__':
    main()

Solution (Python):
s = str(input())
ans1 = s[::2].count("0") + s[1::2].count("1")
ans2 = s[::2].count("1") + s[1::2].count("0")
print(min(ans1, ans2))

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

def check(s, ans):
    cnt = 0
    for i, v in enumerate(s):
        if v == ans[i]:
            cnt += 1
    return cnt

ans01 = ([0, 1] * (len(s) // 2 + 1))[:len(s)]
ans10 = ([1, 0] * (len(s) // 2 + 1))[:len(s)]
print(min(check(s, ans01), check(s, ans10)))