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] == '0':
        S[i+1] = '1'
        cnt += 1
    elif S[i] == S[i+1] == '1':
        S[i+1] = '0'
        cnt += 1
    else:
        pass

print(cnt)

Submission status: Accepted

Solution code:
s=input()
o1=0
o0=0
e1=0
e0=0
for i in range(0,len(s),2):
  if s[i]=='1': o1+=1
  else: o0+=1
for i in range(1,len(s),2):
  if s[i]=='1': e1+=1
  else: e0+=1
if o1+e0<o0+e1: print(len(s)-(o0+e1))
else: print(len(s)-(o1+e0))

Submission status: Accepted

Solution code:
S = list(input())
ans = 0
ans2 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            ans += 1
    else:
        if S[i] == "1":
            ans += 1

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

print(min(ans,ans2))

Submission status: Accepted

Solution code:
S = list(input())

#白から
cnt1 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s != '0':
            cnt1 += 1
    else:
        if s != '1':
            cnt1 += 1

#黑から
cnt2 = 0
for i, s in enumerate(S):
    if i % 2 == 0:
        if s != '1':
            cnt2 += 1
    else:
        if s != '0':
            cnt2 += 1

print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

S = input()
N = len(S)
cnt_wb = 0 # 白黒
cnt_bw = 0 # 黒白
for i in range(N):
    if (S[i] == '0') ^ (i % 2 == 0):
        cnt_wb += 1
    else:
        cnt_bw += 1
print(min(cnt_wb, cnt_bw))

Submission status: Accepted

Solution code:
s = input()

if s[0] == "1":
    ans = 0
    for i in range(len(s)) :
        if i % 2 == 0 and s[i] != "1" :
            ans += 1
        elif i % 2 == 1 and s[i] != "0" :
            ans += 1
else :
    ans = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != "0":
            ans += 1
        elif i % 2 == 1 and s[i] != "1":
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def examA():
    A = LI()
    A.sort()
    ans = A[1] + max(A[1]-1,A[0])
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    S = SI()
    N = len(S)
    S12 = ["01"*N, "10"*N]
    ans = inf
    for s in S12:
        cnt = 0
        for i in range(N):
            if s[i]==S[i]:
                continue
            cnt += 1
        ans = min(ans,cnt)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
l=len(s)
a,b="", ""
for i in range(l):
  if i %2==0:
    a += "1"
    b += "0"
  else:
    a += "0"
    b += "1"
diff_a, diff_b = 0, 0
for i in range(l):
  if a[i] != s[i]:
    diff_a += 1
  if b[i] != s[i]:
    diff_b += 1
print(min(diff_a, diff_b))

Submission status: Accepted

Solution code:
def main():
    s = list(input())
    n = len(s)
    cnt0, cnt1 = 0, 0

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

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

    print(min(cnt0, cnt1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

result = 10 ** 9
# 0始まりで揃える場合
tmp = 0
for i, c in enumerate(s):
  if i & 1:
    if c == '0':
      tmp += 1
  else:
    if c == '1':
      tmp += 1
      
result = min(result, tmp)
tmp = 0

# 1始まりで揃える場合
for i, c in enumerate(s):
  if i & 1:
    if c == '1':
      tmp += 1
  else:
    if c == '0':
      tmp += 1
      
result = min(result, tmp)
print(result)

Submission status: Accepted

Solution code:
import copy
S=input()
ListS = list(S)
revListS = copy.deepcopy(ListS)
norm = 0
rev = 0
N = len(ListS)
for i in range(1,N):
  if ListS[i] == ListS[i-1]:
    ListS[i] = str(abs(int(ListS[i])-1))
    norm += 1
  if revListS[N-i-1] == revListS[N-i]:
    revListS[N-i-1] = str(abs(int(revListS[N-i-1])-1))
    rev += 1
res = min(norm,rev)
print(res)

Submission status: Accepted

Solution code:
s=input()
canw=0
canb=0
for i in range(len(s)):
  if i%2==1:
    if s[i]=='1':
      canw+=1
    else:
      canb+=1
  elif i%2==0:
    if s[i]=='1':
      canb+=1
    else:
      canw+=1

print(min(canb,canw))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
d=[]
for i in range(n):
  d.append(int(s[i]))
s1=[0]
s2=[1]
for i in range(1,n):
  if s1[i-1]==0:
    s1.append(1)
  else:
    s1.append(0)
  if s2[i-1]==1:
    s2.append(0)
  else:
    s2.append(1)
a,b=0,0
for i in range(n):
  if d[i]!=s1[i]:
    a+=1
  if d[i]!=s2[i]:
    b+=1
print(min(a,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
f = S[0]
c = 0
for i in range(1, len(S)):
  if i % 2 == 1:
    if f == S[i]:
      c += 1
  else:
    if f != S[i]:
      c += 1
print(c)

Submission status: Accepted

Solution code:
S = list(input())
f = S[0]
c = 0
for i in range(1, len(S)):
  if i % 2 == 1:
    if f == S[i]:
      c += 1
  else:
    if f != S[i]:
      c += 1
print(c)

Submission status: Accepted

Solution code:
s = input()

start = ['0', '1']
ans = 10**6
for offset in [0,1]:
    now = 0
    for i in range(len(s)):
        j = (i+offset) % 2
        if s[i] != start[j]:
            now += 1
    ans = min(ans, now)

print(ans)

Submission status: Accepted

Solution code:
s=input()

start_0=0
start_1=0

for i,j in enumerate(s):
  if i%2==0 and j=="1":
    start_0+=1
  elif i%2!=0 and j=="0":
    start_0+=1
  elif i%2==0 and j=="0":
    start_1+=1
  elif i%2!=0 and j=="1":
    start_1+=1
    
print(min(start_0, start_1))

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:
s=input()
mae=""
cnt=0
for i in range(len(s)):
  if mae==s[i]:
    cnt+=1
    if s[i]=="0":
      mae="1"
    else:
      mae="0"

  else:
    mae=s[i]
    
print(cnt)

Submission status: Accepted

Solution code:
S = input()

c = 0
l = len(S)

for i in range(l):
    if S[i] == str(i % 2):
        c += 1

print(min(c, l-c))

Submission status: Accepted

Solution code:
s = input()
x = ""
y = ""
x_con = 0
y_con = 0
for i in range(len(s)):
  if i % 2 == 0:
    x += "0"
    y += "1"
  else:
    x += "1"
    y += "0"

for i in range(len(s)):
  if s[i] != x[i]:
    x_con += 1
  if s[i] != y[i]:
    y_con += 1
  
print(min(x_con, y_con))

Submission status: Accepted

Solution code:
s = list(map(int, input()))
ans1 = 0
ans2 = 0
for i in range(len(s)):
    if i%2 == 0:
        if s[i] == 0:
            ans1 += 1
        else:
            ans2 += 1
    else:
        if s[i] == 0:
            ans2 += 1
        else:
            ans1 += 1
ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans=[0,0]
for i in range(len(s)):
    now=int(s[i])
    ans[0]+=now^0^(i%2)
    ans[1]+=now^1^(i%2)
print(min(ans))

Submission status: Accepted

Solution code:
S = input()
A = S[0::2].count("1") + S[1::2].count("0")
B = S[0::2].count("0") + S[1::2].count("1")
  
print(min(A,B))

Submission status: Accepted

Solution code:
S = input()
ans = 0

if S[0]=="0":
  ans += S[0::2].count("1")
  ans += S[1::2].count("0")
  
else:
  ans += S[0::2].count("0")
  ans += S[1::2].count("1")
  
print(ans)

Submission status: Accepted

Solution code:
s = [int(x) for x in list(input())]
x = len(s)
y = [0 if i % 2 ==0 else 1 for i in range(x)]
z = [1 if i % 2 ==0 else 0 for i in range(x)]
count1 = 0
count2 = 0
ans1 = list(zip(s,y))
ans2 = list(zip(s,z))
for a in ans1:
  if a[0] != a[1]:
    count1 += 1
for a in ans2:
  if a[0] != a[1]:
    count2 += 1
print(min(count1,count2))

Submission status: Accepted

Solution code:
S = input()
L = len(S)
c = 0
j = 0
for i in range(L):
  c += abs(j-int(S[i]))
  j ^= 1
print(min(c, L-c))

Submission status: Accepted

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

cnt_1 = 0
cnt_2 = 0

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

for j in range(N):
  if j%2 == 0:
    if S[j] == "1":
      cnt_2 += 1
  else:
    if S[j] == "0":
      cnt_2 += 1
      
print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
S=input()
chars = []
moves1 = 0
moves2 = 0
n = 0
for c in S:
    n += 1
    if c == '0':
        if n % 2 == 0:
            moves1 += 1
        else:
            moves2 += 1
    else:
        if n % 2 == 0:
            moves2 += 1
        else:
            moves1 += 1

print(min(moves1,moves2))

Submission status: Accepted

Solution code:
s=input()

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

diff_tmp1 = 0
diff_tmp2 = 0
for i in range(len(s)):
  if tmp1[i] != s[i]:
    diff_tmp1 += 1
  elif tmp2[i] != s[i]:
    diff_tmp2 += 1
print(min(diff_tmp1,diff_tmp2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str10,str01 = '',''
for i in range(5 * (10**4) + 1):
    str10 += '10'
    str01 += '01'

s = str(input())
len_s = len(s)
str10 = str10[:len_s]
str01 = str01[:len_s]
#print(str10,str01)

cnt10,cnt01 = 0,0
for i in range(len_s):
    if s[i]!=str10[i]:
        cnt10 += 1
    if s[i]!=str01[i]:
        cnt01 += 1
print(min(cnt10,cnt01))

Submission status: Accepted

Solution code:

s=input()
S=len(s)

li_0=[]
for i in s:
    li_0.append(int(i))

li=[0,1]*10**5
li_1=[]
li_2=[]

cnt1=0
cnt2=0

for i in range(S):
    li_1.append(li[i])
    li_2.append(li[i+1])

for i in range(S):
    if li_0[i]==li_1[i]:
        cnt1+=1
    if li_0[i]==li_2[i]:
        cnt2+=1

if cnt1>=cnt2:
    print(S-cnt1)
else:
    print(S-cnt2)

Submission status: Accepted

Solution code:
s = input()
oi = "01"*(len(s)//2)
io = "10"*(len(s)//2)
if len(s)%2 == 1:
    oi += "0"
    io += "1"

oans = 0
ians = 0
for i in range(len(s)):
    if s[i] != oi[i]:
        oans += 1
    if s[i] != io[i]:
        ians += 1
print(min(oans, ians))

Submission status: Accepted

Solution code:
s = input()

words = [w for w in s]

cnt = 0
for r in range(len(words) - 1):
    if words[r+1] == words[r]:
        if words[r+1] == '0':
            words[r+1] = '1'
        else:
            words[r+1] = '0'
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    S = input()

    ans1 = 0
    res1 = 0
    ans2 = 1
    res2 = 0
    for item in S:
        item = int(item)
        if ans1%2 != item:
            res1 += 1
        if ans2%2 != item:
            res2 += 1

        ans1 += 1
        ans2 += 1

    print(min(res2, res1)) 


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
s0 = "01" * (n//2)
s1 = "10" * (n//2)
if n % 2 == 1:
  s0 += "0"
  s1 += "1"

a0 = 0
a1 = 0
for i in range(n):
  if s[i] != s0[i]:
    a0 += 1
  if s[i] != s1[i]:
    a1 += 1
print(min(a0, a1))

Submission status: Accepted

Solution code:
def main():
    S = list(input().rstrip())
    list1, list2 = [], []
    for i in range(len(S)):
        if i % 2 == 0:
            list1.append('1')
            list2.append('0')
        else:
            list1.append('0')
            list2.append('1')
    v1 = sum([1 for e, s in zip(list1, S) if e != s])
    v2 = sum([1 for e, s in zip(list2, S) if e != s])
    print(min([v1, v2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

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

    print(min(count, len(S) - count))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    ans1 = ans2 = 0
    for i, c in enumerate(S):
        if i % 2 == int(c):
            ans1 += 1
        else:
            ans2 += 1

    print(min(ans1, ans2))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
n = int(len(s))
ans_1,ans_2 = 0,0

for i in range(n):
    if i % 2 == 0:
        t = "0"
    if i % 2 == 1:
        t = "1"
    if s[i] != t:
        ans_1 += 1

for i in range(n):
    if i % 2 == 0:
        t = "1"
    if i % 2 == 1:
        t = "0"
    if s[i] != t:
        ans_2 += 1

print(min(ans_1,ans_2))

Submission status: Accepted

Solution code:
S = input().rstrip()
w = 0
b = 0
for i in range(len(S)):
    if i%2==0 and int(S[i])==0:
        w += 1
    elif  i%2==1 and int(S[i])==1:
        w += 1
    elif  i%2==0 and int(S[i])==1:
        b += 1
    elif  i%2==1 and int(S[i])==0:
        b += 1
print(min(w,b))

Submission status: Accepted

Solution code:
S = list(input())

goal = [str(i%2) for i in range(len(S))]    #完成形１'01010101...'
diff1 = 0 #完成形1'01010101...'と比較したとき、異なる文字の数
diff2 = 0 #完成形2'10101010...'と比較したとき、異なる文字の数

for i in range(len(S)):
    if S[i] != goal[i]:
        diff1 += 1
    else:
        diff2 += 1
        
print(min(diff1,diff2))

Submission status: Accepted

Solution code:
S=input()
a1=0
a2=0
p1='1'
p2='0'
for s in S:
  if s!=p1:
    a1+=1
  else:
    a2+=1
  p=p1
  p1=p2
  p2=p
print(min(a1,a2))

Submission status: Accepted

Solution code:
S = list(input())
p = S.copy()

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

for j in range(len(p)-2,-1,-1):
    if p[j] == p[j+1]:
        if p[j] == '1':
            p[j] = '0'
        else:
            p[j] = '1'
        cnt2 += 1

print(min(cnt1,cnt2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
len_s= len(s)
#print(s)
if len_s%2==0:
    ans_0=['0','1']*int(len_s/2)
    ans_1=['1', '0']*int(len_s/2)
else:
    ans_0=['0'] + ['1', '0']*int((len_s-1)/2)
    ans_1=['1'] + ['0','1']*int((len_s-1)/2)
    
#print(ans_0)
#print(ans_1)

count_0 =0
for i in range(len_s):
    if ans_0[i] is not s[i]:
        count_0+=1

count_1 =0
for i in range(len_s):
    if ans_1[i] is not s[i]:
        count_1 += 1
print(min(count_0, count_1))

Submission status: Accepted

Solution code:
s = str(input())
o1 = s[::2].count('1')
e1 = s[1::2].count('0')
x = len(s)-(o1+e1) 
o2 = s[::2].count('0')
e2 = s[1::2].count('1')
y = len(s)-(o2+e2)
print(min(x,y))

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    s = input().rstrip()
    l = len(s)
    a = 0
    ans = 0

    t = 1
    for i in s:
        if t != int(i):
            a += 1
        t = 1-t
    ans = a
    t = 0
    a = 0
    for i in s:
        if t != int(i):
            a += 1
        t = 1-t
    ans = min(a,ans)
    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
s = list(input())
now_1 = "0"
cnt_1 = 0
for i in range(len(s)):
    if s[i] != now_1:
        cnt_1 += 1
    if now_1 == "0":
        now_1 = "1"
    else:
        now_1 = "0"
now_2 = "1"
cnt_2 = 0
for i in range(len(s)):
    if s[i] != now_2:
        cnt_2 += 1
    if now_2 == "0":
        now_2 = "1"
    else:
        now_2 = "0"
print(min(cnt_1,cnt_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a, b = 0, 0
SS = '01'
for i in range(len(S)):
	if S[i] != SS[i % 2]:
		a += 1
	if S[i] != SS[1 - i % 2]:
		b += 1
print(min(a, b))

Submission status: Accepted

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    s = input().rstrip()

    pattern1 = 0
    pattern2 = 0

    for i, c in enumerate(s):
        if i % 2 == 0:
            if c == "0":
                pattern1 += 1
            else:
                pattern2 += 1
        else:
            if c == "0":
                pattern2 += 1
            else:
                pattern1 += 1

    print(min(pattern1, pattern2))

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = input()

count = 0
for i, s in enumerate(S):
    if i % 2 and s == S[0]:
        count += 1
    if i % 2 == 0 and s != S[0]:
        count += 1

if count > len(S):
    count = len(S) - count

print(count)

Submission status: Accepted

Solution code:
s = input()


e0=e1=o0=o1=0
for i in range(len(s)):
    if s[i]=="0" :
        if i%2!=0 :
            e0+=1
        else:
            o0+=1
    else:
        if i%2!=0 :
            e1+=1
        else:
            o1+=1

# print(e0,e1,o0,o1)
ot = len(s)//2 if len(s)%2==0 else (len(s)+1)//2
et = len(s)//2

ans = min(abs(e0-et)+abs(o1-ot),abs(e1-et)+abs(o0-ot))
print(ans)

Submission status: Accepted

Solution code:
s = input()
 
start0 = 0
start1 = 0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i] == "0":
      start1 += 1
    elif s[i] == "1":
      start0 += 1
  elif i % 2 == 1:
    if s[i] == "0":
      start0 += 1
    elif s[i] == "1":
      start1 += 1

print(min([start0, start1]))

Submission status: Accepted

Solution code:
#C - Coloring Colorfully
S = list(input())
S_rev = list(reversed(S))
if len(S) == 1:
    count_min = 0
else:    
    count_front = 0
    for i in range(1,len(S)):
        if S[i] == S[i-1] == '1':
            S[i] = '0'
            count_front += 1
        elif S[i] == S[i-1] == '0':
            S[i] = '1'
            count_front += 1
    count_back = 0
    for j in range(1,len(S)):
        if S_rev[j] == S_rev[j-1] == '1':
            S_rev[j] = '0'
            count_back += 1
        elif S_rev[j] == S_rev[j-1] == '0':
            S_rev[j] = '1'
            count_back += 1
    count_min = min(count_front,count_back)
print(count_min)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
S = input()
count = 0
for i,tile in enumerate(S):
    if i % 2 and tile == "0":
        count += 1
    if i % 2 == 0 and tile == "1":
        count += 1

ans = min(count, len(S) - count)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(input())

n = len(a)

c = 0

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

print(min(c, n-c))

Submission status: Accepted

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

n = int(len(s)/2)

a = [0]*len(s)
b = [0]*len(s)

for i in range(n):
  a[2*i] = 0
  a[2*i+1] = 1
  b[2*i] = 1
  b[2*i+1] = 0

if len(s)%2 ==1:
  a[len(s)-1] = 0
  b[len(s)-1] = 1 


an = 0
bn = 0

for j in range(len(s)):
  if a[j] != s[j]:
    an += 1
  if b[j] != s[j]:
    bn += 1

print(min(an, bn))

Submission status: Accepted

Solution code:
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""

s = input()
cnt = 0
new = s[0]
for i in range(1,len(s)):
    if (s[i]==new[i-1]) : 
        cnt += 1
        new +=  str((int(s[i])+1)%2)
    else: new += s[i]

print(cnt)

Submission status: Accepted

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

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

ans2=0
for i in range(0,len(S),2):
  if S[i]==0:
    ans2+=1
for i in range(1,len(S),2):
  if S[i]==1:
    ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
N=list(str(input()))
ans=0
if len(N)==1:
  print("0")
  exit()
for i in range(len(N)-1):
  if N[i]=="0" and N[i+1]=="0":
    N[i+1]="1"
    ans+=1
  elif N[i]=="1" and N[i+1]=="1":
    ans+=1
    N[i+1]="0"
print(ans)

Submission status: Accepted

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

count1 = 0
count2 = 0
for i in range(N):
    ex = str(i % 2)
    if S[i] == ex:
        count1 += 1
    else:
        count2 += 1
print(min(count1, count2))

Submission status: Accepted

Solution code:
s=input()

c1=0
c2=0

for i in range(len(s)):
    if i%2==0:
        c1+=1 if s[i]=='1' else 0
        c2+=1 if s[i]=='0' else 0
    else:
        c1+=1 if s[i]=='0' else 0
        c2+=1 if s[i]=='1' else 0
    
print(min(c1,c2))

Submission status: Accepted

Solution code:
def solve(i,S):
    t = i
    ret = 0
    for c in S:
        if c != t:
            ret += 1
        t ^= 1
    return ret

S = list(map(int,input()))
print(min(solve(0,S),solve(1,S)))

Submission status: Accepted

Solution code:
def readinput():
    s=input()
    return s

def main(s):
    count=0
    t=['0','1']
    for i in range(len(s)):
        if s[i]==t[i%2]:
            count+=1
    return min(count,len(s)-count)

if __name__=='__main__':
    s=readinput()
    ans=main(s)
    print(ans)

Submission status: Accepted

Solution code:

S = input()

ctr = [0, 0]
for i in range(len(S)):
    if i % 2 == 0:
        ctr[0] += int(S[i]) == 0
        ctr[1] += int(S[i]) == 1
    else:
        ctr[0] += int(S[i]) == 1
        ctr[1] += int(S[i]) == 0

print(min(ctr))

Submission status: Accepted

Solution code:
word = input()

res = 0
colour = 0
for s in word:
    if colour % 2 != int(s):
        res += 1
    colour += 1
if len(word) // 2 < res:
    res = len(word) - res

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from distutils.util import strtobool
s = input()
ss = [int(s[0]) if x % 2 == 0 else int(s[0])^1 for x in range(len(s))]

cnt = 0
for i in range(len(s)):
    if int(s[i]) != ss[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from distutils.util import strtobool
s = input()
ss = [int(s[0]) if x % 2 == 0 else int(s[0])^1 for x in range(len(s))]

cnt = 0
for i in range(len(s)):
    if int(s[i]) != ss[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
S=input()

st1 = 0
st0 = 0

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

print(min(st1, st0))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF = 10**20
def main():
    S=list(input())
    N=len(S)

    A,B=[],[]
    pre = "0"
    for i in range(N):
        if pre == "0":
            new = "1"
        else:
            new = "0"
        A.append(new)
        pre = new
        
    pre = "1"
    for i in range(N):
        if pre == "0":
            new = "1"
        else:
            new = "0"
        B.append(new)
        pre = new

    ans = INF
    for X in [A,B]:
        count = 0
        for i in range(N):
            if S[i] != X[i]:
                count += 1

        ans = min(ans,count)

    print(ans)





if __name__ == "__main__":
    main()

Submission status: Accepted

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

x=[i%2 for i in range(n)]
y=[(i+1)%2 for i in range(n)]
d=0
f=0

for i in range(n):
    if int(s[i])!=x[i]:
        d+=1
for i in range(n):
    if int(s[i])!=y[i]:
        f+=1
print(min(d,f))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

S1 = S[0::2]
S2 = S[1::2]

S1_0 = S1.count("0")
S1_1 = S1.count("1")
S2_0 = S2.count("0")
S2_1 = S2.count("1")

#101010
ans1 = S1_0 + S2_1
#010101
ans2 = S1_1 + S2_0

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input().strip()
L = len(S)
p = 0
for i in zip(S, "01"*L):
    if i[0] != i[1]:
        p += 1
q = 0
for i in zip(S, "10"*L):
    if i[0] != i[1]:
        q += 1
print(min(p, q))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
li = list(input())
l = [int(n) for n in li]
x = len(l)
li_0 = [0 for i in range(x)]
li_1 = [0 for i in range(x)]
for i in range(x):
    if i % 2 == 0:
        li_0[i] = 1
    else:
        li_1[1] = 1
a = 0
b = 0
for i in range(x):
    if li_0[i] != l[i]:
        a += 1
    else:
        b += 1
print(min(a,b))

Submission status: Accepted

Solution code:
s=input()
l=len(s)
p0=[0]*l
p1=[1]*l
for i in range(l):
    if i%2==1:
        p0[i]=1
        p1[i]=0
c0=0
c1=0
for i in range(l):
    if int(p0[i])!=int(s[i]):
        c0+=1
for i in range(l):
    if int(p1[i])!=int(s[i]):
        c1+=1
print(min(c0,c1))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
if n%2 == 0:
    im1 = '01'*(n//2)
    im2 = '10'*(n//2)
else:
    im1 = '01'*(n//2) + '0'
    im2 = '10'*(n//2) + '1'
cnt1 = 0
cnt2 = 0
for i in range(n):
    if s[i] != im1[i]:
        cnt1 += 1
    if s[i] != im2[i]:
        cnt2 += 1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
S = input()

a = ''
for i in range(len(S)//2):
    a += '0'
    a += '1'
if len(S)/2 % 1 != 0:
    a += '0'
b = ''
for i in range(len(S)//2):
    b += '1'
    b += '0'
if len(S)/2 % 1 != 0:
    b += '1'

count_a = 0
for i in range(len(S)):
    if S[i] != a[i]:
        count_a += 1

count_b = 0
for i in range(len(S)):
    if S[i] != b[i]:
        count_b += 1

print(min(count_a, count_b))