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:
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 heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
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

# N = INT()
S = list(input())
c = Counter(S)
# print(c)
ans = INF
# if len(c) == 1:
ans = min(ans, c["0"], c["1"])
print(ans * 2)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    c = [0, 0]
    for i in range(len(S)):
        c[int(S[i])] += 1
    print(2 * min(c))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
S = input().strip()
C = {"0":0,"1":0}
for i in range(len(S)):
    C[S[i]] += 1
print(min(C["0"],C["1"])*2)

Submission status: Accepted

Solution code:
S = list(input())

pair = 0
stack = [-1]
for s in S:
    tmp = int(s)
    if 1 - tmp == stack[-1]:
        pair += 1
        stack.pop()
    else:
        stack.append(tmp)

ans = 2 * pair
print (ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()
    ans = 0
    red = 0
    blue = 0
    for ss in reversed(s):
        if ss == '0':
            red += 1
            if blue > 0:
                red -= 1
                blue -= 1
                ans += 2
        else:
            blue += 1
            if red > 0:
                red -= 1
                blue -= 1
                ans += 2

    print(ans)

Submission status: Accepted

Solution code:
def resolve():
  s = input()
  red = 0
  blue = 0
  for c in s:
    if c == '0':
      red += 1
    else:
      blue += 1
  print(min(red, blue) * 2)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

    ans = 0
    st = []
    for x in s:
        st.append(x)
        if len(st) >= 2:
            if st[-1] != st[-2]:
                st.pop()
                st.pop()
                ans += 2

    print(ans)

if __name__ == '__main__':
    main()

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:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    s=input()
    z=s.count("0")
    o=s.count("1")
    print(min(z,o)*2)

main()

Submission status: Accepted

Solution code:
S = input()

n_0 = S.count('0')
n_1 = S.count('1')

ans = 2 * min(n_0, n_1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(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:
def main():
    S = input()
    from collections import Counter
    c = Counter(S)
    print(min(c["0"], c["1"])*2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
def unification(s):

    ans = 0
    d = defaultdict(int)
    for k in s:
       d[k] += 1

    ans = len(s) - abs(d["0"]-d["1"])

    return ans

def main():
    s = str(input())
    print(unification(s))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
a=n.count('1')
b=n.count('0')
if a<b:
    print(2*a)
else:
    print(2*b)

Submission status: Accepted

Solution code:
S = input()
a = S.count('0')
b = S.count('1')
ab = abs(b-a)
print(len(S) - ab)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
cnt1 = 0
cnt2 = 0
for i in s:
    if i == "0":
        cnt1 += 1
    else:
        cnt2 += 1
print(2*min(cnt1,cnt2))

Submission status: Accepted

Solution code:
s = input()
cnt_0, cnt_1 = s.count('0'), s.count('1')
print(len(s) - (max(cnt_0, cnt_1) - min(cnt_0, cnt_1)))

Submission status: Accepted

Solution code:
from collections import Counter

c = Counter(input())

print(2*min(c['1'], c['0']))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(S:list) -> int:
   zero = 0
   one = 0
   for s in S:
      if(s == "0"):
         zero += 1
      else:
         one += 1
   return min(zero,one)*2

def modelAnswer(S:list) -> int:
   return

def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)
n_0 = s.count("0")
n_1 = s.count("1")
d = abs(n_0 - n_1)
print(n - d)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()

r = S.count("0")
b = S.count("1")

print(min(r,b)*2)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
c0=0
for i in range(n):
  if s[i]=='0':
    c0+=1
print(2*min(c0, n-c0))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class DoubleLinkedList:
    def __init__(self, v):
        self.value = v
        self.prev = None
        self.next = None


s = input().rstrip()

root = DoubleLinkedList(None)
current = root

count = 0
for i in range(len(s)):
    node = DoubleLinkedList(s[i])

    if (current.value == '0' and node.value == '1') or (current.value == '1' and node.value == '0'):
        current = current.prev
        count += 2
    else:
        current.next = node
        node.prev = current
        current = node

print(count)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()

cnt = Counter(S)
low = min(cnt["0"],cnt["1"])
ans = low*2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# solution

data=input()
print(min(data.count('0'),data.count('1'))*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
S = [Si for Si in S]

i = len(S) - 2
number_of_deleted_qube = 0
while i >= 0 and len(S) >= 2:
    if i >= len(S) - 1:
        i -= 1
        continue

    current = S[i]
    right = S[i + 1]

    if current != right:
        del S[i + 1]
        del S[i]
        number_of_deleted_qube += 2

    i -= 1

print(number_of_deleted_qube)

Submission status: Accepted

Solution code:
#A
"""
a, b, c = map(int, input().split())
print(min(b//a, c))
"""
#B
"""
a, b, k = map(int, input().split())
for i in range(max(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
             print(i)
"""

#C

s = list(input())
an0 = 0
an1 = 0
for i in s:
    if i == "1":
        an1 += 1
    if i == "0":
        an0 += 1
print(min(an0, an1)*2)
"""

#D

n, m = map(int, input().split())
ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))

ab = ab[-1::-1]
size = [1 for _ in range(n)]
height = [1 for _ in range(n)]
par = [i for i in range(n)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def union(x, y):
    s1 = find(x)
    s2 = find(y)
    if s1 != s2:
        if height[s1] < height[s2]:
            par[s1] = s2
            size[s2] += size[s1]
            size[s1] = 0
        else:
            par[s2] = s1
            size[s1] += size[s2]
            size[s2] = 0
            if height[s1] == height[s2]:
                height[s1] += 1
 

ans = [0 for i in range(m)]
ans[0] = n * (n - 1) // 2
for num, i in enumerate(ab):
    if num == m-1:
        break
    a = i[0] - 1
    b = i[1] - 1
    sizea = size[find(a)]
    sizeb = size[find(b)]
    if find(a) == find(b):
        ans[num + 1] = ans[num]
    else:
        ans[num + 1] = ans[num] - (sizea * sizeb)
    union(a,b)
    
    
ans = ans[-1::-1]
for i in ans:
    print(i)
"""

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
s = list(input())

x = [0, 0]
for si in s:
    x[int(si)] += 1

print(2*min(x))

Submission status: Accepted

Solution code:
def myAnswer(S:list) -> int:
   C0 = 0
   C1 = 0
   for s in S:
      if(s =="0"):
         C0+=1
      else:
         C1 += 1
   return 2*min(C0,C1)

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
one = 0
zero = 0
for i in s:
    if i == "0": zero += 1
    else: one += 1
print(len(s) - abs(one - zero))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
red = S.count('0')
blue = S.count('1')
answer = 2 * min(red, blue)
print(answer)

Submission status: Accepted

Solution code:
import collections

S = input()
c = collections.Counter(S)
if len(c)==2:
    print(2 * min(c.values()))
else:
    print(0)

Submission status: Accepted

Solution code:
S=list(map(int,input()))
N=len(S)
x=sum(S)
print(2*min(x,N-x))

Submission status: Accepted

Solution code:
s=input()

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

print(len(s)-abs(zero-one))

Submission status: Accepted

Solution code:
def resolve():
    s = list(input())
    rcount = 0
    bcount = 0
    for i in s:
        if i == "0":
            rcount += 1
        else:
            bcount += 1
    print(min(rcount, bcount) * 2)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
c0 = 0
c1 = 0
for i in S:
    if i == '0':
        c0 += 1
    else:
        c1 += 1
ans = min(c0,c1) * 2
print(ans)

Submission status: Accepted

Solution code:
import math
s = input()

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:
s = list(input())
before = []
cnt = 0
for i,now in enumerate(s):
    if i == 0 or len(before) == 0:
        before.append(now)

        continue
    if before[-1] != now:
        before.pop()
        cnt += 2
    else:
        before.append(now)

print(cnt)

Submission status: Accepted

Solution code:
a = input()
c_zero = 0
c_one = 0
for digit in a:
    if digit == '0':
        c_zero += 1
    else:
        c_one += 1
print(min(c_one, c_zero) * 2)

Submission status: Accepted

Solution code:
s = list(input())

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

Submission status: Accepted

Solution code:
s=input()
c0=0
c1=0

for i in range(len(s)):
  if (s[i]=="0"):
    c0+=1
  else:
    c1+=1
print(2*min(c0,c1))

Submission status: Accepted

Solution code:
import sys

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

def main():
    c = s.count('0')
    print(min(n-c, c) * 2)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque
s=input()
d=deque()
for i in range(len(s)):
  if len(d)>0:
    if d[len(d)-1]!=s[i]:
      d.pop()
    else:
      d.append(s[i])
  else:
    d.append(s[i])
print(len(s)-len(d))

Submission status: Accepted

Solution code:
s = input()
l0, l1 = 0, 0
for i in s:
    if i == '0':
        l0 += 1
    else:
        l1 += 1
        
print(len(s)-abs(l0-l1))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    zero = s.count('0')
    one = s.count('1')
    print(min(zero*2,one*2))
if __name__ == '__main__':
  main()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = input()
predicted_value = 0
finished = False
i = 1
while i < len(num):
    if num[i] != num[i-1]:
        num = num[:i-1] + num[i+1:]
        predicted_value += 2
        if i > 1:
            i -= 2
        elif i == 1:
            i = 0
    i += 1
print(predicted_value)

Submission status: Accepted

Solution code:
s = input()

ones = 0
zeros = 0
for c in s:
    if c == '1':
        ones += 1
    else:
        zeros += 1

remove = 2 * min(ones, zeros)
print(remove)

Submission status: Accepted

Solution code:
s = input()

a = 0
tmp = 0
for i in s:
    if i == '1':
        a += 2
    else:
        tmp += 2
        
print(min(a, tmp))

Submission status: Accepted

Solution code:
sl = list(input())

a = [0, 0]
for s in sl:
    a[int(s)] += 1

print(min(a) * 2)

Submission status: Accepted

Solution code:
from collections import Counter
d={chr(i):0 for i in range(2)}
s=Counter(input())
d=d.update(s)
print(min(s["0"],s["1"])*2)

Submission status: Accepted

Solution code:
from collections import deque
s=deque(input())
N=len(s)
A=[]
for i in range(N):
  a=s.popleft()
  if len(A)!=0:
    if A[-1]!=a:
      A.pop()
    else:
      A.append(a)
  else:
    A.append(a)
print(N-len(A))

Submission status: Accepted

Solution code:
def main():
    s = input()
    mi = min(s.count(c) for c in '01')
    ans = mi * 2
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

Solution code:
def main():
    from collections import Counter

    s = input()

    ctr = Counter(s)
    ctr.update({'0': 0, '1': 0})

    ans = min(ctr.values()) * 2

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

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

Submission status: Accepted

Solution code:
S = list(input())

zero = 0
one = 0
for i in S:
  if i == '0':
    zero += 1
  else:
    one += 1
else:
  print(min([zero, one]) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
a=S.count('1')
b=S.count('0')

print(2*min(a,b))

Submission status: Accepted

Solution code:
s = input()

total = len(s)
cnt_one = 0
cnt_zero = 0

for i in s:
    if i == '1':
        cnt_one += 1
    else:
        cnt_zero += 1

print(min(cnt_zero, cnt_one) * 2)

Submission status: Accepted

Solution code:
from collections import deque
N = list(input())
S = [int(i) for i in N]
cnt = 0
que = deque(([-1,S[0]]))

for i in range(1,len(S)):
    jdg = que.pop()

    if (S[i] + jdg) == 1:
        cnt += 2
    else:
        que.append(jdg)
        que.append(S[i])
        
print(cnt)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
ones=S.count("1")
zeros=S.count("0")
print(N-abs(ones-zeros))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
d = dict()
d['0'] = 0
d['1'] = 0

S = input()

for x in S:
    d[x] += 1
print(min(d['0'], d['1'])*2)

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
ans = dict(Counter(s))
if '0' in ans and '1' in ans:
    print(min(ans['0'],ans['1'])*2)
else:
    print(0)

Submission status: Accepted

Solution code:
S = list(input())

o_count = S.count('0')
i_count = S.count('1')

print(min(o_count,i_count)*2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
  S = input()
  arr = []
  for s in S:
    if len(arr) != 0 and arr[-1] != s:
      arr.pop()
    else:
      arr.append(s)

  print(len(S) - len(arr))
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
s = input()
cnt = 0
n = len(s)
for x in s:
    if x == '0':
        cnt+=1
ans = min(cnt,n-cnt)*2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
S = list(input())
S = list(map(int, S))

cnt = Counter(S)
setS = set(S)
if len(setS) == 1:
    print(0)
else:
    print(2*min(cnt[0], cnt[1]))

Submission status: Accepted

Solution code:
n = input()
import collections
c = collections.Counter(n)
a = c['1']
b = c['0']
print(min(a,b)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

count_1=0
count_0=0

for s in S:
    if s=="0":
        count_0+=1
    else:
        count_1+=1

print(min(count_0,count_1)*2)

Submission status: Accepted

Solution code:
N = str(input())

count1=N.count('1')
count0=N.count('0')

print(min(count1, count0)*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:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    from collections import Counter
    c = Counter(S)
    print(min(c['0'], c['1'])*2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def main():
    s=SI()
    cnt0=s.count("0")
    cnt1=len(s)-cnt0
    print(min(cnt0,cnt1)*2)

main()

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, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
t = Counter(s)
print(min(t['0'], t['1']) * 2)

Submission status: Accepted

Solution code:
def main():
    S = list(map(int, list(input())))

    cnt1 = sum(S)
    cnt0 = len(S) - cnt1
    print(2 * min(cnt0, cnt1))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S=str(input())
s=[]
c1=0
c0=0
for i in range(len(S)):
  s.append(S[i])
  if S[i]=='0':
    c0+=1
  else:
    c1+=1
print(2*min(c0,c1))

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
T = []
while True:
    for i in S:
        if not T or T[-1] == i:
            T.append(i)
        else:
            T.pop()
    if S == T:
        break
    S = T[:]
    T.clear()
print(N - len(S))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    cunt1=0
    cunt2=0
    for ss in s:
        if ss=='1':cunt1+=1
        else:cunt2+=1
    print(min(cunt1,cunt2)*2)

if __name__=='__main__':
    main()

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()

S = [s for s in S]
cnt = {'0': 0, '1': 0}
for s in S:
    cnt[s] += 1

print(min(cnt.values()) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
ary1 = [int(x) for x in S]
ary2 =[]

for x in ary1:
  if ary2 == []:
    ary2.append(x)
  elif ary2[-1] == x:
    ary2.append(x)
  else :
    ary2.pop()

print(len(S)-len(ary2))

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
for i in range(n):
  s[i] = int(s[i])
ones = sum(s)
zeros = n-sum(s)
print(min(ones,zeros)*2)

Submission status: Accepted

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

l = []
tmp = []
i = 0
ans = 0
while i < n-1:
	if s[i] != s[i+1]:
		ans += 1
		num = 2
		while i+num < n:
			if len(l) == 0:
				break
			left = l.pop()
			right = s[i+num]
			if s[left] != right:
				ans += 1
				num += 1
			else:
				l.append(left)
				break
		i += num
	else:
		l.append(i)
		i += 1

print(2*ans)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
from collections import deque
 
s=input()
sd=deque(s)
d=deque()
while(len(sd)>0):
  crr = sd.popleft()
  if(len(d)<1):
    d.append(crr)
    continue
  if(len(d)>=1 and d[-1]!=crr):
    d.pop()
  else:
    d.append(crr)
print(len(s)-len(d))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
stack = []
s = input()
ans = 0
for c in s:
    if stack:
        tmp = stack.pop()
        if c == tmp:
            stack.append(tmp)
            stack.append(c)
        else:
            ans+=2
    else:
        stack.append(c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
S = input()
C = Counter(S).values()
if len(C) == 2:
    print(min(2*c for c in C))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

s = list(input())
c = Counter(s)
print(min(c["0"], c["1"]) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import deque

def main():
    s = IS()
    dq = deque()
    dq.append(s[0])
    cnt = 0
    for i in range(1, len(s)):
        if len(dq) == 0: dq.append(s[i]); continue
        a = dq[-1]
        b = s[i]
        if a == b: dq.append(b)
        else: dq.pop(); cnt += 2
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

red = S.count('0')
blue = N - red

print(min(red, blue) * 2)

Submission status: Accepted

Solution code:
S = input()

O = S.count("0")
I = S.count("1")

diff = abs(O-I)

print(len(S)-diff)

Submission status: Accepted

Solution code:
s = input()
#print(s)

score=0
for i in range(len(s)):
	if s[i]=="0":
		score = score +1
	else:
		score = score -1
#	print(s[i])
print(len(s)-abs(score))

Submission status: Accepted

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

for i in range(n):
  if s[i] == "1":
    count = count + 1
    
ans = min((n-count),count)*2
print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:

s = list(input())
ZERO = s.count("0")
#print(ZERO)
ONE = s.count("1")

print(2*min(ZERO,ONE))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from collections import deque

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

S = i_s()
d = deque()

for s in S:
    if not d:
        d.append(s)
        continue
    tmp = d.popleft()
    if tmp == s:
        d.append(tmp)
        d.append(s)

print(len(S)-len(d))

Submission status: Accepted

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

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

print(min(x,y)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().strip()
x = sum(c == '0' for c in S)
y = len(S) - x
print(2 * min(x, y))