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 main():
    S = [int(i) for i in input()]

    counterOne = coloringColorful(0, S)
    counterZero = coloringColorful(1, S)

    print(counterOne if counterOne <= counterZero else counterZero)


def coloringColorful(preNumber, S):
    pre = preNumber
    counter = 0
    for s in S:
        if s != pre:
            pre = 1 if pre == 0 else 0
        else:
            pre = 1 if s == 0 else 0
            counter += 1

    return counter


if __name__ == '__main__':
    main()

Solution (Python):
mojiretu = input()
nagasa = len(mojiretu)

zero_ichi = ''
ichi_zero = ''

for i in range(nagasa):
    if i % 2 == 0:
        zero_ichi += '0'
        ichi_zero += '1'
    if i % 2 == 1:
        zero_ichi += '1'
        ichi_zero += '0'

counter_0 = 0
counter_1 = 0
for i in range(nagasa):
    if zero_ichi[i] != mojiretu[i]:
        counter_0 += 1
    if ichi_zero[i] != mojiretu[i]:
        counter_1 += 1

if counter_0 <= counter_1:
    print(counter_0)
else:
    print(counter_1)

Solution (Python):
l = input()
m = []
mx = []
for x in range(len(l)):
    m.append(str(int(x % 2)))
    mx.append(str(abs(int(x % 2) - 1)))
l = list(l)
mng = 0
mxng = 0
for i in range(len(l)):
    if m[i] != l[i]:
        mng += 1
    if mx[i] != l[i]:
        mxng += 1
print(mng if mng <= mxng else mxng)

Solution (Python):
S = input()

cnt1 = 0
cnt2 = 0

nc = '0'
for c in S :
    if c != nc :
        cnt1 += 1
    
    if nc == '0' :
        nc = '1'
    else :
        nc = '0'
        
nc = '1'
for c in S :
    if c != nc :
        cnt2 += 1
    
    if nc == '0' :
        nc = '1'
    else :
        nc = '0'
        
print(min(cnt1, cnt2))

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

to_z = [z for z in s[0::2] if z == '1']
to_o = [o for o in s[1::2] if o == '0']
a = len(to_z) + len(to_o)
to_z = [z for z in s[1::2] if z == '1']
to_o = [o for o in s[0::2] if o == '0']
b = len(to_z) + len(to_o)
if a < b:
    print(a)
else:
    print(b)

Solution (Python):
s=list(input())
m=0
if s[0]=="0":
    for i in range(1,len(s),2):
        if s[i]=="0":
            m+=1
    for i in range(2,len(s),2):
        if s[i]=="1":
            m+=1
if s[0]=="1":
    for i in range(1,len(s),2):
        if s[i]=="1":
            m+=1
    for i in range(2,len(s),2):
        if s[i]=="0":
            m+=1
print(m)

Solution (Python):

import sys



def solve(lines):
    S = lines.pop(0)
    L = R = 0
    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == '0':
                L += 1
            else:
                R += 1
        else:
            if s == '1':
                L += 1
            else:
                R += 1
    print(min(L,R))
    
lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Solution (Python):
add_flag = False
tiles = input()
if tiles.__len__() % 2 != 0:
    tiles += "0"
    add_flag = True
pair_tiles_list = [tiles[i: i + 2] for i in range(0, len(tiles), 2)]
base_pair = ""
count = 0
if pair_tiles_list.count("01") < pair_tiles_list.count("10"):
    base_pair = "10"
else:
    base_pair = "01"
if add_flag:
    pair_tiles_list[-1] = pair_tiles_list[-1][0]
for pair in pair_tiles_list:
    if pair != base_pair:
        if pair[0] != base_pair[0]:
            count += 1
        if pair.__len__() > 1:
            if pair[1] != base_pair[1]:
                count += 1
print(count)

Solution (Python):
color_str = input()
color_str_arr = list(color_str)

count_a = 0
count_b = 0

color_pattern = ['0', '1']

index_a = 0
index_b = 1

for color in color_str_arr:
    if color != color_pattern[index_a]:
        count_a += 1
    if color != color_pattern[index_b]:
        count_b += 1
    index_a = 1 - index_a
    index_b = 1 - index_b

min_count = count_a if count_a < count_b else count_b

print(min_count)

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

p1 = ""
p2 = ""
for i in range(N):
    if i % 2 == 0:
        p1+=str(0)
        p2+=str(1)
    else:
        p1+=str(1)
        p2+=str(0)



a1 = 0
a2 = 0
for i in range(N):
    if p1[i] != S[i]:
        a1 += 1
    if p2[i] != S[i]:
        a2 += 1

print(min(a1,a2))

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

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

even_1 = sum(even)
even_0 = len(even) - even_1
odd_1 = sum(odd)
odd_0 = len(odd) - odd_1

ans = 0
if even_0 + odd_1 <= even_1 + odd_0:
    ans = even_0 + odd_1
else:
    ans = even_1 + odd_0

print(ans)

Solution (Python):
s=list(input())
n=len(s)
for i in range(n):
  s[i]=int(s[i])
n=len(s)
a=[0]*n
b=[0]*n
cnta=0
cntb=0

for i in range(n):
  if i%2==1:
    a[i]=1
    if a[i]!=s[i]:
      cnta+=1
  else:
    if a[i]!=s[i]:
      cnta+=1

for j in range(n):
  if j%2==0:
    b[j]=1
    if b[j]!=s[j]:
      cntb+=1
  else:
    if b[j]!=s[j]:
      cntb+=1

if cnta<cntb:
  print(cnta)
else:
  print(cntb)

Solution (Python):
S = input()

count = 0
a = int(S[0])
b = 0 if a == 1 else 1

for i in range(1,len(S)):
    color = int(S[i])
    if i % 2 == 1 and color !=b:
        count += 1
    elif i % 2 == 0 and color != a:
        count += 1
print(count)

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

Solution (Python):
x = input()
count = 0
if x[0] == '1':
  for i in range(1, len(x)):
    if i % 2 == 1 and x[i] != '0':
      count = count + 1
    elif i % 2 == 0 and x[i] != '1':
      count = count + 1
else:
  for i in range(1, len(x)):
    if i % 2 == 1 and x[i] != '1':
      count = count + 1
    elif i % 2 == 0 and x[i] != '0':
      count = count + 1
print(count)

Solution (Python):
s = [int(i) for i in list(input())]
count = 0
pre = -1
for x in s:
    if x == pre:
        count = count + 1
        pre = (pre+1) % 2
    else:
        pre = x

print(count)

Solution (Python):
S = list(input())
import copy
S1 = copy.copy(S)
S1[0] = '0' if S1[0] == '1' else '1'
ans = 0
ans1 = 1
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        S[i] = '0' if S[i-1] == '1' else '1'
        ans+=1
    

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

print(min(ans, ans1))

Solution (Python):
import numpy as np

S = np.array([int(s) for s in input()])
p1 = np.tile(np.arange(2), len(S) // 2 + 1)[:len(S)]
p2 = np.tile([1,0], len(S) // 2 + 1)[:len(S)]

c1 = np.abs(S - p1).sum()
c2 = np.abs(S - p2).sum()

print(min(c1, c2))

Solution (Python):
S = input()
n = len(S)
T = ['{}'.format(i % 2) for i in range(n)]
tmp = 0
for i in range(n):
    if S[i] == T[i]:
        tmp += 1
if tmp >= n - tmp:
    ans = n - tmp
else:
    ans = tmp
print(ans)

Solution (Python):
S = str(input())
BW, WB = 0, 0
for n in range(0, len(S)):
    if n % 2 == 0:
        
        if S[n] == "0":
            
            WB += 1
        else:
            
            BW += 1
    else:
        
        if S[n] == "0":
            
            BW += 1
        else:
            
            WB += 1

if BW < WB:
    print(BW)
else:
    print(WB)

Solution (Python):
a=str(input())
n=len(a)
def hamming_dis(b,c,n):
    count=0
    for i in range(n):
        if b[i]!=c[i]:
            count+=1
    return count
c=[0]*n
d=[1]*n
e=''
f=''
for i in range(0,n,2):
    c[i]=1
    d[i]=0
for i in range(0,n):
    e=e+str(c[i])
    f=f+str(d[i])
s=hamming_dis(a,e,n)
t=hamming_dis(a,f,n)
print(min(s,t))

Solution (Python):
m = str(input())
n = len(m)
s = 0

for i in range(0, n):
    if(i % 2 == 0) and (m[i] == "0"):
        s += 1
    if(i % 2 == 1) and (m[i] == "1"):
        s += 1

if(2 * s > n):
    s = n - s
    
print(s)

Solution (Python):
colors = [int(i) for i in list(input())]

def func(colors):
  count = 0
  prev_color = colors[0]
  for i in range(1, len(colors)):
    if colors[i] == prev_color:
      colors[i] = 1 if prev_color == 0 else 0
      count += 1
    prev_color = colors[i]
  return count

print(max(func(colors), func(list(reversed(colors)))))

Solution (Python):
S = [i for i in input()]
S2=S[:]
result1=0
result2=0
for i in range(len(S)-1):
	if S[i] ==S[i+1]:
		S[i+1] = '0' if S[i] == '1' else '1'
		result1 += 1
for i in range(len(S2)-1,0,-1):
	if S2[i] == S2[i-1]:
		S2[i-1] = '0' if S2[i] == '1' else '1'
		result2 += 1
print(min(result1,result2))

Solution (Python):
S = input()
N = len(S)
if N % 2 == 0:
    S1 = "10"*round((N/2))
    S2 = '01'*round((N/2))
else:
    S1 = "10"*round((N/2))+'1'
    S2 = '01'*round((N/2))+'0'

s1 = N - sum([a==b for a, b in zip(S,S1)])
s2 = N - sum([a==b for a, b in zip(S,S2)])
print(min(s1,s2))

Solution (Python):
S = input()
n = len(S)
i = n-1
B = ["0","1"]
n0,n1,b = 0,0,0
while i>=0:
  if S[i]==B[b] : n0+=1
  else : n1+=1
  b = 1-b
  i -= 1
if n0>n1 : print(n1)
else : print(n0)

Solution (Python):
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

S = read_str()
N = len(S)

def solve():
    ans = 0
    if N == 1:
        return ans
    ans_01 = 0
    ans_10 = 0
    
    for i in range(-(-N//2)):
        if i * 2 == N - 1:
            if S[2*i] == '1': ans_01 += 1
        else:
            if S[2*i:2*i + 2] == '00' or S[2*i:2*i + 2] == '11':
                ans_01 += 1
            elif S[2*i:2*i + 2] == '10':
                ans_01 += 2
    
    for i in range(-(-N//2)):
        if i * 2 == N - 1:
            if S[2*i] == '0': ans_10 += 1
        else:
            if S[2*i:2*i + 2] == '00' or S[2*i:2*i + 2] == '11':
                ans_10 += 1
            elif S[2*i:2*i + 2] == '01':
                ans_10 += 2
    ans = min(ans_01, ans_10)
    return ans


if __name__ == "__main__":
    print(solve())

Solution (Python):

S = input()
t = len(S)
ans = 0

for i in range(t):
  if S[i:i+1] in S[i+1:i+2]:
    ans +=1
    if S[i+1:i+2] in "0":
      S = S[:i+1]+"1"+S[i+2:] 
    else:
      S = S[:i+1]+"0"+S[i+2:] 
    
print(ans)

Solution (Python):

S = input()

ans = 0

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


z = sum(x == '1' for x in S[0::2]) + sum(x == '0' for x in S[1::2])


o = sum(x == '0' for x in S[0::2]) + sum(x == '1' for x in S[1::2])


print(min(z, o))

Solution (Python):
S = list(input())
s_1 = S[0::2]
s_2 = S[1::2]
s_1_w = s_1.count('0')
s_2_w = s_2.count('0')
s_1_b = s_1.count('1')
s_2_b = s_2.count('1')

if s_1_w+s_2_b <= s_1_b+s_2_w:
  print(s_1_w+s_2_b)
elif s_1_b+s_2_w <= s_1_w+s_2_b:
  print(s_1_b+s_2_w)

Solution (Python):
S = input()
count = 0
for i in range(1,len(S)):
	if int(S[i]) != (int(S[0])+i)%2:
		count+=1
if count > len(S)//2 :
	count = len(S)-count
print(count)

Solution (Python):
s = str(raw_input())
count0 = 0
for i in range(int(len(s)/2)):
	if s[2*i] == '0':
		count0 += 1
	if s[2*i+1] == '1':
		count0 += 1
if len(s) % 2 == 1:
	if s[-1] == '0':
		count0 += 1
print min(count0, len(s)-count0)

Solution (Python):

S = input()

res = 0
t = '0'
for s in S:
    if s != t:
        res += 1
    if t == '0':
        t = '1'
    else:
        t = '0'
res_1 = res

res = 0
t = '1'
for s in S:
    if s != t:
        res += 1
    if t == '0':
        t = '1'
    else:
        t = '0'
res_2 = res

if res_1 >= res_2:
    print(res_2)
else:
    print(res_1)

Solution (Python):
def main():
    S = input()
    odd_cnt = [0,0]
    even_cnt = [0,0]

    for i in range(len(S)):
        if i % 2 == 0 and S[i] == '0':
            even_cnt[0] += 1
        elif i % 2 == 0 and S[i] == '1':
            even_cnt[1] += 1
        elif i % 2 == 1 and S[i] == '0':
            odd_cnt[0] += 1
        elif i % 2 == 1 and S[i] == '1':
            odd_cnt[1] += 1

    if even_cnt[0] + odd_cnt[1] < even_cnt[1] + odd_cnt[0]:
        print(even_cnt[0] + odd_cnt[1])
    else:
        print(even_cnt[1] + odd_cnt[0])


if __name__ == '__main__':
    main()

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

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

c = 0
for i in s:
    if i == '0' and flag:
        flag = not flag
    elif i == '1' and not flag:
        flag = not flag
    else:
        flag = not flag
        c += 1

print(c)

Solution (Python):
from sys import stdin
S = stdin.readline().rstrip()

N = len(S)
s0 = ''
s1 = ''
c0 = 0
c1 = 0
for itr in range(0,N):
    if itr%2 == 0:
        s0 += "0"
        s1 += "1"
    else:
        s0 += "1"
        s1 += "0"



for itr in range(0,N):
    if S[itr] != s0[itr]: c0 += 1
    if S[itr] != s1[itr]: c1 += 1


if c0 >= c1:
    print(c1)
else:
    print(c0)

Solution (Python):
S = list(input())
ans = 0
if S[0] == '0':
    for i in range(1,len(S),2):
        if S[i] == '0':
            ans += 1
    for i in range(2,len(S),2):
        if S[i] == '1':
            ans += 1

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

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

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

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


def generator(length, prev):
    start = prev
    dic = {'0':'1', '1':'0'}
    while len(start) < length:
        next = dic[prev]
        start += next
        prev = next

    return start

first_zero = generator(N, '0')
first_one = generator(N, '1')

cnt_zero = 0
for i in range(N):
    if first_zero[i] == S[i]:
        cnt_zero += 1


cnt_one = 0
for i in range(N):
    if first_one[i] == S[i]:
        cnt_one += 1

print(min(cnt_zero, cnt_one))

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

for i in range(len(s)-1):
    if s[i] == 1 and s[i+1] == 1:
        s[i+1] = 0
        c += 1
    elif s[i] == 0 and s[i+1] == 0:
        s[i+1] = 1
        c += 1

print(c)

Solution (Python):
import sys

a=input()
count1=0
count2=0
for x in range(len(a)):
    if x%2==0:
        if a[x] != "0":
            count1=count1+1
    else:
        if a[x] != "1":
            count1=count1+1
for x in range(len(a)):
    if x%2==0:
        if a[x] != "1":
            count2=count2+1
    else:
        if a[x] != "0":
            count2=count2+1
        
if count1>count2:
    print(count2)
    sys.exit()
print(count1)

Solution (Python):
S = input()

p = [0, 0]
for i, c in enumerate(S):
	p[0] += 0 if i % 2 == int(c) else 1
	p[1] += 1 if i % 2 == int(c) else 0
print(min(p))

Solution (Python):
S = [x for x in input()]
N = len(S)

T1_ = "0"
T2_ = "1"

c1 = c2 = 0

for i in range(N):
    if T1_ == "0":
        T1 = "1"
    if T1_ == "1":
        T1 = "0"
    if T2_ == "0":
        T2 = "1"
    if T2_ == "1":
        T2 = "0"
    if S[i] != T1:
        c1 += 1
    if S[i] != T2:
        c2 += 1

    T1_ = T1
    T2_ = T2

print(min(c1, c2))

Solution (Python):
s = [int(i) for i in list(input())]
n = len(s)
start0 = []
start1 = []
for i in range(n):
    if i % 2 == 0:
        start0.append(0)
        start1.append(1)
    else:
        start0.append(1)
        start1.append(0)

idx = 0
tmp0 = 0
tmp1 = 0
for i in s:
    if i != start0[idx]:
        tmp0 += 1
    if i != start1[idx]:
        tmp1 += 1
    idx += 1

print(min(tmp0,tmp1))

Solution (Python):

s = input()

diffBlackWhite = 0
diffWhiteBlack = 0
index = 0
for c in s:
  if index % 2 == 0:
    if c == '0':
      diffWhiteBlack += 1
    else:
      diffBlackWhite += 1
  else:
    if c == '0':
      diffBlackWhite += 1
    else:
      diffWhiteBlack += 1
  index += 1

print(min(diffBlackWhite, diffWhiteBlack))

Solution (Python):
s = input()
s1 = ''
s2 = ''
s1s = '0'
s2s = '1'
dems1 = 0
dems2 = 0
for i in range(len(s)):
    s1+=s1s
    if s1s != s[i]:
        dems1+=1
    tam = s1s
    s1s = s2s
    s2+=s2s
    if s2s != s[i]:
        dems2+=1
    s2s = tam
print(min(dems1,dems2))

Solution (Python):
s=input()
lists=list(s)
lists=list(map(int,lists))
a=len(lists)
li=[0]*a
for i in range (0,a):
  if i%2==0:
    li[i]=1
counts=0
for j in range (0,a):
  if li[j]==lists[j]:
    counts=counts+1
if counts>=(a-counts):
  print(a-counts)
else:
  print(counts)

Solution (Python):
s = str(input())
bk = 0
wk = 0
bg = 0
wg = 0
k = s[::2]
g = s[1::2]
bk = k.count('0')
wk = k.count('1')
bg = g.count('0')
wg = g.count('1')
if bk + wg > wk + bg:
  print(wk + bg)
else:
  print(bk + wg)

Solution (Python):
S=input()
Sgusu=[S[i] for i in range(0,len(S),2)]
Skisu=[S[i] for i in range(1,len(S),2)]
answer1=Sgusu.count("1")+Skisu.count("0")
answer2=Sgusu.count("0")+Skisu.count("1")
answer=min([answer1,answer2])
print(answer)

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

if len(s) % 2 == 0:
  ideal1 = '01' * int(l / 2)
  ideal2 = '10' * int(l / 2)
else:
  ideal1 = '01' * (l // 2) + '0'
  ideal2 = '10' * (l // 2) + '1'

cnt1, cnt2 = 0, 0

for si, i1i, i2i in zip(s, ideal1, ideal2):
  if si != i1i:
    cnt1 += 1
  if si != i2i:
    cnt2 += 1
    
print(min(cnt1, cnt2))

Solution (Python):
n = input ()
m = list(n)
cnt = 0
for i in range(len(m)-1):
  if m[i] != m[i+1] :
    pass
  elif m[i] == m[i+1] and m[i] == '0':
    m[i+1] = '1'
    cnt += 1
  elif m[i] == m[i+1] and m[i] == '1':
    m[i+1] = '0'
    cnt += 1
print(cnt)

Solution (Python):
def main():

    S = input()

    n = len(S)

    candid0 = [i % 2 for i in range(n)]
    candid1 = [1 - (i % 2) for i in range(n)]

    count0 = 0
    count1 = 0
    for i in range(n):
        if int(S[i]) == candid0[i]:
            count0 += 1
        if int(S[i]) == candid1[i]:
            count1 += 1

    print(min(count0, count1))


main()

Solution (Python):
s = input() 


difCount = 0
col = 1 
for i in range(len(s)):
  if s[i:i+1] != str(col): 
    difCount += 1
  col = abs(col - 1)
  
print(min(difCount,len(s)-difCount))

Solution (Python):
s=str(input())
acont=0 
bcont=0 
for i in range(len(s)):
	if i%2==0:
		if s[i]=="0":
			bcont+=1
		else:
			acont+=1
	if i%2==1:
		if s[i]=="0":
			acont+=1
		else:
			bcont+=1
print(min(acont,bcont))

Solution (Python):

"""
Created on Sat Apr 13 09:53:07 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""
S = str(input())

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

    for i in range(len(S)):
        if int(S[i]) != i%2:
            cnt_01 +=1
    print(min(cnt_10, cnt_01))
    
 
if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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 = input()
count_o = 0
count_z = 0

for i in range(0, len(s), 2):
	if s[i] == '1':
		count_o += 1
	else :
		count_z += 1
	if i + 1 < len(s):
		if s[i+1] == '0':
			count_o += 1
		else :
			count_z += 1
print(min(count_z, count_o))

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

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

Solution (Python):
S = input()

'''
考え方

1.奇数番目、偶数番目に0,1のいずれが何個多いのか、を確認する。
1-1.それぞれ0,1,と異なる数字の方が多く出現する。
それぞれの奇数＆偶数番目の少数派の数字を合わせる。

1-2.奇数・偶数共に同じ数字が多く出現する
多く出現する方をその数字に合わせる。
'''

len_S = len(S)


odd_0 = 0
for s in range(0,len_S,2):
  if S[s] == '0':
    odd_0 += 1


even_0 = 0
for s in range(1,len_S,2):
  if S[s] == '0':
    even_0 += 1


import math
odd_1 = math.ceil(len_S / 2) - odd_0
even_1 = math.floor(len_S / 2) - even_0



if odd_0 >= odd_1:
  
  if odd_0 <= even_0:
    ans = even_1 + odd_0
  
  else:
    ans = even_0 + odd_1

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

Solution (Python):
import sys

S = input()

if len(S) == 1:
    print(0)
    sys.exit()


def f(i):
    ans = 0
    for s in range(len(S)):
        if int(S[s]) != i % 2:
            ans += 1
        i += 1
    return ans


print(min(f(0), f(1)))

Solution (Python):
a = input()
b = []
c = []
bb = 0
cc = 0
for i in range(len(a)):
    if i % 2 == 0:
        b.append("0")
    else:
        b.append("1")
for i in range(len(a)):
    if i % 2 == 0:
        c.append("1")
    else:
        c.append("0")
for i in range(len(a)):
    if a[i] != b[i]:
        bb += 1
for i in range(len(a)):
    if a[i] != c[i]:
        cc += 1
print(min(bb, cc))

Solution (Python):
S=list(input())
S1 = S[:]
S2 = S[:]
N=len(S)
output=0
n1=0
n2=0
if N>1:
    for i in range(1,N):
        if int(S1[i])==int(S1[i-1]):
            S1[i]=str(1-int(S1[i]))
            n1 += 1
    n2 += 1
    S2[0]=str(1-int(S2[0]))
    for i in range(1,N):
        if int(S2[i])==int(S2[i-1]):
            S2[i]=str(1-int(S2[i]))
            n2 += 1

    output = min(n1,n2)

print(output)

Solution (Python):
S = input()

SO = S[::2]  
SE = S[1::2] 

SOC0 = SO.count("0")
SOC1 = SO.count("1")
SEC0 = SE.count("0")
SEC1 = SE.count("1")


print(min(SOC0+SEC1, SOC1+SEC0))

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

s_ = "10"*(l//2) + "1"*(l%2)

x = 0
for a,b in zip(s, s_):
    if a != b:
        x += 1

if x > l/2:
    x = l-x

print(x)

Solution (Python):
def bc(x):
  return bin(x).count("1")

n = input()
s = int('0b' + n, 2)
m1 = ('01' * len(n))[:len(n)]
m2 = ('10' * len(n))[:len(n)]
b1 = int('0b' + m1, 2)
b2 = int('0b' + m2, 2)

c1 = s ^ b1
c2 = s ^ b2

print(min(bc(c1), bc(c2)))

Solution (Python):
s = list(map(int, input()))
s = list(map(bool, s))
should = not s[0]
counter = 0

for color in s[1:]:
    if not color == should:
        counter += 1
    should = not should
print(counter)

Solution (Python):
S = input()
slist = []
for i in S:
    slist.append(i)

ans = 0

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

Solution (Python):

n=list((input()))  

n = [int(s) for s in n]
count = 0

for i in range(len(n)-1):
    onezero = n[i]
    
    if onezero == n[i+1]:
        count += 1
        if n[i+1] == 0:
            n[i+1] = 1
        else:
            n[i+1] = 0

        
print(count)

Solution (Python):
import math

S = input()

n = len(S)

case1 = [0, 1] * int(math.floor(n/2))
case2 = [1, 0] * int(math.floor(n/2))

if n % 2 == 1:
    case1.append(0)
    case2.append(1)





c1 = 0
c2 = 0
for i in range(n):
    if int(S[i]) != case1[i]:
        c1 += 1
    if int(S[i]) != case2[i]:
        c2 += 1

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

Solution (Python):
from collections import Counter

S = input()
s_o = S[::2]
s_e = S[1::2]

cnt_o = Counter(s_o).most_common(1)
cnt_e = Counter(s_e).most_common(1)

if len(S) == 1:
    print(0)
else:
    if cnt_o[0][1] >= cnt_e[0][1] and cnt_o[0][0] == '0':
        print(s_o.count('1')+s_e.count('0'))
    elif cnt_o[0][1] >= cnt_e[0][1] and cnt_o[0][0] == '1':
        print(s_o.count('0')+s_e.count('1'))
    elif cnt_o[0][1] < cnt_e[0][1] and cnt_e[0][0] == '0':
        print(s_o.count('0')+s_e.count('1'))
    else:
        print(s_o.count('1')+s_e.count('0'))

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

tmp = 0
tmp2 = 0

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

Solution (Python):
S2 = input()
N = len (S2)
Z2 = '0'
O2 = '1'
for i in range(1,N):
    if (i+1)%2==0:
        Z2+='1'
        O2+='0'
    else:
        Z2+='0'
        O2+='1'

S10 = int(S2,2)
Z10 = int(Z2,2)
O10 = int(O2,2)
ChangeSZ=bin(S10^Z10).count('1')
ChangeSO=bin(S10^O10).count('1')
print(min(ChangeSZ,ChangeSO))

Solution (Python):
def get_next_expect_color(color) :
    if (color == "1") :
        return "0"
    else :
        return "1"

S = input()

must_reversed_count = 0
expect_color = S[0]

must_reversed_count2 = 1 
expect_color2 = get_next_expect_color(S[0])

for i in range(1,len(S)) :
    if (S[i] == expect_color) :
        must_reversed_count += 1
    
    if (S[i] == expect_color2) :
        must_reversed_count2 += 1

    expect_color = get_next_expect_color(expect_color)
    expect_color2 = get_next_expect_color(expect_color2)



print(min([must_reversed_count,must_reversed_count2]))

Solution (Python):
s=input()
lst = list(s)
l=[]
for i in range(len(lst)):
    l.append(int(lst[i]))

cnt=0

if l[0]==0:
    for i in range(len(l)):
        if i%2==0:
            if l[i]==1:
                cnt+=1
        else:
            if l[i]==0:
                cnt+=1
else:
    for i in range(len(l)):
        if i%2==0:
            if l[i]==0:
                cnt+=1
        else:
            if l[i]==1:
                cnt+=1

print(cnt)

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

Solution (Python):
s = input()
n = len(s)
count = 0
for i in range(n):
  count += int(int(s[i]) != i%2)
print(min(count, n-count))

Solution (Python):
S = input()
cnt = [[0,0],[0,0]]
for i, s in enumerate(S):
    x = int(i) % 2
    y = int(s)
    cnt[x][y] += 1
if cnt[0][0] > cnt[1][0]:
    print(cnt[0][1] + cnt[1][0])
else:
    print(cnt[0][0] + cnt[1][1])

Solution (Python):
S = input()
res = [0, 0]
flag = 0
while(S != ""):
    res[abs(int(S[0]) - flag)] += 1
    S = S[1:]
    flag = 1 - flag
print(min(res[0], res[1]))

Solution (Python):

S = input()
x = y = ''
for i in range(len(S)):
    if i % 2 == 0:
        x += S[i]
    else:
        y += S[i]

c1 = x.count('1') + y.count('0')
c2 = x.count('0') + y.count('1')
print(min(c1, c2))

Solution (Python):
N=input()
count = 0

for i in range(len(N)):
    P = int(N[i])
    if i%2 == 0:
        if P == 1:
            count += 1
    else:
        if P == 0:
            count += 1
N =str(N)
print(min([count,len(N)-count]))

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

if __name__ == '__main__':
    main()

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

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

print(x)

Solution (Python):

colors = input()

start_0 = 0
start_1 = 0

for i in range(len(colors)):
	color = int(colors[i])
	if i % 2:
		if color == 1:
			start_0 += 1
		else:
			start_1 += 1
	else:
		if color == 1:
			start_1 += 1
		else:
			start_0 += 1

print(min(start_0, start_1))

Solution (Python):
S = input()

odd = []
even = []

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


count = 0
if sum(even) == sum(odd):
    if len(even) > len(odd):
        count = len(odd) - sum(odd) + sum(even)
    else:
        count = len(even) - sum(even) + sum(odd)
elif sum(even) > sum(odd):
    count = len(even) - sum(even) + sum(odd)
else:
    count = len(odd) - sum(odd) + sum(even)

print(count)

Solution (Python):
import numpy as np


S = [True if i == '1' else False for i in list(input())]

pat1 = [True, False] * (len(S) // 2)
pat2 = [False, True] * (len(S) // 2)
if len(S) % 2 == 1:
    pat1.append(True)
    pat2.append(False)

print(min(
    np.sum(np.logical_xor(S, pat1) == False),
    np.sum(np.logical_xor(S, pat2) == False)
))

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

Solution (Python):
S = input()

Se = [s for i, s in enumerate(S) if i % 2 == 0]
So = [s for i, s in enumerate(S) if i % 2 == 1]
result = min(Se.count('0') + So.count('1'), Se.count('1') + So.count('0'))
print(result)

Solution (Python):
S = list(str(input()))
ini0,ini1 = 0,0
for i,s in enumerate(S):
    if i%2 == 0:
        if s == '0':
            ini1 += 1
        else:
            ini0 += 1
    else:
        if s == '0':
            ini0 += 1
        else:
            ini1 += 1
print(min(ini0,ini1))