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: Wrong Answer

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

Submission status: Wrong Answer

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

s = input()

s0 = s.count('0')
s1 = s.count('1')

if len(s)%2 == 0:
    sa = abs(len(s)//2-s0)
else:
    max = max(s0,s1)

    max = max - 1
    sa = abs(len(s)//2 - max)

print(sa)

Submission status: Wrong Answer

Solution code:
s = str(raw_input())
count0 = 0
for i in range(int(len(s)/2)):
	if s[i] == '0':
		count0 += 1
	if s[i+1] == '1':
		count0 += 1
if len(s) % 2 == 1:
	if s[-1] == '0':
		count0 += 1
print min(count0, len(s)-count0)

Submission status: Wrong Answer

Solution code:

line = raw_input()
odd_one = 0
even_one = 0
for i, val in enumerate(line):
    if val == '1':
        if (i + 1)% 2 == 0:
            even_one += 1
        else:
            odd_one +1

odd_zero = len(line) / 2 + 1 - odd_one
even_zero = len(line) / 2 - even_one

maximum = max([odd_one, even_one, odd_zero, even_zero])
result = 0
if maximum == odd_one:
    result += even_one + odd_zero
elif maximum == even_one:
    result += odd_one + even_zero
elif maximum == odd_zero:
    result += even_zero + odd_one
else:
    result += odd_zero + even_one

print result

Submission status: Wrong Answer

Solution code:
s = input()
len_s = len(s)
even_zero, even_one, odd_zero, odd_one = 0, 0, 0, 0

for i in range(len_s):
    if i % 2 == 0:
        if i == 0:
            even_zero += 1
        else:
             even_one += 1
    else:
        if i == 0:
            odd_zero += 1
        else:
             odd_one += 1

print(min(len_s - even_zero - odd_one, len_s - even_one - odd_zero))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()

count_left = 0
count_right = 0
n = len(s)
i = 0
while i < n:
  if i % 2 == 0: #odd
    if s[i] == "0":
      count_left += 1
    if s[n-i-1] == "1":
      count_right += 1
  else: #even
    if s[i] == "1":
      count_left +=1
    if s[n-i-1] == "0":
      count_right += 1
  i += 1
    
    
print(min(count_left, count_right))

Submission status: Wrong Answer

Solution code:
import collections
S = list(input())
S_g = [S[i] for i in range(len(S)) if i%2 == 0]
S_k = [S[i] for i in range(len(S)) if i%2 != 0]

S_g_count = collections.Counter(S_g)
S_k_count = collections.Counter(S_k)

S_g_count = sorted(S_g_count.items(),key = lambda x:x[1],reverse=True)
S_k_count = sorted(S_k_count.items(),key = lambda x:x[1],reverse=True)

count = 0
if len(S) == 1:
  print(0)
  exit()
  

if len(S_g_count) <= 1 or len(S_k_count) <= 1:
  if len(S_g_count) == 1 and len(S_k_count) == 1:
    count = len(S)//2
  elif len(S_g_count) == 1:
    count = len(S_k)-S_k_count[1][1]
  else:
    count = len(S_g)-S_g_count[1][1]
else:
  
  if S_g_count[0][0] != S_k_count[1][0]:
    count = len(S_k)-S_k_count[0][1] + len(S_g)-S_g_count[0][1]
  else:
    if S_g_count[1][0] > S_k_count[1][0]:
      count = len(S_g)-S_g_count[0][1] + len(S_k)-S_k_count[1][1]
    elif S_g_count[1][0] < S_k_count[1][0]:
      count = len(S_g)-S_g_count[1][1] + len(S_k)-S_k_count[0][1]
    else:
      count = len(S)//2
print(count)

Submission status: Wrong Answer

Solution code:
S = input()
cnt = [[0,0],[0,0]]
for i, s in enumerate(S):
    x = int(i) % 2
    y = int(s)
    cnt[x][y] += 1
print(cnt)
if cnt[0][0] >= cnt[1][0]:
    print(cnt[0][1] + cnt[1][0])
else:
    print(cnt[0][0] + cnt[1][1])

Submission status: Wrong Answer

Solution code:
def main():
    result = sub()
    print(result)


def sub():
    maskA = '10' * 10 ** 5
    maskB = '01' * 10 ** 5

    raw = input()
    length = len(raw)
    maskA = maskA[:length]
    maskB = maskB[:length]
    a = int(raw, 2) | int(maskA, 2)
    b = int(raw, 2) | int(maskB, 2)
    return min(bin(a).count("1"),
               bin(a).count("0"),
               bin(b).count("1"),
               bin(b).count("0"),
               )


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=list(input())
o = len(s)
j = 0

for i in range(o-2):
    if s[i] == s[i+1]:
        s[i+1] = str((int(s[i]) + 1)%2)
        j += 1

print(j)

Submission status: Wrong Answer

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

print(h_list)

score_z = 0
score_o = 0


# 0101で並び替える
counter = 0
for n in h_list:
    # 偶数更新
    if counter%2 == 0:
        if 0 != n:
            score_z += 1
    if counter%2 == 1:
        if 1 != n:
            score_z += 1
    counter+=1

# 1010で並び替える
counter = 0
for n in h_list:
    if counter%2 == 1:
        if 0 != n:
            score_o += 1
    if counter%2 == 0:
        if 1 != n:
            score_o += 1
    counter+=1


print(min(score_z,score_o))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
n = len(s)
start0 = 0
start1 = 0
for i in range(n):
    if i % 2 == 0 and s[i] == "0":
        start0 += 1
    elif i % 2 == 0 and s[i] == "1":
        start1 += 1
    elif i % 2 == 1 and s[i] == "1":
        start0 += 1
    else:
        start1 += 1
if start0 > start1:
    print(start1)
else:
    print(start0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    s = list(input_string[0][:])
    c = 0
    for i in range(len(s))[1:]:
        print(i)
        if s[i] == s[i-1]:
            if s[i] == "1":
                s[i] = "0"
            else:
                s[i] = "1"
            c += 1
    return c



def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

s = input()

s0 = s.count('0')
s1 = s.count('1')

if len(s)%2 == 0:
    sa = abs(len(s)-s0)
else:
    max = max(s0,s1)
    max = max - 1
    sa = abs(len(s)//2 - max)

print(sa)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def c_doloring_colorfully(S):
    if len(S) == 1:
        return 0
    if len(S) == 2:
        if S in ('11', '00'):
            return 1
        else:
            return 0
    ans = 0
    tmp = list(S)
    for i in range(len(S) - 2):
        t = ''.join(tmp[i:i + 3])
        if t == '000':
            tmp[i], tmp[i + 1], tmp[i + 2] = '010'
            ans += 1
        elif t == '001':
            tmp[i], tmp[i + 1], tmp[i + 2] = '101'
            ans += 1
        elif t == '010':
            tmp[i], tmp[i + 1], tmp[i + 2] = '010'
        elif t == '011':
            tmp[i], tmp[i + 1], tmp[i + 2] = '010'
            ans += 1
        elif t == '100':
            tmp[i], tmp[i + 1], tmp[i + 2] = '101'
            ans += 1
        elif t == '101':
            tmp[i], tmp[i + 1], tmp[i + 2] = '101'
        elif t == '110':
            tmp[i], tmp[i + 1], tmp[i + 2] = '010'
            ans += 1
        elif t == '111':
            tmp[i], tmp[i + 1], tmp[i + 2] = '101'
            ans += 1
    return ans

S = input()
print(c_doloring_colorfully(S))

Submission status: Wrong Answer

Solution code:
s = input()
count_o = 0
count_z = 0

for i in range(0, len(s), 2):
	if s[i] == '1':
		count_o += 1
	else :
		count_z += 1
	if i + 1 < len(s) and s[i+1] == '0':
		count_o += 1
	else :
		count_z += 1
print(min(count_z, count_o))

Submission status: Wrong Answer

Solution code:
S = input()
lo,ol = 0,0

if len(S)==0:
    print(0)
    exit()

for i in range(len(S)//2):
    #print(lo,ol)
    #print(S[i*2:(i+1)*2])
    if S[i*2:(i+1)*2]=="10":
        ol += 2
    elif S[i*2:(i+1)*2] =="01":
        lo += 2
    else:
        ol += 1
        lo += 1
else:
    """
    if len(S)%2!=0:
        if S[-1] == "1":
            ol += 1
        else:
            lo += 1
    """
    print(min(lo,ol))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
S = stdin.readline()
L = len(S)
cnt = 0
# 0101010101
for i, s in enumerate(S):
    if i & 1 == 1:
        incr = 1 if s == '1' else 0
        cnt += incr
    else:
        incr = 1 if s == '0' else 0
        cnt += incr
print(min(cnt, L-cnt))

Submission status: Wrong Answer

Solution code:
S = list(input())
del S[0]
flag = 0
ans_1 = 0
ans_2 = 0
for i in S:
    if (flag == 1):
        if (i == "0"):
            ans_1 += 1
        flag = 0
    else:
        if (i == "1"):
            ans_1 += 1
        flag = 1
flag = 1
for i in S:
    if (flag == 1):
        if (i == "0"):
            ans_2 += 1
        flag = 0
    else:
        if (i == "1"):
            ans_2 += 1
        flag = 1
print(min(ans_1, ans_2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = list(input())
import copy
S1 = copy.copy(S)
ans = 0
ans1 = 0 
for i in range(1, len(S)):
    if S[i] == S[i-1]:
        S[i] = '0' if S[i-1] == '1' else '1'
        ans+=1

for i in range(1, len(S1)):
    if S1[i] == S1[i-1]:
        S1[i-1] = '0' if S1[i] == '1' else '1'
        ans1+=1

print(min(ans, ans1))

Submission status: Wrong Answer

Solution code:
S = input()
T = []
tmp = '1'
for i in range(len(S)-1):
    if tmp[-1] == '0':
        tmp += '1'
    else:
        tmp += '0'
T.append(tmp)
tmp = '0'
for i in range(len(S)-1):
    if tmp[-1] == '0':
        tmp += '1'
    else:
        tmp += '0'
T.append(tmp)
print(T)
ans = float('inf')
for j in range(2):
    cnt = 0
    for i in range(len(S)):
        if S[i] != T[j][i]:
            cnt += 1
    if cnt < ans:
        ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
even_zero, even_one, odd_zero, odd_one = 0, 0, 0, 0

for i in range(len(s)):
    if i % 2 == 0:
        if i == 0:
            even_zero += 1
        else:
             even_one += 1
    else:
        if i == 0:
            odd_zero += 1
        else:
             odd_one += 1

print(min(even_zero + odd_one, even_one + odd_zero))

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
odd = 0
even = 0

for i in range(0,N):
    odd += int(S[i])

for i in range(1,N):
    even += int(S[i])

print(min(N-int(N/2) - odd + even,int(N/2) - even + odd))

Submission status: Wrong Answer

Solution code:
def load_input():
    s = [int(c) for c in list(input())]
    return s


def main():
    s = load_input()

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

    diff = [0, 0]
    for i in range(2):
        for j in range(len(s)):
            if s[j] != cand[i][j]:
                diff[i] += 1
    if diff[0] < diff[1]:
        print(diff[0])
    else:
        print(diff[1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(len(s)):
    if s[i] != str(i%2):
        ans1 += 1

for i in range(len(s)):
    if s[i] != str((i+1)%2):
        ans2 += 1

print(ans2)

Submission status: Wrong Answer

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

print(list1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
s = list(stdin.readline().rstrip())
odd_zero = s[0::2].count('0')
even_zero = s[1::2].count('0')
if odd_zero < even_zero:
    print(odd_zero+len(s[1::2])-even_zero)
if odd_zero > even_zero:
    print(len(s[0::2])-odd_zero+even_zero)
else:
    print(odd_zero+even_zero)

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

s = ns()
o = 0
e = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            e += 1
    else:
        if s[i] == '0':
            o += 1
if len(s) % 2 == 0:
    half = len(s) // 2
    print(min((half - e) + o, e + (half - o)))
else:
    half = len(s) // 2
    if s[-1] == '0':
        print(min((half - e) + o + 1, e + (half - o)))
    else:
        print(min((half - e) + o, e + (half - o)))

Submission status: Wrong Answer

Solution code:
def load_input():
    s = [int(c) for c in list(input())]
    return s


def main():
    s = load_input()

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

    diff = [0, 0]
    for i in range(2):
        for j in range(len(s)):
            if s[j] != cand[i][j]:
                diff[i] += 1
    if diff[0] < diff[1]:
        print(diff[0])
    else:
        print(diff[1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()

flag = True
length = len(S)
count = 0
for c in S:
    if int(flag) == int(c):
        count += 1
    flag = not flag

if count > divmod(length, 2)[1]:
    count = length - count
print(count)

Submission status: Wrong Answer

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

num_0_even = 0
num_0_odd = 0

for i in range(n // 2):
    if S[2 * i] == 0:
        num_0_even += 1
    if S[2 * i + 1] == 0:
        num_0_odd += 1

a = n // 2 + 1 - num_0_even + num_0_odd
b = num_0_even + n // 2 - num_0_odd

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

Submission status: Wrong Answer

Solution code:
S = input()

#01010..
ans = 10 * 5
count = 0
for i in range(len(S)):
    if S[i] != '0' and i % 2 == 0:
        count += 1
    elif S[i] != "1" and i % 2 == 1:
        count += 1
ans = min(ans, count)

#10101...
count = 0
for i in range(len(S)):
    if S[i] != '1' and i % 2 == 0:
        count += 1
    elif S[i] != "0" and i % 2 == 1:
        count += 1
ans = min(ans, count)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

now_col = S[0]
ans = 0
if len(S)==1:
    print(ans)
if len(S)!=1:
    for i in range(1,len(S)):
        if now_col != int(S[i]):
            now_col = int(S[i])
            continue
        else:
            ans += 1
            if now_col == 1:
                now_col = 0
            else:
                now_col = 1

print(ans)

Submission status: Wrong Answer

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

num_0_even = 0
num_0_odd = 0

for i in range(n // 2):
    if S[2 * i] == 0:
        num_0_even += 1
    if S[2 * i + 1] == 0:
        num_0_odd += 1

a = n // 2 - num_0_even + num_0_odd
b = num_0_even + n // 2 + 1 - num_0_odd

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

Submission status: Wrong Answer

Solution code:
S=input()
lens=len(S)
S=int(S, 2)
a=[]
b=[]

def popcnt0(n):
    c = 0
    for i in range(64):
        c += (n >> i) & 1
    return c

for i in range(lens):
	if i%2==0:
		a.append('0')
		b.append('1')
	if i%2==1:
		a.append('1')
		b.append('0')
aa=''.join(a)
bb=''.join(b)
aaa=int(aa,2)
bbb=int(bb,2)
c=S^aaa
d=S^bbb

print(min(popcnt0(c),popcnt0(d)))

Submission status: Wrong Answer

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 k in range(len(s)):
    if k%2==0:
        if s[k]=="1":
            ans2+=1
    else:
        if s[k]=="0":
            ans2+=1
print(ans1,ans2)

Submission status: Wrong Answer

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 k in range(len(s)):
    if k%2==0:
        if s[i]=="1":
            ans2+=1
    else:
        if s[i]=="0":
            ans2+=1
print(ans1,ans2)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
S = stdin.readline()
L = len(S)
cnt = 0
# 0101010101
for i, s in enumerate(S):
    if i & 1 == 1:
        cnt += 1 if s == '1' else 0
    else:
        cnt += 1 if s == "0" else 0
print(min(cnt, L-cnt))

Submission status: Wrong Answer

Solution code:
s=list(str(raw_input()))

n=len(s)

if n%2==0:
	list1=[str(0),str(1)]*(n//2)
	list2=[str(1),str(0)]*(n//2)
else:
	list1=[str(0),str(1)]*(n//2)
	list1.append(str(0))
	list2=[str(1),str(2)]*(n//2)
	list2.append(str(1))

ctr1=0
ctr2=0

for i in range(n):
	if s[i]!=list1[i]:
		ctr1+=1
	if s[i]!=list2[i]:
		ctr2+=1

print min(ctr1,ctr2)

Submission status: Wrong Answer

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

s = input()

s01 = "01"*(len(s)//2)
s10 = "10"*(len(s)//2)

c1 = sum([1 if i==j else 0 for i,j in zip(s,s01)])
c2 = sum([1 if i==j else 0 for i,j in zip(s,s10)])

print(min(c1,c2))

Submission status: Wrong Answer

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

num_0_even = 0
num_0_odd = 0

for i in range(n // 2):
    if S[2 * i] == 0:
        num_0_even += 1
    if S[2 * i + 1] == 0:
        num_0_odd += 1

a = n // 2 - num_0_even + num_0_odd
b = num_0_even + n // 2 - num_0_odd

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

Submission status: Wrong Answer

Solution code:
s = [int(item) for item in list(input())]
ans = 0
i = 0
while i < len(s) - 1:
    if s[i] != s[i + 1]:
        i += 1
        continue

    if i == len(s) - 2:
        ans += 1
        s[i + 1] ^= 1
        i += 1
        continue

    if s[i] == s[i + 1] == s[i + 2]:
        ans += 1
        s[i + 1] ^= 1
        i += 2
    elif i == 0:
        ans += 1
        s[i] ^= 1
        i += 1
    else:
        ans += 2
        s[i + 1] ^= 1
        s[i + 2] ^= 1
        i += 2


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
n = len(s)
start0 = 0
start1 = 0
for i in range(n):
    if i % 2 == 0 and s[i] == "0":
        start0 += 1
    elif i % 2 == 0 and s[i] == "1":
        start1 += 1
    elif i % 2 == 1 and s[i] == "1":
        start0 += 1
    else:
        start1 += 1
if start0 > start1:
    print(n - start0)
else:
    print(n - start1)

Submission status: Wrong Answer

Solution code:
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

s = input()
bef = ""
ct = 0
for i in range(len(s)):
    if i == 1:
        bef = s[i]
        continue
    else:
        if bef != s[i]:
            bef = s[i]
        else:
            ct +=1
            if s[i] == "0":
                bef = "1"
            else:
                bef = "0"

ct1 = ct

s = s[::-1]


bef = ""
ct = 0
for i in range(len(s)):
    if i == 1:
        bef = s[i]
        continue
    else:
        if bef != s[i]:
            bef = s[i]
        else:
            ct +=1
            if s[i] == "0":
                bef = "1"
            else:
                bef = "0"

ct2 = ct

print(min([ct1,ct2]))

Submission status: Wrong Answer

Solution code:
s=input()
c1=c2=0
f1='0'
f2='1'
for x in s:
  if f1==x:
    pass
  else:
    c1+=1
  if f1=='0':
    f1='1'
  else:
    f1='0'
for x in s:
  if f2==x:
    pass
  else:
    c2+=1
  if f2=='0':
    f2='1'
  else:
    f2='0'
print(c1,c2)
print(min(c1,c2))

Submission status: Wrong Answer

Solution code:
S = str(input())

S_10 = '10' * (len(S) // 2)
if len(S) % 2 == 1:
  S_10 += '1'
S_01 = '01' * (len(S) // 2)
if len(S) % 2 == 1:
  S_10 += '0'
  
s_10 = sum([x != y for (x, y) in zip(list(S), list(S_10))])
s_01 = sum([x != y for (x, y) in zip(list(S), list(S_01))])
print(min(s_10, s_01))

Submission status: Wrong Answer

Solution code:
str = input()
cnt = 0
num = 0
for i in str:
    if cnt % 2 == 0:
        if i == 0:
            num += 1
    else:
        if i == 1:
            num += 1
    cnt += 1

cnt2 = 0
num2 = 0
for i in str:
    if cnt2 % 2 == 0:
        if i == 1:
            num2 += 1
    else:
        if i == 0:
            num2 += 1
    cnt2 += 1
print(min(3-cnt,3-cnt2))

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    n = len(s)
    a = 0
    b = 0
    for i in range(n):
        if i & 1:
            if s[i] == '1':
                a += 1
            else:
                b += 1
        else:
            if s[i] == '1':
                b += 1
            else:
                a += 1
        print(min(a, b))
    return 0
main()

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
str = input()
cnt = 0
num = 0
for i in str:
    if cnt % 2 == 0:
        if i == '0':
            num += 1
    else:
        if i == '1':
            num += 1
    cnt += 1
cnt2 = 0
num2 = 0
for i in str:
    if cnt2 % 2 == 0:
        if i == '1':
            num2 += 1
    else:
        if i == '0':
            num2 += 1
    cnt2 += 1
print(min(cnt,cnt2))

Submission status: Time Limit Exceeded

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

import sys
sys.setrecursionlimit(10**6)

def operation(s,memo=-1,ans=0):
    if len(s) <= 0:
        return ans
    elif s[0] == memo == "0": #変えるパターン
        return operation(s[1:],"1",ans+1)
    elif s[0] == memo == "1": #変えるパターン
        return operation(s[1:],"0",ans+1)
    else:
        return operation(s[1:],s[0],ans)

def solve(s):
    return min(operation(s,"0"),operation(s,"1"))

def main():
    S = input()
    print(solve(S))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    S = sys.stdin.readline().rstrip()
    N = len(S)
    s1 = ""
    s2 = ""
    for i in range(N):
        if i % 2 == 0:
            s1 = s1 + "1"
            s2 = s2 + "0"
        elif i % 2 == 1:
            s1 = s1 + "0"
            s2 = s2 + "1"

    ans = float("inf")
    tmp = 0
    for i, j in zip(S, s1):
        if i != j:
            tmp += 1
    ans = min(ans, tmp)
    tmp = 0
    for i, j in zip(S, s2):
        if i != j:
            tmp += 1
    ans = min(ans, tmp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=input()
s0=''
s1=''
n=len(S)
for i in range(n):
  if i%2==0:
    s0+='0'
    s1+='1'
  else:
    s0+='1'
    s1+='0'
is0=bin(int(s0,2)^int(S,2))[2:]
is1=bin(int(s1,2)^int(S,2))[2:]
lis0=[]
lis1=[]
for i in range(len(is0)):
  lis0.append(is0[i])
for i in range(len(is1)):
  lis1.append(is1[i])
while '0' in lis0:
  lis0.remove('0')
while '0' in lis1:
  lis1.remove('0')
print(min(len(lis0),len(lis1)))

Submission status: Time Limit Exceeded

Solution code:
#abc124 c
def func(keta):
    ans1=0
    ans2=0
    for i in range(len(s)):
        if i%2==0:
            ans1+=2**i
        else:
            ans2+=2**i
    return ans1,ans2
s=input()
c1,c2=func(len(s))
s=int(s,2)
cnt1=bin(c1^s).count("1")
cnt2=bin(c2^s).count("1")
ans=min(cnt1,cnt2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

s1 = ''
s2 = ''
for i in range(len(S)):
	if i % 2 == 0:
		s1 += '0'
		s2 += '1'
	else:
		s1 += '1'
		s2 += '0'
dif1 = 0
dif2 = 0
for i in range(len(S)):
	if S[i] != s1[i]:
		dif1 += 1
	if S[i] != s2[i]:
		dif2 += 1

print(min([dif1, dif2]))

Submission status: Time Limit Exceeded

Solution code:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    N = len(S)

    s = ["", ""]
    flag = True
    for i in range(N):
        s[0] += str(i%2)
        s[1] += str((i + 1)%2)

    cnt = [0, 0]
    for i in range(N):
        for j in range(2):
            if s[j][i] != S[i]: cnt[j] += 1

    print(cnt[0] if cnt[0] < cnt[1] else cnt[1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
a=""
b=""
c="01"
for i in range(N):
    a+=str(c[i%2])
    b+=str(c[(i+1)%2])

ans_a=0
ans_b=0


for i in range(N):
    if a[i]!=S[i]:
        ans_a+=1
    if b[i]!=S[i]:
        ans_b+=1
        
print(min(ans_a,ans_b))

Submission status: Time Limit Exceeded

Solution code:
#ABC124_C
S=input()
 
S_rev=list(S)[::-1]
 
s=0
st0=0
st1=0
 
def bit_count(x):
    x=bin(x)[2:]
    ans=0
    for i in range(len(x)):
        if int(x[i])==1:
            ans+=1
    return ans
            
 
for i in range(len(S)):
    if i%2==0:
        st0+=2**i
    else:
        st1+=2**i
    if int(S_rev[i])==1:
        s+=2**i
 
cand0=st0^s
cand1=st1^s
 
    
bc0=bit_count(cand0)
bc1=bit_count(cand1)
if bc0>bc1:
    print(bc1)
else:
    print(bc0)

Submission status: Time Limit Exceeded

Solution code:
#ABC124_C
S=input()

S_rev=list(S)[::-1]

s=0
st0=0
st1=0

def bit_count(x):
    x=bin(x)[2:]
    ans=0
    for i in range(len(x)):
        if int(x[i])==1:
            ans+=1
    return ans
            

for i in range(len(S)):
    if i%2==0:
        st0+=2**i
    else:
        st1+=2**i
    if int(S_rev[i])==1:
        s+=2**i

cand0=st0^s
cand1=st1^s

if bit_count(cand0)>bit_count(cand1):
    print(bit_count(cand1))
else:
    print(bit_count(cand0))

Submission status: Time Limit Exceeded

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

ss=s

def change(x):
    if x=="0":
        ans="1"
    else:
        ans="0"
    return ans

count_1=0
#1枚目をそのまま使う
for i in range(1,n):
    if s[i-1]==s[i]:
        if i!=n-1:
            s=s[:i]+change(s[i])+s[i+1:]
        else:
            s=s[:i]+change(s[i])
        count_1+=1

count_2=1
ss=change(ss[0])+ss[1:]
for i in range(1,n):
    if ss[i-1]==ss[i]:
        if i!=n-1:
            ss=ss[:i]+change(ss[i])+ss[i+1:]
        else:
            ss=ss[:i]+change(ss[i])
        count_2+=1

if count_1>count_2:
    print(count_2)
else:
    print(count_1)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
for i in range(1,len(s)):
    if s[i-1] == s[i]:
        new = (int(s[i])+1)%2
        s_li = list(s)
        s_li[i] = str(new)
        s = ''.join(s_li)
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
i =input()

a = i.find('11') 
b = i.find('00')

c=0

while a !=-1 or b !=-1:
  if b>=0 and (a<0 or b<a):
    i = i.replace('00','01',1)
    c+=1
  elif a>=0 and (b<0 or a<b):
    i = i.replace('11','10',1)
    c+=1
  a = i.find('11') 
  b = i.find('00')

print(c)

Submission status: Time Limit Exceeded

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

A = 0
for i in range(0, n, 2):
    A += 2**i

B = 0
for i in range(1, n, 2):
    B += 2**i

ans = min(bin(S^A).count('1'), bin(S^B).count('1'))
print(ans)

Submission status: Time Limit Exceeded

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

a=0
b=0
for i in range(n):
        if i%2==0:
                a+=2**i
        elif i%2==1:
                b+=2**i
a=format(a,'b').zfill(n)
b=format(b,'b').zfill(n)

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