Problem:


Score : 300 points

Problem Statement

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?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0



Sample input:
0011


Sample output:
4

Submission status: Runtime Error

Solution code:
#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input()

Nblock = 0

while '0' in S and '1' in S:
    for i in range(len(S)-1):
        if S[i:i+1] != S[i+1:i+2]:
            Nblock += 2
            S = S[:i] + S[i+2:]
            print(S)
            break

print(Nblock)

Submission status: Runtime Error

Solution code:
import re

S = input()
xs = list(S)

i, j = 0, 1
while j < len(xs):
    if xs[i] != xs[j]:
        xs[i:j + 1] = []
        i -= 1
        j = i + 1
    else:
        i += 1
        j += 1
print(len(S) - len(xs))

Submission status: Runtime Error

Solution code:
def solve(S,crs=0):
    if crs >= len(S):
        return 0
    while crs + 1 < len(S):
        if S[crs] != S[crs+1]:
            return max(solve(S,crs+1),solve(S[:crs]+S[crs+2:],crs-1)+2)
        crs += 1
        
    return 0
  
S = input()
print(solve(S,0))

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import defaultdict

#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

#A, B, K = map(int, input().split())  #
S = input()
S_list = list()
for i in range(len(S)):
    S_list.append(S[i])
#print(len(S_list))

flag = True
cnt = 0
while flag:
    flag = False
    k = 0
    #print(S_list)
    for i in range(len(S_list)-1):
        #print(i+1)
        if S_list[i - k] != S_list[i+1 - k]:
            #print(i, i+1)
            S_list.pop(i-k)
            S_list.pop(i-k)
            cnt += 2
            flag = True
            k += 2
            #break
        pass
    pass
print(cnt)

Submission status: Runtime Error

Solution code:
s=input()
zero=0
one=0
for i in s:
  if i="0":
    zero+=1
  elif i="1":
    one+=1
print(min(zero,one)*2)

Submission status: Runtime Error

Solution code:
a = list(map(int,list(input())))
c = 1
co = 0
p = a[0]
pp = []
for i in range(len(a)-1):
	if a[(i+1)] == p:
		c += 1
	else:
		pp.append(c)
		c = 1
		p = a[i+1]
ppp = pp[0]

kkk = 0
for i in range(len(pp)-1):
	if pp[i] >= 0:
		co += 2*(max(pp[i],pp[i+1]) - abs(pp[i] - pp[i+1]))
		pp[i+1] = pp[i+1] - pp[i]
	else:
		pp[i+1] = pp[i+1] - pp[i]
print(co)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
dp = [0 for i in range(N)]
last = ['' for i in range(N)]
last[0] = S[0]
for i in range(1, N):
    if last[i-1][-1] != S[i]:
        dp[i] = dp[i-1] + 1
        if i >= 2:
            last[i] = last[i-2]
    else:
        dp[i] = dp[i-1]
        last[i] = last[i-1] + S[i]
print(dp[N-1]*2)

Submission status: Runtime Error

Solution code:
def solve(s):
    count = 0
    i = 0

    while True:
        if i >= len(s) - 1:
            break
        if s[i] != s[i + 1]:
            count += 1
            s = s[0:i] + s[i + 2:]
            i -= 1
            continue
        i += 1
    return count


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(S) * 2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main(){
  string s;
  cin >> s;
  
  stack<char> st;
  
  long long i = 0;
  for(auto c:s){
    if(st.empty()){
      st.push(s[i]);
    }
    else if(st.top() == s[i])
      st.push(s[i]);
    else
      st.pop();
    
    i++;
  }
  
  long long stack_count = 0;

  cout << s.size() - st.size() << endl;
}

Submission status: Runtime Error

Solution code:
import numpy as np
from collections import defaultdict

#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

#A, B, K = map(int, input().split())  #
S = input()
S_list = list()
for i in range(len(S)):
    S_list.append(S[i])
#print(len(S_list))

flag = True
cnt = 0
while flag:
    flag = False
    #print(S_list)
    for i in range(len(S_list)-1):
        #print(i+1)
        if S_list[i] != S_list[i+1]:
            #print(i, i+1)
            S_list.pop(i)
            S_list.pop(i)
            cnt += 2
            flag = True
            #break
        pass
    pass
print(cnt)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
answer = 0
while 1:
  c_01 = s.count("01")*2
  answer += c_01*2
  s = s.replace("01","")
  
  c_10 = s.count("10")
  answer += c_10*2
  s = s.replace("10","")
  
  if c_01 == 0 and c_02 == 0:
    break
print(answer)

Submission status: Runtime Error

Solution code:
s = input()
k = 0
while True:
  if "10" in s:
    i = s.index("10")
    s = list(s)
    s.pop(i)
    s.pop(i)
    s = "".join(s)
    k += 2
  elif "01" in s:
    i = s.index("10")
    s = list(s)
    s.pop(i)
    s.pop(i)
    s = "".join(s)
    k += 2
  else:
    print(k)
    break

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
dp = [0 for i in range(N)]
last = [False for i in range(N)]
last[0] = S[0]
for i in range(1, N):
    if last[i-1][-1] != S[i]:
        dp[i] = dp[i-1] + 1
        if i >= 2:
            last[i] = last[i-2]
    else:
        dp[i] = dp[i-1]
        last[i] = last[i-1] + S[i]
print(dp[N-1]*2)

Submission status: Runtime Error

Solution code:
def solve(start, s):
    for i in range(start, len(s) - 1):
        if s[i] != s[i + 1]:
            return 1 + solve(i - 1, s[:i] + s[i + 2:])
    return 0


def solve2(s):
    count = 0
    i = 0

    while True:
        if i == len(s) - 1:
            break
        if s[i] != s[i + 1]:
            count += 1
            s = s[:i] + s[i + 2:]
            i -= 1
            continue
        i += 1
    return count


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    # print(solve(0, S) * 2)
    print(solve2(S) * 2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

length = 0
ans = 0

def remove_data(data, ind_pre, ind_after):
    if ind_pre == 0:
        data_pre = ''
    else:
        data_pre = data[:ind_pre]
    if ind_after == len(data) - 1:
        data_after = ''
    else:
        data_after = data[ind_after + 1:]
    data_remove = data_pre + data_after
    return data_remove

def calc_ans(data):
    global length, ans
    ans_kari = length - len(data)
    if ans_kari > ans:
        ans = ans_kari


def calc_data(data):
    for i in range(len(data) - 1):
        if data[i] != data[i + 1]:
            data_remove = remove_data(data, i, i+1)
            calc_data(data_remove)
    calc_ans(data)

def main():
    global length, ans
    data = input()
    length = len(data)
    calc_data(data)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()

pos, c = 0, 0
while pos < len(S) - 1:
	if S[pos] != S[pos + 1]:
		S = S[:pos] + S[pos+2:]
		c += 2
		pos -= 2
	pos += 1
print(c)

Submission status: Runtime Error

Solution code:
s = input()

cnt = 0

while '01' in s or '10' in s:
    if '01' in s:
        s = s.replace('01','', 1)
        print(s,cnt)
        cnt += 1
        continue
    if '10' in s:
        s = s.replace('10','', 1)
        print(s,cnt)
        cnt += 1
        continue

print(cnt*2)

Submission status: Runtime Error

Solution code:
def solve(start, s):
    for i in range(start, len(s) - 1):
        if s[i] != s[i + 1]:
            return 1 + solve(i - 1, s[:i] + s[i + 2:])
    return 0


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(0, S) * 2)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()

i = 0
while(True):
    if ("01" in s ) :
        s = s.replace("01","",1) 
        i += 1
    elif "10" in s:
        s = s.replace("10","",1)
        i += 1
    else:
        break
    print(s)
print(i*2)

Submission status: Runtime Error

Solution code:
s = list(map(int, input()))0
print(min(len(s)-sum(s), sum(s))*2)

Submission status: Runtime Error

Solution code:
def inpl():
    return list(map(int, input().split()))


S = inpu()
print(min(S.count('0'), S.count('1')))