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(input())
cnt=0
for i in range(len(s)-1):
    if s[i]==s[i+1] and s[i]=='0':
        s[i+1]='1'
        cnt+=1
    elif s[i]==s[i+1] and s[i]=='1':
        s[i+1]='0'
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# ABC124C - Coloring Colorfully
def main():
    S = input()
    a = S[::2].count("1") + S[1::2].count("0")
    b = len(S) - a
    print(min(a, b))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC124C - Coloring Colorfully
def main():
    S = input()
    a = sum(i != "1" for i in S[::2]) + sum(i != "0" for i in S[1::2])
    b = len(S) - a
    print(min(a, b))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC124C - Coloring Colorfully
def main():
    s = input()
    a, ans = s[0], 0
    for i, j in enumerate(s):
        if (i % 2 and j == a) or (not i % 2 and j != a):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

s=list(input())
ans=0
for i in range(len(s)-1):
    if s[i]=="0" and s[i+1]=="0":
        s[i+1]="1"
        ans+=1
    elif s[i]=="1" and s[i+1]=="1":
        s[i+1]="0"
        ans+=1
    else:
        pass
    
print(ans)

Submission status: Accepted

Solution code:
S = str(raw_input())
n = len(S)

pattern0 = ("10" * (n//2 + 1))
pattern1 = ("01" * (n//2 + 1))
count0 = 0
count1 = 0

for i in range(n):
    if pattern0[i] != S[i]:
        count0 += 1
    if pattern1[i] != S[i]:
        count1 += 1

print min(count0, count1)

Submission status: Accepted

Solution code:
s = input()

ans_a = 0
ans_b = 0
for i in range(len(s)):
	if i%2 == 0 and s[i] =="0":
		pass
	elif i%2 == 1 and s[i]=="1":
		pass
	else:
		ans_a += 1

for i in range(len(s)):
	if i%2 == 0 and s[i] =="1":
		pass
	elif i%2 == 1 and s[i]=="0":
		pass
	else:
		ans_b += 1
print(min(ans_a, ans_b))

Submission status: Accepted

Solution code:
s = list(str(input()))
l = len(s)
ans = 0
for i in range(l-1):
    if s[i] == s[i+1]:
        if s[i] == '0':
            s[i+1] = '1'
            ans += 1
        else:
            s[i+1] = '0'
            ans += 1
    else:
        continue

print(ans)

Submission status: Accepted

Solution code:
S=input()
a,c=0,True
for i in range(len(S)):
    if int(S[i])!=c:
        a+=1
    c=not c
print(min(a,len(S)-a))

Submission status: Accepted

Solution code:
s = list(input())
s = [int(_) for _ in s]
if len(s)%2 == 0:
    li1 = [0,1]*(len(s)//2)
    li2 = [1,0]*(len(s)//2)
if len(s)%2 == 1:
    li1 = [0,1]*(len(s)//2) + [0]
    li2 = [1,0]*(len(s)//2) + [1]
cnt1,cnt2 = 0,0
for i in range(len(s)):
    if s[i] != li1[i]:
        cnt1 += 1
    if s[i] != li2[i]:
        cnt2 += 1

print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
def solve():
    s = [i for i in input()]
    n = len(s)
    return min([len([True for i, j in zip(s, ["1" if i % 2 == mod else "0" for i in range(n)]) if i != j]) for mod in [0, 1]])


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

Submission status: Accepted

Solution code:
From0 = ['0','1']*(10**6)
From1 = ['1','0']*(10**6)
s = list(input())
F0 = From0[:len(s)]
F1 = From1[:len(s)]
count_0 = 0
count_1 = 0
for i in range(len(s)):
  if s[i] != F0[i]:
    count_0 += 1
for i in range(len(s)):
  if s[i] != F1[i]:
    count_1 += 1
print(min(count_0,count_1))

Submission status: Accepted

Solution code:
# ABC 124 c
s = input()
n = len(s)

# 1010...
t = ''.join(['0' if i % 2 == 0 else '1' for i in range(n)])
t_count = 0
for i, j in zip(s, t):
    if i == j:
        pass
    else:
        t_count += 1

# 0101...
u = ''.join(['1' if i % 2 == 0 else '0' for i in range(n)])

u_count = 0
for i, j in zip(s, u):
    if i == j:
        pass
    else:
        u_count += 1
print(min(t_count, u_count))

Submission status: Accepted

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

top_zero = []
top_one = []

for i in range(len(s)):
    if i % 2 == 0:
        top_zero.append(0)
        top_one.append(1)
    else:
        top_zero.append(1)
        top_one.append(0)

count_zero = 0
count_one = 0

for i in range(len(s)):
    if top_zero[i] == s[i]:
        count_zero += 1
    if top_one[i] == s[i]:
        count_one += 1

print(min(count_zero, count_one))

Submission status: Accepted

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

count_even = 0
count_odd = 0

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

if len(s) % 2 == 0:
    ans = (int(len(s)/2) - max(count_even, count_odd)) + min(count_even, count_odd)
else:
    if count_even >= (len(s)+1)/4:
        ans = (((len(s)+1)/2) - count_even) + count_odd
    else:
        ans = count_even + (len(s)-1)/2 - count_odd

print(int(ans))

Submission status: Accepted

Solution code:
s = input()
b = True
a1 = 0
a2 = 0
for i in range(len(s)):
    if s[i] != ("0" if b else "1"):
        a1 += 1
    if s[i] != ("1" if b else "0"):
        a2 += 1
    b = not b
print(min(a1, a2))

Submission status: Accepted

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

for i in range(1,len(s)):
    if s[0]==0:
        if i%2==0 and s[i]==1:
            an+=1
        elif i%2==1 and s[i]==0:
            an+=1
    else:
        if i%2==0 and s[i]==0:
            an+=1
        elif i%2==1 and s[i]==1:
            an+=1

print(an)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

s = input()
n = len(s)

case1 = []
case2 = []
now = 0
for i in range(n):
    c = '0' if now else '1'
    case1.append(c)
    c = '1' if c == '0' else '0'
    case2.append(c)
    now = 1 - now

case1 = "".join(case1)
case2 = "".join(case2)

res1, res2 = 0, 0
for i in range(n):
    res1 += 1 if case1[i] != s[i] else 0
    res2 += 1 if case2[i] != s[i] else 0

print(min(res1, res2))

Submission status: Accepted

Solution code:
s = input()

chenge_01 = 0
chenge_10 = 0

for i in range(len(s)):
    if i%2 == 0:
        if s[i] == '0':
            chenge_01 += 1
        else:
            chenge_10 += 1
    else:
        if s[i] == '1':
            chenge_01 += 1
        else:
            chenge_10 += 1

print(min(chenge_01,chenge_10))

Submission status: Accepted

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

l1 = ["0" if i % 2 == 0 else "1" for i in range(n)]
l2 = ["1" if i % 2 == 0 else "0" for i in range(n)]

diff1, diff2 = 0, 0

for i in range(n):
    if s[i] == l1[i]:
        diff1 += 1
    if s[i] == l2[i]:
        diff2 += 1

print(diff1 if diff1 <= diff2 else diff2)

Submission status: Accepted

Solution code:
list_S = list(input())
S = [int(s) for s in list_S]
s1 = S[::2]
s2 = S[1::2]
sums1 = sum(s1)
sums2 = sum(s2)
if sums1>sums2: print(len(s1)-sums1+sums2)
else: print(len(s2)-sums2+sums1)

Submission status: Accepted

Solution code:
def resolve():
    list_S = list(input())
    S = [int(s) for s in list_S]
#    print()
#    print(S)
    s1 = S[::2]
    s2 = S[1::2]
#    print(s1)
#    print(s2)
    
#    print(sum(s1))
#    print(sum(s2))
    sums1 = sum(s1)
    sums2 = sum(s2)
    if sums1>sums2:
        print(len(s1)-sums1+sums2)
    else:
        print(len(s2)-sums2+sums1)

resolve()

Submission status: Accepted

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

a = []
c = []
b = True
for i in range(len(S)):
    if b:
        a.append(1)
        c.append(0)
        b=False
    else:
        a.append(0)
        c.append(1)
        b=True

combined1 = [abs(x-y) for (x, y) in zip(S, a)]
combined2 = [abs(x-y) for (x, y) in zip(S, c)]

if len(S)==1:
    print(0)
else:
    print(min(sum(combined1), sum(combined2)))

Submission status: Accepted

Solution code:
s = input()
l = [int(x) for x in list(str(s))]

ans_a = 0
for i in range(len(s)):
	if i%2 ==0 and l[i] == 0:
		pass
	elif i%2==1 and l[i] ==1:
		pass
	else:
		ans_a += 1

ans_b = 0
for i in range(len(s)):
	if i%2 ==0 and l[i] == 1:
		pass
	elif i%2 ==1 and l[i] == 0:
		pass
	else:
		ans_b += 1
print(min(ans_b,ans_a))

Submission status: Accepted

Solution code:
from collections import deque

S = input()

Sint = int(S,2)
Slen = len(S)

def create_wbint(l, start_with_white=True):
    is_white = start_with_white
    wbdeque = deque([])
    for i in range(l):
        if is_white:
            wbdeque.append('0')
        else:
            wbdeque.append('1')
        is_white = not is_white
    return int(''.join(wbdeque),2)


WBint = create_wbint(Slen, start_with_white=True)
BWint = create_wbint(Slen, start_with_white=False)

WBxor = Sint ^ WBint
count_1_in_wb = 0
for c in bin(WBxor):
    if c == '1':
        count_1_in_wb +=1

BWxor = Sint ^ BWint
count_1_in_bw = 0
for c in bin(BWxor):
    if c == '1':
        count_1_in_bw +=1

print(min(count_1_in_wb, count_1_in_bw))

Submission status: Accepted

Solution code:
s = input()
cnt = 0
if len(s) ==1:
    print("0")
elif len(s) ==2:
    if len(set(s))==1:
        print("1")
    else:
        print("0")
elif len(s) ==3:
    if len(set(s)) == 1:
        print("1")
    else:
        if s[0] == s[2]:
            print("0")
        else:
            print("1")
else:
    pass
if  len(s)>=2 and s[0]==s[1]:
    s = list(s)
    s[1] = str(abs(int(s[0])-1))
    s = "".join(s)
    cnt +=1
if len(s)%2 and len(s)>=4:
    for i in range(0,len(s)+1,2):
        if s[i] != s[0]:
            cnt +=1
    for i in range(1,len(s),2):
        if s[i] != s[1]:
            cnt +=1
    print(cnt)
elif len(s)%2==0 and len(s)>=4:
    for i in range(0,len(s),2):
        if s[i] != s[0]:
            cnt +=1
    for i in range(1,len(s)+1,2):
        if s[i] != s[1]:
            cnt +=1
    print(cnt)

Submission status: Accepted

Solution code:
s = input()
cnt_a = 0
cnt_b = 0

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

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

print(min(cnt_a, cnt_b))

Submission status: Accepted

Solution code:
S = input()

s0 = 0
s1 = 0
for i, s in enumerate(list(S)):
    s0 += int(str(i % 2) == s)
    s1 += int(str((i + 1) % 2) == s)
print(min(s0, s1))

Submission status: Accepted

Solution code:
S = input()

s0 = [0 for i in range(len(S))]
s1 = [1 for i in range(len(S))]
for i in range(0, len(S), 2):
    s0[i] = (s0[i] + 1) % 2
    s1[i] = (s1[i] + 1) % 2

s0 = ''.join(map(str, s0))
s1 = ''.join(map(str, s1))


def cnt(x):
    cnt = 0
    while x > 0:
        cnt += x & 1
        x = x >> 1
    return cnt


print(min(cnt(int(S, 2) ^ int(s0, 2)), cnt(int(S, 2) ^ int(s1, 2))))

Submission status: Accepted

Solution code:
S = input().strip()
l = len(S)

if l == 1:
    print(0)
    exit()

cnt10 = 0
cnt01 = 0
for i in range(l):
    if i % 2:
        # odd
        if S[i] == '1':
            cnt10 += 1
        else:
            cnt01 += 1
    else:
        # even
        if S[i] == '0':
            cnt10 += 1
        else:
            cnt01 += 1

print(min(cnt01, cnt10))

Submission status: Accepted

Solution code:
def count(S, val):
    ret = 0
    for i in range(0, len(S)):
        if S[i] != val:
            ret = ret + 1
        if val == '0':
            val = '1'
        else:
            val = '0'
    return ret
  
def main():
    S = input()
    print(min(count(S,'0'),count(S,'1')))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
N = len(S)
even = S[0::2]
odd = S[1::2]
ptn0 = N - (even.count('1') + odd.count('0'))
ptn1 = N - (even.count('0') + odd.count('1'))
print(min(ptn0, ptn1))

Submission status: Accepted

Solution code:
s=input()
d=s[0]
for i in range(len(s)-1):
	if d[i]=="0":
		d+="1"
	else:
		d+="0"
cnt=0
for i in range(len(s)):
	if s[i]!=d[i]:
		cnt+=1
print(cnt)

Submission status: Accepted

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

a=''
for i in range(n):
        if i%2==0:
                a+='1'
        else:
                a+='0'
c=0
d=0
for j in range(n):
        if s[j]==a[j]:
                c+=1
        else:
                d+=1
print(min(c,d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(string):
    return str(
        len(string) - max(sum([s == str(i % 2) for i, s in enumerate(string)]),
                          sum([s == str(i % 2) for i, s in enumerate(string, start=1)])))


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
s=list(map(int,str(input())))
n=len(s)
a=0
b=0
for i in range(n):
  if ((i%2)+s[i])%2==0:
    a+=1
  else:
    b+=1
print(n-max(a,b))

Submission status: Accepted

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

cnt0=0
cnt1=0

for i in range(n):
  if i%2==0:
    cnt0+=(1-(0^int(s[i])))
    cnt1+=(1&int(s[i]))
  else:
    cnt0+=(1&int(s[i]))
    cnt1+=(1-(0^int(s[i])))
    
print(min(cnt0,cnt1))

Submission status: Accepted

Solution code:
S = input()
L = []
for i in range(len(S)):
  c = S[i]
  c2 = 0 if c == "0" else 1
  if i%2 == 0:
    c2 = 1-c2
  L.append(c2)
count1 = len(list(filter(lambda c: c == 0, L)))
count2 = len(list(filter(lambda c: c == 1, L)))
count = min(count1, count2)
print(count)

Submission status: Accepted

Solution code:
s = input()

a1 = a2 = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            a2 += 1
        else:
            a1 += 1
    else:
        if s[i] == '0':
            a1 += 1
        else:
            a2 += 1

print(min(a1, a2))

Submission status: Accepted

Solution code:
import numpy as np
S = str(input())
moji1 = "0"
moji2 = "1"
while len(moji1) < len(S):
    if moji1[-1] == "0":
        moji1 += "1"
        moji2 += "0"
    else:
        moji1 += "0"
        moji2 += "1"

Sarr = np.array([int(i) for i in S])
arr1 = np.array(([int(i) for i in moji1]))
arr2 = np.array(([int(i) for i in moji2]))
S1 = np.count_nonzero(Sarr - arr1 != 0)
S2 = np.count_nonzero(Sarr - arr2 != 0)
print(min(S1, S2))

Submission status: Accepted

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


def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())

origin = [int(s) for s in input()]

length = len(origin)
cand_list = [0 for _ in range(length)]
for i in range(0, length, 2):
    cand_list[i] = 1

cnt1 = 0
cnt2 = 0
for i in range(length):
    if origin[i] == cand_list[i]:
        cnt2 += 1
    else:
        cnt1 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

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

S_int = int(S, 2)

count_b = 0
black_ff = [str(i % 2) for i in range(N)]
for i, d in enumerate(black_ff):
    if S[i] != d: count_b += 1

count_w = 0
white_ff = ["0" if i % 2 == 1 else "1" for i in range(N)]
for i, d in enumerate(white_ff):
    if S[i] != d: count_w += 1
        
print(min(count_b, count_w))

Submission status: Accepted

Solution code:
S = input()
sum1 = 0
sum2 = 0
for i in range(len(S)):
	if i % 2 == 0 and S[i] == '0':
		sum1 += 1
	elif i % 2 == 0 and S[i] == '1':
		sum2 += 1
	elif i % 2 == 1 and S[i] == '0':
		sum2 += 1
	elif i % 2 == 1 and S[i] == '1':
		sum1 += 1
print(min(sum1, sum2))

Submission status: Accepted

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

txt1 = ''
txt2 = ''

for i in range(l):
    if i%2==0:
        txt1 += '0'
        txt2 += '1'
    else:
        txt1 += '1'
        txt2 += '0'

cnt1 = 0
cnt2 = 0

for i in range(l):
    if s[i] != txt1[i]:
        cnt1 += 1
    if s[i] != txt2[i]:
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()
s1 = '01' * (10 ** 5 // 2)
s1 = s1[:len(s)]
count = [0, 0]

for i in range(len(s)):
    if s[i] != s1[i]:
        count[0] += 1
    else:
        count[1] += 1

print(min(count))

Submission status: Accepted

Solution code:
s = input()
s1 = '01' * (10 ** 5 // 2)
s2 = '10' * (10 ** 5 // 2)
s1 = s1[:len(s)]
s2 = s2[:len(s)]
count = [0, 0]

for i in range(len(s)):
    if s[i] != s1[i]:
        count[0] += 1
    else:
        count[1] += 1

print(min(count))

Submission status: Accepted

Solution code:
# Coloring Colorfully

S = list(map(int, input()))

S_ = S[:]
cnt_0 = 0
for i in range(1, len(S_)):
	if S_[i] == S_[i-1]:
		S_[i] = (S_[i]+1)%2
		cnt_0 += 1

S_ = S[:]
cnt_1 = 1
S_[0] = (S_[0]+1)%2
for i in range(1, len(S_)):
	if S_[i] == S_[i-1]:
		S_[i] = (S_[i]+1)%2
		cnt_1 += 1
		
print(min(cnt_0, cnt_1))

Submission status: Accepted

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

t1='01'*(n//2+1)
t2='10'*(n//2+1)

t1_chk=0
t2_chk=0

for i in range(n):
	if s[i]!=t1[i]:
		t1_chk+=1
	if s[i]!=t2[i]:
		t2_chk+=1

print(min(t1_chk,t2_chk))

Submission status: Accepted

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces1197
gi = lambda : list(map(int,input()))
l = gi()
n = len(l)
print(min(sum([abs(k%2 - l[k]) for k in range(n)]), sum([abs((k + 1)%2 - l[k]) for k in range(n)])))

Submission status: Accepted

Solution code:
import numpy as np

def main():
    S = input()
    S_np = np.array([int(S[i]) for i in range(len(S))])
    final_0_origin = np.array([i % 2 for i in range(len(S))])
    final_1_origin = np.array([(i+1) % 2  for i in range(len(S))])

    ans = min(cal_dist(S_np, final_0_origin), cal_dist(S_np, final_1_origin))
    print(ans)

def cal_dist(S_np, T_np):
    return np.sum(S_np ^ T_np)

main()

Submission status: Accepted

Solution code:
s = sss = [_ for _ in input()]

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

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

Submission status: Accepted

Solution code:
sss = [i for i in input()]
n = int(len(sss))
if n%2 == 0:
  g1 = "01"*n
  g2 = "10"*n
else:
  g1 = "01"*int((n-1)/2) + "0"
  g2 = "10"*int((n-1)/2) + "1"
count_1 = 0
count_2 = 0
for i in range(n):
  if not sss[i] == g1[i]:
    count_1 += 1
  if not sss[i] == g2[i]:
    count_2 += 1
print(min(count_1, count_2))

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	s = input()
	a = []
	b = []
	for i in range(len(s)//2):
		a.append('1')
		a.append('0')
		b.append('0')
		b.append('1')
	if(len(s)%2==1):
		a.append('1')
		b.append('0')
	ac = 0
	bc = 0
	for i in range(len(s)):
		if(a[i] != s[i]):
			ac+=1
		if(b[i] != s[i]):
			bc+=1
	print(min(ac,bc))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
s = input()

candi = []

candi.append(s[0::2].count('0') + s[1::2].count('1'))
candi.append(s[0::2].count('1') + s[1::2].count('0'))

print(min(candi))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s = input()

ans1 = ans2 = 0
for i,c in enumerate(s):
    if str(i&1) == c:
        ans1 += 1
    else:
        ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

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

a = S[0:N:2].count("0")
b = S[1:N:2].count("1")
c = S[0:N:2].count("1")
d = S[1:N:2].count("0")

print(min(a+b,c+d))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
if  N ==1:
    print(0)
    exit()
a = S[0:N:2].count("0")
b = S[1:N:2].count("1")
c = S[0:N:2].count("1")
d = S[1:N:2].count("0")

print(min(a+b,c+d))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC124C
import sys

s = input()
n=len(s)

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

print(min(n-num,num))

Submission status: Accepted

Solution code:
S = input()

def flip_num(goal):
    return sum([0 if S[i] == goal[i] else 1 for i in range(len(S))])

def stripe(zero_first):
    if (zero_first):
        return ['0' if i % 2 == 0 else '1' for i in range(len(S))]
    else:
        return ['0' if i % 2 == 1 else '1' for i in range(len(S))]

print(min(flip_num(stripe(True)), flip_num(stripe(False))))

Submission status: Accepted

Solution code:
s = list(input())
cnt = 0
for i in range(len(s) - 1):
    if s[i] == s[i+1]:
        if s[i+1] == "0":
            s[i+1] = "1"
        elif s[i+1] == "1":
            s[i+1] = "0"
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
S = input()
a=[]
b=[]
for i in range(len(S)):
    if i%2 == 0:
        a.append(0)
        b.append(1)
    else:
        a.append(1)
        b.append(0)
Slist = [int(i) for i in S]
counta=0
countb=0

for i in range(len(Slist)):
    if Slist[i] != a[i]:
        counta+=1
    if Slist[i] != b[i]:
        countb+=1
if counta<=countb:
    print(counta)
else:
    print(countb)

Submission status: Accepted

Solution code:
N = list(map(int, input()))
# 最初が0のとき
if N[0] == 0:
    seikai = [0] * int(len(N))
    for i in range(1, len(N), 2):
        seikai[i] = 1
else:
    seikai = [1] * int(len(N))
    for i in range(1, len(N), 2):
        seikai[i] = 0

ans = 0
for m in range(len(N)):
    if not N[m] == seikai[m]:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect







def main():
    s = list(input())
    s = list(map(int, s))
    scopy = deepcopy(s)
    scopy[0] ^= 1

    cnt = 0
    cntc = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            s[i] ^= 1
            cnt += 1
        if scopy[i] == scopy[i-1]:
            scopy[i] ^= 1
            cntc += 1
    print(min(cnt,cntc))







main()

Submission status: Accepted

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

if S[0] == '0' and N % 2 == 0:
    white_black = [0,1]*(N//2)
elif S[0] == '1' and N % 2 == 0:
    white_black = [1,0]*(N//2)
elif S[0] == '0' and N % 2 == 1:
    white_black = [0,1]*(N//2) + [0]
elif S[0] == '1' and N % 2 == 1:
    white_black = [1,0]*(N//2) + [1]

count = 0

for i in range(N):
    if S[i] != str(white_black[i]):
        count += 1

print(count)

Submission status: Accepted

Solution code:
s = input().split()[0]

pat_1_list = []
pat_2_list = []

for i in range(len(s)):
    if i % 2 == 0:
        pat_1_list.append('0')
        pat_2_list.append('1')
    else:
        pat_1_list.append('1')
        pat_2_list.append('0')

change_count_list = []

for pat_list in [pat_1_list, pat_2_list]:
    # print('pat_list: {}'.format(pat_list))
    change_count = 0
    for pat_char, s_char in zip(pat_list, s):
        if pat_char != s_char:
            change_count += 1
    change_count_list.append(change_count)

# print(change_count_list)
ans = min(change_count_list)

print(ans)

Submission status: Accepted

Solution code:
S = input()
S_2 = list(map(int,S))

even = 0 #[0,1,0,1]
odd = 0 #[1,0,1,0]

for i,v in enumerate(S_2):
        if i % 2 == 0:
                #偶数
                if v == 0:
                        odd += 1
                else:
                        even += 1
        else:
                #偶数
                if v == 1:
                        odd += 1
                else:
                        even += 1

print(min(odd,even))

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
Mod = 1000000007



def main(): #startline-------------------------------------------
    S = input()
    keep = "A"
    ans = 0
    for i in S:
        if keep == "A":
            keep = i
        elif keep == i:
            ans += 1
            keep = ("0" if i == "1" else "1")
        else:
            keep = i
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================




def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Accepted

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


even0 = 0
even1 = 0
odd0 = 0
odd1 = 0

for i in range(n):
    if i%2 == 0:
        if s[i] == "0":
            even0 += 1
        else:
            even1 += 1
    else:
        if s[i] == "0":
            odd0 += 1
        else:
            odd1 += 1
print(min(n-even0-odd1,n-odd0-even1))

Submission status: Accepted

Solution code:
stri=input()
c1=0
c2=0
n=len(stri)
i=0

c1beg=0
c2beg=1
while(i<n):
	if(int(stri[i])!=(c1beg%2)):
		c1+=1
	if(int(stri[i])!=(c2beg%2)):
		c2+=1
	c1beg+=1
	c2beg+=1
	i+=1
print(min(c1,c2))

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

ans1 = sum([1 for i in range(N) if i % 2 == 0 and S[i] == "0"]) + sum([1 for i in range(N) if i % 2 != 0 and S[i] == "1"])
ans2 = sum([1 for i in range(N) if i % 2 == 0 and S[i] == "1"]) + sum([1 for i in range(N) if i % 2 != 0 and S[i] == "0"])
print(min(ans1, ans2))

Submission status: Accepted

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

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

print(min([cnt, leng - cnt]))

Submission status: Accepted

Solution code:
s=list(map(int,input()))
l=[1,0]*(len(s)//2+1)
r=[0,1]*(len(s)//2+1)
lc=0
rc=0
for i in range(len(s)):
    if s[i]!=l[i]:
        lc+=1
    elif s[i]!=r[i]:
        rc+=1
print(min(lc,rc))

Submission status: Accepted

Solution code:
def check(s,l,num):
    dif=0
    for i in range(l):
        if s[i] != str(num):
            dif+=1
        num=(num+1)%2
    return dif

s=input()
l=len(s)
print(min(check(s,l,0),check(s,l,1)))

Submission status: Accepted

Solution code:
def zero(s,l):
    dif=0
    num=0
    for i in range(l):
        if s[i] != str(num):
            dif+=1
        num=(num+1)%2
    return dif

def one(s,l):
    dif=0
    num=1
    for i in range(l):
        if s[i] != str(num):
            dif+=1
        num=(num+1)%2
    return dif

s=input()
l=len(s)
print(min(zero(s,l),one(s,l)))

Submission status: Accepted

Solution code:
a = input()
count = 0
mojiretu_01 = ""
mojiretu_10 = ""

for i in range(len(a)):
    if i % 2 == 0:
        mojiretu_01 += "0"
        mojiretu_10 += "1"
    else:
        mojiretu_01 += "1"
        mojiretu_10 += "0"
count01 = 0
count10 = 0

for i in range(len(a)):
    if a[i] != mojiretu_01[i]:
        count01 += 1
    else:
        count10 += 1

print(min(count01, count10))

Submission status: Accepted

Solution code:
s = input()

c1 = 0
c2= 0

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

print(min(c1, c2))

Submission status: Accepted

Solution code:
S = input()

s1, s2 = 0, 0
for i, s in enumerate(S) :
    if i % 2 != int(s) :
        s1 += 1
    else :
        s2 += 1

print(min(s1, s2))

Submission status: Accepted

Solution code:
# 2019/07/24

s=list(input())

a=['1','0']
b=['0','1']

cnta=0
cntb=0

for i in range(len(s)):
    r=i%2
    if s[i]!=a[r]:cnta+=1
    elif s[i]!=b[r]:cntb+=1

print(min(cnta,cntb))

Submission status: Accepted

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

aim = 1

for _ in range(int(N/2)):
    aim <<= 2
    aim |= 0b10
if N % 2 == 1 and N != 0:
    aim <<= 1
    aim |= 0b1

S = int(S, 2)
mask = "1" * (N)
mask = int(mask, 2)
aim = aim & mask

differences = bin(S ^ aim)
Num1 = differences.count("1")
Num0 = N - Num1

print(min(Num1, Num0))

Submission status: Accepted

Solution code:
s="0b"+input()
a=int("0b"+"10"*(len(s)//2-1)+"1"*(len(s)%2==1),0)
s=int(s,0)
c=lambda x:str(bin(x)).count("1")
print(min(c(s^a),c(s^a^int("0b"+"1"*(len(bin(a))-2),0))))