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:
def resolve():
    inp = input()

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

    print(min(c0, c1)*2)

resolve()

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
a = 0
b = 0
for i in range(N):
  if S[i] == '0':
    a += 1
  else:
    b += 1
m = min(a, b)
ans = 2 * m
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

s = list(map(int,list(input())))

num = [0,0]
for i in s:
  num[i]+=1
print(min(num)*2)

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

s = list(map(int,list(input())))

d = [-1]
ans = 0
for i in s:
  if d[-1]+i==1:
    del d[-1]
    ans+=1
  else:
    d.append(i)
print(ans*2)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
red = sum([ 1 for i in s if i == '0' ])
blue = n - red
print(n-abs(red-blue))

Submission status: Accepted

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

    c0 = 0
    c1 = 0

    for x in s:
        if x == 1:
            c1 += 1
        else:
            c0 += 1

    print(2*min(c0, c1))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(int,list(input())))
count0 = S.count(1)
count1 = S.count(0)
print(2*min(count0,count1))

Submission status: Accepted

Solution code:
from  collections import Counter

s = list(input())

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

print(min(c0, c1)*2)

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt, gcd
from copy import deepcopy

def main():
    s = input()
    c_zero = s.count("0")
    c_one = s.count("1")
    num = min(c_one,c_zero)
    print(num*2)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

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

Submission status: Accepted

Solution code:
s=list(input())
from collections import Counter
d=Counter(s)
print(min(d["0"], d["1"])*2)

Submission status: Accepted

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

Submission status: Accepted

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

L = abs(S.count('0') - S.count('1'))

print(N - L)

Submission status: Accepted

Solution code:
from collections import deque
S=input().strip()
N=len(S)

a=[0 if x == '0' else 1 for x in S]

q = deque()
for i in a:
    if q:
        if q[-1] != i:
            q.pop()
        else:
            q.append(i)
    else:
        q.append(i)

print(N-len(q))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

s = raw_input()
stack = collections.deque([])
i = 0
j = 0
while(j < len(s)):
	while(j < len(s) and s[i] == s[j]): j += 1	
	stack.append(j-i)
	i = j
n = len(s)
while(len(stack) > 1) :
	v = stack.pop()
	u = stack.pop()
	if v > u: 
		if stack:
			stack[-1] += v-u
		else:
			stack.append(v-u)
	elif v < u: stack.append( u - v)

print n - (stack[-1] if stack else 0)

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(1000000)

S=input()
s=[]
for i in S:
    s+=[i]
ans=0
que=[]
que+=[s[0]]
def cube(i):
    global ans
    if i==len(s):
        print(ans)
    else:
        que.append(s[i])
        flag=True
        while flag:
            if len(que)==0 or len(que)==1:
                flag=False
            elif que[-1]==que[-2]:
                flag=False
            elif que[-1]!=que[-2]:
                del que[-1]
                del que[-1]
                ans+=2
        cube(i+1)
cube(1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
S=input()
s=[]
for i in S:
    s+=[i]
ans=0
que=[]
que+=[s[0]]
def cube(i):
    global ans
    if i==len(s):
        print(ans)
    else:
        que.append(s[i])
        flag=True
        while flag:
            if len(que)==0 or len(que)==1:
                flag=False
            elif que[-1]==que[-2]:
                flag=False
            elif que[-1]!=que[-2]:
                del que[-1]
                del que[-1]
                ans+=2
        cube(i+1)
cube(1)

Submission status: Accepted

Solution code:
import collections
S = input()
T = collections.deque([])
for s in S:
    T.append(s)
stack = []
for t in T:
    if not stack:
        stack.append(t)
    else:
        if stack[-1] != t:
            stack.pop()
        else:
            stack.append(t)
print(len(T)-len(stack))

Submission status: Accepted

Solution code:
stack = []
top = -1

def push(x):
    global stack
    global top

    top += 1
    stack.append(x)

def pop2():
    global top
    global stack

    top -= 1
    stack.pop()

def main():
    global top
    global stack

    S = input()
    ans = 0

    for i in range(len(S)):
        if i == 0:
            push(S[0])
            continue

        push(S[i])
        if stack[top] != stack[top-1]:
            pop2()
            pop2()
            ans += 2
            continue

    return ans

print(main())

Submission status: Accepted

Solution code:
import sys

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    S = list(map(int, in_s()))
    ans = min(S.count(0), S.count(1))
    print(ans * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

s = input()
n = len(s)
last = []
ans = 0
i = 0
last = []
while i<n:
    if last and s[i]!=last[-1]:
        ans += 2
        last.pop()
        i += 1
    else:
        last.append(s[i])
        i += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

def solve():
    A = input()
    c = Counter(A)

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

print(solve())

Submission status: Accepted

Solution code:
import collections


def resolve():
    S = input()
    counter_S = collections.Counter(S)

    appear_0 = counter_S['0']
    appear_1 = counter_S['1']

    ans = min(appear_0, appear_1) * 2
    print(ans)


resolve()

Submission status: Accepted

Solution code:
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""
s=ip()
a=s.count('1')
b=s.count('0')
print(min(a,b)*2)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    s = list(input())
    Count = Counter(s)
    if "0" not in s or "1" not in s:
        ans = 0
        print(ans)
        exit()
    min_key = min(Count, key=Count.get)
    ans = Count[min_key] * 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

count1=n-count0

if count0<=count1:
    ans=count0*2
else:
    ans=count1*2

print(ans)

Submission status: Accepted

Solution code:
ans = 0
now = 0 # # of red blocks left
for c in input():
    if c == '1':
        if now > 0:
            ans += 2
        now -= 1
    else:
        if now < 0:
            ans += 2
        now += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
k = len(s)
a = s.count('0')
b = s.count('1')
ans = 0
if a >= b:
  ans = k - a + b
else:
  ans = k + a - b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
ans = 0
a = s.count('1')
b = s.count('0')
if a == 0 or b == 0:
    print(0)
    quit()
print(min(a, b)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

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

print(len(S) - abs(blue - red))

Submission status: Accepted

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

if len(s) == 1:
	print(0)
else:
	print(len(s)-c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print(min(a,b)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
#11011010001011
c = max(s.count("1") - s.count("0"),s.count("0") - s.count("1"))

if len(s) == 1:
	print(0)
else:
	print(len(s)-c)

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

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

Submission status: Accepted

Solution code:
s=list(map(int,list(input())))
from collections import Counter
s+=[0,1]
cs=Counter(s)
print(min(cs.values())*2-2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

s=list(input())
n=len(s)

#print(s[0],s[1])

cnt0=0
cnt1=0
for i in range(n):
    if s[i]=="0":
        cnt0+=1
    elif s[i]=="1":
        cnt1+=1

print(2*min(cnt0,cnt1))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
length = len(S)
count_0 = 0
for i in range(length):
  if S[i] == '0':
    count_0 += 1
res = min(count_0, length - count_0) * 2
print(res)

Submission status: Accepted

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

print(min(zero,one)*2)

Submission status: Accepted

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

ans = 0
stack = [2]
for e in s:
    if stack[-1] ^ e == 1:
        stack.pop()
        ans += 2
    else:
        stack.append(e)

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
a = 0
b = 0
N = len(S)
for i in range(N):
  if S[i] == '0':
    a += 1
  else:
    b += 1
m = min(a, b)
ans = m*2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(2*min(zero,one))

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)
cnt = 0
for i in range(N):
    if S[i]=="1":
        cnt += 1
print(min(cnt,N-cnt)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
apple = []
for i in s:
    apple.append(i)
a = apple.count("1")
b = apple.count("0")
print(2 * (min(a, b)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


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

Submission status: Accepted

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

Submission status: Accepted

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

s = list(str(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:
s = list(input())

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

Submission status: Accepted

Solution code:
from collections import Counter

s = list(input())

c = Counter(s)

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

Submission status: Accepted

Solution code:
from collections import Counter

s = list(input())

c = Counter(s)

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

Submission status: Accepted

Solution code:
#C

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

s0 = 0
s1 = 0
for i in S:
    if i == "0":
        s0 += 1
    elif i == "1":
        s1 += 1
    
print(min(s0, s1) * 2)

Submission status: Accepted

Solution code:
import sys
from collections import deque

input = sys.stdin.readline


def main():
    S = input().rstrip()

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

    print(ans)


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 = list(input())
c0 = s.count("0")
c1 = s.count("1")
if c0 >= c1:
    print(2*c1)
else:
    print(2*c0)

Submission status: Accepted

Solution code:
S = input()
#文字列Sの長さをS_lenに代入


num_0 = S.count('0')
num_1 = S.count('1')

 
print(min(num_0,num_1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n=str(input())
lst=list(collections.Counter(n).most_common())
if len(lst)==1:
  print(0)
else:
  print(lst[1][1]*2)

Submission status: Accepted

Solution code:
def main():
    S = input()
    L = len(S)
    c = S.count('0')
    print(min(c, L - c) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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:
def main():
    s = input()
    a = s.count('0')
    b = s.count('1')
    print(len(s) - abs(a - b))       

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

# 結局最後には0の塊か1の塊が残る
S = list(map(int, list(input())))
zerocounter = 0
onecounter = 0
for st in S:
    if st == 0:
        zerocounter += 1
    else:
        onecounter += 1
print(min(zerocounter, onecounter) * 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()
    cubes = []
    for c in s:
        if c == "0":
            cubes.append("red")
        else:
            cubes.append("blue")

    buffer = [] #キューブの一時保存場所。同じ色が続くとここにたまっていく
    buffer.append(cubes.pop()) #cubesの最後の要素をbufferの最後に移し替える。
    counter = 0
    while cubes:
        if len(buffer) <= 0 or buffer[-1] == cubes[-1]: #bufferが空じゃないことを確認してからbufferとcubesの最後の要素を比較
            buffer.append(cubes.pop()) #同じ色はbufferに格納
        else: #もし違う色だったら
            buffer.pop() #bufferの最後のキューブをひとつ消す
            cubes.pop() #cubesの最後のキューブをひとつ消す
            counter += 2 #2個消去
    print(counter)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

A = S.count(0)
B = len(S) - A

print(min(A, B) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

zeros = 0
ones = 0

for char in S:
  if char == '0':
    zeros += 1
  else:
    ones += 1
    
print(min(zeros, ones) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

ss = []
ans = 0
for i in range(len(S)): ss.append(S[i])

zeros = 0
ones = 0

for i in range(len(ss)):
    if ss[i] == "0":
        zeros += 1
    elif ss[i] == "1":
        ones += 1

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

Submission status: Accepted

Solution code:
S = input()

N = len(S)
O = S.count('1')
Z = N - O

print(2*min(O,Z))

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

#input=sys.stdin.readline

s=list(map(int,input()))
n=len(s)
n0=n1=0
for i in range(n):
    if s[i]==1:
        n1+=1
    else:
        n0+=1
print(n-max(n0,n1)+min(n0,n1))

Submission status: Accepted

Solution code:
s=input()

l=list(s)

zeros = l.count('0')
ones = l.count('1')

if zeros<=ones:
    print(2*zeros)
else:
    print(2*ones)

Submission status: Accepted

Solution code:
S = list(input())
L = len(S)
from collections import Counter
c = Counter(S)
one = c['1']
zero = c['0']

print(L-abs(one-zero))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
def resolve():
    s = input()
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] =="0":
            zero += 1
        else:
            one += 1
    print(2*min(zero, one))

resolve()

Submission status: Accepted

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

r = 0
b = 0
ans = 0

for i in range(n):
    if s[i] == "0":
        r += 1
    elif s[i] == "1":
        b += 1
    
    if 0 < r and 0 < b:
        r -= 1
        b -= 1
        ans += 2

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
import fractions
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
from collections import Counter, deque

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


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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
S = input().strip()
N = len(S)
k = 0
for i in range(N):
    if S[i]=="0":
        k += 1
m = min(k,N-k)
print(2*m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
red = s.count("0")
blue = s.count("1")

ans = min(red,blue)

print(ans*2)

Submission status: Accepted

Solution code:
#n=int(input())
#n,m=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())

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

print(min(count1,count0)*2)

Submission status: Accepted

Solution code:
S = list(input())

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

Submission status: Accepted

Solution code:
s = input()
red = s.count("0")
blue = s.count("1")

ans = min(red,blue)

print(ans*2)

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
S = [int(x) for x in list(str(s))]
if sum(S) == 0 or sum(S) == len(S)*1:
    print(0)
else:
    cnt = Counter(s)
    v = cnt.values()

    print(min(v)*2)

Submission status: Accepted

Solution code:
s = input()
a,b = 0,0
for i in range(len(s)):
    if s[i] == '0':
        a += 1
    else:
        b += 1

print(min(a,b)*2)

Submission status: Accepted

Solution code:
s = input()
a,b = 0,0
for i in range(len(s)):
    if s[i] == '0':
        a += 1
    else:
        b += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

print(len(s)-abs(a-b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
S = [int(s) for s in S]
#N = len(S)
#print('S:', S)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

s=S()
l=[s[0]]
ans=0
for i in range(1,len(s)):
    if len(l)==0:
        l.append(s[i])
        continue
    if l[-1]!=s[i]:
        ans+=2
        l.pop()
    else:
        l.append(s[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

S = list(input())
C = Counter(S)

if len(C) == 1:
    print(0)
else:
    print(2 * min(C.values()))

Submission status: Accepted

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