Problem:


Score : 300 points

Problem Statement

N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N.

The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1.

You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors.

At least how many tiles need to be repainted to satisfy the condition?

Constraints

1 \leq |S| \leq 10^5

S_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the minimum number of tiles that need to be repainted to satisfy the condition.

Sample Input 1

000

Sample Output 1

1

The condition can be satisfied by repainting the middle tile white.

Sample Input 2

10010010

Sample Output 2

3

Sample Input 3

0

Sample Output 3

0



Sample input:
000


Sample output:
1

Submission status: Accepted

Solution code:
s = list(str(input()))
S = []
for i in range(len(s)):
  S.append(int(s[i]))
ans1 = 100000
ans2 = 100000
ans = 0
t = 0
s = 0

if S[0]==0:
  for i in range(1,len(S),2):
    if S[i] != 1:
      t += 1
  for i in range(0,len(S),2):
    if S[i] != 0:
      s += 1
  ans1 = min(t+s,len(S)-t-s)
else:
  for i in range(1,len(S),2):
    if S[i] != 0:
      t += 1
  for i in range(0,len(S),2):
    if S[i] != 1:
      s += 1
  ans2 = min(t+s,len(S)-t-s) 
ans=min(ans1,ans2)
print(ans)

Submission status: Accepted

Solution code:
s=input()
p=int(''.join(map(str,[i%2 for i in range(1,len(s)+1)])),2)
print(min(bin(int(s,2)^n).count('1')for n in[p,p>>1]))

Submission status: Accepted

Solution code:
s = input()
p = int(''.join(map(str, [i % 2 for i in range(1, len(s) + 1)])), 2)
print(min(bin(int(s, 2) ^ n).count('1') for n in [p, p >> 1]))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
t = int(s, 2)

l = [i % 2 for i in range(1, n + 1)]
b = ''.join(map(str, l))

p = int(b, 2)
q = p >> 1

a = bin(t ^ p).count('1')
b = bin(t ^ q).count('1')

print(min(a, b))

Submission status: Accepted

Solution code:
s = input()
b = ''.join(map(str, [i % 2 for i in range(1, len(s) + 1)]))
p = int(b, 2)
q = p >> 1
print(min(bin(int(s, 2) ^ n).count('1') for n in [p, q]))

Submission status: Accepted

Solution code:
s = input()
t = int(s, 2)
b = ''.join(map(str, [i % 2 for i in range(1, len(s) + 1)]))
p = int(b, 2)
q = p >> 1
print(min(bin(t ^ n).count('1') for n in [p, q]))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
s = int(S, 2)
b = ''.join(map(str, [i % 2 for i in range(1, n + 1)]))
p = int(b, 2)
q = p >> 1
print(min(bin(s ^ n).count('1') for n in [p, q]))

Submission status: Accepted

Solution code:
S = input()
n = len(S)
s = int(S, 2)
b = ''.join(map(str, [i % 2 for i in range(n)]))
p = int(b, 2)
q = int(b[1:] + str(int(b[-1]) ^ 1), 2)
print(min(bin(s ^ n).count('1') for n in [p, q]))

Submission status: Accepted

Solution code:
s = input()
print(min(sum(1 if ord(s[i])==i%2+48 else 0 for i in range(len(s))),sum(0 if ord(s[i])==i%2+48 else 1 for i in range(len(s)))))

Submission status: Accepted

Solution code:
s = input()
s1, s2 = s[::2], s[1::2]
bwr1, bwr2 = (s1.count('0'), s1.count('1')), (s2.count('0'), s2.count('1'))
print(min(bwr1[1] + bwr2[0], bwr1[0] + bwr2[1]))

Submission status: Accepted

Solution code:
s=input()
even=list(s[::2])
odd=list(s[1::2])
ans1=sum(i!='0' for i in even)+sum(i!='1' for i in odd)
ans2=sum(i!='1' for i in even)+sum(i!='0' for i in odd)
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
S_list = list(S)
S_length = len(S)
Count = 0

for i in range(S_length-1):
    if S_list[i] == S_list[i+1]:
        Count += 1
        if S_list[i+1] == "0":
            S_list[i+1] = "1"
        else:
            S_list[i+1] = "0"
    else:
        continue

print(Count)

Submission status: Accepted

Solution code:
S = input()
count = 0
m = S[0]
for s in S[1:]:
    if s == m:
        count += 1
        m = "1" if s == "0" else "0"
    else:
        m = s
print(count)

Submission status: Accepted

Solution code:
# C - Coloring Colorfully

S = input()

ans1 = 0
ans2 = 0


# 010101...

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

# 101010...

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

Submission status: Accepted

Solution code:
S = input()

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

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

print(min(cnt1,cnt2))

Submission status: Accepted

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

cnt = 0

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

	else:
		if s[i] == "1" :
			cnt += 1

cnt_r = 0

for j in range(l):
	if j % 2 == 0 :
		if s[j] == "1" :
			cnt_r += 1

	else:
		if s[j] == "0" :
			cnt_r += 1

print(min(cnt, cnt_r))

Submission status: Accepted

Solution code:
S = input()
A = []
ans =0
for i in range(len(S)) :
    if i%2 == 0 :
        A.append(1)
    else :
        A.append(0)
for i in range(len(S)) :
    if int(S[i]) != int(A[i]) :
        ans +=1
print(min(ans, len(S)-ans))

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))
s0 = s[::2]
s1 = s[1::2]
x0 = sum(s0)
x1 = sum(s1)
print(min(x0 + len(s1) - x1, x1 + len(s0) - x0))

Submission status: Accepted

Solution code:
s = input()
o1e0 = 0
o0e1 = 0

for n, i in enumerate(s):
    if n % 2 == 0:
        if i == "0":
            o1e0 += 1
        else:
            o0e1 += 1

    else:
        if i == "1":
            o1e0 += 1
        else:
            o0e1 += 1

print(min(len(s) - o1e0, len(s) - o0e1))

Submission status: Accepted

Solution code:
s=input()
tmp=0

count=0
for i in s:
	if i!=str(tmp):
		count+=1
	tmp=1-tmp

tmp=1
ccount=0
for i in s:
	if i!=str(tmp):
		ccount+=1
	tmp=1-tmp

print(min(count,ccount))

Submission status: Accepted

Solution code:
S = input()
count = 0
for i, c in enumerate(S):
    if c == "0" and i % 2 == 0:
        count += 1
    if c == "1" and i % 2 == 1:
        count += 1
print(min(len(S)-count, count))

Submission status: Accepted

Solution code:
def solve(s):
    n = len(s)
    best = n
    for flip in range(2):
        cnt = 0
        for i in range(n):
            if (i+flip) % 2 == 0:
                if s[i] == '1':
                    cnt += 1
            else:
                if s[i] == '0':
                    cnt += 1
        best = min(best, cnt)
    return best

s = input()
print(solve(s))

Submission status: Accepted

Solution code:
S = str(input())



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

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

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

Submission status: Accepted

Solution code:
S = input()
length = len(S)

ans1, ans2 = 0, 0

# even: 0, odd: 1
for i in range(length):
    if i % 2 == 0 and S[i] == '0':
        pass
    elif i % 2 == 1 and S[i] == '1':
        pass
    else:
        ans1 += 1

for i in range(length):
    if i % 2 == 0 and S[i] == '1':
        pass
    elif i % 2 == 1 and S[i] == '0':
        pass
    else:
        ans2 += 1
        
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
Sarr = tuple(map(int, list(input())))

x = 0
c = 0
for i in Sarr:
  c += (x ^ i)
  x = x ^ 1

print(min(len(Sarr) - c, c))

Submission status: Accepted

Solution code:
S=input()
n=len(S)
A='01'*(n//2)+'0'*(n%2)
B='10'*(n//2)+'1'*(n%2)
a=0
b=0
for i in range(n):
    if S[i]!=A[i]: a+=1
    if S[i]!=B[i]: b+=1
print(min(a,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

even_s = ''
odd_s = ''
for i in range(len(s)):
    if i & 1:
        odd_s += s[i]
    else:
        even_s += s[i]

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

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

print(min(odd_1_count + even_0_count, odd_0_count + even_1_count))

Submission status: Accepted

Solution code:
s=list(map(int,list(str(input()))))
a=s[:: 2]
b=s[1:: 2]
c=a.count(1)+b.count(0)
d=a.count(0)+b.count(1)
print(min(c,d))

Submission status: Accepted

Solution code:
S = input()
S = list(S)
N = len(S)
change = ['1','0']

icchi0 = 0
count = 0
S0 = ['0'] * N
for i in range(N):
    if i%2 == 1:
        S0[i] = '1'
        
for i in range(N):
    if S[i] == S0[i]:
        icchi0 += 1
        
if icchi0 >= N/2:
    print(N-icchi0)
else:
    print(icchi0)

Submission status: Accepted

Solution code:
S = input()
S = list(S)
N = len(S)
change = ['1','0']

count = 0
for i in range(1,N):
    if S[i] == S[i-1]:
        count += 1
        idx = int(S[i])
        S[i] = change[idx]
        
print(count)

Submission status: Accepted

Solution code:
s = input()
ans = float('inf')
for j in range(2):
    c = 0
    val = j
    for i in s:
        if val == int(i):
            c += 1
        val = (val + 1) % 2
    ans = min([ans, c])
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

S = list(input())

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

Submission status: Accepted

Solution code:
def zeroOne(start=0):
    """Infinite sequence of alternating zero and one."""
    assert start == 0 or start == 1
    x = start
    while True:
        yield x
        x = 1 - x

def cost(S, zeroOne):
    """The number of different tiles between S and zeroOne sequence."""
    return sum(1 for c, z in zip(S, zeroOne) if int(c) == z)

S = input()

v = min(cost(S, zeroOne(0)), cost(S, zeroOne(1)))
print(v)

Submission status: Accepted

Solution code:
s = input()
li = [int(a) for a in s]
tem = []
cnt = 0
for i in range (len(li)):
    if i%2 == 1:
        tem.append(0)
    else:
        tem.append(1)
    if li[i] == tem[i]:
        cnt+= 1
if cnt <= (len(li) / 2):
    print(str(cnt))
else:
    print(str(len(li) - cnt))

Submission status: Accepted

Solution code:
a = input()
kazu = 0
a = [int(i) for i in a]
if a[0]==0:
    check = [ 0 if i%2==0 else 1 for i in range(len(a))]
else:
    check = [ 1 if i%2==0 else 0 for i in range(len(a))]
for i in range(len(a)):
    if a[i]!=check[i]:
        kazu+=1
print(kazu)

Submission status: Accepted

Solution code:
S = input()
oddblack, oddwhite = 0,0
evenblack, evenwhite = 0,0
for i,x in enumerate(S):
    if i % 2 == 1:
        if x == '0':
            oddblack += 1
        else:
            oddwhite += 1
    else:
        if x == '0':
            evenblack += 1
        else:
            evenwhite += 1

answer = min(oddblack + evenwhite , oddwhite + evenblack)
print(answer)

Submission status: Accepted

Solution code:
import sys
import math

mat = list(sys.stdin.readline().strip())

odd = 0
even = 0
for i, x in enumerate(mat):
    flg = i % 2
    if flg:
        if int(x) == 1:
            even += 1
        else:
            odd += 1
    else:
        if int(x) == 1:
            odd += 1
        else:
            even += 1

print(min(odd, even))

Submission status: Accepted

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

if N%2 == 0:
    S_1 = "01"*(N//2)
    S_2 = "10"*(N//2)
else:
    S_1 = "01"*(N//2) + "0"
    S_2 = "10"*(N//2) + "1"
    
    
def distance(S,T,N):
    cnt = 0
    for i in range(N):
        if S[i] != T[i]:
            cnt += 1
    return cnt

print(min(distance(S,S_1,N),distance(S,S_2,N)))

Submission status: Accepted

Solution code:
import numpy as np
s = [int(i) for i in input()]

n = len(s)

list01 = [int(i%2) for i in range(n)]
list10 = [int((i+1)%2) for i in range(n)]

        
list_a = np.array(s) - np.array(list01)
list_b = np.array(s) - np.array(list10)

count0 = np.sum(list_a == 0)
count1 = np.sum(list_b == 0)
countmin = min((n-count0),(n-count1))
print(countmin)

Submission status: Accepted

Solution code:
S = input()
even_0 = 0
even_1 = 0
odd_0 = 0
odd_1 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            even_0 = even_0 + 1
        else:
            even_1 = even_1 + 1
    else:
        if S[i] == "0":
            odd_0 = odd_0 + 1
        else:
            odd_1 = odd_1 + 1
print(min(even_0 + odd_1, even_1 + odd_0))

Submission status: Accepted

Solution code:
S = list(input())
s = len(S)

p = [S[i] for i in range(0,s) if i%2 == 0]
q = [S[i] for i in range(1,s) if i%2 == 1]

p_1 = p.count('1')
p_0 = len(p)-p_1

q_1 = q.count('1')
q_0 = len(q)-q_1

if p_1 > p_0:
    if q_0 > q_1:
        ans = p_0 + q_1

    else:
        if p_1-p_0 > q_1-q_0:
            ans = p_0+q_1
        else:
            ans = p_1+q_0

else:
    if q_1 > q_0:
        ans = p_1 + q_0

    else:
        if p_0-p_1 > q_0-q_1:
            ans = p_1+q_0
        else:
            ans = p_0+q_1

print(ans)

Submission status: Accepted

Solution code:
number = input()
tile = [int(i) for i in number]
even = sum(tile[0::2])
odd = sum(tile) - even
ex1 = ((len(tile) // 2) - odd) + even
ex2 = ((len(tile) - (len(tile) // 2)) - even) + odd
print(min(ex1,ex2))

Submission status: Accepted

Solution code:
S = [int(i) for i in input()]
A = sum([int(i % 2 == 0) == v for i, v in enumerate(S)])
B = sum([int(i % 2 != 0) == v for i, v in enumerate(S)])
print(min(A, B))

Submission status: Accepted

Solution code:
s = input()
s = [int(x) for x in s]
length = len(s)
a,b=[],[]
counter = 0
countera = 0
counterb =0
for index,val in enumerate(s):
  if counter == 0:
    if val == 0:
      counterb += 1
    else:
      countera += 1
  else:
    if val == 0:
      countera += 1
    else:
      counterb += 1
  counter ^= 1
print(min(countera,counterb))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
tempa = []
tempb = []
for i in range(n):
    if i%2 == 0:
        tempa.append("0")
        tempb.append("1")
    else:
        tempa.append("1")
        tempb.append("0")
    
countera = 0
counterb = 0
for i in range(n):
    if s[i] != tempa[i]:
        countera += 1
    if s[i] != tempb[i]:
        counterb += 1
print(min(countera,counterb))

Submission status: Accepted

Solution code:
c = 0
for i, n in enumerate(input()):
  c += i%2 ^ int(n)
print(min(c, i-c+1))

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
dif = 0
for i in range(n):
  if s[i] != str(i % 2):
    dif += 1
print(min(dif, n - dif))

Submission status: Accepted

Solution code:
import sys

a = input()
S = [int(c) for c in a]

ans = 0

if S[0] == 0:
	nxt = 1
else:
	nxt = 0

for i, tar in enumerate(S):
	if tar == 0:
		nxt = 1
	else:
		nxt = 0

	if i!=len(S)-1 and S[i] == S[i+1]:
		S[i+1] = nxt
		ans += 1
	

print(ans)

Submission status: Accepted

Solution code:
s = input()

mod = 0
temp = 0
for c in s:
    if int(c) == mod:
        temp += 1
    mod = (mod + 1) % 2

ans = temp

mod = 1
temp = 0
for c in s:
    if int(c) == mod:
        temp += 1
    mod = (mod + 1) % 2

ans = min(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
if N%2==0:
    pattern_A = "01"*(N//2)
    pattern_B = "10"*(N//2)
else:
    pattern_A = "01"*(N//2)+"0"
    pattern_B = "10"*(N//2)+"1"
error_A, error_B = 0, 0
for i in range(N):
    if pattern_A[i] != S[i]:
        error_A += 1
    if pattern_B[i] != S[i]:
        error_B += 1
ans = error_A if error_A<error_B else error_B
print(ans)

Submission status: Accepted

Solution code:
S = input()
correct_case1 = "".join(["0" if i%2 == 0 else "1" for i in range(len(S))])
correct_case2 = "".join(["0" if i%2 == 1 else "1" for i in range(len(S))])
c1 = 0
c2 = 0
for i in range(len(S)):
  if correct_case1[i] != S[i]:
    c1 += 1
  if correct_case2[i] != S[i]:
    c2 += 1
print(min([c1, c2]))

Submission status: Accepted

Solution code:
str = input()
S = list(str)
N = len(S)
count = 0
for x in range(N):
    if x % 2 == 0 and S[x] == "0":
        count += 1
    elif x % 2 == 1 and S[x] == "1":
        count += 1
if count > N / 2:
    print(N - count)
else:
    print(count)

Submission status: Accepted

Solution code:
tile = list(input())

if len(tile) == 1:
  print(0)
else:
  tile_odd = tile[0::2]
  tile_odd_0 = tile_odd.count("0")
  tile_odd_1 = tile_odd.count("1")
  tile_even = tile[1::2]
  tile_even_0 = tile_even.count("0")
  tile_even_1 = tile_even.count("1")
  ans = min(tile_odd_0 + tile_even_1, tile_odd_1 + tile_even_0)
  print(ans)

Submission status: Accepted

Solution code:
s=[int(i) for i in input()]
a=s[1::2]
b=s[::2]
print(min(a.count(0)+sum(b),sum(a)+b.count(0)))

Submission status: Accepted

Solution code:
l = [int(i) for i in list(input())]

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

l = sum(map(lambda x:abs(1-x), even)) + sum(odd)
r = sum(map(lambda x:abs(1-x), odd)) + sum(even)

print(min(l, r))

Submission status: Accepted

Solution code:

s=input()
n=len(s)
ch=['0','1']
ans=[0,0]
x,y=0,1
for i in range(n):
    if s[i]==ch[x]:
        ans[0]+=1
    if s[i]==ch[y]:
        ans[1]+=1
    x=1-x
    y=1-y
    
print(min(ans))

Submission status: Accepted

Solution code:
n = input()
c1 = c2 = 0
l = len(n)
c1 = l - len([i for i in n[0::2] if i == "0"]) - len([i for i in n[1::2] if i == "1"])
c2 = l - len([i for i in n[0::2] if i == "1"]) - len([i for i in n[1::2] if i == "0"])

print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()
c1 = c2 = 0
 
N = len(S)
c1 = N - len([s for s in S[0::2] if s == "0"]) - len([s for s in S[1::2] if s == "1"])
c2 = N - len([s for s in S[0::2] if s == "1"]) - len([s for s in S[1::2] if s == "0"])
 
print(min(c1, c2))

Submission status: Accepted

Solution code:
S = input()
c1 = c2 = 0

N = len(S)
c1 = N - (len([s for s in S[0::2] if s == "0"]) + len([s for s in S[1::2] if s == "1"]))
c2 = N - (len([s for s in S[0::2] if s == "1"]) + len([s for s in S[1::2] if s == "0"]))

print(min(c1, c2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

answer1 = '0'
for i in range(len(s)):
    if i % 2 == 1:
        answer1 += '0'
    else:
        answer1 += '1'

answer2 = '1'
for i in range(len(s)):
    if i % 2 == 1:
        answer2 += '1'
    else:
        answer2 += '0'


wrong1, wrong2 = 0, 0
for i in range(len(s)):
    if s[i] != answer1[i]:
        wrong1 += 1
    if s[i] != answer2[i]:
        wrong2 += 1

print(min([wrong1, wrong2]))

Submission status: Accepted

Solution code:
import sys

if __name__ == '__main__':
    S = list(map(lambda x: int(x), sys.stdin.readline().rstrip()))
    M1 = [0 if i % 2 == 0 else 1 for i in range(len(S))]
    M2 = [0 if i % 2 == 1 else 1 for i in range(len(S))]
    d1 = sum([1 if S[i] != M1[i] else 0 for i in range(len(S))])
    d2 = sum([1 if S[i] != M2[i] else 0 for i in range(len(S))])
    if d1 < d2:
        print(d1)
    else:
        print(d2)

Submission status: Accepted

Solution code:
S = input()

length_S = len(S)

wrong_10 = 0
wrong_01 = 0

for i in range(length_S):
	if i%2 == 0:
		if S[i] == '1':
			wrong_01 += 1
		else:
			wrong_10 += 1
	else:
		if S[i] == '1':
			wrong_10 += 1
		else:
			wrong_01 += 1
			
print(min(wrong_01, wrong_10))

Submission status: Accepted

Solution code:
s = input()
cnt = 0

t = "01"*(-((-1)*len(s)//2))

cnt_1 = 0
cnt_2 = 0

for i in range(len(s)):
    if s[i] == t[i]:
        cnt_1 += 1

    else:
        cnt_2 += 1

print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
s = input()
cnt = 0

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

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

Submission status: Accepted

Solution code:
tile = input()

cor_list = ["10"*50000, "01"*50000]

diff_1 = int("0b"+tile, 2) ^ int("0b"+cor_list[0][:len(tile)], 2)  
diff_2 = int("0b"+tile, 2) ^ int("0b"+cor_list[1][:len(tile)], 2)

score = [0, 0]
score[0] = sum([int(s) for s in bin(diff_1)[2:]])
score[1] = sum([int(s) for s in bin(diff_2)[2:]])

print(min(score))

Submission status: Accepted

Solution code:
S = input().rstrip()
s = list(S)
N = len(S)
c = 0
v = [None] * N
v[0] = s[0]
if N == 1:
  print(c)
else:
  for i in range(1,N):
    
    if s[i]=='0' and v[i-1] =='0':
      v[i] = '1'
      c +=1
    elif s[i] =='1' and v[i-1] == '1':
      v[i] = '0'
      c +=1
    elif s[i] =='1' and v[i-1] == '0':
      v[i] = '1'
    elif s[i] =='0' and v[i-1] == '1':
      v[i] = '0'
    

  print(c)

Submission status: Accepted

Solution code:
S = list(map(str, input()))
listA = ["0"]
listB = ["1"]
countA = 0
countB = 0

for i in range(len(S)):
  listA.append(str((i+1)%2))
  listB.append(str(i%2))
  if listA[i] != S[i]:
    countA = countA + 1
  if listB[i] != S[i]:
    countB = countB + 1

if countA <= countB:
  print(countA)
else:
  print(countB)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)

w = []
for i in range(n):
    w.append(int(s[i]))

counta = 0
for i in range(n):
    if i % 2 == 0:
        if w[i] != 0:
            counta = counta + 1
    else:
        if w[i] != 1:
            counta = counta + 1

countb = 0
for i in range(n):
    if i % 2 == 0:
        if w[i] != 1:
            countb = countb + 1
    else:
        if w[i] != 0:
            countb = countb + 1

print(min(counta, countb))

Submission status: Accepted

Solution code:
s = input()

s_val = int(s, 2)


s1 = ''
s2 = ''
for i in range(len(s)):
    if i%2==0:
        s1 = s1 + '1'
        s2 = s2 + '0'
    else:
        s1 = s1 + '0'
        s2 = s2 + '1'

num = min(str(bin(s_val^int(s1,2))).count('1'), str(bin(s_val^int(s2,2))).count('1'))
print(num)

Submission status: Accepted

Solution code:
s = str(input())

input_array = list(s)

# patarn 0
correct_data = []
patarn0 = 0
for i in range(len(input_array)):
  if (i % 2) == 0:
    correct_data.append("0")
  else:
    correct_data.append("1")

for i in range(len(input_array)):
  if correct_data[i] != input_array[i]:
    patarn0 += 1


# patarn 1
correct_data = []
patarn1 = 0
for i in range(len(input_array)):
  if (i % 2) == 0:
    correct_data.append("1")
  else:
    correct_data.append("0")


for i in range(len(input_array)):
  if correct_data[i] != input_array[i]:
    patarn1 += 1


if patarn1 > patarn0:
  print(patarn0)
else:
  print(patarn1)

Submission status: Accepted

Solution code:
import numpy as np

S = np.array(list(map(int, list(input()))))
q, r = len(S) // 2, len(S) % 2
a1 = np.array([1, 0] * q + [1] * r)  # 1010...01 (偶数長なら 1010...10)
a2 = np.array([0, 1] * q + [0] * r)  # 1010...01 (偶数長なら 1010...10)

print(min(sum(abs(a1 - S)), sum(abs(a2 - S))))

Submission status: Accepted

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

b,w=0,0
for i in range(N):
    if i%2==0:
        if s[i]=="1": b+=1
        else: w+=1

    
    else:
        if s[i]=="1": w+=1
        else: b+=1

print(min(b,w))

Submission status: Accepted

Solution code:
s = list(input())
bw, wb = 0, 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != "0":
            bw += 1
        else:
            wb += 1
    else:
        if s[i] != "1":
            bw += 1
        else:
            wb += 1
print(min(wb, bw))

Submission status: Accepted

Solution code:
S = input()

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

n = len(S) // 2
S1 = '01' * n
S2 = '10' * n
if n % 2 == 1:
    S1 += '0'
    S2 += '1'
ret1 = 0
ret2 = 0
for idx, s in enumerate(S):
    if S1[idx] != s:
        ret1 += 1
    if S2[idx] != s:
        ret2 += 1


print(min(ret1, ret2))

Submission status: Accepted

Solution code:
color = [int(x) for x in list(input())]

cnt1 = 0
cnt2 = 0

for i in range(len(color)):
    if color[i] == i % 2:
        cnt1 += 1
    else:
        cnt2 += 1
        
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()
chars = len(s)
model1 = ['0' if i % 2 == 0 else '1' for i in range(chars)]
model2 = ['1' if i % 2 == 0 else '0' for i in range(chars)]
ans1, ans2 = 0, 0
for i in range(chars):
    if s[i] != model1[i]:
        ans1 += 1
    if s[i] != model2[i]:
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
*s,=map(int,input())
n=len(s)
a=sum(s[::2])+n//2-sum(s[1::2])
print(min(a,n-a))

Submission status: Accepted

Solution code:
S = input()

size = len(S)

# 偶数を 0 として書き換える

swaps = 0

for i, s in enumerate(S):
    # 余りが = 偶数ならば 0 に書き換え
    if (i % 2 == 0 and s == '1') or (i % 2 == 1 and s == '0'):
        swaps += 1

print(min(swaps, size - swaps))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

    case1 = [0] * n
    case2 = [0] * n

    for i in range(n):
        if i % 2 == 0:
            case1[i] = 1
        else:
            case2[i] = 1

    count1 = 0
    count2 = 0

    for one, si in zip(case1, s):
        if one != si:
            count1 += 1

    for two, si in zip(case2, s):
        if two != si:
            count2 += 1

    print(min(count1, count2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
inp = input()
w = 0
list0 = []
list1 = []
for i in inp:
  if w == 0:
    list0.append(int(i))
    w = 1
  else:
    list1.append(int(i))
    w = 0

sum0 = sum(list0)
sum1 = sum(list1)
pat0 = sum(list0) + len(list1) - sum(list1)
pat1 = sum(list1) + len(list0) - sum(list0) 


print (min(pat0, pat1))

Submission status: Accepted

Solution code:
S = list(input())

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

a = 0
for s,c in zip(S, C):
    if s == c:
        a += 1

print(min([a, len(S)-a]))

Submission status: Accepted

Solution code:
import numpy as np
tile=str(input())
a=['01','10'][int(tile[0])]*(10**5//2)
print(sum(np.array(list(tile),dtype=int)^np.array(list(a[:len(tile)]),dtype=int)))

Submission status: Accepted

Solution code:
str = input()

count = 0
for i, s in enumerate(str):
    if (i + int(s)) % 2 == 0:
        count += 1

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

Submission status: Accepted

Solution code:
S = input()
S_len = len(S)

X1 = "10" * ((S_len // 2)+1)
X2 = "01" * ((S_len // 2)+1)

ans = 0
if S[0] == "0":
    for i in range(S_len):
        if X2[i] != S[i]:
            ans += 1
elif S[0] == "1":
    for i in range(S_len):
        if X1[i] != S[i]:
            ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
from copy import *
s = str(input())
n = len(s)
ans = 0
S = s
for i in range(n):#偶数で0  01010
    if i % 2 == 0:
        if s[i] == "1":
            ans += 1

    else:
        if s[i] == "0":
            ans += 1

aans = 0
for i in range(n):#奇数で0  10101
    if i % 2 == 0:#偶数
        if S[i] == "0":
            aans += 1

    else:
        if S[i] == "1":
            aans += 1

print(min(ans,aans))

Submission status: Accepted

Solution code:
import sys
 
def main():
    input = sys.stdin.readline
    S = str(input().strip())
 
    cnt_01 = 0
    cnt_10 = 0
    for i in range(len(S)):
        s = S[i]
 
        if i % 2 == 0:
            if s != '0':
                cnt_01 += 1
            else:
                cnt_10 += 1
        else:
            if s != '0':
                cnt_10 += 1
            else:
                cnt_01 += 1
 
    return min(cnt_01, cnt_10)
 
 
if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
s1 = ""
s2 = ""
for i in range(n):
    if(i&1):
        s1 += "0"
        s2 += "1"
    else:
        s1 += "1"
        s2 += "0"
ans1 = 0 ; ans2 = 0
for i in range(n):
    if(s[i] != s1[i]):
        ans1 += 1
    if(s[i] != s2[i]):
        ans2 += 1
print(min(ans1 , ans2))

Submission status: Accepted

Solution code:
s=input()
print(len(s)-max(s[0::2].count("0")+s[1::2].count("1"),s[0::2].count("1")+s[1::2].count("0")))

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
for i in range(len(S)):
  if(i != 0):
    if(S[i] == S[i-1]):
      ans += 1
      if(S[i] == '0'):
        S[i] = '1'
      else: 
        S[i] = '0'
print(ans)

Submission status: Accepted

Solution code:
#C

S = input()

s0 = 0
s1 = 0
flag = False

for i in S:
    if (i == "1") ^ flag:
        s0 += 1
    if (i == "0") ^ flag:
        s1 += 1
    flag = not(flag)
    
print(min(s0, s1))

Submission status: Accepted

Solution code:
import numpy as np

S = input()

tile_color = []
for i in S:
    tile_color.append(int(i))

candidate = np.zeros((2,len(S)))
candidate[0, 0::2] = 1
candidate[1, 1::2] = 1

distance = [np.sum(np.abs(candidate[0,:] - tile_color)), np.sum(np.abs(candidate[1,:] - tile_color))]

print(int(min(distance)))

Submission status: Accepted

Solution code:
s=input()
s1='01'*(len(s)//2)+'0'*(len(s)%2)
s2='10'*(len(s)//2)+'1'*(len(s)%2)
ans1=0
ans2=0
for i,j,k in zip(s,s1,s2):
    if i!=j:ans1+=1
    if i!=k:ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
a = list(input())
a = [int(x) for x in a]

cou = 0
cou2 = 0
b = [0]
c = [1]

if a[0] == 0:
    cou2 += 1
else:
    cou += 1
    
for i in range(len(a)-1):
    if b[i] == a[i+1]:
        cou += 1
        if b[i] == 1:
            x = 0
            b.append(x)
        else:
            x = 1
            b.append(x)
    else:
        b.append(a[i+1])
        
for i in range(len(a)-1):
    if c[i] == a[i+1]:
        cou2 += 1
        if c[i] == 1:
            x = 0
            c.append(x)
        else:
            x = 1
            c.append(x)
    else:
        c.append(a[i+1])
        
print(cou if cou < cou2 else cou2)

Submission status: Accepted

Solution code:
g = True
a=[0,0]
for i in map(int,list(input())):
  if g == bool(i):
    a[0]+=1
  else:
    a[1]+=1
  g = not g
print(min(a))

Submission status: Accepted

Solution code:
S = list(input())
odds = [S[i] for i in range(len(S)) if i % 2 == 0]
evens = [S[i] for i in range(len(S)) if i % 2 != 0]
ans = []
ans.append(odds.count("0")+evens.count("1"))
ans.append(odds.count("1")+evens.count("0"))
print(min(ans))

Submission status: Accepted

Solution code:
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

S = input()[:-1]
N = len(S)
if len(S) != 1:
    C1 = Counter(S[::2])
    C2 = Counter(S[1::2])

    odd = C1['0']+C2['1']
    even = C1['1']+C2['0']
    print(N-max(odd, even))
else:
    print(0)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    l = str(input())
    l = [int(x) for x in list(str(l))]
    length = len(l)
    temp1 = []
    temp2 = []
    for i in range(length):
        temp1.append(i % 2)
        temp2.append((i + 1) % 2)
    t1 = 0
    t2 = 0
    for n in range(length):
        if temp1[n] != l[n]:
            t1 += 1
        if temp2[n] != l[n]:
            t2 += 1
    print(min(t1, t2))