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:
# coding: utf-8
# Your code here!
s = input()

S = []
for i in s:
    S.append(int(i))
    
if len(S) % 2 == 0: #要素数が偶数の時
    ans = 0
    num1 = 0
    num2 = 0
    
    
    for i, Si in enumerate(S): #左0 右1
        if i % 2 == 0:
            if S[i] != 0:
                num1 += 1
        if i % 2 != 0:
            if S[i] != 1:
                num1 += 1
    
    for i, Si in enumerate(S): #左1 右0
        if i % 2 == 0:
            if S[i] != 1:
                num2 += 1
        if i % 2 != 0:
            if S[i] != 0:
                num2 += 1
    
    ans = min([num1, num2])
    print(ans)

if len(S) % 2 != 0: #要素数が奇数の時
    ans = 0
    num1 = 0
    num2 = 0
    
    
    for i, Si in enumerate(S): #両方1
        if i % 2 == 0:
            if S[i] != 1:
                num1 += 1
        if i % 2 != 0:
            if S[i] != 0:
                num1 += 1
    
    for i, Si in enumerate(S): #両方0
        if i % 2 == 0:
            if S[i] != 0:
                num2 += 1
        if i % 2 != 0:
            if S[i] != 1:
                num2 += 1
    
    ans = min([num1, num2])
    print(ans)

Submission status: Accepted

Solution code:
s = input()
type_A = 0
type_B = 0
for i in range(len(s)):
  if i%2 == 0:
    if int(s[i])!=0:
      type_A += 1
  else:
    if int(s[i])!=1:
      type_A += 1

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

if type_A > type_B:
  print(type_B)
else:
  print(type_A)

Submission status: Accepted

Solution code:
def c_coloring_colorfully(S):
    s1 = '10' * (len(S) // 2) + ('1' if len(S) % 2 == 1 else '')
    s2 = '01' * (len(S) // 2) + ('0' if len(S) % 2 == 1 else '')
    ans1, ans2 = 0, 0
    for k, s in enumerate(S):
        if s != s1[k]:
            ans1 += 1
        if s != s2[k]:
            ans2 += 1
    return min(ans1, ans2)

S = input()
print(c_coloring_colorfully(S))

Submission status: Accepted

Solution code:
s = input();l = [];h=[]
n=len(s)
for i in range(n):
    l += s[i] 
    
h += l 
cnt1=0;cnt2=0

if l[0]=='1':
    l[0]='0'
    cnt1 += 1
for i in range(n-1):
    if l[i]==l[i+1]:
        if l[i]=='0':
            l[i+1]='1'
        else:
            l[i+1]='0'
        cnt1 += 1

if h[0] == '0':
    h[0] = '1'
    cnt2 += 1
for j in range(n-1):
    if h[j]==h[j+1]:
        if h[j]=='0':
            h[j+1]='1'
        else:
            h[j+1]='0'
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

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

S = str(input())
ans = 0
if len(S)==1:
    print(0)
    exit()
elif S=="00" or S=="11":
    print(1)
    exit()

flg = True
if S[0]=="0":
    for i in range(len(S)):
        if i == 0:
            continue
        if i%2 == 0:
            if S[i]!="0":
                ans+=1
                continue
        else:
            if S[i]!="1":
                ans+=1
                continue
else:
    for i in range(len(S)):
        if i == 0:
            continue
        if i%2 == 0:
            if S[i]!="1":
                ans+=1
                continue
        else:
            if S[i]!="0":
                ans+=1
                continue
print(ans)

Submission status: Accepted

Solution code:
l = list(map(int,list(input())))
sum = 0

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

print(sum)

Submission status: Accepted

Solution code:
S = input()
if len(S) % 2 == 0:
    N1 = "01" * (len(S)//2)
    N2 = "10" * (len(S)//2)
else:
    N1 = "01" * (len(S)//2) + "0"
    N2 = "10" * (len(S)//2) + "1"
n1 = 0
n2 = 0 
for i in range(len(S)):
    if S[i] != N1[i]:
        n1 = n1+1
    elif S[i] != N2[i]:
        n2 = n2+1
print(min(n1, n2))

Submission status: Accepted

Solution code:
S = list(input())

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

for i, value in enumerate(S):
    # 偶数のとき
    if i % 2 == 0:
        if value == "0":
            even_0 += 1
        else:
            even_1 += 1

    # 奇数のとき
    else:
        if value == "0":
            odd_0 += 1
        else:
            odd_1 += 1

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

Submission status: Accepted

Solution code:
def color(s):
    k = 0
    for i in range(len(s)-1):
        if s[i+1]==s[i]:
            if s[i]=='0':
                s[i+1]='1'
            if s[i]=='1':
                s[i+1]='0'
            k = k+1
    return k
    
s=list(input())
print(color(s))

Submission status: Accepted

Solution code:
S = list(input())
len(S)
ans1 = 0
ans2 = 1
cnt1 = 0
cnt2 = 0
for i in range(len(S)):
  if not ans1 == int(S[i]):
    cnt1 = cnt1 + 1
  if ans1 == 0:
    ans1 = 1
  else:
    ans1 = 0

for i in range(len(S)):
  if not ans2 == int(S[i]):
    cnt2 = cnt2 + 1
  if ans2 == 0:
    ans2 = 1
  else:
    ans2 = 0

if cnt1 > cnt2:
  cnt1 = cnt2
  
print(cnt1)

Submission status: Accepted

Solution code:
def subtract_lst (lst1, lst2):
    ans = 0
    for i in range(len(lst1)):
        e1 = lst1[i]
        e2 = lst2[i]
        if e1 != e2:
            ans += 1
    return ans

if __name__ == '__main__':
    s = input()
    lenS = len(s)
    a = ""
    b = ""
    for i in range(lenS // 2):
      a = a + "10"
      b = b + "01"
    if lenS % 2 == 1:
        a = a + "1"
        b = b + "0"
    aAns = subtract_lst (a, s)
    bAns = subtract_lst (b, s)
    print (min(aAns, bAns))

Submission status: Accepted

Solution code:
data = [int(s) for s in input()]
count1 = 0
if data[0] == 0:
  
  
  for s in range(1,len(data)):
    
    
    
    if s % 2 == 0:
        if data[s] != 0:
            count1 += 1
    else :
        if data[s] != 1:
            count1 += 1
            
else:
  
  
  for s in range(1,len(data)):
    
    if s % 2 == 0:
      if data[s] != 1:
        count1 += 1
        
    else:
      if data[s] != 0:
        count1 += 1
          


print(count1)

Submission status: Accepted

Solution code:
s=input()
a="01"
b=x=y=0
for i in s:
  if i==a[b]: x+=1
  if i==a[~b]:y+=1
  b=~b
print(len(s)-max(x,y))

Submission status: Accepted

Solution code:
S=[]
for char in input():
  S.append(char)
#route 1
C1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='1':
      C1+=1
  else:
    if S[i]=='0':
      C1+=1

#route 2
C2=0
for n in range(len(S)):
  if n%2==0:
    if S[n]=='0':
      C2+=1
  else:
    if S[n]=='1':
      C2+=1

if C2>=C1:
  print(C1)
else:
  print(C2)

Submission status: Accepted

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

def poe(b):
  res = 0
  for i in range(size):
    if b:
      a = '1' if i % 2 == 0 else '0'
    else:
      a = '0' if i % 2 == 0 else '1'
 
    if a != s[i]:
      res+=1

  return res

print(min(poe(True), poe(False)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ans1 = ans2 = 0
for i, s in enumerate(S):
    if i % 2 == 0 and s == '0':
        ans1 += 1
    if i % 2 == 1 and s == '1':
        ans1 += 1
    if i % 2 == 0 and s == '1':
        ans2 += 1
    if i % 2 == 1 and s == '0':
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s=list(str(input()))
c=0
for x in range(len(s)-1):
    if s[x+1]==s[x]:
        if s[x]=="0":
            s[x+1]="1"
        else:
            s[x+1]="0"
        c+=1
print(c)

Submission status: Accepted

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

a=0
b=0
a=sum(int(s[i]) for i in range(0,l,2))
b=sum(int(s[i]) for i in range(1,l,2)) 

print(int(min(abs(l/2+0.5-a)+b,abs(l/2-b)+a)))

Submission status: Accepted

Solution code:
tiles=list(map(int,input()))
def create(x,y):
    sample=[]
    for i in range(0,len(tiles)):
        if i%2==0:
            sample.append(x)
        else:
            sample.append(y)
    return sample

sample1=create(1,0)
sample2=create(0,1)

def dif_count(list):
    count=0
    for i in range(0,len(list)):
        if list[i]!=tiles[i]:
            count+=1
    return count
print(min(dif_count(sample1),dif_count(sample2)))

Submission status: Accepted

Solution code:
n = input()
n_split = list(n)
count = 0

for i in range(len(n_split)):
    if i != 0:
        if n_split[i] == n_split[i-1]:
            if n_split[i] == "0":
                n_split[i] = "1"
            else:
                n_split[i] = "0"
            count += 1

print(count)

Submission status: Accepted

Solution code:
st=list(input())
n=list(map(int,st))
a=0
b=0
N=len(st)
retu10=[1,0]*(N//2  +1)
retu01=[0,1]*(N//2 +1)
r1=retu10[:N]
r0=retu01[:N]
for i in range(N):
  if r1[i]!=n[i]:
    a=a+1
  else:
    pass
for i in range(N):
  if r0[i]!=n[i]:
    b=b+1
  else:
    pass
print(min(a,b))

Submission status: Accepted

Solution code:
S = input()
l = len(S) // 2
s1 = [S[i*2] for i in range(l+(len(S) % 2))]
s2 = [S[i*2+1] for i in range(l)]
c = s1.count('1') + s2.count('0')
ret = c if c <= l else len(S) - c
print(ret)

Submission status: Accepted

Solution code:
S=list(input())
S=[int(i) for i in S]
sum_0=0
sum_1=0
if len(S)%2==1:
    S.append(2)
for i in range(0,len(S),2):
    if S[i]==1:#0から探す
        sum_0+=1
    elif S[i]==0:
        sum_1+=1
    if S[i+1]==0:
        sum_0+=1
    elif S[i+1]==1:
        sum_1+=1
if sum_0>sum_1:
    print(sum_1)
else:
    print(sum_0)

Submission status: Accepted

Solution code:
S = input()
S2 = ""
S3 = ""
co1 = 0
co2 = 0
f = 1
for i in range(len(S)):
 if f == 1:
  S2 += "1"
  S3 += "0";f=0
 else:
  S2 += "0";S3 += "1";f=1
for i in range(0,len(S)):
  if S[i] != S2[i]:
   co1 += 1;print
for i in range(0,len(S)):
  if S[i] != S3[i]:
   co2 += 1
if co1 > co2:
 print(co2)
else:
 print(co1)

Submission status: Accepted

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

counter = 0
if len(s) == 1:
    print(0)
else:
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            s[i] = int(int(s[i-1]) ==  0)
            counter += 1
    print(counter)

Submission status: Accepted

Solution code:
S = list(input())
S = [int(i) for i in S]
sum1,sum2 = 0,0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == 0:
            sum1 += 1
    else:
        if S[i] == 1:
            sum1 += 1

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == 1:
            sum2 += 1
    else:
        if S[i] == 0:
            sum2 += 1
if sum1 <= sum2:
    print(sum1)
else:
    print(sum2)

Submission status: Accepted

Solution code:
S = input()
H = len(S) 
a = '0'
b = '1'
A = 0
B = 0
while len(a) < H:
    a = a + '1'
    if len(a) < H:
        a = a + '0'

        
while len(b) < H:
    b = b + '0'
    if len(b) < H:
        b = b + '1'

        
for i in range(H):
    if a[i] == S[i]:
        A = A + 1

for i in range(H):
    if b[i] == S[i]:
        B = B + 1

print(H - max(A,B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

# patarn of 010101...
a1 = 0
for i, item in enumerate(s):
    # i is even, s[i] should 0
    if i % 2 == 0 and item != "0":
        a1 += 1

    if i % 2 == 1 and item != "1":
        a1 += 1

# patarn of 101010...
a2 = 0
for i, item in enumerate(s):
    # i is even, s[i] should 0
    if i % 2 == 0 and item != "1":
        a2 += 1

    if i % 2 == 1 and item != "0":
        a2 += 1
print(min(a1, a2))

Submission status: Accepted

Solution code:
S = list(map(str, input()))

cnt = 0

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1

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

print(cnt)

Submission status: Accepted

Solution code:
S=input()
Slist =list(S)
Sg=Slist[0::2]
Sk=Slist[1::2]
SG = ''.join(Sg)
SK = ''.join(Sk)
a=SG.count("0")
b=SG.count("1")
x=SK.count("0")
y=SK.count("1")
	
print(min(a+y,b+x))

Submission status: Accepted

Solution code:
s = str(input())
l = len(s)
a = 0

for i in range(l):
    if i != 0:
        if s[0] == '0':
            if i % 2 == 1:
                if s[i] != '1':
                    a += 1
            else:
                if s[i] != '0':
                    a += 1
        else:
            if i % 2 == 1:
                if s[i] != '0':
                    a += 1
            else:
                if s[i] != '1':
                    a += 1

print(a)

Submission status: Accepted

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

if N % 2 == 0:
    s1 = "10"*int(N/2)
    s2 = "01"*int(N/2)
    c1 = 0
    c2 = 0
    for i,j,k in zip(S,s1,s2):
        if i != j:
            c1 += 1
        elif i != k:
            c2 += 1
        else:
            continue

    print(min(c1,c2)) 

else:
    s1 = "10"*int(N//2) + "1" 
    s2 = "01"*int(N//2) + "0"
    c1 = 0
    c2 = 0

    for i,j,k in zip(S,s1,s2):
        if i != j:
            c1 += 1
        elif i != k:
            c2 += 1
        else:
            continue

    print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()

counter = 0

sa = []
sb = []

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

sa_0 = sa.count('0')
sa_1 = sa.count('1')
sb_0 = sb.count('0')
sb_1 = sb.count('1')
if sa_0 +sb_1 >= sa_1 +sb_0:
  counter = sa_1 +sb_0
else:
  counter = sa_0 + sb_1
  
print(counter)

Submission status: Accepted

Solution code:
def main():
    li = list(map(int, input()))
    option_0 = []
    option_1 = []
    count_0 = 0
    count_1 = 0

    #print(li)
    for i in range(len(li)):
        if i%2 == 0:
            option_0.append(0)
            option_1.append(1)
        else:
            option_0.append(1)
            option_1.append(0)
    
    #print(option_0)
    #print(option_1)
    for i in range(len(li)):
        if option_0[i] != li[i]:
            count_0 += 1
        if option_1[i] != li[i]:
            count_1 += 1

    print(min(count_0, count_1))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = str(input())
l1 = []
for c in n:
	l1.append(c)

z, o = '0', '1'

one, zero = [], []

for i in range(len(l1)):
	if i%2 == 0:
		one.append(o)
		zero.append(z)
	else:
		one.append(z)
		zero.append(o)

c1, c2 = 0,0
for i in range(len(l1)):
	if l1[i] == one[i]:
		c1 += 1
	if l1[i] == zero[i]:
		c2 += 1

ans = min(c1, c2)
print(ans)

Submission status: Accepted

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

o1 = "10" * (n // 2) + "1" * (n % 2 == 1)
o2 = "01" * (n // 2) + "0" * (n % 2 == 1)

count1 = 0
count2 = 0
for i in range(n):
	if s[i] != o1[i]:
		count1 += 1
	if s[i] != o2[i]:
		count2 += 1
		
print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_bin = bin(int(s, 2))

text_10 = ''
text_01 = ''

for i in range(len(s)):
    j = i % 2
    k = (i + 1) % 2
    text_10 += str(j)
    text_01 += str(k)

x = bin(int(s, 2) ^ int(text_10, 2)).count("1")
y = bin(int(s, 2) ^ int(text_01, 2)).count("1")

print(min(x, y))

Submission status: Accepted

Solution code:
T = input()
S = [int(x) for x in list(str(T))]

if len(S) == 1:
    print(0)
elif len(S) == 2:
    print(1 - (S[0] + S[1]) % 2)
else:
    n = len(S)
    S_1 = [0] + S
    S_2 = [1] + S
    num_1 = 0
    num_2 = 0

    for i in range(n):
        if int(S_1[i]) == int(S_1[i+1]) == 0:
            S_1[i+1] = 1
            num_1 += 1
        elif S_1[i] == S_1[i+1] == 1:
            S_1[i+1] = 0
            num_1 += 1
    
    for i in range(n):
        if S_2[i] == S_2[i+1] == 0:
            S_2[i+1] = 1
            num_2 += 1
        elif S_2[i] == S_2[i+1] == 1:
            S_2[i+1] = 0
            num_2 += 1       
    print(min(num_1, num_2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    ans0 = 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] != '0':
            ans0 += 1
        if i % 2 == 1 and S[i] != '1':
            ans0 += 1
    ans1 = 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] != '1':
            ans1 += 1
        if i % 2 == 1 and S[i] != '0':
            ans1 += 1
    return min(ans1, ans0)


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
answer = 0
if len(n)<=1:
    pass
else:
    for i in range(1,len(n)):
        if n[i]==n[i-1]:
            answer+=1
            if n[i]=='0':
                n = n[:i]+'1'+n[i+1:]
            else:
                n = n[:i]+'0'+n[i+1:]

print(answer)

Submission status: Accepted

Solution code:
S_str = input()
S = int(S_str, 2)
S_len = len(S_str)

if S_len % 2 :
	E = '1' + '01'*(S_len//2)
else :
	E = '10'*(S_len//2)

E = int(E, 2)
num = format(S ^ E, 'b').count('1')
ans = min(num, S_len - num)
print(ans)

Submission status: Accepted

Solution code:
S=list(input())
A=[]
B=[]
countA=0
countB=0
for i in range(0,len(S)):
  if i%2==0:
    A.append('1')
    B.append('0')
  else:
    A.append('0')
    B.append('1')
for i in range(0,len(S)):
  if S[i]!=A[i]:
    countA+=1
for i in range(0,len(S)):
  if S[i]!=B[i]:
    countB+=1
if countA>=countB:
  print(countB)
else:
  print(countA)

Submission status: Accepted

Solution code:
import numpy as np
S = list(str(input()))
S = [int(s) for s in S]
S = np.array(S)
n = len(S)

N1 = np.zeros(n)
N2 = np.zeros(n)
N1[0::2] = 1
N2[1::2] = 1

a = N1 + S
a_num = np.sum(a[np.where(a == 1)])
b = N2 + S
b_num = np.sum(b[np.where(b == 1)])
print(int(min(a_num, b_num)))

Submission status: Accepted

Solution code:
S = input()

length_S = len(S)

S_check = []

count = 0

for i in range(length_S):
  if i % 2 == 0:
    S_check.append("0")
  else:
    S_check.append("1")

for i in range(length_S):
  if S[i] == S_check[i]:
    count += 1

print(min(count, length_S-count))

Submission status: Accepted

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

le=len(S)
counter=0

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

Submission status: Accepted

Solution code:
pat = input()
if len(pat) == 1:
    print(0)            
else:
    #generate
    pat1 = "0"
    pat2 = "1"

    for i in range(len(pat)-1):
        if pat1[-1:]=="0":
            pat1 = pat1+"1"
        else:
            pat1 = pat1+"0"
        
    for i in range(len(pat)-1):
        if pat2[-1:]=="0":
            pat2 = pat2+"1"
        else:
            pat2 = pat2+"0"

    count1 = 0
    count2 = 0
    for s in range(len(pat)):
        if pat[s] != pat1[s]:
            count1 = count1 + 1

        if pat[s] != pat2[s]:
            count2 = count2 + 1


    if count1 <= count2:
        print(count1)

    else:
        print(count2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
pattern_a_count = 0
pattern_b_count = 0

# 1010パターン
for index, value in enumerate(s):
  if index % 2 == 0:
    if value == "0":
      pattern_a_count += 1
  if index % 2 == 1:
    if value == "1":
      pattern_a_count += 1

# 0101
for index, value in enumerate(s):
  if index % 2 == 0:
    if value == "1":
      pattern_b_count += 1
  if index % 2 == 1:
    if value == "0":
      pattern_b_count += 1
      
res = pattern_b_count
if pattern_a_count <= pattern_b_count:
  res = pattern_a_count
print(res)

Submission status: Accepted

Solution code:
str=input()
n=len(str)
evenzero=0
evenone=0
oddzero=0
oddone=0
count=0
for x in range(n):
    if x%2==0:
        if str[x]=="0":
            evenzero +=1
        else:
            evenone +=1
    else:
        if str[x]=="0":
            oddzero +=1
        else:
            oddone +=1

t=max(evenzero+oddone,evenone+oddzero)

if t==evenzero+oddone:
    for x in range(n):
        if x % 2 == 0:
            if str[x] != "0":
                count += 1
        else:
            if str[x] != "1":
                count += 1
elif t==evenone+oddzero:
    for x in range(n):
        if x % 2 == 0:
            if str[x] != "1":
                count += 1
        else:
            if str[x] != "0":
                count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
ans0=0
ans1=0

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

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

Submission status: Accepted

Solution code:
ls=list(input())
ls1=['0','1']
ls2=['1','0']
a=int(len(ls)/2)
ls1=ls1*a
ls2=ls2*a
#print(ls1)
b=0
c=0
if len(ls)%2 == 1:
    ls1.append('0')
    ls2.append('1')
#print(ls1)
#print(type(ls1))
for i in range(len(ls)):
    if ls[i]==ls1[i]:
        b=b+1
    if ls[i] == ls2[i]:
        c=c+1
ans=min([b,c])
print(ans)

Submission status: Accepted

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

ss = input()
#print(ss)

s = []
for i in range(len(ss)):
    s.append(int(ss[i]))
#print(s)

if len(s)%2 == 0:
    s0 = [0,1] *(len(s)//2)
    s1 = [1,0] *(len(s)//2)
else:
    s0 = [0,1] *(len(s)//2)
    s0.append(0)
    s1 = [1,0] *(len(s)//2)
    s1.append(1)

#print(s0)
#print(s1)

sum0 = 0
sum1 = 0
for i in range(len(s)):
    
    if s0[i] != s[i]:
        #print(s0[i] , s[i])
        sum0 = sum0 +1

    if s1[i] != s[i]:
        #print(s1[i] , s[i])
        sum1 = sum1 +1

ans = min(sum0, sum1)
print(ans)

Submission status: Accepted

Solution code:
N = "0b" + input()
M = "0b" + "1"*(len(N)-2)
a = int(N, 0)^int(M, 0)
if len(N) % 2 == 0:
    K = "0b"+"10"*((len(N)-2)//2) #10101010...10(偶数)
else:
    K = "0b"+"10"*((len(N)-2)//2)+"1" #1010...01(奇数)
uK = bin(int(K, 0)^int(M, 0)) #Kの逆
q = bin(int(N, 0)^int(K, 0))
w = bin(int(N, 0)^int(uK, 0))
q = q[2:]
w = w[2:]
print(min(w.count("1"), q.count("1")))

Submission status: Accepted

Solution code:
s = input()
l=len(s)
s1=0
s0=0
l0=[]
l1=[]
for i in range(l):
    l0.append(str(i%2))
    l1.append(str((i+1)%2))
l0="".join(l0)
l1="".join(l1)
for i in range(l):
    if(l1[i]!=s[i]):
        s1=s1+1
    if(l0[i]!=s[i]):
        s0=s0+1
print(min(s0,s1))

Submission status: Accepted

Solution code:
S = list(input())

counter = 0

for num in range(len(S)-1):
  if num == len(S):
    break
  if S[num] == S[num+1]:
    counter += 1
    if S[num+1] == '0':
      S[num+1] = '1'
    else:
      S[num+1] = '0'

print(counter)

Submission status: Accepted

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

a = 0
b = 0
for i in range(len(s)):
    if (i % 2) == s[i]:
        a = a + 1
    else:
        b = b + 1
if a > b:
    print(b)
else:
    print(a)

Submission status: Accepted

Solution code:
s = list(map(int,list(input())))
a = 0
b = 1
counta = 0
countb = 0
for binary in s:
    if binary != a:
        counta += 1
    a += 1
    if a == 2:
        a = 0
for binary in s:
    if binary != b:
        countb += 1
    b += 1
    if b == 2:
        b = 0
print(counta if counta < countb else countb)

Submission status: Accepted

Solution code:
s=input()
ls=[c for c in s]
ct=0
j=0
for i in range(len(ls)):
    if ls[i]==ls[j]:
        if (i-j)%2!=0 and i-j!=0 and i-j!=1 and i!=len(ls)-1:
            ct+=int((i-j-1)/2)+1
            ls[i]=ls[j+1]
            j=i
        elif (i-j)%2!=0 and i-j!=0 and i-j!=1 and i==len(ls)-1:
            #print(i,j)
            ct+=int((i-j-1)/2-1)
        elif (i-j)%2==0 and i-j!=0 and i-j!=2:
            ct+=int((i-j)/2-1)
            j=i
            #print(i,j)
        elif i-j==1:
            ct+=1
            if ls[i]=='0':
                ls[i]='1'
            else:
                ls[i]='0'
            j=i
        elif i-j==2:
            j=i
            
        else:pass
if j<len(ls)-2:
    if (len(ls)-1-j)%2==0:
        ct+=int((len(ls)-1-j)/2)
    else:
        ct+=int((len(ls)-2-j)/2)
print(ct)

Submission status: Accepted

Solution code:
def main():
	S = input()
	start0 = "0"
	ans0 = 0
	ans1 = 0
	for i, c in enumerate(S):
		if i % 2 == 0:
			if c != start0:
				ans1 += 1
			else:
				ans0 += 1
		else:
			if c != start0:
				ans0 += 1
			else:
				ans1 += 1
	print(min(ans0, ans1))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
A =[int(c) for c in s]

a = 0
b = 0
for i in range(len(A)):
    if A[i] != i % 2:
        a += 1
    else:
        b += 1

if a < b:
    print(a)
else:
    print(b)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
k = 0
l = 0

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

for i in range(N):
	if i % 2 == 0:
		if int(S[i]) == 1:
			l += 0
		else:
			l += 1
	else:
		if int(S[i]) == 0:
			l += 0
		else:
			l += 1
            
print(min(k,l))

Submission status: Accepted

Solution code:
import numpy as np

num = np.array([i=="1" for i in input()])
s_1 = np.array([i%2==0 for i in range(len(num))])
s_0 = np.array([i%2==1 for i in range(len(num))])

#print(num)
#print(s_1)
#print(s_0)

#print(s_1 == num)
#print(s_0 == num)
r_1 = np.sum(s_1 == num)
r_0 = np.sum(s_0 == num)
print(min(r_0, r_1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
S2 = S[:]
now = S[0]
ans = 0
ans2 = 0
for i in range(len(S)-1):
  if now == "1":
    if S[i+1] == "0":
      now = "0"
    else:
      ans += 1
      now = "0"
      S[i+1] = "0"
  else:
    if S[i+1] == "1":
      now = "1"
    else:
      ans += 1
      now = "1"
      S[i+1] = "1"
S2.reverse()
now = S2[0]
for i in range(len(S2)-1):
  if now == "1":
    if S2[i+1] == "0":
      now = "0"
    else:
      ans2 += 1
      now = "0"
      S2[i+1] = "0"
  else:
    if S2[i+1] == "1":
      now = "1"
    else:
      ans2 += 1
      now = "1"
      S2[i+1] = "1"
print(min(ans, ans2))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n % 2 == 1:
    n += 1
pattern = '01' * ((n + 10) // 2)

ans_a = 0
ans_b = 0
for i, (a, b, ss) in enumerate(zip(pattern[1:], pattern[:-1], s)):
    if ss != a:
        ans_a += 1
    if ss != b:
        ans_b += 1
print(min(ans_a, ans_b))

Submission status: Accepted

Solution code:
S = str(input())
S = list(S)

result = 0

#変更すべきものだったら変更したあとの前のものもの
#変更するべきものではない場合は前のもの
tempChangedTile = S[0]

for index, tile in enumerate(S):
    
    try:
        if tempChangedTile != S[index+1]:
            tempChangedTile = S[index+1]
            #print("TRUE")
            #print(index)
        else:
            #print("ELSE")
            #print(index)
            result += 1
            if S[index + 1] == "0":
                tempChangedTile = "1"
            else:
                tempChangedTile = "0"
    except:
        pass

print(result)

Submission status: Accepted

Solution code:
s = input()
a,b = 0,0

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

print(min(a,b))

Submission status: Accepted

Solution code:
N = input()

length = len(N)

ans1 = ''
ans2 = ''

for i in range(length):
    if i % 2 == 0:
        ans1 = ans1 + "1"
        ans2 = ans2 + "0"
    else:
        ans1 = ans1 + "0"
        ans2 = ans2 + "1"

count1 = 0
count2 = 0



for i in range(length):
    if N[i] != ans1[i]:
        count1 = count1 + 1

    if N[i] != ans2[i]:
        count2 = count2 + 1

print(min(count1,count2))

Submission status: Accepted

Solution code:
s = input()
s = [int(i) for i in s]
n = len(s)
start_one = []
start_zero = []
for i in range(n):
    if i % 2 == 0:
        start_one.append(1)
        start_zero.append(0)
    else:
        start_one.append(0)
        start_zero.append(1)
count_one = 0
count_zero = 0
for i in range(n):
    if s[i] != start_one[i]:
        count_one += 1
    elif s[i] != start_zero[i]:
        count_zero += 1
ans = min(count_one, count_zero)
print(ans)

Submission status: Accepted

Solution code:
s =list(input())
g_s = s[0::2]
k_s = s[1::2]
g_zero = g_s.count('0')
k_zero = k_s.count('0')
if g_zero > k_zero:
  print(k_zero + len(g_s)-g_zero) 
else:
  print(g_zero+ len(k_s)-k_zero)