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: Time Limit Exceeded

Solution code:
#c

S = input()

def clean(seq):
    if len(seq) == 1:
        return seq
    
    cleaned_seq = []
    remove_flag = False
    for idx, s in enumerate(seq):
        if remove_flag:
            remove_flag = False
            continue
            
        if idx == len(seq)-1:
            cleaned_seq.append(s)
            break

        this_ = int(s)
        next_ = int(seq[idx+1])
        if this_ + next_ == 1:
            remove_flag = True
        else:
            cleaned_seq.append(s)
            
    return cleaned_seq

former_cleaned = []
cleaned = S
while(not len(cleaned) == len(former_cleaned)):
    former_cleaned = cleaned
    cleaned = clean(former_cleaned)
    
print(len(S) - len(cleaned))

Submission status: Time Limit Exceeded

Solution code:
S = input()
SS = S
while SS.find('01') >= 0 or SS.find('10') >= 0:
    SS = SS.replace('01', '').replace('10', '')
    SS = SS.replace('10', '').replace('01', '')

print(len(S) - len(SS))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
ans = 0
while True:
    end = 0
    for i in range(len(s) - 1):
        if len(s) == 0:
            end = 0
            break
        if s[i] != s[i + 1]:
            ans += 2
            end = 1
            del s[i:i + 2]
            break
    if end == 0:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=list(map(str,input()))
c=0
while "1" in s and "0" in s:
    for i in range(1,len(s)):
        if s[i-1] != s[i]:
            del s[i-1]
            del s[i-1]
            c+=2
            break
        else:
            pass
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt1 = 0
cnt2 = 0
while True:
    before = S
    S = before.replace("01", "", 1)
    if before != S:
        cnt1 += 1
    else:
        break

while True:
    before = S
    S = before.replace("10", "", 1)
    if before != S:
        cnt2 += 1
    else:
        break

print(2 * (cnt1 + cnt2))

Submission status: Time Limit Exceeded

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

if initial_length == 1:
    print("0")
else:
    len_S = 0
    while len_S != len(S):
        len_S = len(S)
        S = S.replace("10", "")
        S = S.replace("01", "")
    print(initial_length - len(S))

Submission status: Time Limit Exceeded

Solution code:
import sys
S = sys.stdin.readline()
X = S
while True:
    new_S = S.replace("01","").replace("10","")
    if S == new_S:
        break
    S = new_S
print(len(X) - len(S))

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=len(s)
b=10**5+1
while True:
#    print(a,b)
    b=len(s)
    s=s.replace("10","")
    s=s.replace("01","")
    c=len(s)
    if c==b:
        break
print(a-c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt=0
while True:
    for i in range(len(s)):
        try: 
            if '10' in s:
                s=s.replace('10', '',1) 
                cnt+=2
        except:
            pass
        try: 
            if '01' in s:
                s=s.replace('01', '',1) 
                cnt+=2
        except:
            pass

    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=[i for i in input()]
cnt=0
while True:
    if len(s)==0 or s.count("0")==len(s) or s.count("1")==len(s):
        break
    else:
        for i in range(len(s)):
            try:
                if int(s[i])+int(s[i+1])==1:
                    cnt+=2
                    s=s[0:i]+s[i+2:]
            except:
                pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
initial_len_S = len(S)
len_S = 1e10
len_S_new = 1e10 - 1

while (len_S_new < len_S):
    len_S= len(S)
    S = S.replace("10", "").replace("01","")
    len_S_new = len(S)

print(initial_len_S - len_S)

Submission status: Time Limit Exceeded

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

while True:
    fn = len(S)
    S = S.replace('01', '').replace('10','')
    if fn == len(S):
        break

print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
len_s = len(S)
while(True):
    S = S.replace("01","")
    S = S.replace("10", "")
    if not "01" in S:
        if not "10" in S:
            break
print(len_s - len(S))

Submission status: Time Limit Exceeded

Solution code:
s=input()
flag=1
length=len(s)
while flag:
    l=len(s)
    if l<=1:
        break
    pre=s[0]
    for i in range(1,l):
        if pre!=s[i]:
            s=s[:i-1]+s[i+1:]
            break
        else:
            pre=s[i]
            if i==l-1:
                flag=0
print(length-len(s))

Submission status: Time Limit Exceeded

Solution code:
def f(s):
  r=0
  for i,x in enumerate(s):
    if len(s)==i+1:
      break
    if(x!=s[i+1]):
      del s[i]
      del s[i]
      r+=2
      break
  return r

s=input()
s=list(s)

r=0

while True:
  buf=f(s)
  r+=buf
  if buf==0:
    break

print(r)

Submission status: Time Limit Exceeded

Solution code:
s = input()
S = [int(s[i]) for i in range(len(s))]
# print(S)
count = 0
while 1:
    #print("S:", S)
    is_continue = False
    # print(len(S))
    for i in range(len(S) - 1):
        #print(S[i], S[i+1])
        if S[i] != S[i + 1]:
            # print(count)
            del S[i]
            del S[i]
            count += 2
            is_continue = True
            break
    if not is_continue:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
ans = 0
i = 1

while i < n:
    if s[i-1] == "0" and s[i] == "1":
        s = s[:i-1] + s[i+1:]
        n -= 2
        ans += 2
        i = 1
        if n == 0 or n == 1:
            print(ans)
            exit()
        continue
    elif s[i-1] == "1" and s[i] == "0":
        s = s[:i-1] + s[i+1:]
        n -= 2
        ans += 2
        i = 1
        if n == 0 or n == 1:
            print(ans)
            exit()
        continue
    else:
        i += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
string = input()

start_length = len(string)

while len(string) > 0:
  if "10" in string or "01" in string:
    string = string.replace("10", "")
    string = string.replace("01", "")
  else:
    break

print(start_length - len(string))

Submission status: Time Limit Exceeded

Solution code:
import sys
input  = sys.stdin.readline

S = input()
N = len(S)

while True:
  n = len(S)
  S = S.replace('10','')
  if n == len(S):
    break
while True:
  n = len(S)
  S = S.replace('01','')
  if n == len(S):
    break
print(N-len(S))

Submission status: Time Limit Exceeded

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

while True:
    T = S[:]
    S = S.replace('10', '')
    S = S.replace('01', '')
    if S == T:
        break

print(L - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0

while '01' in S:
    count += 1
    S = S.replace('01', '', 1)

while '10' in S:
    count += 1
    S = S.replace('10', '', 1)

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
import collections
s=list(map(str,input()))
c=0
cl=collections.Counter(s)
while cl["1"]!=0 and cl["0"]!=0 :
    for i in range(1,len(s)):
        if s[i-1] != s[i]:
            del s[i-1]
            del s[i-1]
            c+=2
            cl=collections.Counter(s)
            break
        else:
            pass

print(c)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
cnt = 0

while True:
    if re.search("01", S) is None and re.search("10", S) is None:
        break
    length = len(S)
    S = re.sub("01", "", S)
    cnt += length - len(S)
    length = len(S)
    S = re.sub("10", "", S)
    cnt += length - len(S)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

S = input()
a = len(S)

for i in range(int(10**5/2)):
    S = S.replace("01","",1)
    S = S.replace("10","",1)

b = len(S)

print(a-b)

Submission status: Time Limit Exceeded

Solution code:
S = input()
stalen = len(S)
beflen = 0
while beflen != len(S):
    beflen = len(S)
    S = S.replace('10', '')
    S = S.replace('01', '')

print(stalen - len(S))

Submission status: Time Limit Exceeded

Solution code:
t = input()
s = [c for c in t]
Removable = True
count = 0
while True and len(s)>1:
    tmp = len(s)
    for i in range(len(s)-1):
        if int(s[i])+int(s[i+1]) == 1:
            count += 2
            s.pop(i)
            s.pop(i)
            break
    if tmp == len(s):
        break
print(count)

Submission status: Time Limit Exceeded

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(i*2)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
N = len(S)
r = re.compile(r"01|10")
T = ""
while S != T:
    T = S
    S = r.sub("", S)
print(N - len(S))
r.sub("", S)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0

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

print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
prev = 0
cnt = 0
while prev != len(S):
    prev = len(S)
    for i, s in enumerate(S):
        if i == 0:
            continue
        if s != S[i-1]:
            del(S[i-1])
            del(S[i-1])
            cnt += 2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

s = S = input()
while '01' in s or '10' in s:
    s = s.replace('01', '').replace('10', '')
print(len(S) - len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
X = S
while True:
    flg = 0
    new_S = S.replace("01","").replace("10","")
    if S == new_S:
        break
    S = new_S
print(len(X) - len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
s = s + "a"
while True:
    if "01" in s:
        s = s.replace("01", "", 1)
        count += 2
    elif "10" in s:
        s = s.replace("10", "", 1)
        count += 2
    else:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(raw_input())

i = 0
cnt = 0
while len(S) > 0:
    if i+1 == len(S):
        break
    if S[i] != S[i+1]:
        del S[i]
        del S[i]
        i = -1
        cnt += 2
    i += 1

print cnt

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
Slist=list(S)
horyu=[]
Slen=len(S)
count=0
for i in range(Slen):
    if Slist[i] == "0":
        if "1" in horyu:
            horyu.remove("1")
            count+=1
        else:
            horyu.append("0")
    else:
        if "0" in horyu:
            horyu.remove("0")
            count+=1
        else:
            horyu.append("1")
print(count*2)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
s = input()
n = len(s)
ok = 0
while ok == 0:
    ok = 1
    i = 0
    while i < len(s) - 1:
        str = s[i] + s[i+1]
        if str == "01" or str == "10":
            s = s[:i] + s[i+2:]
            ok = 0
        i += 1
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
string = input()

start_length = len(string)

while len(string) > 0:
  if "10" in string:
    string = string.replace("10", "")
  elif "01" in string:
    string = string.replace("01", "")
  else:
    break

print(start_length - len(string))

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


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 [int(x) for x in sys.stdin.readline().split()]
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)

S = S()


result = 0
while True:
    if S.find('01') < 0 and S.find('10') < 0:
        print(result)
        exit()
    if S.find('01') >= 0:
        idx = S.find('01')
        S = S[:idx] + S[idx+2:]
        result += 2

    if S.find('10') >= 0:
        idx = S.find('10')
        S = S[:idx] + S[idx+2:]
        result += 2

Submission status: Time Limit Exceeded

Solution code:
s = input()
t=s

while("01" in t or "10" in t):
	t = t.replace("01","")
	t = t.replace("10","")
print(len(s)-len(t))

Submission status: Time Limit Exceeded

Solution code:
s=input()

ans=0
while "10" in s:
  s=s.replace("10","",1)
  ans+=1
while "01" in s:
  s=s.replace("01","",1)
  ans+=1
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:

S = input()
N = len(S)
n = 10 ** 6
while n != len(S):
    n = len(S)
    S = S.replace('01', '')
    S = S.replace('10', '')

ans = N - len(S)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0

while True:
    change = False
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            change = True
            count += 2
            break
    if not change:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
L = len(s)
while True:
    l = len(s)
    s = s.replace("01","")
    s = s.replace("10","")
    if l==len(s): 
        break
print(L-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
l = n+1
while l > len(s):
    l = len(s)
    s = s.replace('01','')
    s = s.replace('10','')
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict
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] = SR()
    return l
mod = 1000000007

#A

#B

#C
s = S()
n = len(s)
while len(s)>1:
    i = 0
    f = True
    while s[i] == s[i+1]:
        if i+1 == len(s)-1:
            f = False
            break
        i += 1
    if not f:break
    s.pop(i)
    s.pop(i)
print(n-len(s))
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
s = input()
l = list(s)

a = l.count('0')
b = l.count('1')

ans = 2 * min(a, b)
print(ans)

Submission status: Accepted

Solution code:
s=input()
print(min(s.count("0"),s.count("1"))*2)

Submission status: Accepted

Solution code:
from collections import Counter
S = str(input())
c = Counter(S)
d = c.most_common()
if len(d) == 2:
  ans = d[1][1] * 2
  print(ans)
else:
  print(0)

Submission status: Accepted

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

a=s.count('0')
b=s.count('1')

print(min(a,b)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
z = S.count("0")
o = S.count("1")

print(len(S)-abs(z-o))

Submission status: Accepted

Solution code:
S = list(input())

c0 = S.count("0")
c1 = S.count("1")

print(2 * min(c0,c1))

Submission status: Accepted

Solution code:
s = input()
z = s.count('0')
print(2*min(z, len(s)-z))

Submission status: Accepted

Solution code:
S=list(input())
a=S.count('0')
b=S.count('1')
if a>b:
    print(2*b)
else:
    print(2*a)

Submission status: Accepted

Solution code:
import sys

cubes = list(input()) # 入力受付
stack = []
count = 0

for cube in cubes:
    if not stack:
        stack.append(cube)
    elif stack[-1] != cube:
        count += 2
        stack.pop()
    else:
        stack.append(cube)
print(count)

Submission status: Accepted

Solution code:
S = list(input())

print(2*min(S.count("1"),S.count("0")))

Submission status: Accepted

Solution code:
def main():
    # n = int(input())
    # n, m = map(int, input().split())
    # a = list(map(int, input().split()))
    s = list(input())
    # h = [int(input()) for _ in rane(n)]
    count0 = 0
    count1 = 0
    for i in s:
        if i == "0":
            count0 += 1
        else:
            count1 += 1

    print(min(count0, count1)*2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
a=S.count('0')
b=S.count('1')
print(min(a,b)*2)

Submission status: Accepted

Solution code:
s = input()

a = 0
b = 0

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

print(min(a,b)*2)

Submission status: Accepted

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

s = [int(i) for i in input().strip()]
o = list()
n = len(s)

while s:
    v = s.pop()
    if len(o) == 0:
        o.append(v)
    else:
        if v + o[-1] == 1:
            o.pop()
        else:
            o.append(v)
print(n - len(o))

Submission status: Accepted

Solution code:
import collections
S=list(str(input()))
cc=collections.Counter(S)
ans=min(cc['0'],cc['1'])
print(ans*2)

Submission status: Accepted

Solution code:
s = input()
num = s.count('0')
print(2 * min(num, len(s) - num))

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    cnt0 = s.count("0")
    cnt1 = s.count("1")

    ans = min(cnt0, cnt1)*2
    print(ans)
main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    d = {'0': 0, '1': 0}
    for s in S:
        d[s] += 1
    print(min(d.values()) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
print(len(s)-abs(s.count('1')-s.count('0')))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
n = len(s)
b = s.count('0')
r = n - b
print(2 * min(b, r))

Submission status: Accepted

Solution code:
s = input()
zero = 0
one = 0
for i in s:
  if i == '0':
    zero += 1
  else:
    one += 1
ans = min(one, zero)
print((ans) << 1)

Submission status: Accepted

Solution code:
S=input()
print(min(S.count('0'),S.count('1'))*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 01:36:50 2020

@author: liang
"""

S = input()
c0 = 0
c1 = 0
for i in range(len(S)):
    if S[i] == "0":
        c0 += 1
    else:
        c1 += 1
ans = len(S) - abs(c0-c1)
print(ans)

Submission status: Accepted

Solution code:
S = list(input())
print(2*(min(S.count("0"),S.count("1"))))

Submission status: Accepted

Solution code:

def resolve():
    import sys
    input = sys.stdin.readline

    s = input().rstrip()
    r = 0
    b = 0
    for c in s:
        if c == "0":
            r += 1
        else:
            b += 1

    print(min(r, b) * 2)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
s=input()
cnt0 = 0
cnt1 = 0
for i in s:
    if i == '0':
        cnt0 +=1
    else:
        cnt1 +=1

print(2*min(cnt0,cnt1))

Submission status: Accepted

Solution code:
a=list(input())
temp1=0
temp0=0

for i in range(len(a)):
    if a[i]=="0":
        temp0+=1
    else:
        temp1+=1
print(min(temp0,temp1)*2)

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 12.09.2020 12:29:36

from collections import Counter
import sys

S = input()

c = Counter(S)

print(len(S) - abs(c["0"] - c["1"]))

Submission status: Accepted

Solution code:
s=list(str(input()))
a=s.count('0')
b=s.count('1')

print(min(a,b)*2)

Submission status: Accepted

Solution code:
def main():
    s = input()
    zero = s.count("0")
    one = s.count("1")
    print(min(zero, one) * 2)

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-11 14:10:37 +0900
# LastModified: 2020-09-11 14:16:43 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    S = input()
    if S.count('0') < S.count('1'):
        print(S.count('0')*2)
    else:
        print(S.count('1')*2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = list(input())

print(2 * min(S.count('0'), S.count('1')))

Submission status: Accepted

Solution code:
s = input()
b = 0
w = 0
for i in range(len(s)):
    if(s[i] == '0'):
        b = b+1
    if(s[i] == '1'):
        w = w+1

print(2*min(b,w))

Submission status: Accepted

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

print(min(num_0,num_1)*2)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
c=s.count("1")
print(2*(min(c,n-c)))

Submission status: Accepted

Solution code:
s=input()

num_0 = 0
num_1 = 0
for i in range(len(s)):
  if s[i] == '0':
    num_0 += 1
  else:
    num_1 += 1
    
print(min(num_0,num_1)*2)

Submission status: Accepted

Solution code:
S = input()

red = 0
blue = 0
for s in S:
    if s == '0':
        red += 1
    elif s == '1':
        blue += 1
print(min(red, blue)*2)

Submission status: Accepted

Solution code:
N = str(input())
one = N.count('1')
zero = N.count('0')

print(min(one,zero)*2)

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
len0 = S.count('0')
len1 = S.count('1')
rm = min(len0,len1)
print(2*rm)

Submission status: Accepted

Solution code:
S=input()
n0,n1=0,0
for s in S:
  if s=='1':
    n1+=1
  elif s=='0':
    n0+=1
print(min(n1,n0)*2)

Submission status: Accepted

Solution code:
from collections import deque

S = input()

d = deque()
cnt = 0
for s in S:
    if d:
        if d[-1] != s:
            d.pop()
            cnt += 2
        else:
            d.append(s)
    else:
        d.append(s)

print(cnt)

Submission status: Accepted

Solution code:
S = str(input())
x = S.count("0")
y = S.count("1")
print(2*min(x, y))

Submission status: Accepted

Solution code:
def main():
    s = input()

    print(min(s.count("0"), s.count("1")) * 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
a=s.count('0')
b=s.count('1')
c=min(a,b)
print(2*c)

Submission status: Accepted

Solution code:
S=input()
List = list(S)
zeroNum = List.count("0")
oneNum = List.count("1")
res = min(zeroNum,oneNum)
print(res*2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    S = input()

    ans = min(S.count('0'), S.count('1'))
    print(ans * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
stack_0 = []
stack_1 = []

for s in S:
    if s == "0":
        if stack_1:
            stack_1.pop()
        else:
            stack_0.append(s)
    else:
        if stack_0:
            stack_0.pop()
        else:
            stack_1.append(s)

print(len(S) - len(stack_0) - len(stack_1))

Submission status: Accepted

Solution code:
S = str(input())
x = len(S)
if '0' in S:
  y0 = S.count('0')
else:
  y0 = 0
if '1' in S:
  y1 = S.count('1')
else:
  y1 = 0
  
d = abs(y0 - y1)
print(x - d)

Submission status: Accepted

Solution code:
S = input()

zero_count=S.count("0")
one_count=S.count("1")

ans=2*min(int(zero_count),int(one_count))
print(ans)

Submission status: Accepted

Solution code:
s = input()

z = 0
o = 0
for c in s:
    if c == '1':
        o += 1
    else:
        z += 1

print(min(o, z) * 2)

Submission status: Accepted

Solution code:
N = input()
count0 = N.count('0')
count1 = len(N)-count0
print(min(count0,count1)*2)

Submission status: Accepted

Solution code:
# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType


def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func


#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007


def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input


def out(var): sys.stdout.write(str(var))  # for fast output, always take string


def lis(): return list(map(int, inp().split()))


def stringlis(): return list(map(str, inp().split()))


def sep(): return map(int, inp().split())


def strsep(): return map(str, inp().split())


def zerolist(n): return [0] * n


def nextline(): out("\n")  # as stdout.write always print sring.


def testcase(t):
    for p in range(t):
        solve()


def printlist(a):
    for p in range(0, len(a)):
        out(str(a[p]) + ' ')

import heapq as hp
from math import ceil
def solve():
    s=inp()
    k=s.count("0")
    n=len(s)-k
    print(2*min(k,n))


    







solve()

Submission status: Accepted

Solution code:
s = input()
r = s.count("0")
b = s.count("1")
print(r + b - abs(r - b))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

s = list(input().strip())
r = s.count('0')
b = s.count('1')
print(2*min(r,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
x = S.count('0')
y = S.count('1')

ans = 2 * (min(x, y))
print(ans)

Submission status: Accepted

Solution code:
S = input()

print(min(S.count("1"), S.count("0")) * 2)

Submission status: Accepted

Solution code:
S = list(input())

print(min(S.count("0"), S.count("1")) * 2)