Problem:


Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0



Sample input:
0011


Sample output:
4

Submission status: Accepted

Solution code:
s = input()
 
num0 = s.count('0')
num1 = len(s) - num0
 
print(min(num0, num1) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
cnt_dict = {'0':0, '1':0}
S = list(input())
for s in S:
    cnt_dict[s] += 1
print(min(cnt_dict['0'], cnt_dict['1']) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

stack = []
ans = 0

for si in s:
    if len(stack) == 0 or si == stack[-1]:
        stack.append(si)
    else:
        stack.pop()
        ans += 2
        
print(ans)

Submission status: Accepted

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

ones = sum(S)
zeros = N - ones
print(2*min(ones,zeros))

Submission status: Accepted

Solution code:
s = input()
zero = []
one = []
for i in range(len(s)):
    if s[i] == '0':
        zero.append(i)
    else:
        one.append(i)
n0 = len(zero)
n1 = len(one)
print(min([n0, n1]) * 2)

Submission status: Accepted

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

S = input()

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

print(min(red, blue)*2)

Submission status: Accepted

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

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

numred = 0
numblue = 0

for c in S:
    if c == '0':
        numred += 1
    else:
        numblue += 1

print(2 * min(numred, numblue))

Submission status: Accepted

Solution code:
cube = input()

zero_count = 0
one_count = 0

for i in range(len(cube)):
    if cube[i] == '0':
        zero_count += 1
    else:
        one_count += 1

if zero_count < one_count:
    print(zero_count * 2)
else:
    print(one_count * 2)

Submission status: Accepted

Solution code:
S=[int(x) for x in input()]
o = sum(S)
z = abs(len(S)-o)
print(min(o,z)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

counter = 0

string = input()

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

print(min(num_0, num_1)*2)

Submission status: Accepted

Solution code:
S = input()
sumOne = 0
sumZero = 0
for i in range(len(S)):
  if S[i] == "1":
    sumOne +=1
  else:
    sumZero +=1
if sumOne < sumZero:
  print(sumOne*2)
else:
  print(sumZero*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

numbers = [int(S[i]) for i in range(len(S))]

one_count = sum(numbers)
zero_count = len(numbers) - one_count

print(2*min(one_count, zero_count))

Submission status: Accepted

Solution code:
s = input()

n0 = 0
n1 = 0

for i in range(0,len(s)):
    if(s[i] == '1'):
        n1 += 1
    else:
        n0 += 1

print(min(n1,n0) * 2)

Submission status: Accepted

Solution code:
cnt0 = 0
cnt1 = 0

nums = input()
for i in range(len(nums)):
  if nums[i] == '0':
    cnt0 += 1
  else:
    cnt1 += 1
  
print(len(nums) - abs(cnt0 - cnt1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

number0 = S.count("0")
number1 = S.count("1")

answer = min(number0, number1) * 2

print(answer)

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()
#N=int(input())
#H,W=map(int,input().split())
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()

r = 0
w = 0
for c in S:
    if c == "0":
        r += 1
    else:
        w += 1

if r == w:
    print(len(S))
else:
    print(len(S) - (max(r,w) - min(r,w)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

ans = 0

s_0 = s.replace('0', '')
n_0 = len(s) - len(s_0)
s_1 = s.replace('1', '')
n_1 = len(s) - len(s_1)

print(2 * min(n_0, n_1))

Submission status: Accepted

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


def solve(S: str):
    S = list(map(lambda x:int(x), S))
    zeros = len(list(filter(lambda x:x==0, S)))
    ones = len(list(filter(lambda x:x==1, S)))
    print(2*min(zeros, ones))
    return


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

if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
S = list(map(str, input()))
num_0 = S.count('0')
num_1 = S.count('1')
print(min(num_0, num_1)*2)

Submission status: Accepted

Solution code:
import collections
s = list(input())
zero = 0
one = 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()
x=0
for i in s:
        if i=="0":
                x+=1
        else:
                x-=1
print(len(s)-abs(x))

Submission status: Accepted

Solution code:
S = list(input())
for i in range(len(S)):
    S[i] = int(S[i])
    if S[i] == 0:
        S[i] = -1

now = S[0]
cnt = 1
ans = 0
for i in range(1, len(S)):
    #print(i, S[i], now, cnt, ans)
    if cnt > 0:
        if S[i] != now:
            ans += 2
            cnt -= 1
            now = S[i] * -1
        else:
            cnt += 1
            now = S[i]
    else:
        now = S[i]
        cnt += 1

print(ans)

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:
#python 3.7.1
s = list(input())
s = [int(i) for i in s]
n = 0
r = 0
b = 0
for i in s:
	if s[n] == 0:
		r += 1
	elif s[n] == 1:
		b += 1
	n += 1
print(min(r,b) * 2)

Submission status: Accepted

Solution code:

s = input()

n = len(s)

stack = [ s[0] ]

rem = 0
# print(stack)

# 0 search

ss = len(stack)

for i in range(1,n):


    if ss==0 or stack[-1] == s[i]:

        stack.append(s[i])
        ss+=1
        
        continue


    
    stack.pop()
    ss -= 1
    i+=1
    rem +=2


print(rem)

Submission status: Accepted

Solution code:
def check(P):
    for i in range(len(P)-1):
        if P[i] != P[i+1]:
            return i
    return "Non"
def min_2(a,b):
    if a < b:
        return a
    else:
        return b
P = list(input())
c0 = P.count("0")
c1 = P.count("1")
print(min_2(c0,c1)*2)
#t = check(P)
#pop = 0
#while t != "Non":
#    P.pop(t)
#    P.pop(t)
#    pop+=1
#    t = check(P)
#print(pop*2)

Submission status: Accepted

Solution code:
s = input()
a = 0
for i in s:
    a += int(i)
print(2 * min(a, len(s)-a))

Submission status: Accepted

Solution code:
#TLE
# 0と1を数えて少ないほうの2倍を取れば勝ち
S = list(input())
count0 = 0
count1 = 0
for i in range(len(S)):
    if S[i]=='0':
        count0 += 1
    else:
        count1 += 1
print(2*min(count0,count1))

Submission status: Accepted

Solution code:
def func(line):
    lp = 0
    res = []
    while lp < len(line):
        while len(res) > 0 and lp < len(line) and res[-1] != line[lp]:
            res.pop()
            lp += 1
        if lp < len(line):
            res.append(line[lp])
            lp += 1
    return res


def main():
    line = [i for i in input()]
    startsize = len(line)
    line = func(line)
    lastsize = len(line)
    print(startsize - lastsize)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    S = input()
    cnt = [0, 0]
    for c in S:
        cnt[int(c)] += 1
    print(min(cnt) * 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
one,zero=0,0
for ss in s:
  if ss=='1':
    one+=1
  else:
    zero+=1
    
print(min(one,zero)*2)

Submission status: Accepted

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

@author: Yamazaki Kenichi
"""
S = input()
print(2*min(S.count('0'),S.count('1')))

Submission status: Accepted

Solution code:
S = input()
red = S.count('0')
blue = S.count('1')
diff = max(red, blue) - abs(red - blue)
print(diff * 2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 16:12:40 2019

@author: iwata
"""

S = input()
zc = S.count('0')
oc = S.count('1')
if zc >= oc:
    print(2*oc)
else:
    print(2*zc)

Submission status: Accepted

Solution code:
string = str(input())
zero = 0
one = 0
chars = set(string)
for char in string:
    if char == list(chars)[0]:
        zero += 1
    else:
        one += 1

if zero == 0 or one == 0:
    print(0)
else:
    print(min(zero, one) * 2)

Submission status: Accepted

Solution code:
S = list(map(int,input()))
n_one = S.count(1)
n_zero = S.count(0)

print(2 * min(n_zero,n_one))

Submission status: Accepted

Solution code:
print(min(map(input().count,'01'))*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans=0
stack=[]
for s in input():
    if len(stack)>0 and stack[-1]!=s:
        del stack[-1]
        ans+=2
    else:
        stack.append(s)
print(ans)

Submission status: Accepted

Solution code:
# # coding: utf-8
# data = list(input())
# removed_block = 0
# i = 1
# log = data[0]
# while i < (len(data) + 1):
#     try:
#         if data[i] != log:
#             data.pop(i)
#             data.pop(i - 1)
#             removed_block += 2
#             i = 1
#             log = data[0]
#         else:
#             i += 1
#     except:
#         break
# print(removed_block)

# coding: utf-8
n = input()
print(min(n.count('0'), n.count('1')) * 2)

Submission status: Accepted

Solution code:
s=input()
sum1=len([i for i in s if i=="1"])
sum0=len([i for i in s if i=="0"])
if sum1>sum0:
	print(sum0*2)
else:
	print(sum1*2)

Submission status: Accepted

Solution code:
S = input()

zeroSum = 0
oneSum = 0
for _ in S:
  if _ == "0":
    zeroSum += 1
  if _ == "1":
    oneSum += 1

t = max(zeroSum, oneSum) - min(zeroSum, oneSum)
print(len(S) - t)

Submission status: Accepted

Solution code:
s = input()
s=list(s)
zeroc=0
onec=0
for i in s:
  if i == "0":
    zeroc+=1
  if i == "1":
    onec+=1
print(min(zeroc,onec)*2)

Submission status: Accepted

Solution code:
a = input()
k = []
k.append(a[0])
s = 0
for i in range(1,len(a)):
    if len(k) !=0:
        if k[-1] != a[i]:
            s+=1
            k.pop()
        else:k.append(a[i])
    else:
        k.append(a[i])

print(s*2)

Submission status: Accepted

Solution code:
string = input()
one = 0
zero = 0

for s in string:
    if s == '1':
        one += 1
    else:
        zero += 1

print(2*min(one, zero))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
S = input()
S = list(S)
counter = 0
que = deque([])
stack = deque([])
for i in range(len(S)):
    que.append(S[i])
for i in range(1000000):
  if stack:
    1
  else:
    if que:
      stack.append(que.popleft())
    else:
      break
  if que:
    s1 = que.popleft()
  else:
    break
  s2 = stack.pop()
  if(s1 != s2):
    counter+=2
  else:
    stack.append(s1)
    stack.append(s2)
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

d = [0, 0]
for c in S:
    d[int(c)] += 1

print(2 * min(d))

Submission status: Accepted

Solution code:
s=input()
stk=0
h=0
for c in s:
  x=int(c)
  if x==1:
    if stk<0:
      h+=1
    stk+=1
  else:
    if stk >0:
      h+=1
    stk -=1
print(2*h)

Submission status: Accepted

Solution code:
l = input()
r = 0;
b = 0;

for c in l:
    if c == "0":
        r +=1
    else:
        b+=1

print(min(r,b)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

flg = None
stack = []
for v in s:
    if not stack:
        stack.append(v)
    elif stack[-1] != v:
        del stack[-1]
    else:
        stack.append(v)
print(len(s) - len(stack))

Submission status: Accepted

Solution code:
S = input()

l0 = 0
l1 = 0

for i in S:
    if i == '0':
        l0 += 1
    elif i == '1':
        l1 += 1

ans = min(l0, l1) * 2

print(ans)

Submission status: Accepted

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

S = input()

l0, l1 = 0, 0
for s in S:
    if s == '0':
        l0 += 1
    elif s == '1':
        l1 += 1

print(min(l0, l1) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
s=[]
c0=0
c1=0
for i in S:
  if i == '0':
    c0 += 1
  else:
    c1 += 1
print(c0+c1-abs(c0-c1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
r = 0
l = None
c = 0
for i in range(N):
  if c==0:
    l = S[i]
    c += 1
  elif S[i]==l:
    c += 1
  else:
    c -= 1
    r += 2
print(r)

Submission status: Accepted

Solution code:
from collections import Counter

S = Counter(input()).most_common()[::-1]

if len(S) == 1:
    print(0)
else:
    print(S[0][1] * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(min(count_0, count_1) * 2)

Submission status: Accepted

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

count = 0
for c in S:
    if len(stack) == 0:
        stack.append(c)
    elif stack[-1] != c:
        stack.pop(-1)
        count += 2
    else:
        stack.append(c)
print(count)

Submission status: Accepted

Solution code:
S = input()

stack = []

ans = 0
for s in S:
    if len(stack)==0 or s==stack[-1]:
        stack.append(s)
    else:
        stack.pop()
        ans += 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()

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

print(min(zero,one)*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar  5 00:23:16 2019

@author: yuta
"""
from collections import Counter
S = input()
def main(s):
    s = list(s)
    c = Counter(s)
    s_len = len(list(set(s)))
    if s_len == 1:
        min_count = 0
    else:
        min_count = c.most_common()[-1][1]
    print(min_count * 2)
main(S)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def compute():
    from sys import stdin
    S = stdin.readline().strip()
    l = len(S)

    x = S.count("1")
    y = min(x, l-x)
    print(y<<1)

if __name__ == "__main__":
    compute()

Submission status: Accepted

Solution code:
def compute():
    from sys import stdin
    S = stdin.readline().strip()

    wew = []
    for x in S:
        if len(wew)>0 and wew[-1]!=x:
            wew.pop()
        else:
            wew.append(x)

    print(len(S) - len(wew))

if __name__ == "__main__":
    compute()

Submission status: Accepted

Solution code:
a=list(str(input()))
b=a.count('0')
c=a.count('1')
print(b*2 if b<=c else c*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:
S = input()
stack = []
ans = 0

for c in S:
    if not stack or stack[-1] == c:
        stack.append(c)
    else:
        stack.pop()
        ans += 2
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for c in s:
    if not stack or stack[-1] == c:
        stack.append(c)
    else:
        stack.pop()
        ans += 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S = list()
zero = 0
one = 0
line = readline()

for i in line:
  if i == '\n':
    break
  n = int(i)
  S.append(n)
  if n == 0:
    zero += 1
  else:
    one += 1

if zero > one:
  print(one * 2)
else:
  print(zero * 2)

Submission status: Accepted

Solution code:
s = input()

start_len = len(s)

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

end_len = abs(num_1 - num_0)

print(abs(end_len - start_len))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a =input()
N=list(a)
b=0
r=0
for i in N:
    if(i=="0"):
        b+=1
    else:
        r+=1
ans=r
if(r>b):
    ans=b
print(ans*2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  s = input().strip()
  cnt = Counter(s)
  if len(cnt) == 1:
    print(0)
  else:
    print(2*min(cnt.values()))
  pass

if __name__=='__main__':
  main()

Submission status: Accepted

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

n_0 = sum([1 for ss in s if ss == '0'])
diff = abs(n_0 - (n-n_0))
print(n - diff)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input().rstrip("\n")
from collections import Counter
count = Counter(s)
if len(count.values()) < 2:
  print(0)
else:
  print(min(count.values()) * 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 = [int(x) for x in list(input())]
print(min([S.count(0), S.count(1)])*2)

Submission status: Accepted

Solution code:
a = list(input())
count0 = 0
count1 = 0

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

print(min(count0,count1)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp = [0 for i in range(len(S))]

for i in range(len(S)):
    if S[i] == '1':
        tmp[i] = 1
    elif S[i] == '0':
        tmp[i] = 0
     
flag = False
for i in range(len(S)-1):
    if S[i] != S[i+1] and flag == False:
        tmp[i] = -1
        tmp[i+1] = -1
        flag = True
    else:
        flag = False
  
count1 = 0
count0 = 0
res = 0
for i in range(len(S)):
    if tmp[i] == 1:
        count1 += 1
        
    elif tmp[i] == 0:
        count0 += 1
        
    else:
        res += 1
        
print(res + min(count0, count1) * 2)

Submission status: Accepted

Solution code:
s=input()
st=[]
ans=0
for i in s:
  # print("入力:",i,"stack:",st)
  if i=="0":
    if not st or st[-1]=="0":
      st.append(i)
    elif st[-1]=="1":
      st.pop()
      ans+=2
  elif i =="1":
    if not st or st[-1]=="1":
      st.append(i)
    elif st[-1]=="0":
      st.pop()
      ans+=2
      # print(" 合体",st)

print(ans)

Submission status: Accepted

Solution code:
n=input()
maru=n.count("0")*2
iti=n.count("1")*2
if maru<iti:
  print(maru)
else:
  print(iti)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()
ans = 0
stack = []
for si in S:
    if stack and si!=stack[-1]:
        stack.pop()
        ans += 2
    else:
        stack.append(si)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
print(s.count('0')*2 if s.count('0') < s.count('1') else s.count('1')*2)

Submission status: Accepted

Solution code:
s = input()

cnt0 = 0
cnt1 = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

S_1 = [S[i] for i in range(len(S)) if S[i]==1]
S_0 = [S[i] for i in range(len(S)) if S[i]==0]

S_min = min(len(S_1), len(S_0))

print(2*S_min)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    q = collections.deque()
    r = 0
    for c in s:
        if q and q[-1] != c:
            r += 2
            q.pop()
        else:
            q.append(c)

    return r



print(main())

Submission status: Accepted

Solution code:
s=str(input())

Rc=s.count('1')
Bc=s.count('0')

print(min(Rc,Bc)*2)

Submission status: Accepted

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

    ans = f(S)
    print(ans)


def f(S):
    stack = []
    ans = 0
    for c in S:
        if stack and stack[-1] != c:
            ans += 2
            stack.pop()
        else:
            stack.append(c)
    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=[i for i in input()]
one=s.count("1")
zero=s.count("0")
print(len(s)-abs(one-zero))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc120c

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(s)
if len(c) == 2:
    cnt = min(c[0][1],c[1][1])
print(cnt*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#S = map(int, list(input().rstrip()))
S = list(map(int, list(input().rstrip())))
v1 = sum(S) 
r = min(v1, len(S) - v1) 
print(r * 2)

Submission status: Accepted

Solution code:
S = input()
zc = S.count('0')
oc = S.count('1')


print(zc * 2 if zc < oc else oc * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = sorted(list(input()))
L = len(S)
# T = str(input())
num0 = 0
for i in range(L):
    if(S[i] == "1"):
        num0 = i
        break
print(min((L-num0)*2,num0*2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
stack=[]
ans=0
for s in S:
    if not stack:
        stack.append(s)
    elif stack[-1]!=s:
        stack.pop()
        ans+=2
    else:
        stack.append(s)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
length1 = S.count('0')
length2 = S.count('1')
if length1 < length2:
    print(length1*2)
else:
    print(length2*2)

Submission status: Accepted

Solution code:
import sys
s = list(sys.stdin.readline())
l = len(s)
cnt0, cnt1 = 0, 0
for i in s:
    if "0" in i:
        cnt0 += 1
    elif "1" in i:
        cnt1 += 1

print(min(cnt0, cnt1)*2)

Submission status: Accepted

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

st = []
res = 0
for i in range(n):
    if len(st)>0:
        top = st[-1]
        if s[i]!=top:
            res += 2
            st.pop()
        else:
            st.append(s[i])
    else:
        st.append(s[i])
print(res)