Problem: There are N cubes stacked vertically on a desk.  You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is `0`, and blue if that character is `1`.  You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.  At most how many cubes can be removed?

Submission attempts (in order):
s = str(input())
print(min(s.count("0"),s.count("1")))

s = str(input())
if s.count("0") > 0 and s.count("1")) > 0:
    print(2*min(s.count("0"),s.count("1")))
else:
    print(0)

s = str(input())
n = len(s)
ans = 0
b = [0 for i in range(n)]
for i in range(n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            while flag:
                nowl = i
                nowr = i+1
                if nowl >= 0 and nowr <= n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False

print(ans)
            

s = str(input())
n = len(s)
ans = 0
b = [0 for i in range(n)]
for i in range(n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            nowl = i
            nowr = i+1
            while flag:
                if nowl < 0 and nowr > n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                elif b[nowl] == 1 and b[nowr] == 0:
                    nowl -= 1
                elif b[nowl] == 0 and b[nowr] == 1:
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False
print(ans)
            

s = str(input())
n = len(s)
ans = 0
b = [0 for i in range(n)]
for i in range(n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            nowl = i
            nowr = i+1
            while flag:
                if nowl < 0 and nowr > n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                elif b[nowl] == 1 and b[nowr] == 0:
                    nowl -= 1
                elif b[nowl] == 0 and b[nowr] == 1:
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False
for i in range(1,n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            nowl = i-1
            nowr = i
            while flag:
                if nowl < 0 and nowr > n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                elif b[nowl] == 1 and b[nowr] == 0:
                    nowl -= 1
                elif b[nowl] == 0 and b[nowr] == 1:
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False
print(ans)
            

s = str(input())
if s.count("0") > 0 and s.count("1") > 0:
    print(2*min(s.count("0"),s.count("1")))
else:
    print(0)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted