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 re
s = input()
first_len = len(s)

ten_3_zo = "0" * 10 * 10 * 10 + "1" * 10 * 10 * 10
ten_3_oz = "1" * 10 * 10 * 10 + "0" * 10 * 10 * 10

ten_1_zo = "0" * 10 + "1" * 10
ten_1_oz = "1" * 10 + "0" * 10


while True:
    s = s.replace(ten_3_zo,"").replace(ten_3_oz,"")
    s = s.replace(ten_1_zo,"").replace(ten_1_oz,"")
    s = s.replace("01","").replace("10","")
    if not re.search('01|10',s):
        break

print(first_len - len(s))

Submission status: Accepted

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

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0

    i = 0
    while True:
        if len(sl) <= i:
            break

        if (prev == 0 and sl[i] == '1') or (prev == 1 and sl[i] == '0'):
            # print(str(sl))
            # print("remove", i, prev, sl[i])
            del sl[i]
            del sl[i-1]
            n += 2
            if i-2 < 0:
                prev = -1
                i = 0
            else:
                prev = int(sl[i-2])
                i = i-1
        else:
            prev = int(sl[i])
            i += 1

    print(n)

main()

Submission status: Accepted

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

count0 = S_list.count("0")
count1 = S_list.count("1")

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

print(min(zero,ichi)*2)

Submission status: Accepted

Solution code:
S = input()
zero = S.count('0')
one = len(S) - zero
num = zero if zero <= one else one
print(num * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

ans = 0
z = 0
o = 0
for c in input():
    if c == '0':
        if o > 0:
            o -= 1
            ans += 2
        else:
            z += 1
    else:
        if z > 0:
            z -= 1
            ans += 2
        else:
            o += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    s = input()
    if len(s) == 0:
        print(0)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

c0,c1 = 0,0
for i in range(len(s)):
    if s[i] == "0":
        c0 += 1
    else:
        c1 += 1
print(min(c0,c1)*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:
import copy
S = list(map(int,input()))
cnt0 = 0
cnt1 = 0
for i in range(len(S)):
    if S[i] == 0:
        cnt0 += 1
    else:
        cnt1 += 1

ans = cnt0 + cnt1 - abs(cnt0-cnt1)
print(ans)

Submission status: Accepted

Solution code:
t = input()
s = [int(c) for c in t]
print(2 * min(len(s)-sum(s), sum(s)))

Submission status: Accepted

Solution code:
S=input()
count=0
o=S.count("1")
z=S.count("0")
if o>=z:
    print(z*2)
else:
    print(o*2)

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
s = str(input()).strip()
t = len(s)
tt = len(s.replace("1", ""))
print(2 * min(t-tt, tt))

Submission status: Accepted

Solution code:
from collections import deque
s=input()
q=deque([])
q.append(s[0])
#print(q)
count=0
for i in s[1:]:
    if len(q)==0:
        q.append(i)
    elif i=='0':
        x=q.pop()
        if x=='1':
            count+=2
        else:
            q.append(x)
            q.append('0')
    else:
        #print('annu')
        x=q.pop()
        if x=='0':
            count+=2
        else:
            q.append(x)
            q.append('1')
print(count)

Submission status: Accepted

Solution code:
a = input()
b = 0
c = 0
for i in a:
  if i =="0":
    b+=1
  else:
    c+=1
if b == 0 or c == 0:
  print(0)
elif b>=c:
  print(c*2)
else:
  print(b*2)

Submission status: Accepted

Solution code:
s = list(input())


if s.count('0') >= s.count('1'):
    print(s.count('1')*2)
else:
    print(s.count('0')*2)

Submission status: Accepted

Solution code:
l = input()
l1 =l
l2 =l1
l1 = l1.replace("0","")
numof0=len(l)-len(l1)
l2 = l2.replace("1","")
numof1=len(l)-len(l2)

print(min(numof0,numof1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
0011 = 4
0101 = 4
00111 = 4
01011 = 4
10011 = 4
000111 = 6
001011 = 6

0または1のいずれか個数の少ない文字を特定する
特定した文字の個数を2倍する
"""

s = input()
n = min(s.count("0"), s.count("1"))
r = n*2
print(r)

Submission status: Accepted

Solution code:
s = input() #文字列

que = list([-10])
ans = 0
for c in s:
    x = int(c)
    if abs(x-que[-1]) == 1:
        que.pop(-1)
        ans += 2
    else:
        que.append(x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(int,list(input())))
N = len(S)
i = 0
cnt = 0
kaisuu = 0
while(kaisuu<N):
	kaisuu += 1
	if(N==0 or N==1 or i+1>len(S)-1):
		break
	elif(S[i]!=S[i+1]):
		del S[i+1]
		del S[i]
		cnt += 1
		if(i!=0):
			i -= 1
		else:
			i = 0
	else:
		i += 1
print(2*cnt)

Submission status: Accepted

Solution code:
s = input()
S=[]
for c in s:
    S.append(int(c))

count0 = 0
count1 = 0

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

remainder = max(count0, count1) - min(count0, count1)

print(len(S) - remainder)

Submission status: Accepted

Solution code:
S = str(input())

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

Submission status: Accepted

Solution code:
S = list(input())
count_0 = 0
count_1 = 0


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

print(min(count_0, count_1)*2)

Submission status: Accepted

Solution code:
[a] = list(map(str, input().split()))

flag=1
rem1=0
count=0

for i in range(len(a)):
  if(int(a[i])==0):
    if(rem1>0):
      count+=2
      rem1-=1
    else:
      rem1-=1
  if(int(a[i])==1):
    if(rem1<0):
      rem1+=1
      count+=2
    else:
      rem1+=1

print(count)

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

Solution code:
S = list(input())
count = [0]*2
for s in S:
    if s == '0':
        count[0] += 1
    else:
        count[1] += 1

print(min(count)*2)

Submission status: Accepted

Solution code:
a = input()

z = 0
i = 0
for b in a:
  if(b == '0'):
    z += 1
  else:
    i += 1
if(z >= i):
  print(i * 2)
else:
  print(z * 2)

Submission status: Accepted

Solution code:
a = input()
count0 = 0
count1 = 0
b = len(a)
for i in range(b):
    if(a[i] == "0") :
        count0 = count0 + 1
    else:
        count1 = count1 + 1

print(min(count0,count1)*2)

Submission status: Accepted

Solution code:
s = str(input())

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

print(min(a,b)*2)

Submission status: Accepted

Solution code:
wlist = list(input())
cnt = 0

for i in wlist:
    if i == "1":
        cnt += 1
if (len(wlist) - cnt) > cnt:
    print(2*cnt)

else:
    print(2*(len(wlist)-cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

S = input()
N = int(len(S))
lst = [int(S[i]) for i in range(N)]

if N % 2 == 0:
  med = int(N/2)
else:
  med = int(N/2 + 1)

left = lst[:med]
right = lst[med:]

left_blue = np.sum(left)
left_red = len(left) - left_blue
right_blue = np.sum(right)
right_red = len(right)-right_blue

ans = N - (np.abs(left_red-right_blue) + np.abs(left_blue-right_red))

print(int(ans))

Submission status: Accepted

Solution code:
s = list(input())
x = list(map(int, s))
k = 0
for i in range(len(x)):
    if x[i] == 0:
        k += 1
print(2 * min(k, len(x) - k))

Submission status: Accepted

Solution code:
S = input()
lst1 = sum([1 for x in S if x == '1'])
lst2 = sum([1 for x in S if x == '0'])
print(min(lst1, lst2) * 2)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

S=input()
N=len(S)

buf = []
h = 0
ans = 0
for s in S:
    if s=='0':
        h -= 1
    else:
        h += 1
ans = N-abs(h)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
print(len(s) - abs(s.count('0') - s.count('1')))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A,B,K = [int(x) for x in input().split()]
S = input()

cnt_1 = 0
cnt_0 = 0

for s in S:
    if s == "0":
        cnt_0 += 1
    else:
        cnt_1 += 1

print(min(cnt_1,cnt_0) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

n = len(S)

red, blue = 0, 0
for s in S:
    if s == "0":
        if blue > 0:
            blue -= 1
        else:
            red += 1
    else:
        if red > 0:
            red -= 1
        else:
            blue += 1

print(n-red-blue)

Submission status: Accepted

Solution code:
S = input()

count_z = S.count('0')
count_o = S.count('1')

if count_o < 1 or count_z < 1:
    print(0)
else:
    print(min(count_z,count_o)*2)

Submission status: Accepted

Solution code:
# /user/bin/python
# -*- coding: utf-8 -*-
import sys
 
s = str(input())
ans = 0

for c in s:
  if c == '0':
    ans -= 1
  else:
    ans += 1
print(len(s) - abs(ans))

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    S = input()

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

input = lambda: stdin.readline().rstrip()
main()

Submission status: Accepted

Solution code:
S = str(input())
cnt1 = 0
cnt2 = 0
for i in range(len(S)):
    if S[i] == "0":
        cnt1 += 1
    else:
        cnt2 += 1

if cnt1 < cnt2:
    print(cnt1*2)
else:
    print(cnt2*2)

Submission status: Accepted

Solution code:
s = input()
one = s.count("1")
zero = s.count("0")
if one == 0 or zero == 0:
    print(0)
else:
    if one >= zero:
        print(zero*2)
    else:
        print(one*2)

Submission status: Accepted

Solution code:
S = input()
cnt = 0
prev = 0
while prev != len(S):
    prev = len(S)
    ans = []
    for i, n in enumerate(S):
        if i == 0:
            ans.append(n)
            continue
        if len(ans) > 0 and ans[-1] != n:
            ans.pop()
            cnt += 2
        else:
            ans.append(n)
    S = ''.join(ans)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
q = []
l = 0
o = 0
for c in s:
    q.append(c)
    l += 1
    while 1 < l and q[l-1] != q[l-2]:
        q.pop()
        q.pop()
        o += 2
        l -= 2
print(o)

Submission status: Accepted

Solution code:
def main():
    str = input()
    str_list = [int(num) for num in list(str)]
    one_counter = 0

    for number in str_list:
        if number == 1:
            one_counter += 1

    zero_counter = len(str_list) - one_counter
    more = zero_counter if zero_counter < one_counter else one_counter
    print(2 * more)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = str(input())

num_red = S.count('0')
num_blu = S.count('1')

diff = min(num_red, num_blu)

ans = diff*2

print(ans)

Submission status: Accepted

Solution code:
s = input()

l = []
for i in range(len(s)):
    l.append(int(s[i]))

def fn(lll):
    if len(lll) < 2:
        return

    if lll[-1] != lll[-2]:
        lll.pop()
        lll.pop()
        fn(lll)

ll = []
for i in l:
    ll.append(i)
    fn(ll)

print(len(l) - len(ll))

Submission status: Accepted

Solution code:
S=input()
ans=0
i=len(S)-1
while len(S)>1 and i>0:
  if S[i]!=S[i-1]:
    S=S[:i-1]+S[i+1:]
    if i==len(S)+1:
      i-=1
    ans+=2
  i-=1
print(ans)

Submission status: Accepted

Solution code:
l = [int(s) for s in list(input())]
n0 = l.count(0)
n1 = l.count(1)
print(len(l) - abs(n1-n0))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cube=input()
red=0
blue=0

for i in range(len(cube)):
    if cube[i] == "0":
        red += 1
    else:
        blue += 1

print(min(red, blue)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input().strip()
N = len(s)
l = [int(c) for c in s]

nl = []
i = 0
while i < N:
    if len(nl) > 0:
        a = nl[-1]
        b = l[i]

        if a + b == 1:
            nl.pop()
            i += 1
        else:
            nl.append(l[i])
            i += 1
    else:
        nl.append(l[i])
        i += 1

print N - len(nl)

Submission status: Accepted

Solution code:
s = input()

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

print(m_cnt*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

S = input()

count_1 = len(re.findall('1', S))
count_0 = len(re.findall('0', S))

if(count_1 < count_0):
    print(2 * count_1)
else:
    print(2 * count_0)

Submission status: Accepted

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def aa(li):
    for i in range(len(li) - 1):
        if li[i] != li[i+1]:
            return i
    return "END"


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    # s = list("11011010001011")
    s = list(ip.S())
    n = len(s)
    iti = s.count("1")
    zero = s.count("0")
    print(min(iti, zero) * 2)



main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
zero = s.count("0")
one = s.count("1")
if zero != one:
    print(min(zero, one) * 2)
elif zero == one:
    print(zero + one)

Submission status: Accepted

Solution code:
S=input()
firstS=len(S)
zero=S.count('0')
one=S.count('1')
if zero!=0 and one!=0:
    print(2*min(one,zero))
else:
    print(0)

Submission status: Accepted

Solution code:
s = list(input())

count_1 = 0
count_0 = 0

for i in s:
    if i == "1":
        count_1 += 1
    elif i == "0":
        count_0 += 1

ans = min(count_0, count_1) * 2
print(ans)

Submission status: Accepted

Solution code:
s = list(map(int,input()))

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

print(a + b - abs(a-b))

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()
a=0
b=0
for i in range(len(s)):
    if s[i]=='0':
        a=a+1
    else:
        b=b+1

if a>b:
    print(2*b)
else:
    print(2*a)

Submission status: Accepted

Solution code:
s=input()
a=0
b=0
c=0
for i in range(len(s)):
    if c==0:
        b=s[i]
        c+=1
    elif not b==s[i]:
        a+=2
        c-=1
    else:
        b=s[i]
        c+=1
print(a)

Submission status: Accepted

Solution code:
s = input()
#最後の文字が何で、いくつ続いているかを記録していく。
last_c = ''
stock_count = 0
remove_count = 0

for c in s:
	# 文字をストック
	if last_c == c:
		stock_count += 1
		continue
		
	# 新しく文字をストック
	# 対消滅でストックがない場合がある。
	if stock_count == 0:
		last_c = c
		stock_count += 1
		continue
		
	stock_count -= 1
	remove_count += 1
	
print(remove_count*2)

Submission status: Accepted

Solution code:
S = input()
zerocounter = 0
for i in S:
    if i == '0':
        zerocounter += 1
n = len(S)
onecounter = n - zerocounter
print(2*min(onecounter, zerocounter))

Submission status: Accepted

Solution code:
def main():
    s = input()
    zeros = 0
    ones = 0
    for c in s:
        if c == '0':
            zeros += 1
        elif c == '1':
            ones += 1
    print(min(zeros, ones) * 2)

main()

Submission status: Accepted

Solution code:
S = input()

zeros = S.count('0')
total = len(S)
ones = total - zeros
print(min(zeros, ones) * 2)

Submission status: Accepted

Solution code:
s=input()

r=0
s0=0
s1=0

for x in s:
  if x=="0":
    if s1!=0:
      s1=s1-1
    else:
      s0=s0+1
  else:
    if s0!=0:
      s0=s0-1
    else:
      s1=s1+1


print(len(s)-s0-s1)

Submission status: Accepted

Solution code:

def calc_data(data):
    count = 0
    c_0, c_1 = 0, 0
    for i in range(len(data)):
        if data[i] == '0':
            if c_1 > 0:
                count += 2
                c_1 -= 1
            else:
                c_0 += 1
        if data[i] == '1':
            if c_0 > 0:
                count += 2
                c_0 -= 1
            else:
                c_1 += 1
    print(count)

def main():
    data = input()
    calc_data(data)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in s:
    x.append(i)

cnt_0 = x.count("0")
cnt_1 = x.count("1")

if cnt_0 == cnt_1:
    print(n)
else:
    print((2*min(cnt_0, cnt_1)))

Submission status: Accepted

Solution code:
s = input()
N = len(s)
s = list(map(int, sorted(s, reverse=True)))

bl = [True for _ in range(N)]

ans = 0
left_edge = 0
a, b = 0, 1
while 0 <= a and b < N:
    if (s[a] == 0 and s[b] == 1) or (s[a] == 1 and s[b] == 0):
        ans += 2
        bl[a] = False
        bl[b] = False
        if a == left_edge:
            while a < N and not bl[a]:
                a += 1
            b = a + 1
            while b < N and not bl[b]:
                b += 1
            left_edge = a
        else:
            while 0 <= a and not bl[a]:
                a -= 1
            if a == -1: break
            while b < N and not bl[b]:
                b += 1
    else:
        a += 1
        while a < N and not bl[a]:
            a += 1
        b = a + 1
        while b < N and not bl[b]:
            b += 1
print(ans)

Submission status: Accepted

Solution code:
S=raw_input()
A=[]
Ans=0
for i in range(len(S)):
    if len(A)>0:
        if A[-1]!=S[i]:
            A.pop()
            Ans+=2
        else:
            A.append(S[i])
    else:
        A.append(S[i])

print Ans

Submission status: Accepted

Solution code:
def solve(S):
    return min(S.count("1"), S.count("0")) * 2

if __name__ == "__main__":
    S = input()
    print(solve(S))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

count_0 = 0
count_1 = 0

for i in s:
    if(i == "0"): count_0 += 1
    else: count_1 += 1

print(min([count_0, count_1])*2)

Submission status: Accepted

Solution code:
def solve(s):
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] == "1":
            one += 1
        elif s[i] == "0":
            zero += 1
    return min(zero, one)


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

    print(solve(S) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
S = ""


def set_inputs():
    global S
    S = get_str()


def main():
    set_inputs()
    stack = []
    ret = 0
    for c in S:
        if stack and stack[-1] != c:
            ret += 2
            stack.pop(-1)
        else:
            stack.append(c)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()
all_count = len(S)
zero_count = S.count('0')
one_count = S.count('1')
print(all_count - abs(zero_count - one_count))

Submission status: Accepted

Solution code:
from sys import stdin
l = stdin.readline().rstrip().split()[0]
print(min(l.count('0'), l.count('1')) * 2)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!


#a,b,c=[int(i) for i in input().split()]


s = input()

st = []


for i in s:
    if len(st) == 0 or st[-1] == i:
        st.append(i)
    else: st.pop()

print(len(s) - len(st))

Submission status: Accepted

Solution code:
ss = input()

zero = 0
one = 0

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

print(min(zero, one)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(input())
ans=0
j=0
while len(S)-1>j:
    if S[j]!=S[j+1]:
        S.pop(j)
        S.pop(j)
        ans+=2
        if j>0:
            j-=1
        continue
    j+=1
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
i = 0
cnt = 0
while i < N-1:
    if (S[i] == "0" and S[i+1] == "1") or (S[i] == "1" and S[i+1] == "0"):
        S = S[:i] + S[i+2:]
        N -= 2
        cnt += 2
        if i > 0:
            i -= 1
    else:
        i += 1
print(str(cnt))

Submission status: Accepted

Solution code:
S = [int(_) for _ in list(input())]
print(len(S) - abs(2 * sum(S) - len(S)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
tmp = 0
ans = 0
for i in range(len(S)):
    if S[i] == "0":
        if tmp > 0:
            ans += 2
        tmp -= 1
    elif S[i] == "1":
        if tmp < 0:
            ans += 2
        tmp += 1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

l = len(s)
c = 0

for i in range(l):
    if s[i]=="1":
        c+=1

if (l>=c*2):
    print(c*2)
else:
    print((l-c)*2)

Submission status: Accepted

Solution code:
string = input()
N = [0, 0]
for c in string:
    N[int(c)] += 1
print(min(N) * 2)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
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()
zero=0
one=0
for i in s:
  if i=="0":
    zero+=1
  elif i=="1":
    one+=1
print(min(zero,one)*2)

Submission status: Accepted

Solution code:
a = input()
a_li = list(map(int, a))


if (a_li.count(0) == 0 or a_li.count(1) == 0):
    print(0)
elif (a_li.count(1) >= a_li.count(0)):
    print(a_li.count(0)*2)
elif (a_li.count(0) >= a_li.count(1)):
    print(a_li.count(1)*2)

Submission status: Accepted

Solution code:
S = input()
count = 0
S = sorted(S)
if '1' in set(S):
  print(2*min(len(S[S.index('1'):]),len(S[:S.index('1')])))
else:
  print(2*min(len(S[S.index('0'):]),len(S[:S.index('0')])))

Submission status: Accepted

Solution code:
S = list(input())
S_len = len(S)
one_num = len(list(filter(lambda x: x == '1', S)))
zero_num = S_len - one_num

print(min(one_num, zero_num) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

zero = 0
one  = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC120C
S=input()
a=''
c=0
for s in S:
	if a=='':
		a+=s
	elif a[-1:]!=s:
		a=a[:-1]
		c+=2
	else:
		a+=s
print(c)