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 = list(input())
count0 = 0
count1 = 0

for i in range(len(s)):
	if s[i] == '1':
		count1 += 1
	else:
		count0 += 1

print(2 * min(count0, count1))

Submission status: Accepted

Solution code:
from sys import stdin

s = list(map(int, list(stdin.readline().rstrip())))
print(min(s.count(1), s.count(0))*2)

Submission status: Accepted

Solution code:
from collections import deque
s = list(input())
queue = deque()
res = 0
count = 0
for c in s:
    queue.append(c)
    count += 1
    if count >= 2:
        if "0" == queue[-1] and "1" == queue[-2] or "0" == queue[-2] and "1" == queue[-1]:
             res += 2
             count -= 2
             queue.pop()
             queue.pop()
print(res)

Submission status: Accepted

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

for i in range(len(S)):
    if len(stack)==0:
        stack.append(S[i])
    elif stack[len(stack)-1]!=S[i]:
        stack.pop()
        ans+=2
    else:
        stack.append(S[i])

print(ans)

Submission status: Accepted

Solution code:
k = input()
z = k.count('0')
o = k.count('1')

if len(k) == 1:
    print(0)
else:
    if z == 0 or o == 0:
        print (0)
    else:
        if z < o:
            print(z*2)
        else:
            print(o*2)

Submission status: Accepted

Solution code:
s = input()
zero_num = s.count('0')
one_num = s.count('1')
if zero_num < one_num:
    print(zero_num * 2)
else:
    print(one_num * 2)

Submission status: Accepted

Solution code:
S = input()
print( min(S.count("0"), S.count("1")) * 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(2*min(a,b))

Submission status: Accepted

Solution code:
s = list(input())

s0 = 0
s1 = 0
for i in range(len(s)):
    if s[i] == '0':
        s0 += 1
    else:
        s1 += 1

ans = min(s0, s1) * 2
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = []
i = 0
ct = 0
for i in range(n):
  a.append(int(s[i]))
i = -1

while ct < 100000000000:
  n = len(a)
  i += 1
  if i >= n-1: break
  if a[i] == 0 and a[i+1] == 1:
    a.pop(i)
    a.pop(i)
    ct += 1
    i -= 2
    if i <= 1: i=-1
    continue
  elif a[i] == 1 and a[i+1] == 0:
    a.pop(i)
    a.pop(i)
    ct += 1
    i -= 2
    if i <= 1 :i = -1
    
print(ct*2)

Submission status: Accepted

Solution code:
S = input()
zenhan0 = 0
zenhan1 = 0
kouhan0 = 0
kouhan1 = 0
for i in range(len(S)//2):
  if S[i] == '0':
    zenhan0 += 1
  else:
    zenhan1 += 1 
for j in range(len(S)//2,len(S)):
  if S[j] == '0':
    kouhan0 += 1
  else:
    kouhan1 += 1
print(len(S)-abs(zenhan0-kouhan1)-abs(zenhan1-kouhan0))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/3
Solved on 2019/3/3
@author: shinjisu
"""


# ABC 120
# import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


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


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def prob_B():
    A, B, K = getIntList()
    dmp((A, B, K))
    count = 0
    i = 1
    while count < K:
        if A % i == 0 and B % i ==0:
            count += 1
            if count == K:
                break
        i += 1
    return i


def prob_C():
    S = input()
    red = 0
    blue = 0
    for cube in S:
        if cube == '0':
            red += 1
        else:
            blue += 1
    dmp((red, blue))
    return min(red, blue)*2


debug = False  # True False
ans = prob_C()
print(ans)
#for row in ans:
#    print(row)


def prob_D():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    return 123


def prob_A():
    A, B, C = getIntList()
    dmp((A, B, C))
    count = min(B // A, C)
    return count

Submission status: Accepted

Solution code:
S = input()
N = len(S)
stack = []
for s in S:
    if stack and stack[-1] != s:
        stack.pop()
    else:
        stack.append(s)
print(N - len(stack))

Submission status: Accepted

Solution code:
temp = input()
cube = [int(part) for part in temp]
test = [0, 0]
for part in cube:
    test[part] += 1
print(min(test)*2)

Submission status: Accepted

Solution code:
s = input()
stack = []
for c in s:
    if not stack or stack[-1] == c:
        stack.append(c)
    else:
        stack.pop()
print(len(s)-len(stack))

Submission status: Accepted

Solution code:
a = input()

cnt0 = a.count("0")
cnt1 = a.count("1")

print(str(min(cnt0,cnt1)*2))

Submission status: Accepted

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


import sys
import math
from functools import lru_cache

s = list(input())
count = 0
for c in s:
    if c == '1':
        count += 1
    else:
        count -= 1

if count < 0:
    count *= -1

print(len(s) - count)

Submission status: Accepted

Solution code:
l = list(input())

num0 = 0
for i in range(0,len(l)):
    if l[i] == "0":
        num0 = num0 + 1

num1 = len(l) - num0

if num1 > num0:
    print(2*num0)
else:
    print(2*num1)

Submission status: Accepted

Solution code:
S = input()

Slist = sorted(S)
if Slist[-1]=="0":
    print(0)
else:
    zero = Slist.index("1")
    print(min(zero,len(Slist)-zero)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
zero = 0
one = 0
for i in range(N):
    if S[i] == "0":
        zero += 1
    else:
        one += 1
print(N-abs(zero-one))

Submission status: Accepted

Solution code:
S = input()

N = len(S)
zero = S.count('0')
one = S.count('1')
print(N - abs(zero - one))

Submission status: Accepted

Solution code:
s = input()
a = s.count("0")
b = s.count("1")
if len(s)==a or len(s)==b:
    print(0)
else:
    print(min(a,b)*2)

Submission status: Accepted

Solution code:
def solve():
    s = raw_input().strip()
    counter = [0, 0]
    for ch in s:
        counter[int(ch)] += 1

    diff = abs(counter[1] - counter[0])
    print len(s) - diff


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = raw_input()
print len(S) - abs(S.count('0') - S.count('1'))

Submission status: Accepted

Solution code:
s = [int(i) for i in list(input())]
n = len(s)

blue = sum(s)
red = n - blue

ans = min(red,blue)*2

print(ans)

Submission status: Accepted

Solution code:
temp = input()
cube = [int(part) for part in temp]

one = 0
zero = 0
for part in cube:
    if part:
        one += 1
    else:
        zero += 1

print(min(one, zero)*2)

Submission status: Accepted

Solution code:
s = input()

n0 = 0
n1 = 0
ans = 0

for i in s:
    if i == "0":
        if n1 == 0:
            n0 += 1
        else:
            n1 -= 1
            ans += 2
    else:
        if n0 == 0:
            n1 += 1
        else:
            n0 -= 1
            ans += 2

print(ans)

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_zero = 0
n_one = 0

for char in S:
    if char == "0":
        n_zero += 1
    else:
        n_one += 1

out = min(n_zero, n_one) * 2
print(out)

Submission status: Accepted

Solution code:
st = input()
countone = st.count('1')
countzero = st.count('0')
if countone > countzero and countzero > 0:
    print(countzero*2)
elif countone <= countzero and countone > 0:
    print(countone*2)
else:
    print('0')

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
s = input()

zero = 0
one = 0

for c in s:
  if c == '0':
    zero += 1
  elif c == '1':
    one += 1
    
print((zero + one - abs(one - zero)))

Submission status: Accepted

Solution code:

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

print(2*min(zero,one))

Submission status: Accepted

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

for i  in range(N):
    one += int(S[i])

zero = N-one

print(2*min(one,zero))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
nzero = s.count("0")
none = s.count("1")
print(len(s) - abs(nzero-none))

Submission status: Accepted

Solution code:

S = input()

count0 = 0
count1 = 0

for i in range(len(S)):
    if S[i] == "0":
        count0 += 1
    elif S[i] == "1":
        count1 += 1

print(int(min(count0, count1)*2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

zero = s.count("0")
one = s.count("1")
if(len(S) == 1):
  if(zero == 1 or one == 1):
    print(0)
elif(zero > one):
  print(one*2)
elif(zero < one):
  print(zero*2)
else:
  print(zero*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
count_0 = S.count("0")
count_1 = S.count("1")

print(min(count_0,count_1) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s_0, s_1 = 0, 0
for i in s:

    if str(0) in i:
        s_0 += 1
    elif str(1) in i:
        s_1 += 1
print(min(s_0, s_1) * 2)

Submission status: Accepted

Solution code:
s = list(input())
i = 1
count = 0
while i != len(s):
  if i == 0:
    i += 1
  elif s[i-1] != s[i]:
    del s[i]
    del s[i-1]
    i -= 1
    count += 2
  else:
    i += 1

print(count)

Submission status: Accepted

Solution code:
l=list(input())
count=0
s=set()
arr=[]
val=0
while True:
    for i in range(len(l)):
        if(l[i]=='0'):
            val+=1
        if(len(arr)>0 and i not in s and((arr[-1]=='1' and l[i]=='0') or (arr[-1]=='0' and l[i]=='1'))):
            del arr[-1]
            count+=2
        else:
            arr.append(l[i])
            s.add(i)
    if(val==l.count('0')):
        break
    #print(count)
print(count)

Submission status: Accepted

Solution code:
import numpy as np
S = str(input())
array = np.array([int(i) for i in S])

num_1 = sum(array)
num_0 = len(array) - num_1

nokori = max(num_1, num_0) - min(num_1, num_0)
answer = len(array) - nokori
print(answer)

Submission status: Accepted

Solution code:
s=raw_input()

r=0	# "0"
b=0	# "1"

for x in s:
	if x=="0": r+=1
	else:	b+=1

print min(b,r)*2

Submission status: Accepted

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

Submission status: Accepted

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

print(min(count0, count1) * 2)

Submission status: Accepted

Solution code:
S = [int(e) for e in input()]
res = min(sum(S), len(S) - sum(S))
print(res*2)

Submission status: Accepted

Solution code:
# 2019/03/03
# AtCoder Beginner Contest 120 - C

# Input
s = input()

rcnt = 0
bcnt = 0

# Count Red and Blue
for idx in range(len(s)):
    if int(s[idx]) == 0:
        rcnt += 1
    else:
        bcnt += 1

# Calc
rem = abs(rcnt - bcnt)
ans = len(s) - rem

# Output
print(ans)

Submission status: Accepted

Solution code:
s = input()
cube_list = [s[0]]
s = s[1:]
count = 0
for c in s:
    if cube_list:
        if cube_list[-1] == c:
            cube_list.append(c)
        else:
            count += 2
            cube_list.pop(-1)
    else:
        cube_list.append(c)
print(count)

Submission status: Accepted

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

print(len(s)-abs(count0-count1))

Submission status: Accepted

Solution code:
S=input()
lenS=len(S)
ls=[]
ls.append(S[0])
for i in range(1,lenS):
	if len(ls)==0:
		ls.append(S[i])
		continue
	tmp=ls.pop(-1)
	if tmp==S[i]:
		ls.append(tmp)
		ls.append(S[i])
print(lenS-len(ls))

Submission status: Accepted

Solution code:
S = input()

print(len(S)-abs(S.count('1')-S.count('0')))

Submission status: Accepted

Solution code:
S = [int(c) for c in input()]
Blue = S.count(0)  
Red = S.count(1)
Rest = abs(Red-Blue)
print(len(S)-Rest)

Submission status: Accepted

Solution code:
s = input()

def dec(n):
    if n == '0':
        return -1
    else:
        return 1

ls = [dec(el) for el in s]
print(len(ls) - abs(sum(ls)))

Submission status: Accepted

Solution code:
"""
C - Unification

どんな状況でも赤青両方のブロックが1つ以上存在しているなら赤青となりあう箇所が最低1か所存在する.
→ 赤青どちらかのブロックがなくなるまでブロックを2つずつ取り除くことができる.
"""


def solve():
    S = input()
    zero_num = S.count('0')
    one_num = S.count('1')
    ans = zero_num * 2 if zero_num < one_num else one_num * 2
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = input()

zero_cnt = S.count('0')
one_cnt = S.count('1')

print(min(zero_cnt, one_cnt) * 2)

Submission status: Accepted

Solution code:
from sys import stdin
N=(stdin.readline().rstrip())
zero=list(N).count("0")
one=list(N).count("1")
ans=min(zero*2,one*2)
print(ans)

Submission status: Accepted

Solution code:
s=input()

zero_num = 0
one_num = 0
for i in range(len(s)):
    if s[i] == '1':
        one_num+=1
    else:
        zero_num+=1

print(2*min(zero_num,one_num))

Submission status: Accepted

Solution code:
from collections import deque

S = input()

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

Submission status: Accepted

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

def main():
    s = input()
    zeros = s.count('0')
    ones = s.count('1')
    print(min(zeros, ones) * 2)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
arr = list(S)

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

print(min([red, blue]) * 2)

Submission status: Accepted

Solution code:
S = input()

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

print(min(a,b)*2)

Submission status: Accepted

Solution code:
S = input()

if S.count('0') == 0 or S.count('1') == 0:
    print(0)
elif S.count('0') > S.count('1'):
    print(2 * S.count('1'))
else:
    print(2 * S.count('0'))

Submission status: Accepted

Solution code:
S = str(input())

Zero = S.count("0")
One  = S.count("1")

print(2*min([Zero , One]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 19:52:53 2019

@author: Yamazaki Kenichi
"""
from collections import deque

S = input()

ans = 0
q=deque([' '])
for c in S:
    tmp = q.pop()
    s = tmp+c
    if s.count('0') >= 1 and s.count('1') >= 1:
        ans += 2
    else:
        q.append(tmp)
        q.append(c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

sl = [int(i) for i in stdin.readline().rstrip()]
zcount = 0
ocount = 0
for i in sl:
    if i == 0:
        zcount += 1
    else:
        ocount += 1
print(min(ocount,zcount)*2)

Submission status: Accepted

Solution code:

s = input()

ma = 0
l = s[0]
an = 0
#s+=str(1-int(s[len(s)-1]))
#print(s)
ar = [-11,s[0]]
ans = 0
for i in range(1,len(s)):
    #print(i,s[i])
    if int(s[i])+int(ar[len(ar)-1])==1:
        ar.pop()
        ans+=2
    else:
        ar.append(s[i])
print(ans)

Submission status: Accepted

Solution code:
S = str(input())
N = len(S)
cube = list(S)
ary = []

for s in cube:
    if len(ary) == 0:
        ary.append(s)
        continue
    if ary[-1] == s:
        ary.append(s)
    else:
        ary.pop()
print(len(cube) - len(ary))

Submission status: Accepted

Solution code:
# coding: utf-8

S = list(input())

n1 = sum(s == "1" for s in S)
n0 = sum(s == "0" for s in S)

print(len(S) - abs(n1 - n0))

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 = list(input())
num0=0
for i in range(len(S)):
  if S[i]=="0":
    num0+=1
num1=len(S)-num0
print(min(num0,num1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
red, blue = 0, 0
for c in s:
    if c=="0":
        red += 1
    elif c=="1":
        blue += 1

print(min(red, blue)*2)

Submission status: Accepted

Solution code:
S = list(input())
lop = 0
cnt = 0
fg = True

while(True):
    if len(S) < 2:
        break

    if not S[lop] == S[lop+1]:
        cnt += 2
        S.pop(lop+1)
        S.pop(lop)
        fg = False
        if not lop == 0:
            lop -= 1
    else:
        lop += 1
    
    
    if lop == len(S)-1:
        if fg == True:
            break
        else:
            lop = 0
            fg = True

print(cnt)

Submission status: Accepted

Solution code:
s = input()

#%%

#%%

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

Submission status: Accepted

Solution code:
import queue
q=queue.Queue()
s=list(input())
c=0
for i in s:
  if q.empty():
    q.put(i)
  else:
    a=q.get()
    if a!=i:
      c+=2
    else:
      q.put(a)
      q.put(i)
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str0 = input()

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

Submission status: Accepted

Solution code:
s = input()

num_0 = s.count("0")
num_1 = s.count("1")
if num_0 < num_1:
    print(num_0*2)
else:
    print(num_1*2)

Submission status: Accepted

Solution code:
S = input()
print(min(sum([1 for s in S if s == "0"]),sum([1 for s in S if s == "1"]))*2)

Submission status: Accepted

Solution code:
S = input()

num_1 = 0
for s in S:
    if s is '1':
        num_1 += 1

num_0 = len(S) - num_1

print(len(S)-abs(num_0-num_1))

Submission status: Accepted

Solution code:
S = input()


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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()
#  S = ''
#  for i in range(10**5):
#      if i % 2 == 0:
#          S += '011'
#      else:
#          S += '1'
#  S = '011'*100000

#  print(S)
result = 0
# 0と1すくない方の数になる絶対
print(min(S.count('1'), S.count('0'))*2)
#  while True:
#      print('loop;')
#      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: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

Solution code:
S = input()

red_num = 0
blue_num = 0

for s in S:
    if s == '0':
        red_num = red_num + 1
    elif s == '1':
        blue_num = blue_num + 1

print(min(red_num, blue_num) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

cnt1=S.count('0')
cnt2=S.count('1')

print(len(S)-abs(cnt1-cnt2))

Submission status: Accepted

Solution code:
s2 = list(input())
n = len(s2)
s = [0]*n
for i in range(n):
    s[i] = int(s2[i])

fi = s.count(0)
se = s.count(1)
print(min(fi,se)*2)

Submission status: Accepted

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]
        j = 0
        while str == "01" or str == "10":
            s = s[:i-j] + s[i+2-j:]
            ok = 0
            j += 1
            if i > j + 1:
                str = s[i-j] + s[i-j+1]
            else:
                break
        i += 1
print(n - len(s))

Submission status: Accepted

Solution code:
S = input()

num_one = S.count('1')
num_zero = S.count('0')

print(min(num_one, num_zero) * 2)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
n0 = S.count('0')
n1 = N-n0
print(min(n0,n1)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
s = input()
x=0
for i in s:
	if(i=='0'):x+=1
	elif(i=='1'):x-=1

print(len(s)-abs(x))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

S=input()
r=0
b=0
for c in S:
    if c=='0':
        r+=1
    else:
        b+=1
print(2*min(r,b))

Submission status: Accepted

Solution code:
stack = []
Q = input()
for q in Q:
    if stack and stack[-1]!=q:
        stack.pop()
    else:
        stack.append(q)

print(len(Q)-len(stack))

Submission status: Accepted

Solution code:
S = input()

from collections import deque

q = deque([]) 

c = 0
for s in S:
    if len(q) == 0:
        q.append(s)
    else:
        p = q.pop()
        if s == p:
            q.append(s)
            q.append(s)
        else:
            c = c + 2
            
print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
S = list(input())
zero = 0
one = 0
ans = 0
for s in S:
    if s == '0':
        zero += 1
        if one > 0:
            zero -= 1
            one -= 1
            ans += 2
    else:
        one += 1
        if zero > 0:
            zero -= 1
            one -= 1
            ans += 2
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
S = input()
dq = deque()
for s in S:
    if not(dq):
        dq.append(s)
        continue
    if int(dq[-1]) + int(s) == 1:
        dq.pop()
    else:
        dq.append(s)
ans = len(S) - len(dq)
print(ans)

Submission status: Accepted

Solution code:
s = input()
zero = s.count("0")
one = s.count("1")

print(2 * min(zero, one))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()


ans = 0
i = 0
while True:
    # print(i, len(s), s)
    if i > len(s) - 2:
        print(ans)
        exit()
    if s[i] != s[i + 1]:
        ans += 2
        if i == len(s) - 2:
            s = s[:i]
        else:
            s = s[:i] + s[i + 2:]
        if i >= 1:
            i -= 1
        continue

    i += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 20:59:27 2019

@author: doppe
"""
S = input()

zero = 0
ichi = 0
for c in S:
    if (c == '0'):
        zero += 1
    elif (c == '1'):
        ichi += 1

if (zero > ichi):
    deleteNum = ichi * 2
else:
    deleteNum = zero * 2

print(deleteNum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

S = input()

zero = 0
one = 0

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

print(min([zero, one]) * 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

Submission status: Accepted

Solution code:
lis = list(input())
num0 = 0
num1 = 0
for item in lis:
  if item == "0":
    num0 += 1
  else:
    num1 += 1
print(min(num0,num1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
lst=[]
ans=0
for i in range(len(s)):
    if len(lst)==0:lst.append(s[i])
    elif lst[len(lst)-1]!=s[i]:
        lst.pop(len(lst)-1)
        ans+=1
        continue
    else:lst.append(s[i])
print(ans*2)

Submission status: Accepted

Solution code:
s = input()
stack = [s[0]]
now = s[0]
ans = 0
#print(stack)

for i in range(1,len(s)):
    cha = s[i]
    if cha == now:
        stack.append(cha)
        now = cha
        #print(stack)
    else:
        if now != "a":
            stack.pop()
            #print(stack)
            ans += 2
            if stack:
                now = stack[-1]
            else:
                now = "a"
        else:
            stack.append(cha)
            now = cha

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

n0 = S.count('0')
n1 = S.count('1')

print(2 * min(n0, n1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

i0 = 0
i1 = 0
for i in range(len(S)):
    if S[i] == "0":
        i0 = i0 + 1
    else:
        i1 = i1 + 1

print(len(S) - abs(i0 - i1))

Submission status: Accepted

Solution code:
s = input()

p = 0
q = 0
for i in range(len(s)):
    if s[i] == "0":
        p += 1
    if s[i] == "1":
        q += 1

print(2 * min(p,q))

Submission status: Accepted

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

S = input()

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

Submission status: Accepted

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


def main():
    s = input()
    zero_count = s.count('0')
    one_count = s.count('1')
    print(min(zero_count, one_count) * 2)


if __name__ == '__main__':
    main()