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()
n = S[::2].count('0')+S[1::2].count('1')
print(min(n, len(S)-n))

Submission status: Accepted

Solution code:
s = list(input())
a = 0
b = 0
f = 0
for i in s:
    if f == 0:
        if i == "0":
            a += 1
        else:
            b += 1
        f = 1
    else:
        if i == "0":
            b += 1
        else:
            a += 1
        f = 0
            
print(min(a,b))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
count1=0
for i in range(1,n+1):
    if int(s[i-1])!=(i%2):
        count1+=1
count2=0
for j in range(n):
    if int(s[j])!=j%2:
        count2+=1
print(min(count1,count2))

Submission status: Accepted

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

a=n
for i in ['01','10']:
 a=min(a,sum(x!=y for x,y in zip(S,(i*(n//2+1))[:n])))
print(a)

Submission status: Accepted

Solution code:
S=input()
n=len(S)
print(min(sum(x!=y for x,y in zip(S,('01'*(n//2+1))[:n])),sum(x!=y for x,y in zip(S,('10'*(n//2+1))[:n]))))

Submission status: Accepted

Solution code:
S = input()
cnt = sum(i % 2 == 0 and s == "1" or i % 2 == 1 and s == "0" for i, s in enumerate(S))
print(min(cnt, len(S) - cnt))

Submission status: Accepted

Solution code:
S = list(input())

ans = 0
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        pass
    else:
        x = S[i+1]
        if x == '0':
            S[i+1] = '1'
        else:
            S[i+1] = '0'
        ans += 1

print (ans)

Submission status: Accepted

Solution code:
cnt=0
cnt_2=0
s = str(input())
for i in range(len(s)):
    if s[i]=='0' and i%2==0:
        cnt+=1
    if s[i]=='1' and i%2==0:
        cnt_2+=1
    if s[i]=='1' and i%2!=0:
        cnt+=1
    if s[i]=='0' and i%2!=0:
        cnt_2+=1
print(min(cnt,cnt_2))

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = [int(i) for i in SS()]
    N = len(S)

    ans0 = 0
    ans1 = 0
    for i in range(N):
        ans0 += abs(S[i] - i % 2)
        ans1 += abs(S[i] - (1 - i % 2))

    print(min(ans0, ans1))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
import copy

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def switch(s):
    if s == '0':
        return '1'
    else:
        return '0'


def main():
    S = list(input())
    S_1 = copy.copy(S)
    S_2 = copy.copy(S)
    ans_1 = 0
    for i in range(1, len(S_1)):
        if S_1[i] == S_1[i - 1]:
            S_1[i] = switch(S_1[i])
            ans_1 += 1
    ans_2 = 1
    S_2[0] = switch(S_2[0])
    for i in range(1, len(S_2)):
        if S_2[i] == S_2[i - 1]:
            S_2[i] = switch(S_2[i])
            ans_2 += 1
    print(min(ans_1, ans_2))


if __name__ == '__main__':
    main()

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 = a+1
    else:
      b = b+1
  else:
    if s[i] == "0":
      b = b+1
    else:
      a = a+1
if a < b:
  print(a)
else:
  print(b)

Submission status: Accepted

Solution code:
S = input()

res1 = 0
res2 = 0

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

print(min(res1, res2))

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = instr()

prev = s[0]
ans = 0

for i in range(1,len(s)):
    if s[i] != prev:
        prev = s[i]
    else:
        ans += 1
        if s[i] == "0":
            prev = "1"
        else:
            prev = "0"

print(ans)

Submission status: Accepted

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

# 0101...にする場合
cnt1 = 0
for i in range(len(S)):
    if S[i] != str(i % 2):
        cnt1 += 1

# 1010...にする場合
cnt2 = 0
for i in range(len(S)):
    if S[i] != str((i + 1) % 2):
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
s=list(input())
id_1=['1' if i%2 else '0' for i in range(len(s))]
id_2=['0' if i%2 else '1' for i in range(len(s))]
cnt=[0,0]
for si,id1,id2 in zip(s,id_1,id_2):
  cnt[0] += si!=id1
  cnt[1] += si!=id2
print(min(cnt))

Submission status: Accepted

Solution code:
#最後がどういう状態になればいいか考えればいい
s=list(input())
s=list(map(int,s))

n=len(s)
check_1=[i%2 for i in range(n)]
check_2=[(i%2+1)%2 for i in range(n)]

cnt_1=0
cnt_2=0
for i in range(n):
  if s[i]!=check_1[i]:
    cnt_1=cnt_1+1
  if s[i]!=check_2[i]:
    cnt_2=cnt_2+1
print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
S = str(input())

ans = 0
cnt = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    cnt += 1
  else:
    ans += (cnt+1) // 2
    if cnt % 2 == 0:
      cnt = 0
    else:
      cnt = 1
ans += (cnt+1) // 2
print(ans)

Submission status: Accepted

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

ans1 = 0
ans2 = 0

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

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

Submission status: Accepted

Solution code:
s = input()

res = 0
previous = s[0]
for i in range(1, len(s)):
    if s[i] == previous:
        res += 1
        previous = str((int(previous) + 1) % 2)
    else:
        previous = s[i]

print(res)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

S = list(input())

ans1 = 0
for i, s in enumerate(S): 
    if i % 2 == 0:
        if s == "0":
            ans1 += 1
    else:
        if s == "1":
            ans1 += 1

ans2 = 0
for i, s in enumerate(S): 
    if i % 2 != 0:
        if s == "0":
            ans2 += 1
    else:
        if s == "1":
            ans2 += 1

ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

Solution code:
import sys

S = str(input())
if len(S) == 1:
  print("0")
  sys.exit()
else:
  c1 = 0
  c2 = 0
  for i in range(len(S)):
    if i%2 == 0:
      if S[i] != "1":
        c1 += 1
    else:
      if S[i] != "0":
        c1 += 1
  for i in range(len(S)):
    if i%2 == 0:
      if S[i] != "0":
        c2 += 1
    else:
      if S[i] != "1":
        c2 += 1
print(min(c1,c2))

Submission status: Accepted

Solution code:
S = list(input())
f = False
c = 0

for i  in range(len(S) - 1):
    # if i == len(S) - 2:
    #     break
    if S[i] != S[i + 1]:
        continue
    else:
        if S[i] == "0":
            S[i+1] = "1"
            c += 1
        else:
            S[i+1] = "0"
            c += 1

print(c)

Submission status: Accepted

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

cnt1 = 0
cnt2 = 0
for s in S[::2]:
    if s == '0':
        cnt1 += 1
    elif s == '1':
        cnt2 += 1
for s in S[1::2]:
    if s == '1':
        cnt1 += 1
    elif s == '0':
        cnt2 += 1

print(N-max(cnt1, cnt2))

Submission status: Accepted

Solution code:
s=[*input()];n=len(s);t=['1' if i%2==0 else '0' for i in range(n)]
r=[i==j for i,j in zip(s,t)];print(min(sum(r),n-sum(r)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s = input()

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

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
s = list(input())

one = 0
zero = 0
for i in s[::2]:
    if i == '1':
        one += 1
    else:
        zero += 1

for i in s[1::2]:
    if i == '0':
        one += 1
    else:
        zero += 1

print(min(one, zero))

Submission status: Accepted

Solution code:
S=input()
if len(S)%2==0:
    black="01"*(len(S)//2)
    white="10"*(len(S)//2)
    countb=0
    countw=0
else:
    black="01"*(len(S)//2)+"0"
    white="10"*(len(S)//2)+"1"
countb=0
countw=0
for i in range(len(S)):
    if S[i]!=black[i]:
        countb=countb+1
    elif S[i]!=white[i]:
        countw=countw+1
    else:
        pass
if countb>=countw:
    print(countw)
else:
    print(countb)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T1 = len(S)*"01"
T2 = len(S)*"10"
ans = []
dif = 0

for s,t in zip(S,T1):
  if s!=t:
    dif+=1

ans+=[dif]
dif = 0

for s,t in zip(S,T2):
  if s!=t:
    dif+=1

ans+=[dif]
print(min(ans))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
a = 0
b = 0
ans = 0
for i in range(0,N,2):
    if S[i] == '0':
        a += 1
    else:
        b += 1
for i in range(1,N,2):
    if S[i] == '1':
        a += 1
    else:
        b += 1
c = max(a,b)
if c == a:
    for i in range(0,N,2):
        if S[i] != '0':
            ans += 1
    for i in range(1,N,2):
        if S[i] != '1':
            ans += 1
else:
    for i in range(0,N,2):
        if S[i] == '0':
            ans += 1
    for i in range(1,N,2):
        if S[i] == '1':
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
S=input()
s1="01"*(len(S)//2+1)
ans1=0
ans2=0
for x in range(len(S)):
  if S[x]==s1[x]:
    ans2 +=1
  else:
    ans1 +=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S=input()

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

print(min(cost1,cost2))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
S = input()
ss0 = []
ss1 = []
for i in range(len(S)):
    ss0.append(str(i%2))
    ss1.append(str((i+1)%2))

c0 = 0
c1 = 0
for s, s0, s1 in zip(S, ss0, ss1):
    if s != s0:
        c0 += 1
    if s != s1:
        c1 += 1

print(min(c0, c1))

Submission status: Accepted

Solution code:
s = str(input())

# print(s)
count =0
for xi in range(len(s)):
    if xi%2 ==0:t="0"
    if xi%2 ==1:t="1"

    if s[xi]==t:
        count+=1

# print(count)
print(min(count,len(s)-count))

Submission status: Accepted

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

# C - Coloring Colorfully /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 左右一列に N枚のタイルが並んでおり、各タイルの初めの色は長さ N の文字列 Sで表されます。
# 左から i番目のタイルは、S の i番目の文字が 0 のとき黒色で、1 のとき白色で塗られています。
# あなたは、いくつかのタイルを黒色または白色に塗り替えることで、どの隣り合う 2枚のタイルも異なる色で塗られているようにしたいです。
# 最小で何枚のタイルを塗り替えることで条件を満たすようにできるでしょうか。

# 制約
#     1≤|S|≤105
#     Siは 0 または 1 である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S

# 出力
# 条件を満たすために塗り替えるタイルの枚数の最小値を出力せよ。

# 入力例 1
# 000

# 出力例 1
# 1

# 中央のタイルを白色に塗り替えれば条件を達成できます。

# 入力例 2
# 10010010

# 出力例 2
# 3

# 入力例 3
# 0

# 出力例 3
# 0


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    line = lines[0]
    # N = int(lines[0])
    # values = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(Q):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 0

    n_even_kuro = 0
    n_even_shiro = 0
    n_odd_kuro = 0
    n_odd_shiro = 0

    # まず観察
    for i, char in enumerate(line):
        if i % 2 == 0:
            if char == '0':
                n_even_kuro += 1
            else:
                n_even_shiro += 1
        else:
            if char == '0':
                n_odd_kuro += 1
            else:
                n_odd_shiro += 1

    log(n_even_kuro)
    log(n_even_shiro)
    log(n_odd_kuro)
    log(n_odd_shiro)

    # 偶数・奇数それぞれ、黒白どちらが多いかを判断
    dif_even_kuro = n_even_kuro - n_even_shiro
    dif_odd_kuro = n_odd_kuro - n_odd_shiro

    # 偶数=黒/奇数=白 or 偶数=白/奇数=黒 を判断
    if dif_even_kuro > dif_odd_kuro:
        # 偶数=黒/奇数=白
        result = n_even_shiro + n_odd_kuro
    else:
        # 偶数=白/奇数=黒
        result = n_odd_shiro + n_even_kuro

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['000']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['10010010']
        lines_export = [3]
    if pattern == 3:
        lines_input = ['0']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
num = len(n)
one_s = 0
zero_s = 0

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

print(min(zero_s, one_s))

Submission status: Accepted

Solution code:
s = input()
count = 0
tmp = s[0]
for i in range(1, len(s)):
    if s[i] == tmp:
        count += 1
        if s[i] == "0":
            tmp = "1"
        else:
            tmp = "0"
    else:
        tmp = s[i]

print(count)

Submission status: Accepted

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

p=['1']
q=['0']

for x in range(1,n):
  if p[x-1]=='0':
    p.append('1')
  else:
    p.append('0')
    
  if q[x-1]=='0':
    q.append('1')
  else:
    q.append('0')
  
ans=0
ans1=0
for i in range(n):
  if s[i]!=p[i]:
    ans+=1
  if s[i]!=q[i]:
    ans1+=1
    
print(min(ans,ans1))

Submission status: Accepted

Solution code:
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))

S = LI2()
N = len(S)
print(min(sum(S[i] for i in range(0,N,2)) + sum(1-S[i] for i in range(1,N,2)),sum(1-S[i] for i in range(0,N,2))+sum(S[i] for i in range(1,N,2))))

Submission status: Accepted

Solution code:
S=list(input())
cnt=0
for n in range(1,len(S)):
    if S[n]==S[n-1]:
        if S[n]=="1":
            S[n]="0"
        else:
            S[n]="1"
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
s=input()
b=c=0
for i in s:
  c+=(int(i)==b)
  b^=1
print(min(c,len(s)-c))

Submission status: Accepted

Solution code:
s=input()
b=l=r=0
for i in s:
  l+=(int(i)==b)
  r+=(int(i)!=b)
  b^=1
print(min(l,r))

Submission status: Accepted

Solution code:
S = str(input())
if len(S) == 1:
    print(0)
    exit()
if len(S) % 2 == 0:
    ans1 = "10" * (len(S)//2)
    ans2 = "01" * (len(S)//2)
else:
    ans1 = "10" * (len(S)//2) + "1"
    ans2 = "01" * (len(S)//2) + "0"

result1 = 0
result2 = 0
for x,y in zip(S,ans1):
    if x != y:
        result1 += 1
for x,y in zip(S, ans2):
    if x != y:
        result2 += 1
print(min(result1,result2))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
a=list(input())
n=[]
for i in range(1,len(a)+1):
    if i%2==0:
        n.append(0)
    else:
        n.append(1)
m=[]
for i in range(1,len(a)+1):
    if i%2==0:
        m.append(1)
    else:
        m.append(0)
ans1=0
for i in range(len(a)):
    if n[i]!=int(a[i]):
        ans1+=1
ans2=0
for i in range(len(a)):
    if m[i]!=int(a[i]):
        ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
length = len(S)
p1 = [0 if i % 2 == 0 else 1 for i in range(length)]
p2 = [1 if i % 2 == 0 else 0 for i in range(length)]
ans1 = 0
ans2 = 0
for index,s in enumerate(S):
  if int(s) != p1[index]:
    ans1 += 1
  if int(s) != p2[index]:
    ans2 += 1
  
print(min(ans1,ans2))

Submission status: Accepted

Solution code:

s=list(str(input()))
ans=len(s)
cntx=0
cnty=0
for j in range(len(s)):
  if (int(s[j])==j%2):
    cntx+=1
  if (int(s[j])!=j%2):
    cnty+=1
  ans=min(cntx,cnty)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    s=input()
    a=0  # 0101...
    b=0  # 1010...
    for i, v in enumerate(s):
        if i % 2 == 0:
            if v == "0":
                a+=1
            else:
                b+=1
        else:
            if v == "0":
                b+=1
            else:
                a+=1
    print(min(a,b))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    tmp1 = 0
    tmp2 = 0
    mae = 0

    for i in range(len(s)):
        if s[i] == mae:
            tmp1 += 1
            if s[i] == "0":
                mae = "1"
            else:
                mae = "0"
        else:
            if s[i] == "0":
                mae = "0"
            else:
                mae = "1"

    mae = 1

    for i in range(len(s)):
        if s[i] == mae:
            tmp2 += 1
            if s[i] == "0":
                mae = "1"
            else:
                mae = "0"
        else:
            if s[i] == "0":
                mae = "0"
            else:
                mae = "1"
    
    print(min(tmp1, tmp2))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
n = len(S)
pattern1 = [i % 2 for i in range(n)]
pattern2 = [i % 2 for i in range(1, n+1)]
ans1 = 0
ans2 = 0
for i in range(n):
    s = S[i]
    if s == str(pattern1[i]):
        ans1 += 1
    if s == str(pattern2[i]):
        ans2 += 1
else:
    ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

Solution code:
s=input()
leng=len(s)
a=0 #0101
b=0 #1010
for i in range(leng):
  if i%2==0:
    if s[i]=="1":
      a+=1
    if s[i]=="0":
      b+=1
  if i%2==1:
    if s[i]=="0":
      a+=1
    if s[i]=="1":
      b+=1
if a>=b:
  print(b)
else:
  print(a)

Submission status: Accepted

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


# 0101010... と変換
sum_1 = 0
# 1010101... と変換
sum_2 = 0

# 0101010...
for i in range(len(s_list)):
    if i % 2 == 0:
        if s_list[i] == 1:
            sum_1 += 1
    else:
        if s_list[i] == 0:
            sum_1 += 1

    
# 1010101...
for i in range(len(s_list)):
    if i % 2 == 0:
        if s_list[i] == 0:
            sum_2 += 1
    else:
        if s_list[i] == 1:
            sum_2 += 1

print(min(sum_1, sum_2))

Submission status: Accepted

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

ans = L
for m in range(2):
  t = 0
  for i in range(L):
    s = S[i]
    if i % 2 == m:
      if s == '0':
        t += 1
    else:
      if s == '1':
        t += 1
  ans = min(ans,t)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# 先頭を1にする
ans1 = 0
for i in range(N):
    if i%2==0 and S[i] == '0':
        ans1 += 1
    elif i%2==1 and S[i] == '1':
        ans1 += 1

# 先頭を0にする
ans2 = 0
for i in range(N):
    if i%2==0 and S[i] == '1':
        ans2 += 1
    elif i%2==1 and S[i] == '0':
        ans2 += 1

print(min(ans1, ans2))

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] != "1":
      ans1 += 1
    else:
      ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

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

ans1 = "".join(["1" if i%2 == 0 else "0" for i in range(N)])
ans2 = "".join(["0" if i%2 == 0 else "1" for i in range(N)])

print(min(bin(int(S, 2)^int(ans1, 2)).count("1"), bin(int(S, 2)^int(ans2, 2)).count("1")))

Submission status: Accepted

Solution code:
S = input()
c = 0
for i in range(len(S)):
    if i&1:
        c += S[i] == "0"
    else:
        c += S[i] == "1"
print(min(c, len(S) - c))

Submission status: Accepted

Solution code:
s=input()

#0はじまりの場合
ans_0=0
count=0
for i in s:
    if int(i) != count % 2: ans_0+=1
    count+=1

#1はじまりの場合
ans_1=0
count=1
for i in s:
    if int(i) != count %2: ans_1+=1
    count+=1

print(min(ans_0,ans_1))

Submission status: Accepted

Solution code:
#010 または 101にするのにかかる変更数を考えればいいということになる
s=str(input())
n=len(s)
c1=0
c2=0
for i in range(n): #奇数のときに１、偶数で０にする場合
  if i%2==0:
    if s[i]=="1":
      c1+=1
  else:
    if s[i]=="0":
      c1+=1
for i in range(n): #奇数のときに１、偶数で０にする場合
  if i%2==0:
    if s[i]=="0":
      c2+=1
  else:
    if s[i]=="1":
      c2+=1
print(min(c1, c2))

Submission status: Accepted

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

Submission status: Accepted

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

cnt_a, cnt_b = 0, 0
for i in range(n):
    if s[i] != a[i]:
        cnt_a += 1
    if s[i] != b[i]:
        cnt_b += 1
print(min(cnt_a, cnt_b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = s[::2].count("0")+s[1::2].count("1")
print(min(a,len(s)-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:
s = list(input())
n = s[0]
p = 0
for i in range(1,len(s)):
    if s[i] == n:
        p += 1
        if s[i] == '0':
            s[i] = '1'
            n = '1'
        else:
            s[i] = '0'
            n = '0'
    else:
        n = s[i] 

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

Submission status: Accepted

Solution code:
S = list(input())

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

ham1, ham2 = 0, 0
for i in range(len(S)):
  if pattern1[i] != S[i]:
    ham1 += 1
  if pattern2[i] != S[i]:
    ham2 += 1
print(min(ham1, ham2))

Submission status: Accepted

Solution code:
#44
S = input()
cou1,cou2 = 0,0
a,b = "",""
if len(S)%2 ==0:
    for i in range(int(len(S)/2)):
        a+="01"
        b+="10"
else:
    for i in range(int(len(S)/2)+1):
        a+="01"
        b+="10"
        
for i in range(len(S)):
    if S[i] != a[i]:
        cou1 +=1
    if S[i] != b[i]:
        cou2 +=1
if cou1 <= cou2:
    cou = cou1
else:
    cou = cou2
        
print(cou)

Submission status: Accepted

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

print(min(b_start,w_start))

Submission status: Accepted

Solution code:
S = list(input())
n = len(S)
for j in range(n):
	S[j] = int(S[j])
cnt = 0
for i in range(n-1):
	if S[i] == S[i+1]:
		S[i+1] = abs(S[i]-1)
		cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
S = input()

if S[0]=="0":
  ans = ["0","1"]*(10**5//2)
    
else:
  ans = ["1","0"]*(10**5//2)

count = 0
for i in range(len(S)):
  if S[i]!=ans[i]:
    count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


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

    count1 = 0
    count2 =0
    b ="1"
    w ="0"
    for i in range(len(S)):
        if int(S[i]) != i%2:
            count1 +=1
        if int(S[i]) != (i+1)%2:
            count2 +=1
    print(min(count1,count2))





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
ans1 = 0 ; ans2 = 0
for i in range(len(s)) :
    #黒スタートで考える
    if i % 2 == 0 :
        if s[i] != "0" :
            ans1 += 1
    else :
        if s[i] != "1" :
            ans1 += 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(ans1,ans2))

Submission status: Accepted

Solution code:
S = input()
L = [i&1 for i in range(len(S))]
m = sum(int(S[i])!=L[i] for i in range(len(S)))
print(m if m<=len(S)//2 else len(S)-m)

Submission status: Accepted

Solution code:
S = input()
L = len(S)
SS = ""
cnt = 0

if S[0] == "0":
    while len(SS) < L:
        SS += "0"
        SS += "1"

else:
    while len(SS) < L:
        SS += "1"
        SS += "0"

for i in range(L):
    if S[i] != SS[i]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
s = input()
l= len(s)
 
if l== 1:
    print(0)
    exit()
 
even = s[::2]
odd = s[1::2]

odd_zero = odd.count("0")
even_one = even.count("1")
 

odd_one = odd.count("1")
even_zero = even.count("0")
 
print(min(odd_zero + even_one, odd_one + even_zero))

Submission status: Accepted

Solution code:
s = input()
start0 = 0
start1 = 0
for i,j in enumerate(s):
    if ~i&1:
        start0 += (j=="1")
        start1 += (j=="0")
    else:
        start0 += (j=="0")
        start1 += (j=="1")
print(min(start0,start1))

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = list(input())
    zero, one = 0, 0
    for i in range(len(s)):
        if i%2 == 0:
            if s[i] == '1':
                zero += 1
            else:
                one += 1
        else:
            if s[i] == '1':
                one += 1
            else:
                zero += 1
    print(min(zero, one))
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s= input()

# 0 start
ans1 = 0
for i,c in enumerate(s):
    if i %2==1:
        if c != '1':
            ans1+=1
    else:
        if c !='0':
            ans1+=1

# 1 start
ans2=0
for i,c in enumerate(s):
    if i%2 ==1:
        if c!='0':
            ans2+=1
    else:
        if c!='1':
            ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
#参考 ： 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: Accepted

Solution code:
s = input()

ans0 = 0
ans1 = 0
for i, s_i in enumerate(s):
    if i % 2 == 0:
        if s_i == '0':
            ans1 += 1
        else:
            ans0 += 1
    else:
        if s_i == '0':
            ans0 += 1
        else:
            ans1 += 1
print(min(ans0, ans1))

Submission status: Accepted

Solution code:
S = input()
C = ['1', '0']
c = S[0]
cnt = 0
for i in range(1, len(S)):
    if c == S[i]:
        c = C[ord(c) - ord('0')]
        cnt += 1
    else:
        c = S[i]
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

s = input().rstrip()

li = ['0'] * len(s)
for i in range(len(s)):
    li[i] = s[i]

ans = 0
for i in range(1, len(s)):
    if li[i-1] != li[i]:
        continue
    else:
        if li[i] == '1':
            li[i] = '0'
        else:
            li[i] = '1'
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()
a = 0
b = 0
for i, s in enumerate(S):
  if i % 2:
    if s == "1":
      a += 1
    else:
      b += 1
  else:
    if s == "1":
      b += 1
    else:
      a += 1
print(min(a, b))

Submission status: Accepted

Solution code:
from copy import deepcopy
s1 = list(input())
s2 = deepcopy(s1)
length = len(s1)

ans1 = 0
ans2 = 0

# 1文字目'0'
for a in range(length):
    if a % 2 == 0:
        if s1[a] == '1':
            s1[a] = '0'
            ans1 += 1
    else:
        if s1[a] == '0':
            s1[a] = '1'
            ans1 += 1

# 1文字目'1'
for a in range(length):
    if a % 2 == 0:
        if s2[a] == '0':
            s2[a] = '1'
            ans2 += 1
    else:
        if s2[a] == '1':
            s2[a] = '0'
            ans2 += 1

print(min(ans1, ans2))