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

counter1 = 0
counter2 = 0
for i in range(len(s)):
    if i % 2 == 1 and s[i] != '0':
        counter1 += 1
    if i % 2 == 0 and s[i] != '1':
        counter1 += 1
    if i % 2 == 1 and s[i] != '1':
        counter2 += 1
    if i % 2 == 0 and s[i] != '0':
        counter2 += 1
print(min([counter1, counter2]))

Submission status: Accepted

Solution code:
S = input()
ans1 = 0
ans2 = 0
for i, c in enumerate(S):
  if str(i % 2) == c:
    ans1 += 1
  else:
    ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = raw_input()
ans = 999999
for i in range(2):
  c = 0
  for j in range(len(S)):
    if S[j]!="01"[(i+j)%2]:
      c += 1
  ans = min(ans, c)
print ans

Submission status: Accepted

Solution code:
S = input()

ans1, ans2 = 0, 0
for i in range(len(S)):
    if i & 1:
        if S[i] == '0':
            ans1 += 1
        else:
            ans2 += 1
    else:
        if S[i] == '1':
            ans1 += 1
        else:
            ans2 += 1

print(min(ans1, ans2))

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:
s=input()
l=len(s)
p=""
ans=0
for i in range(l):
    if i%2==0:
        if s[i]=="1":
            ans+=1
    else:
        if s[i]=="0":
            ans+=1
print(min(ans,l-ans))

Submission status: Accepted

Solution code:
S = input()
L1 = "".join(["1" if i % 2 == 0 else "0" for i in range(len(S))])
L2 = "".join(["0" if i % 2 == 0 else "1" for i in range(len(S))])
num1 = sum([1 if s != l else 0 for s, l in zip(S, L1)])
num2 = sum([1 if s != l else 0 for s, l in zip(S, L2)])
print(min(num1, num2))

Submission status: Accepted

Solution code:
s=str(input())
if len(s)%2==0:
  char1='01'*(int(len(s)/2))
  char2='10'*(int(len(s)/2))
else:
  char1='01'*(int(len(s)/2))+'0'
  char2='10'*(int(len(s)/2))+'1'
count1=0
count2=0
for i in range(len(s)):
  if char1[i]!=s[i]:
    count1+=1
  if char2[i]!=s[i]:
    count2+=1
print(min(count1,count2))

Submission status: Accepted

Solution code:
a = list(input())
su = 0
ko = 0
p = 0

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

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

print(min(su,ko))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

ans = float('inf')
for init in '01':
    t = 0
    x = init
    for ss in s:
        # print(ss, x)
        if ss != x:
            t += 1
        if x == '0':
            x = '1'
        else:
            x = '0'
    ans = min(ans, t)
print(ans)

Submission status: Accepted

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

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

pat0 = []
pat1 = []
for i in range(len(s)):
    if i % 2 == 0:
        pat0.append(0)
        pat1.append(1)
    else:
        pat0.append(1)
        pat1.append(0)

cnt0 = 0
cnt1 = 0
for i in range(len(s)):
    if s[i] != pat0[i]:
        cnt0 += 1
    else:
        cnt1 += 1

print(min(cnt0,cnt1))

Submission status: Accepted

Solution code:
s = input().strip()

answ, ansb = 0, 0
prevw, prevb = '1', '0'
for _s in s:
  if prevw == '1':
    if _s == '1':
      answ += 1
    prevw = '0'
  elif prevw == '0':
    if _s == '0':
      answ += 1
    prevw = '1'
  if prevb == '1':
    if _s == '1':
      ansb += 1
    prevb = '0'
  elif prevb == '0':
    if _s == '0':
      ansb += 1
    prevb = '1'

print(min(answ, ansb))

Submission status: Accepted

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

def count(s, t):
    ret = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            ret += 1
    return ret


def solve(S: int):
    t1 = []
    t2 = []
    for i in range(len(S)):
        t1.append(str(i % 2))
        t2.append(str((i + 1) % 2))
    t1 = ''.join(t1)
    t2 = ''.join(t2)
    ret = min(count(S, t1), count(S, t2))
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

def kakaka():
    a = list(map(int, input().split()))
    b = map(int, input().split())
    c = int(input())

def start_process():
    return
def main():
    a = list(input())
    data = a[0]
    count = 0
    dic = {'0': '1', '1':'0'
           }
    for i in range(1, len(a)):
        if a[i] == data:
            count += 1
        data = dic[data]
    print(count)





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

a = ['0', '1']
count = 0
n = len(S)
for i in range(n):
    if S[i] == a[i%2]:
        count += 1

print(min(n-count, count))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if a < b:
        a, b = b, a
    ans = a
    a -= 1
    ans += max(a, b)
    print(ans)
    return

#B
def B():
    n = II()
    h = LI()
    dp = [0 for i in range(n)]
    ans = 0
    for i in range(n):
        dp[i] = max(dp[i - 1], h[i])
        if dp[i - 1] <= h[i]:
            ans += 1
    print(ans)
    return

#C
def C():
    s = S()
    ans = 0
    for num, i in enumerate(s):
        if num % 2:
            if i == "0":
                ans += 1
        else:
            if i == "1":
                ans += 1
    ansb = 0
    for num, i in enumerate(s):
        if not num % 2:
            if i == "0":
                ansb += 1
        else:
            if i == "1":
                ansb += 1
    print(min(ans, ansb))
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
s = input()
s1 = [i % 2 for i in range(len(s))]
s2 = [(i + 1) % 2 for i in range(len(s))]
c1 = 0
c2 = 0

for i in range(len(s)):
    if int(s[i]) != s1[i]:
        c1 += 1
    else:
        c2 += 1

print(min(c1, c2))

Submission status: Accepted

Solution code:
s = input()
v = 1
c = 0
cc = 0
for i in s:
    if i == '0' and v == -1:
        c+=1
    if i == '1' and v == 1:
        c+=1
    v*=-1

v = -1
for i in s:
    if i == '0' and v == -1:
        cc+=1
    if i == '1' and v == 1:
        cc+=1
    v*=-1
print(min(c,cc))

Submission status: Accepted

Solution code:
Ss = input()

ans1 = 0
for i, S in enumerate(Ss):
    if S != '01'[i%2]:
        ans1 += 1

ans2 = 0
for i, S in enumerate(Ss):
    if S != '10'[i%2]:
        ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S=list(input())

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

print(min(e,o))

Submission status: Accepted

Solution code:
S = input()

count_0101 = 0
count_1010 = 0

for i, s in enumerate(S):
	if i & 1:
		if '1' == s:
			count_1010 += 1
		else:
			count_0101 += 1
	else:
		if '1' == s:
			count_0101 += 1
		else:
			count_1010 += 1

print(min(count_0101, count_1010))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc124/tasks/abc124_c

import itertools
from collections import Counter
import bisect

def main():
    S = list(input())

    even_black = 0
    even_white = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == '0':  # black
                even_white += 1
            else:  # white
                even_black += 1
        else: # odd
            if S[i] == '0':  # black
                even_black += 1
            else:  # white
                even_white += 1

    print(min(even_black, even_white))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

n = len(S)

start_0 = ""
start_1 = ""

for i in range(n):
    if i % 2 == 0:
        start_0 += "0"
        start_1 += "1"
    else:
        start_0 += "1"
        start_1 += "0"

ans_0 = 0
ans_1 = 0

for i in range(n):
    t1 = start_0[i]
    t2 = start_1[i]
    s = S[i]
    if t1 != s:
        ans_0 += 1
    if t2 != s:
        ans_1 += 1

print(min(ans_1, ans_0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

a1=('01'*len(S))[:len(S)]
a2=('10'*len(S))[:len(S)]

answer1 = 0
for s, a in zip(S,a1):
  if s!=a:
    answer1 +=1
  
answer2 = 0
for s, a in zip(S,a2):
  if s!=a:
    answer2 +=1
    
print(min(answer1,answer2))

Submission status: Accepted

Solution code:
String = input();

num0_odd = 0;
num1_odd = 0;
num0_even = 0;
num1_even = 0;

odd_check=1;
num_of_tile=0;

for i in String:
    num_of_tile+=1;
    if(odd_check==0):
        if(i=="0"):
            num0_odd+=1;
        else:
            num1_odd+=1;
    else:
        if(i=="0"):
            num0_even+=1;
        else:
            num1_even+=1;

    odd_check+=1;
    if(odd_check==2):
        odd_check=0;

answer = max(num0_odd+num1_even, num0_even+num1_odd);
print(num_of_tile - answer);

Submission status: Accepted

Solution code:
listS=list(input())
odd1=0
odd0=0
even1=0
even0=0
index=0
while index < len(listS):
    if index%2==0:
        if listS[index]=="1":
            even1+=1
        else:
            even0+=1
    else:
        if listS[index] == "1":
            odd1 += 1
        else:
            odd0 += 1
    index+=1

print(min(even0+odd1, even1+odd0))

Submission status: Accepted

Solution code:
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
N = len(s)

cnt = 0
for i in range(N):
    if i%2==0:
        if s[i]=="0":
            cnt += 1
    else:
        if s[i]=="1":
            cnt += 1
print(min(cnt,N-cnt))

Submission status: Accepted

Solution code:
S = input()

x = y = 0
for i,c in enumerate(S):
    if i%2:
        a,b = 0,1
    else:
        a,b = 1,0
    if int(c) == a:
        x += 1
    if int(c) == b:
        y += 1
print(min(x,y))

Submission status: Accepted

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

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

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
s = input()
n,a,b = len(s),0,0
for i in range(n):
    if i%2 and s[i]=="0": a+=1
    elif not i%2 and s[i]=="1": b+=1
c,d = (n+1)//2-a,n//2-b
print(min(a+b,c+d))

Submission status: Accepted

Solution code:
x=input()

ans1,ans2=0,0

for n,i in enumerate(x):
    if n%2==0: gg='0'
    else: gg='1'
    if i!=gg: ans1+=1

for n,i in enumerate(x):
    if n%2==1: gg='0'
    else: gg='1'
    if i!=gg: ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
s = input().strip()

start = '0'
ans = 0
for idx, c in enumerate(s):
    if idx % 2 == 0 and c != start:
        ans += 1
    elif idx % 2 != 0 and c == start:
        ans += 1

start = '1'
ans1 = 0
for idx, c in enumerate(s):
    if idx % 2 == 0 and c != start:
        ans1 += 1
    elif idx % 2 != 0 and c == start:
        ans1 += 1
    
print(min(ans, ans1))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ev = ('01' * n)[:n]
od = ('10' * n)[:n]
ans = [0, 0]
for si, a, b in zip(s, ev, od):
    if si != a:
        ans[0] += 1
    elif si != b:
        ans[1] += 1
print(min(ans))

Submission status: Accepted

Solution code:
S = input()

p1 = [('0' if i % 2 == 0 else '1') for i in range(len(S))]
p2 = [('1' if i % 2 == 0 else '0') for i in range(len(S))]


tmp_ans1 = 0
for s, p in zip(S, p1):
    if s != p:
        tmp_ans1 += 1

tmp_ans2 = 0
for s, p in zip(S, p2):
    if s != p:
        tmp_ans2 += 1

print(min(tmp_ans1, tmp_ans2))

Submission status: Accepted

Solution code:
S=input()

#0101...
c=0
for i in range(len(S)):
	if i%2==0 and S[i]=="1": c+=1
	if i%2==1 and S[i]=="0": c+=1

#1010...
d=0
for i in range(len(S)):
	if i%2==0 and S[i]=="0": d+=1
	if i%2==1 and S[i]=="1": d+=1

print(min(c,d))

Submission status: Accepted

Solution code:
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
count=0
for i in range(Slen-1):
    if Slist[i] == Slist[i+1]:
        if Slist[i+1] == "0":
            Slist[i+1] = "1"
        else:
            Slist[i+1] = "0"
        count+=1
print(count)

Submission status: Accepted

Solution code:
from collections import deque
S = input()
cnt = 0
dq = deque()
for i in range(len(S)):
    if not dq:
        dq.append(S[i])
    elif dq[-1] == "0" and S[i] == "0":
        cnt += 1
        dq.append("1")
    elif dq[-1] == "1" and S[i] == "1":
        cnt += 1
        dq.append("0")
    else:
        dq.append(S[i])
print(cnt)

Submission status: Accepted

Solution code:
s = input()
def check(s):
    ans = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != '0':
            ans += 1
        if i % 2 == 1 and s[i] != '1':
            ans += 1
    ans2 = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != '1':
            ans2 += 1
        if i % 2 == 1 and s[i] != '0':
            ans2 += 1
    return min(ans,ans2)
print(check(s))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
S = input()
ans1 = 0
ans2 = 0
for i, s in enumerate(S):
    if i%2:
        ans1 += s == "0"
        ans2 += s != "0"
    else:
        ans1 += s != "0"
        ans2 += s == "0"
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
S = input()

result1 = 0
result2 = 0

for i, c in enumerate(S):
    if i % 2 == 0:
        if c == '0':
            result1 += 1
        else:
            result2 += 1
    else:
        if c == '0':
            result2 += 1
        else:
            result1 += 1

#print(result1, result2)
result = min(result1, result2)
print(result)

Submission status: Accepted

Solution code:
s = input()

bw = 0
wb = 0
for i,c in enumerate(s):
	if i%2 == 0:
		if c == '0':
			wb += 1
		else:
			bw += 1
	else:
		if c == '0':
			bw += 1
		else:
			wb += 1

print(min(bw,wb))

Submission status: Accepted

Solution code:
S = input()
T = '01'*len(S)
ans = 10**8
ctr = 0
for s , t in zip(S, T):
    if t != s:
        ctr += 1
ans = min(ans, ctr)
T = '10'*len(S)
ctr = 0
for s , t in zip(S, T):
    if t != s:
        ctr += 1
ans = min(ans, ctr)
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = (input())
e = S[::2].count("0")
o = S[1::2].count("1")
print(min(e+o,len(S)-(e+o)))

Submission status: Accepted

Solution code:
s = list(input())
ans = 0

for i in range(1,len(s)):
    if s[i] == "0" and s[i-1] == "0":
        s[i] = "1"
        ans += 1
    if s[i] == "1" and s[i-1] == "1":
        s[i] = "0"
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
S = raw_input()

T = '01' * (len(S) / 2) + ('0' if len(S) % 2 == 1 else '')
U = '10' * (len(S) / 2) + ('1' if len(S) % 2 == 1 else '')

t, u = 0, 0
for i in xrange(len(S)):
    if S[i] != T[i]:
        t += 1
    if S[i] != U[i]:
        u += 1

print min(t, u)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

S = list(map(int,list(str(input()))))
N = len(S)
ans = 0
for i in range(N):
    if i%2 == 0 and S[i] == 0:
        ans += 1
    elif i%2 == 1 and S[i] == 1:
        ans += 1

print(min(ans,N-ans))

Submission status: Accepted

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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    costA = 0
    costB = 0
    for i in range(len(S)):
        if int(S[i]) != (i % 2):
            costA += 1
        else:
            costB += 1
    print(min(costA, costB))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A = list(map(int, list(input())))
N = len(A)
ans = 1<<29

for x in range(2):
    tmp = 0
    B = [0 for _ in range(N)]
    for i in range(x, N, 2):
        B[i] = 1
    for i in range(N):
        if A[i] != B[i]:
            tmp += 1
    ans = min(ans, tmp)

print (ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

cand1 = 0
for i, si in enumerate(s):
    if i % 2:
        if si == '0':
            cand1 += 1
            
    else:
        if si == '1':
            cand1 += 1
       
        
cand2 = 0
for i, si in enumerate(s):
    if i % 2:
        if si == '1':
            cand2 += 1
            
    else:
        if si == '0':
            cand2 += 1

print(min(cand1, cand2))

Submission status: Accepted

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

print(f0 if f0<=len(s)//2 else len(s)-f0)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
x = sum(1 if int(s[i]) != i%2 else 0 for i in range(n))
y = sum(0 if int(s[i]) != i%2 else 1 for i in range(n))
print(min(x, y))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(min(k, s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = [1 if i % 2 == 0 else 0 for i in range(len(s))]
b = [0 if i % 2 == 0 else 1 for i in range(len(s))]


da = 0
db = 0
for i in range(len(s)):
    if str(a[i]) != s[i]:
        da += 1
    if str(b[i]) != s[i]:
        db += 1

print(min(da, db))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans1 = 0
for i in range(n):
    if i%2 == 0:
        if s[i] != "0":
            ans1 += 1
    else:
        if s[i] != "1":
            ans1 += 1
ans2 = 0
for i in range(n):
    if i%2 == 0:
        if s[i] == "0":
            ans2 += 1
    else:
        if s[i] == "1":
            ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
def d201(a):
    count=0
    N=len(a)
    for i in range(N):
        if(i%2==0):
            if(a[i]=='0'):
                count+=1
        else:
            if(a[i]=='1'):
                count+=1
    return count

                
def d210(a):
    count=0
    N=len(a)
    for i in range(N):
        if(i%2==0):
            if(a[i]=='1'):
                count+=1
        else:
            if(a[i]=='0'):
                count+=1
    return count

a=input()
print(min(d210(a),d201(a)))

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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [tuple(map(int, l.split())) for l in sys.stdin]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    s = [int(c) for c in S()]
    l = len(s)
    t = u = 0
    for i in range(l):
        if s[i] == i % 2:
            t += 1
        else:
            u += 1

    return min(t,u)


print(main())

Submission status: Accepted

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

ANS1=0
ANS2=0

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

        else:
            ANS2+=1

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

    #print(ANS1,ANS2)

print(min(ANS1,ANS2))

Submission status: Accepted

Solution code:
S = input()
ans = 0
if S[0] == '0':
    for i, x in enumerate(S):
        if i%2 == 0 and x == '1':
            ans +=1
        elif i%2 == 1 and x =='0':
            ans += 1
elif S[0] == '1':
    for i, x in enumerate(S):
        if i%2 == 0 and x == '0':
            ans +=1
        elif i%2 == 1 and x =='1':
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if a == b:
        print(2*a)
    else:
        print(2*max(a,b)-1)
    return

#B
def B():
    n = I()
    h = LI()
    m = h[0]
    ans = 1
    for i in range(1,n):
        if m <= h[i]:
            ans += 1
            m = h[i]
    print(ans)
    return

#C
def C():
    s = S()
    ans = 0
    n = len(s)
    t = ["1" if i%2 else "0" for i in range(n)]
    for i in range(n):
        if t[i] != s[i]:
            ans += 1
    ans2 = 0
    t = ["0" if i%2 else "1" for i in range(n)]
    for i in range(n):
        if t[i] != s[i]:
            ans2 += 1
    print(min(ans,ans2))
    return

#D
def D():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
*S, = map(int, input())
ans = len(S)
for k in range(2):
    r = 0
    for i in range(len(S)):
        if (i%2)^k != S[i]:
            r += 1
    ans = min(ans, r)
print(ans)

Submission status: Accepted

Solution code:
s=list(map(int,input()))
lis=[]
for i in range(len(s)):
    if i%2==0:
        lis.append(0)
    else:
        lis.append(1)
cnt=0
for i in range(len(s)):
    if s[i]!=lis[i]:
        cnt+=1
print(min(cnt,len(s)-cnt))

Submission status: Accepted

Solution code:
S = list(map(int, input().strip()))
best = N = len(S)
for c in range(2):
    n_flip = 0
    for i in range(N):
        n_flip += S[i] ^ c
        c ^= 1
    best = min(best, n_flip)
print(best)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
S=list(input())
cnt1,cnt2=0,0
#S[0]='0'
for i,s in enumerate(S):
    if i%2==0:
        if s=='1':
            cnt1+=1
    else:
        if s=='0':
            cnt1+=1
#S[0]='1'
for i,s in enumerate(S):
    if i%2==1:
        if s=='1':
            cnt2+=1
    else:
        if s=='0':
            cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()
res1, res2 = 0, 0
for i, j in enumerate(s):
    if i % 2 == 0:
        if j == '0':
            res1 += 1
    else:
        if j == '1':
            res1 += 1
for i, j in enumerate(s):
    if i % 2 == 1:
        if j == '0':
            res2 += 1
    else:
        if j == '1':
            res2 += 1
print(min(res1, res2))

Submission status: Runtime Error

Solution code:
from collections import Counter
moji = str(input())
guall = len(moji)//2
kiall = guall + len(moji) % 2
gucount=dict(Counter(moji[1::2]))
kicount=dict(Counter(moji[0::2]))
if max(gucount, key=gucount.get) != max(kicount, key=kicount.get):
    ans = guall - max(gucount.values()) + kiall - max(kicount.values())
else:
    if kiall - max(kicount.values()) > guall - max(gucount.values()):
        ans = max(kicount.values()) + guall - max(gucount.values())
    else:
        ans = max(gucount.values()) + kiall - max(kicount.values())
print(ans)

Submission status: Runtime Error

Solution code:
n = input()

counta = 0
countb = 0
if N%2==0:
  for i in range(0,len(n)-2,2):
    if n[i]=="0":
      counta+=1
    elif n[i]=="1":
      countb+=1
  for i in range(1,len(n)-1,2):
    if n[i]=="1":
      counta+=1
    elif n[i]=="0":
      countb+=1
  print(min(counta,countb))

counta = 0
countb = 0
if N%2==1:
  for i in range(0,len(n)-1,2):
    if n[i]=="0":
      counta+=1
    elif n[i]=="1":
      countb+=1
  for i in range(1,len(n)-2,2):
    if n[i]=="1":
      counta+=1
    elif n[i]=="0":
      countb+=1
  print(min(counta,countb))

Submission status: Runtime Error

Solution code:
a=input()
b=int(len(a))
c=0
d=0
for i in range(b):
  if a[2*i]==1:
    c=c+1
  if a[2*1+1]==0:
    c=c+1
for i in range(b):
  if a[2*i]==0:
    d=d+1
  if a[2*1+1]==1:
    d=d+1
if c>d:
  print(d)
else:
  print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = int(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: Runtime Error

Solution code:
s = list(input())

n = int(len(s)/2)
c = 0

if s[1] == s[0]:
  c +=1
  if s[0] == 0:
    s[1] = 1
  elif s[0] == 1:
    s[1] = 0

for i in range(n):
  if s[0] != s[2*i]:
    c += 1
  if s[1] != s[2*i+1]:
    c += 1

print(c)

Submission status: Runtime Error

Solution code:
import math
n, k = map(int, input().split())
ans = 0.0
if n >= k:
  ans += (n-k+1)/n
  
for i in range(1, min(n+1, k)):
  now = i
  p = 1/n
  while(now <k):
    now *= 2
    p /= 2
  ans += p
  
print(ans)

Submission status: Runtime Error

Solution code:
ースコード 

Copy
Copy
#参考 ： AtCoder # 14682107
s = input()
len = len(s)
 
if len == 1:
    print(0)
    exit()
 
even = s[::2]
odd = s[1::2]
 
#偶数番目に0が並ぶと仮定したときの異物の数
# 0101...
odd_zero = odd.count("0")
even_one = even.count("1")
 
 
#奇数番目に0が並ぶと仮定したときの異物の数
# 1010...
odd_one = odd.count("1")
even_zero = even.count("0")
 
print(min(odd_zero + even_one, odd_one + even_zero))

Submission status: Runtime Error

Solution code:
import collections

s = list(raw_input())
count = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		s[i] = 1- s[i]
		count +=1
print count

Submission status: Runtime Error

Solution code:
import collections

s = raw_input()
count = 0
for i in range(len(s) - 1):
	if s[i] == s[i + 1]:
		s[i] = 1- s[i]
		count +=1
print count