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: Accepted

Solution code:
s = input()
color = [0, 0]
for i in s:
    if i == '0':
        color[0] += 1
    else:
        color[1] += 1
print(min(color) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = list(input())

n = len(s)
ans = 0
tmp = []
for i in range(n):
    if len(tmp) != 0 and s[i] == '0' and tmp[len(tmp) - 1] == '1':
        tmp.pop()
        ans += 2
    elif len(tmp) != 0 and s[i] == '1' and tmp[len(tmp) - 1] == '0':
        tmp.pop()
        ans += 2
    else:
        tmp.append(s[i])
    #print(tmp)
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

one = 0
zero = 0
for s in S:
    if s == "1":
        one += 1
    else:
        zero += 1
print(min(one, zero) * 2)

Submission status: Accepted

Solution code:
S = list(input())

last = S.pop(0)
stack = [last]
can_pop = True
cnt = 0
for s in S:
    if last != s and can_pop:
        stack.pop()
        if len(stack) == 0:
            can_pop = False
        # stack.append(s) 読み捨て
        cnt += 2
    else:
        stack.append(s)
        last = s
        can_pop = True

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

s = STR()
n = len(s)
stack = deque()
for i in range(n):
    if not len(stack) or stack[len(stack)-1] == s[i]:
        stack.append(s[i])
    else:
        stack.pop()
print(n - len(stack))

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

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

s = STR()
n = len(s)
stack = deque(s[0])
for i in range(1, n):
    if not len(stack) or stack[len(stack)-1] == s[i]:
        stack.append(s[i])
    else:
        stack.pop()
print(n - len(stack))

Submission status: Accepted

Solution code:
import re

s = input()

c0, c1 = 0, 0
for i in s:
    if i=='0':
        c0 += 1
    else:
        c1 += 1

print(min(c0, c1)*2)

"""TLE
def trans_word(text):
    replacements = {'01': '', '10': ''}
    return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text)

ans = 0
flag = True

while flag:
    s_tmp = s
    s = trans_word(s)
    ans += (len(s_tmp) - len(s))
    flag = len(s_tmp) - len(s)

print(ans)
"""

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
S=list(input())
S=list(map(int,S))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

one = s.count('1')
zero = s.count('0')

print(2*min(one,zero))

Submission status: Accepted

Solution code:
S = input()

ans = len(S) - abs(S.count("1") - S.count("0"))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
s_0,s_1 = 0,0
for i in range(len(s)):
    if(s[i] == "0"):
        s_0 += 1
    else:
        s_1 += 1
c = len(s)-(max(s_0,s_1)-min(s_0,s_1))
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

red=s.count("0")
blue=s.count("1")

print(2*min(red,blue))

Submission status: Accepted

Solution code:
# coding: utf-8

s = input().rstrip()

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

print(ans)

Submission status: Accepted

Solution code:
S = str(input())

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

Submission status: Accepted

Solution code:
s = input()
li = []

for i in s:
    if i=="1":
        li.append(1)

ans = 2*min(len(li), len(s)-len(li))
print(ans)

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

X = 0
Y = 0

for i in range(N):
    if S[i]=="0":
        X += 1
    else:
        Y += 1

print(min(X,Y)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

s = np.array(list(map(int , input())))
n = np.count_nonzero(s == 0)
print(2 * min(len(s)-n, n))

Submission status: Accepted

Solution code:
a=[int(i) for i in input()]
st=[]
for i in a:
    flag=0
    while st and st[-1]!=i:
        st.pop()
        flag=1
        break
    if flag==0: st.append(i)
print(len(a)-len(st))

Submission status: Accepted

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

S = input().strip()
#-----

num_red = S.count("0")
num_blue = len(S) - num_red

print( min(num_red,num_blue) * 2 )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
S=s.count("0")
print(n-abs(S-n+S))

Submission status: Accepted

Solution code:
s=list(input())
x=s.count('1')
y=s.count('0')
z=min(x,y)
print(z*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:
s = input()
# ans = 0
# while '01' in s or '10' in s:
#     # print('yes')
#     if '01' in s:
#         s = s.replace('01', '', 1)
#         ans += 2
#     if '10' in s:
#         s = s.replace('10', '', 1)
#         ans += 2
#     # print(s, ans)

# # print(ans)

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

Submission status: Accepted

Solution code:
s = input()

stack = []

ans = 0

for s_i in s:
  if len(stack) == 0:
    stack.append(s_i)
    continue
  if (s_i == "0" and stack[-1] == "1") or (s_i == "1" and stack[-1] == "0"):
    stack.pop()
    ans += 2
  else:
    stack.append(s_i)
print(ans)

Submission status: Accepted

Solution code:
s = input()
count0 = 0
count1 = 0
for i in s:
    if i=="0":
        count0 += 1
    else:
        count1 += 1

print(min(count0,count1)*2)

Submission status: Accepted

Solution code:
s = input()

odd = 0
even = 0

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

print(2*min(odd, even))

Submission status: Accepted

Solution code:
s=input()
a=s.count("0")
b=len(s)-a
if a>=b:
  print(2*b)
else:
  print(2*a)

Submission status: Accepted

Solution code:

S = input()

dic = [0,0]

for i in S:

    dic[int(i)] += 1

print (min(dic)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

S = str(input())

A = S.count('0')

B = S.count('1')

ans = len(S)-int(abs(A-B))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
s = list(input())
s = [int(i) for i in s]

t = collections.Counter(s)
print(min(t[0], t[1]) * 2)

Submission status: Accepted

Solution code:
S = list(input())
n = len(S)
red = S.count("0")
blue = n - red
print(n if red == blue else n - abs(red - blue))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

count0 = 0
count1 = 0

for i in s:
    if i == '0':
        count0 += 1
    else:
        count1 += 1
print(min(count0, count1)*2)

Submission status: Accepted

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

count_0 = 0
count_1 = 0
for i in range(0, len(s)):
    if s[i] == "0":
        count_0 += 1
    if s[i] == "1":
        count_1 += 1

if count_0 >= count_1:
    print(count_1*2)
else:
    print(count_0*2)

Submission status: Accepted

Solution code:
s = input()
cnt=0
for c in s:
   if c=="0":
       cnt+=1
print(2*min(cnt,len(s)-cnt))

Submission status: Accepted

Solution code:
s = input()

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

print(min(c0, c1)*2)

Submission status: Accepted

Solution code:
s = list(input())
count0 =s.count('0')      
count1 =s.count('1')

print(min(count0,count1)*2)

Submission status: Accepted

Solution code:
s = str(input())

count0 = s.count('0')
count1 = len(s) - count0

answer = min(count0,count1) * 2
print(answer)

Submission status: Accepted

Solution code:
#120_C
S=input()
r=S.count('0')
b=S.count('1')
print(len(S)-abs(r-b))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
ones = 0
zeros = 0
for s in S:
    if s == '0':
        zeros += 1
    else:
        ones += 1
ans = zeros - ones
if ans < 0:
    ans *= -1
print(N - ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
c = Counter(list(input())).values()
print(0 if len(c) == 1 else 2 * min(c))

Submission status: Accepted

Solution code:
st = []
S = input()
ans = 0
for c in S:
    if st != [] and c != st[-1]:
        st.pop(-1)
        ans += 2
    else:
        st.append(c)
print(ans)

Submission status: Accepted

Solution code:
s = input()
a = 0
b = 0
for i in s:
    if i == '0':
        a += 1
    else:
        b += 1
print(min(a,b)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
l = len(S)
a = S.count('0')
print(2 * min(a, l - a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
A = [int(c) for c in S]

l = len(S)
L = [[0 for j in range(l + 1)] for i in range(2)]
R = [[0 for j in range(l + 1)] for i in range(2)]

for i in range(l):
    L[0][i + 1] = L[0][i]
    L[1][i + 1] = L[1][i]
    L[A[i]][i + 1] += 1

for i in range(l - 1, -1, -1):
    R[0][i] = R[0][i + 1]
    R[1][i] = R[1][i + 1]
    R[A[i]][i] += 1

k = 0
for a, b, c, d in zip(L[0], R[1], L[1], R[0]):
    k = max(k, min(a, b) + min(c, d))

print(k * 2)

Submission status: Accepted

Solution code:
s=list(input());t=len(s);a=s.count("0");b=t-a;print(min(a,b)*2)

Submission status: Accepted

Solution code:
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = readline().decode('utf8')
n1 = N.count('1')
n0 = N.count('0')
print(min(n1, n0)*2)

Submission status: Accepted

Solution code:
s=list(map(int,input()))
a=len(s)
b=0
c=0
for i in range(a):
  if s[i]==0:
    b+=1
  else:
    c+=1
d=min(b,c)*2
print(d)

Submission status: Accepted

Solution code:
import collections


class Solution:
    def solve(self, S: str) -> int:

        c = collections.Counter(S + "01")
        zeros = c["0"] - 1
        ones = c["1"] - 1

        return 2 * min(zeros, ones)


if __name__ == '__main__':

    # standard input
    S = input()

    # solve
    solution = Solution()
    print(solution.solve(S))

Submission status: Accepted

Solution code:
s = input()

t = s[0]
for i in s[1:]:
  if not t:
    t=i
    continue
  if i != t[-1]:
    t=t[:-1]
  else:
    t+=i

print(len(s) - len(t))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
cntd = {'0':0, '1':0}

for i in range(n):
    cntd[s[i]] += 1
ans = 0
ans = 2 * min(cntd.values())
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('1'), S.count('0'))*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

stack = []
stack.append(S[0])
S = S[1:]

for s in S:
    if len(stack) != 0 and s != stack[-1]:
        stack.pop()
    else:
        stack.append(s)

print(N - len(stack))

Submission status: Accepted

Solution code:
from collections import deque
S = input()

res = 0 

stack = deque()

for cube in S:
    if (not stack) or cube == stack[0]:
        stack.appendleft(cube)
    else:
        stack.popleft()
        res += 2

print(res)

Submission status: Accepted

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

x = s.count(0)
y = s.count(1)

print(min(x, y) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
zero = 0
one = 0
for i in S:
  if i == "0":
    zero += 1
  else:
    one += 1
ans = min(zero,one)*2
print(ans)

Submission status: Accepted

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

    zero = s.count('0')
    one = len(s) - zero

    print(min(zero, one) * 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()

s0 = 0
s1 = 0

for c in s:
    if c == '0':
        s0 += 1
    else:
        s1 += 1

print(min(s0, s1)*2)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
sub = [0] * 2

for i in range(n):
    sub[int(s[i])] += 1
    
ans = min(sub[0],sub[1])*2
print(ans)

Submission status: Accepted

Solution code:
s = input()

cnt = 0
for c in s:
    if c == '0':
        cnt += 1

remove = 2*min(cnt, len(s)-cnt)
print(remove)

Submission status: Accepted

Solution code:
S = input()

now = S[0]
c = 1
ans = 0

for s in S[1:]:
  if now == '':
    now = s
    c = 1
  else:
    if s == now:
      c += 1
    else:
      ans += 2
      c -= 1
      if c == 0:
        now = ''

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
stack=[]
cnt=0

for s in S:
  if not stack:
    stack.append(s)
  elif stack[-1]!=s:
      stack.pop()
      cnt+=2
  else:
    stack.append(s)
print(cnt)

Submission status: Accepted

Solution code:
s=input()
stack=[2]
n=len(s)

cnt=0
for i in range(n):
  if s[i]=='0' and stack[-1]=='1':
    stack.pop()
    cnt+=2
  elif s[i]=='1' and stack[-1]=='0':
    stack.pop()
    cnt+=2
  else:
    stack.append(s[i])
print(cnt)

Submission status: Accepted

Solution code:
S = str(input())

cnt_0 = S.count('0')
cnt_1 = S.count('1')

print(min(cnt_0,cnt_1)*2)

Submission status: Accepted

Solution code:
def main():
    S=input()
    s=0
    for i in range(0,len(S)):
        s=s+int(S[i])
    t=len(S)-s
    print(2*min(s,t))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
a_1=sum(i=="1" for i in s)
a_0=len(s)-a_1
print(min(a_0,a_1)*2)

Submission status: Accepted

Solution code:
s = input()
a = 0
b = 0
for i in s:
    if i == "0":
        a += 1
b = len(s) - a
print(min(a, b) * 2)

Submission status: Accepted

Solution code:
N = input()

a = N.count("0")
b = N.count("1")

if a == 0 or b == 0:
    ans = 0
else:
    ans = min(a, b) * 2
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

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

if a == 0 or b == 0:
    ans = 0
elif a > b:
    ans = (a+b)-(a-b)
else:
    ans = (a+b)-(b-a)

print(ans)

Submission status: Accepted

Solution code:
# g, algolism Q

a = [int(i) for i in list(input())]
print(min(a.count(0), a.count(1))*2)

Submission status: Accepted

Solution code:
a = [int(i) for i in list(input())]
print(min(a.count(0), a.count(1))*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    n0 = s.count("0")
    n1 = s.count("1")

    if n0 == n1:
        print(n0*2)
    elif n0 > n1:
        print(n1 * 2)
    else:
        print(n0 * 2)



calculate()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
count1 = 0
count0 = 0
for s in S:
  if s == '1':
    count1 += 1
  else:
    count0 += 1
if count1 == 0 or count0 == 0:
  print(0)
else:
  print(2 * min(count1, count0))

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input()
one=0
zero=0
for i in a:
  if i=="0":
    zero+=1
  else:
    one+=1

print(2*min(zero,one))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
num_0 = s.count("0")
num_1 = n - num_0

print(n - abs(num_0 - num_1))

Submission status: Accepted

Solution code:
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if nall==0:
    print(0)
elif none<=nzero:
    print(none*2)
else:
    print(nzero*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N_0 = S.count('0')
N_1 = S.count('1')

answer = 2 * min(N_0, N_1)
print(answer)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    print(len(S) - abs(S.count('1') - S.count('0')))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

sys.setrecursionlimit(10 ** 9)


def main():
    S = INPUT()
    c = Counter(S)
    print(min(c['0'], c['1']) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
s=input()
stack = deque()
count=0
for i in s:
  if not stack:
    stack.append(i)
  elif stack[-1]!=i:
    stack.pop()
    count+=2
  else:
    stack.append(i)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

red = s.count('0')
blue = s.count('1')

print(min(red, blue) * 2)

Submission status: Accepted

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

if b<w:
    print(2*b)
else:
    print(2*w)

Submission status: Accepted

Solution code:
S = input()
stack = []
ans = 0
for s in S:
  if not stack:
    stack.append(s)
  elif stack[-1] != s:
    stack.pop()
    ans += 2
  else:
    stack.append(s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
c1, c2 = 0, 0
for i in s:
    if i == "0":
        c1 += 1
    else:
        c2 += 1
print(min(c1, c2)*2)

Submission status: Accepted

Solution code:
s=input()
c=0
for i in s:
    c+=(i=="0")
    c-=(i=="1")
print(len(s)-abs(c))

Submission status: Accepted

Solution code:
class Stack(object):
    def __init__(self):
        self.container = []
    
    def __len__(self):
        return len(self.container)
    
    def push(self, elem):
        self.container.append(elem)
    
    def pop(self):
        idx = len(self.container) -1
        if idx < 0:
            return None
        ret = self.container[idx]
        del self.container[-1]
        return ret
    
    def compare(self, val):
        return self.container[-1] == val

if __name__ == '__main__':
    string = [int(i) for i in input()]
    ret = 0
    stack = Stack()
    stack.push(string[0])
    for s in string[1:]:
        if stack.__len__() == 0:
            stack.push(s)
            continue
        if stack.compare(s):
            stack.push(s)
        else:
            ret += 2
            stack.pop()

    print(ret)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    S = cin.string()
    print(min(S.count("0"),S.count("1")) * 2)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
List = list(S)
Length = len(List)
Sum = 0
for item in List:
  Sum += int(item)
Answer = Length - abs(2*Sum - Length)
print(Answer)

Submission status: Accepted

Solution code:
S=input()
na=S.count("0")
nb=len(S)-na
print(min(na,nb)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
cnt = 0
for i in range(len(s)):
    cnt += int(s[i])

print(2*min(cnt, len(s)-cnt))

Submission status: Accepted

Solution code:
s =list(input())


m = min(s.count('0'),s.count('1'))

print(2*m)

Submission status: Accepted

Solution code:
S = str(input())
s0 = s1 = 0
for s in S:
  if s == "1":
    s1 += 1
  else:
    s0 += 1
print(min(s0, s1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

cnt_0 = s.count('0')
cnt_1 = s.count('1')
print(2 * min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
def main():
    A = input()
    print(2*min(A.count("0"),A.count("1")))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

t = ns()
n = len(t)
s = [t[i] for i in range(n)]

a, b = 0, 0

for i in range(n):
    if s[i] == '0':
        a += 1
    elif s[i] == '1':
        b += 1

print(2 * min(a, b))

Submission status: Accepted

Solution code:
s = input()
x,y = 0,0
for i in list(s):
  if i == "0":
    x += 1
  else:
    y += 1
print(min([x,y])*2)

Submission status: Accepted

Solution code:
S = input()
zero = 0
one = 0

for s in S:
    if s == '0':
        zero += 1
    else:
        one += 1

if zero < one:
    print(zero*2)
else:
    print(one*2)

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:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

S = input()

red = 0
ble = 0

for s in S:
    if s == '0':
        red += 1
    else:
        ble += 1

ans = min(red, ble)*2
print(ans)

Submission status: Accepted

Solution code:
S = input()

ones = 0
zeros = 0

for c in S:
    n = int(c)
    if n:
        ones += 1
    else:
        zeros += 1

print(min(ones, zeros) * 2)

Submission status: Accepted

Solution code:
S=input()

num0=0
num1=0

for i in range(len(S)):
    if S[i]=='0':
        num0+=1
    else:
        num1+=1
print(2*min(num0,num1))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
 
def main():
    S  = list(map(int, input()))
    o = S.count(0)
    l = S.count(1)
 
    print(min(o, l) * 2)
 
main()

Submission status: Accepted

Solution code:
import sys

s = sys.stdin.readline().rstrip()

def main():
    return min(s.count('0'), s.count('1')) * 2

if __name__ == '__main__':
    ans = main()
    print(ans)

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()
print(2*min(s.count('1'),s.count('0')))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from queue import LifoQueue

S = str(input())

q = LifoQueue()

ans = 0
for s in S:
    if not q.empty():
        before = q.get()
        if before != s:
            ans += 1
        else:
            q.put(before)
            q.put(s)
    else:
        q.put(s)

print(ans*2)

Submission status: Accepted

Solution code:
S = input()

count1 = 0
count0 = 0

for i in S:
    if i == '1':
        count1 += 1
    else:
        count0 += 1

print(min(count0, count1) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
if len(set(s))==1:
    print(0)
else:
    c=s.count('1')
    print(min(c,n-c)*2)

Submission status: Accepted

Solution code:
import sys

def main():
    S  = list(map(int, input()))
    o = S.count(0)
    l = S.count(1)

    print(min(o, l) * 2)

main()

Submission status: Accepted

Solution code:
s = list(input())

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

print(len(s)-(max(zero,one)-min(zero,one)))

Submission status: Accepted

Solution code:
# coding: utf-8
S = input()
zero, one = 0, 0
for i in range(len(S)):
    if S[i] == "0":
        zero += 1
    else:
        one += 1
print(min(zero, one)*2)

Submission status: Accepted

Solution code:
s = input().strip()
red_cnt = s.count("0")
blue_cnt = len(s) - red_cnt
if (red_cnt <= blue_cnt):
    print(2 * red_cnt)
else:
    print(2 * blue_cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    S=map(int,list(input()))
    c=[0,0]
    for s in S:
        c[s]+=1
    print(min(c)*2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    S = input().strip()
    print(min(list(S).count('1'), list(S).count('0')) * 2)
    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()
l=[]
for ak in range(len(s)):
    l.append(s[ak])
no=[]
s=l
no.append(s[0])
br=0
for i in range(1,len(s)):
    no.append(s[i])
   
    if len(no) >= 2 and no[-1]!=no[-2]:
        no.pop(-1)
        no.pop(-1)
        br+=2
print(br)