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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()

d = DD(int)
for s in S:
  d[s] += 1
print(min(d["0"],d["1"])*2)

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:
s = input()
c0 = 0
c1 = 0
for si in s:
    if si == '0':
        c0 += 1
    else:
        c1 += 1


print(2*min(c0,c1))

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 collections import Counter
s = input()
if len(set(s))<2:
    print(0);exit()
print(min(Counter(s).values())*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
c0 = s.count('0')
c1 = s.count('1')
print(2*min(c0, c1))

Submission status: Accepted

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

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:
from collections import Counter
s = list(input())
c = Counter(s)

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

Submission status: Accepted

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

if '0' in c and '1' in c:
	print(min(c['0'],c['1'])*2)
else:
  print(0)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
S = [int(s) for s in S()]
ans = 0
stack = []
for x in S:
    if stack and x^stack[-1]:
        stack.pop()
        ans += 2
    else:
        stack.append(x)
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans = min(s.count('0'),s.count('1'))*2
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:
## C - Unification
S = list(input())
cnt1 = len([i for i in range(len(S)) if S[i] == '1'])
cnt0 = len([i for i in range(len(S)) if S[i] == '0'])
print(min(cnt0,cnt1)*2)

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
#sInt = int(s)
count = Counter(s)
num0 = count['0']
num1 = count['1']

diff = num0 - num1
if (diff == 0):
    ans = num0 * 2
elif (diff > 0):
    ans = num1 * 2
else:
    ans = num0 * 2


print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy
s = list(input())
one = s.count("1")
zero = s.count("0")

print(min(one,zero)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
import re

s = input()
a = copy.copy(s)
s = re.sub("0","",s)
a = re.sub("1","",a)
print(min(len(a),len(s))*2)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    qu = []
    ret = 0

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


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

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

print(min(zero, one)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
c1 = Counter(S[0::2])
c2 = Counter(S[1::2])

print(len(S) - abs(c1['0'] - c2['1']) - abs(c1['1'] - c2['0']))

Submission status: Accepted

Solution code:
s = list(map(int,input()))
cnt0 = s.count(0)
cnt1 = s.count(1)

print(min(cnt0,cnt1)*2)

Submission status: Accepted

Solution code:
import collections

l=list(input())
c=collections.Counter(l)
#print(c['0'],c['1'])
if c['0']==c['1']:
    print(c['0']*2)
else:
    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:
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    cnt_0 = s.count('0')
    cnt_1 = s.count('1')
    print(min(cnt_0, cnt_1) * 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
cnt = 0
prev = s[0]
stock = 1
for i in range(1, len(s)):
    if stock == 0:
        prev = s[i]
        stock += 1
    else:
        if s[i] != prev:
            cnt += 2
            stock -= 1
            if stock > 0:
                if s[i] == '0':
                    prev = '1'
                else:
                    prev = '0'
        else:
            prev = s[i]
            stock += 1
print(cnt)

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()
        count+=2
    else:
        stack.append(s)
print(count)

Submission status: Accepted

Solution code:
s = input()
s_list = list(s)
c0 = 0
c1 = 0
for num in s_list:
  if num == '0':
    c0 += 1
  else:
    c1 += 1
print(min(c0,c1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    N = 0
    arr = []
    pre = S[0]
    num = 0
    for c in S:
        N += 1
        if c == pre:
            num += 1
        else:
            arr.append(num)
            num = 1
        pre = c
    arr.append(num)
    #print(arr)

    ans = 0
    for i in range(len(arr)):
        ans += arr[i] * (-1) ** i
    print(N - abs(ans))
    """
    i = 0
    while i < N:
        if arr[i] <= arr[i + 1]:
            arr[i + 1] -= arr[i]
            arr[i] = 0
            i += 1
        else:
            arr[i + 2] += arr[i] - arr[i + 1]
            arr[i] = 0
            arr[i + 1] = 0
            i += 2
    """

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

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

Submission status: Accepted

Solution code:
s = list(input())

len_s = len(s)
s0 = s.count('0')
s1 = len_s - s0

print(len_s - abs(s0 - s1))

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()
r, b = 0, 0
for i in range(len(s)):
    if s[i] == '0':
        r += 1
    else:
        b += 1
print(min(r, b) * 2)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    s=input()
    print(min(s.count("1"),s.count("0"))*2)
#%%submit!
resolve()

Submission status: Accepted

Solution code:
s = input()
stk = []
ret = 0
for i in range(len(s)):
    if len(stk) == 0:
        stk.append(s[i])
    elif stk[-1] == '0':
        if s[i] == '1':
            stk.pop(-1)
            ret += 2
        else:
            stk.append('0')
    else:
        if s[i] == '0':
            stk.pop(-1)
            ret += 2
        else:
            stk.append('1')

print(ret)

Submission status: Accepted

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


def solve(S: str):
    print(min(S.count("0"), S.count("1")) * 2)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

num0 = S.count("0")
num1 = S.count("1")

print(2*min(num0, num1))

Submission status: Accepted

Solution code:
s = input()
ones = 0
zeros = 0
for x in s:
  if x=="1":
    ones += 1
  else:
    zeros += 1
print(min(ones,zeros)*2)

Submission status: Accepted

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


if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
n=len(s)
one,zero=0,0
for i in range(n):
    if int(s[i])==1:
        one+=1
    else:
        zero+=1
print(n-abs(one-zero))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import sys


def solve():
    s = input()
    if len(s) == 1:
        print(0)
        sys.exit(0)
    zero = 0
    one = 0
    for i in range(len(s)):
        if s[i] == '0':
            zero += 1
        else:
            one += 1
    if zero > one:
        print(one*2)
    else:
        print(zero*2)


solve()

Submission status: Accepted

Solution code:
S=str(input())
l=len(S)
S_int=[0]*l
for i in range(l):
  S_int[i]=int(S[i])
print(min(S_int.count(0),S_int.count(1))*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    stack = list()
    cnt = 0
    for c in S:
        if len(stack) == 0:
            stack.append(c)
        else:
            if stack[-1] != c:
                stack.pop()
                cnt += 2
            else:
                stack.append(c)
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools

string = input()
s = []
for i in range(len(string)):
    s.append(int(string[i]))
count = [0,0]
for i in range(len(s)):
    if s[i] == 0: count[0] += 1
    if s[i] == 1: count[1] += 1

print(min(count)*2)

Submission status: Accepted

Solution code:
s = input()

red = 0
blue = 0
for i in s:
    if i == '0': red += 1
    else: blue += 1

if red > blue:
    print(blue*2)
elif red < blue:
    print(red*2)
else:
    print(red+blue)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
l = len(s)
o = s.count("0")

print(min(o*2, (l - o)*2))

Submission status: Accepted

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

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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())

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

print(min(cnt0, cnt1) * 2)

Submission status: Accepted

Solution code:
import collections

s = list(input())

num_1 = s.count("1")
num_0 = s.count("0")

print(min(num_0,num_1)*2)

Submission status: Accepted

Solution code:
s=list(input())
count=0
kaisu=1
while kaisu>0:
  kaisu=0
  n=len(s)
  for i in range(0,n):
    i=n-i-1
    try:
      if s[i]!=s[i-1]:
        count+=1
        kaisu+=1
        s.pop(i)
        s.pop(i-1)
    except IndexError:
      pass

print(count*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
a = [0,0]
res = 0
for i in range(len(s)):
  if s[i] == '0':
    a[0] += 1
  elif s[i] == '1':
    a[1] += 1
  if a[0] >= 1 and a[1] >= 1:
    res += 2
    a[0] -= 1
    a[1] -= 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

s = input()

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

ans = min(c0, c1)*2
print(ans)

Submission status: Accepted

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

zeros = 0
for s in S:
    if s == '0':
        zeros += 1
res = min(zeros, N-zeros) * 2

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
z = 0
o = 0
for c in s:
    if c=='0':
        z += 1
    else:
        o += 1
print(z+o-abs(z-o))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

s = list(input())

count = collections.Counter(s)

zero = count['0']
one = count['1']

print(2 * min(zero,one))

Submission status: Accepted

Solution code:
from collections import Counter

S = input()
c = Counter(S)    
    
print(len(S)- abs(c['0'] - c['1']))

Submission status: Accepted

Solution code:
s=input()

blue_count=s.count("1")
red_count=s.count("0")

print(2*min(blue_count, red_count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May  2 21:55:08 2020

@author: matha
"""


#import sys

#sys.stdin = open(r"C:\Users\oshim\Documents\contestCodes\Lab_02\quarantine_individual_practice_contest_01\input.txt", "r")


s = list(input())

c = 0


i = 1
while i < len(s):
    if (s[i] != s[i-1]):
        s.pop(i-1)
        s.pop(i-1)
        c += 2
        if (i>2):
            i = i-2
        if i ==2:
            i = i-1
    else:
        i+=1
    

print(c)

Submission status: Accepted

Solution code:
s = input()
count_0 = s.count('0')
count_1 = s.count('1')
len_s = len(s)
print("{}".format(len_s-abs(count_0 - count_1)))

Submission status: Accepted

Solution code:
from collections import Counter
S = input()
l = list()
for i in S:
    l.append(i)
c = Counter(l)
print(min(c['0'], c['1'])*2)

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

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

print(2*min(c0,c1))

Submission status: Accepted

Solution code:
s=[c for c  in input()]
print(min(s.count('0'),s.count('1'))*2)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter
#from itertools import accumulate #list(accumulate(A))

S = input()

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

Submission status: Accepted

Solution code:
# C - Unification

S = str(input())

zeroCnt = S.count('0')
oneCnt = S.count('1')

print(min(zeroCnt, oneCnt)*2)

Submission status: Accepted

Solution code:
# C - Unification

S = str(input())

zeroCnt = 0
oneCnt = 0
ans = 0
for i in range(len(S)):
    if S[i]=='0':
        if oneCnt==0:
            zeroCnt += 1
        else:
            ans += 2
            oneCnt -= 1
    else:
        if zeroCnt==0:
            oneCnt += 1
        else:
            ans += 2
            zeroCnt -= 1

print(ans)

Submission status: Accepted

Solution code:

def solve():

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


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
S= input()

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

Submission status: Accepted

Solution code:
s = input()
c = 0
for i in range(len(s)):
    if s[i] == '0':
        c += 1
if c > len(s)/2:
    ans = (len(s) -c) * 2
else:
    ans = c * 2
print(ans)

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(len(s)-(max(zero,one)-min(zero,one)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    S_count = Counter(S)
    cnt = len(S) - abs(S_count['0']-S_count['1'])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
cube = ["?"]

ans = 0

for s in S:
    if cube[-1] == "?":
        cube.append(s)
    elif s != cube[-1]:
        ans += 2
        cube.pop()
    else:
        cube.append(s)

print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
N=len(S)
prezero=0
preone=0
for i in range(N):
    s=S[i]
    if s=="0":
        if preone>0:
            preone-=1
        else:
            prezero+=1
    if s=="1":
        if prezero>0:
            prezero-=1
        else:
            preone+=1
print(N-prezero-preone)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
from collections import Counter
C=Counter(S)
print(len(S)-abs(C['0']-C['1']))