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

zero_count=0
one_count=0
for c in S:
    if c=='1':
        one_count+=1
    else:
        zero_count+=1

print(min(zero_count,one_count)*2)

Submission status: Accepted

Solution code:
x = input()
cnt1 = 0
cnt2 = 0
for i in x:
  if i == '1':
    cnt1 += 1
  else:
    cnt2 += 1
print(min(cnt1, cnt2)*2)

Submission status: Accepted

Solution code:
str = input()
num0,num1 = 0,0
for i in range(len(str)):
	if str[i] == '0':
		num0 += 1
	elif str[i] == '1':
		num1 += 1
if num1 >= num0:
	count = num0*2
	print(count)
else:
	count = num1*2
	print(count)

Submission status: Accepted

Solution code:
S = input()
 
num_0 = S.count('0')
num_1 = S.count('1')

print(min(num_0, num_1) * 2)

Submission status: Accepted

Solution code:
nums=str(input())
arr=list(map(int,nums))
l=len(arr)
a=0
i=0
while i<len(arr)-1:
    if i<0:
        i=0
    if arr[i]!=arr[i+1]:
        del arr[i:i+2]
        #print(arr)
        a+=2
        i-=2
    i+=1
print(a)

Submission status: Accepted

Solution code:
S = list(input())
SL = len(S)
L = len(S)
i = 1
while len(S)>1 and i<len(S):
  if int(S[i]) != int(S[i-1]):
    S.pop(i-1)
    S.pop(i-1)
    i-=1
  else:
    i+=1
  if i==0:
    i+=1
print(L-len(S))

Submission status: Accepted

Solution code:
in_s = input().rstrip()
lst = list(in_s)
cur=0
while True:
    if cur+1 >= len(lst):
        break
    if lst[cur]!=lst[cur+1]:
        del lst[cur+1]
        del lst[cur]
        cur = max(0,cur-1)
    else:
        cur+=1
 
print(len(in_s) - len(lst))

Submission status: Accepted

Solution code:
def main():
    S = input()
    
    one = S.count("1")
    zero = len(S) - one
    
    print(min(zero,one)*2)
    
main()

Submission status: Accepted

Solution code:
P=map(int,list(raw_input()));print min(sum(P),len(P)-sum(P))*2

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(int, input()))
ans = 0
l = len(S)
i = 0
while len(S)-1 > i:
    if S[i] != S[i+1]:
        S.pop(i)
        S.pop(i)
        ans += 2
        if i == 0:
            i -= 1
        else:
            i -= 2
    i += 1


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
li = []
for i in range(len(s)):
	li.append(s[i])
cnt0 = li.count("0")
cnt1 = li.count("1")
print(cnt0*2 if cnt0 < cnt1 else cnt1*2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input().rstrip()
 
if s.count("0") != 0 and s.count("1") != 0:
    if s.count("0") > s.count("1"):
        print(2*s.count("1"))
    elif s.count("1") > s.count("0"):
        print(2*s.count("0"))
    else:
        print(len(s))
else:
    print(0)

Submission status: Accepted

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

S = list(map(int, input().replace('\n', '')))

N = len(S)
stack = []
cnt = 0
index = N - 1
while index > -1:
    if(len(stack) == 0):
        stack.append(S.pop())
        index -= 1
    else:
        if stack[-1] != S[index]:
            stack.pop()
            S.pop()
            index -= 1
            cnt += 2
        else:
            stack.append(S.pop())
            index -= 1
print(cnt)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

S = input()
stack = []
ans = 0
for ch in S:
    if len(stack) == 0 or stack[-1] == ch:
        stack.append(ch)
    else:
        ans += 2
        # stack = stack[:-1]  # 遅い??
        del stack[-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

s = str(sys.stdin.readline())
c0 = s.count('0')
c1 = s.count('1')
r = c0 if c0 < c1 else c1
print(r*2)

Submission status: Accepted

Solution code:
S = list(input())

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

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

Submission status: Accepted

Solution code:
S = input()
cnt = [0] * 2
for c in S:
    if c == '0':
        cnt[0] += 1
    else:
        cnt[1] += 1
print(min(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 = input()

nums = []
for s in S:
    nums.append(int(s))

count = 0
i = 0
while i < len(nums)-1:
    if nums[i] != nums[i+1]:
        nums.pop(i+1)
        nums.pop(i)
        count += 1
        if i != 0:
            i -= 1
        continue
    i += 1

print(count*2)

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    ones = sum(n)
    zeros = len(n) - ones
    return len(n) - abs(ones - zeros)

print(solve())

Submission status: Accepted

Solution code:
import sys

def parse(inp):
    S=list(next(inp))
    return S
  
def main(inp):
    S = inp
    zeros=0
    ones=0
    for i in range(len(S)):
        if(S[i]=='0'): zeros+=1
        elif(S[i]=='1'): ones+=1
            
    return 2*min(ones,zeros)
  
print(main(parse(sys.stdin)))

Submission status: Accepted

Solution code:
inp = input()

cnt_0 = inp.count('0')
cnt_1 = inp.count('1')

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Ss = input()

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

print(len(Ss) - len(stack))

Submission status: Accepted

Solution code:
S=input()

count0=0
count1=0
# print(S)

for s in S:
	if s == '0':
		count0 += 1
	else:
		count1 += 1

print(min(count0,count1) * 2)

Submission status: Accepted

Solution code:
# coding: utf-8

def _main():
    text = input()

    zero_count = text.count('0')
    one_count = len(text) - zero_count

    ans = min(zero_count, one_count) * 2

    print(ans)



if __name__ == '__main__':
    _main()

Submission status: Accepted

Solution code:
S = input()

c0=0
c1=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()
cnt = 0

l = list(s)
a = l.count('0')
b = l.count('1')

# print(a)
# print(b)

print(min(a,b) * 2)
exit()
while '10' in s:
    ind = s.find('10')
    temp = []
    temp.append(str(s[0:ind]))
    temp.append(str(s[ind + 2:len(s)]))
    #print(s)
    s = "".join(temp)
    cnt = cnt + 2

while '01' in s:
    ind = s.find('01')
    # print(ind)
    temp = []
    temp.append(str(s[0:ind]))
    temp.append(str(s[ind + 2:len(s)]))
    s = "".join(temp)
    #print(s)
    cnt = cnt + 2

print(cnt)

Submission status: Accepted

Solution code:
S = input()
len_S = len(S)
zero_lst = [S[i] for i in range(len_S) if S[i] == "0"]
one_lst = [S[i] for i in range(len_S) if S[i] == "1"]
ans = min(len(zero_lst), len(one_lst)) * 2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
s = list(input())
d = Counter(s).most_common(2)

# 文字列すべてが同じ文字のとき
if len(d) == 1:
    print(0)
else:
    print(min(d[0][1],d[1][1])*2)

Submission status: Accepted

Solution code:
s=input()
li=list(s)
r=0
b=0
for i in li:
  if i=='0':
    r+=1
  if i=='1':
    b+=1
if r>b:
  print(b*2)
else:
  print(r*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
x0 = 0
x1 = 0

Ni = [int(s) for s in N]


for x in range(len(N)):
    if Ni[x] == 0:
        x0 += 1
    elif Ni[x] == 1:
        x1 += 1

print(min([x0, x1])*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(map(int, input()))
c1,c0=0,0
for i in s:
  if i==1:
    c1+=1
  if i==0:
    c0+=1  
print(len(s)-abs(c1-c0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


from collections import Counter

cnt = Counter()
s = input()
for c in s:
    cnt[c] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
q = s[0]
for c in s[1:]:
    if len(q) >= 1:
        if q[-1] != c:
            q = q[:-1]
        else:
            q += c
    else:
        q += c
print(len(s) - len(q))

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

Submission status: Accepted

Solution code:
S = input()
z_cnt = 0
o_cnt = 0
for i in S:
    if i == '0':
        z_cnt += 1
    if i == '1':
        o_cnt += 1
print(len(S)-(max(z_cnt,o_cnt)-min(z_cnt,o_cnt)))

Submission status: Accepted

Solution code:
S = input()

save = []
flag = False
modori_flag = False
count = 0
for idx, s in enumerate(S):
    if modori_flag:
        modori_flag = False
    elif flag:
        flag = False
        continue
            
    this_ = int(s)
    if len(save) > 0 and this_ + save[-1] == 1:
        modori_flag = True
        del save[-1]
        count += 2
        continue
    if idx == len(S) -1:
        break
    next_ = int(S[idx+1])
    if this_ + next_ == 1:
        flag = True
        count += 2
        continue
        
    save.append(this_)
    
print(count)

Submission status: Accepted

Solution code:
s = input()

n = len(s)

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

print(n - abs(red - blue))

Submission status: Accepted

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

A = input()
N = len(A)

zero_num = A.count('0')
one_num = A.count('1')


if N == 1 or zero_num == 0 or one_num == 0:
    print(0)
    exit()

if zero_num == 1 or one_num == 1:
    print(2)
    exit()

if zero_num == one_num:
    ans = one_num*2
elif zero_num > one_num:
    ans = one_num*2
else:
    ans = zero_num*2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
ans=0
i=0
while i!=len(s) and len(s)>=2:
  if s[i:i+2]=="01" or s[i:i+2]=="10":
      s=s[:i]+s[i+2:]
      ans+=2
      i=max(0,i-1)
  else:
    i+=1
print(ans)

Submission status: Accepted

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

if n < 2:
    print(0)

else:
    ans, i = 0, 0
    rem = []

    while i < n:

        if not rem:

            if i+1 < n:
                if s[i] == s[i+1]:
                    rem.append(s[i])
                    i += 1

                else:
                    i += 2
                    ans += 2

            else:
                i += 1

        else:
            if rem[-1] != s[i]:
                rem.pop()
                i += 1
                ans += 2
            
            else:
                if i + 1 < n:
                    if s[i] == s[i+1]:
                        rem.append(s[i])
                        i += 1

                    else:
                        i += 2
                        ans += 2

                else:
                    i += 1
    print(ans)

Submission status: Accepted

Solution code:
S = input()
temp0 = S[:int(len(S)/2)]
temp1 = S[int(len(S)/2):]
temp01 = min(temp0.count('0'), temp1.count('1'))
temp10 = min(temp0.count('1'), temp1.count('0'))
print(temp01 * 2 + temp10 * 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/python
# coding: UTF-8

S = list(input())
S = list(map(int,S))
#S.append(-1)
#S.insert(0,-2)
#Count = 0
#Before = len(S)
#L = len(S)
#S1 = S[0:L//2]
#S2 = S[L//2:L]
zero = 0
for i in S:
    if i == 0:
        zero += 1
one = len(S) - zero
ans = one - zero if one > zero else zero - one
print(len(S) - ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s == '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s == '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)

Submission status: Accepted

Solution code:
s = str(input())

ct1 = s.count('1')
ct0 = s.count('0')

print(int(min(ct1,ct0)*2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Solver:

    def __init__(self):
        pass


    def solve(self, s):
        one = 0
        zero = 0
        for ch in s:
            if ch == '1':
                one += 1
            else:
                zero += 1
        return len(s) - abs(one-zero)


if __name__ == '__main__':

    solver = Solver()
    s = input()
    n = solver.solve(s)
    print(n)

Submission status: Accepted

Solution code:
S=input()
N=len(S)
X=0
Y=0
for i in S:
    if i=="0":
        X+=1
    else:
        Y+=1
print(N-abs(X-Y))

Submission status: Accepted

Solution code:
S = list(input())
R = S.count('0')
B = S.count('1')

if(len(S) <= 1):
    print(0)
else:
    print(len(S) - abs(R-B))

Submission status: Accepted

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

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:
a = list(map(int, list(input())))
sum = 0
for i in a:
  sum += i
b = len(a) - sum
if sum == 0:
  print("0")
elif b <= sum:
  print(b * 2)
else:
  print(sum * 2)

Submission status: Accepted

Solution code:
import collections


def main() -> None:
    S = list(input())
    a = collections.Counter(S)
    zero = a['0']
    one = a['1']
    if zero >= one:
        print(one * 2)
    else:
        print(zero * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
l = list(stdin.readline().rstrip())
zero_count=l.count('0')
one_count=l.count('1')
if zero_count > one_count:
    print(one_count*2)
elif zero_count < one_count:
    print(zero_count*2)
elif zero_count == one_count:
    print(len(l))
elif len(l) == 1:
    print(0)

Submission status: Accepted

Solution code:
S = input()
s = [int(S[i:i + 1]) for i in range(len(S))]
ans = 0
v1 = s[0]
index = []
index.append(0)
for i in range(1, len(s)):
    if v1 != s[i] and len(index) != 0:
        ans += 2
        index.pop(-1)
        if len(index) != 0:
            v1 = s[index[-1]]
        else:
            v1 = 10
    else:
        index.append(i)
        v1 = s[i]
print(ans)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
import random
import bisect
#from statistics import mean, median, variance, stdev

#template input

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)
def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val
def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

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

def main():

    s = input()
    one = s.count("1")
    two = s.count("0")
    print(len(s) - abs(one-two))


main()

Submission status: Accepted

Solution code:
import sys
S = sys.stdin.readline().rstrip()
count = 0
stack = ''
for s in S:
    if len(stack) == 0 or s == stack[-1]:
        stack += s
        continue
    count += 2
    stack = stack[:-1]
print(count)

Submission status: Accepted

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

s = str(input())

x = int(0)
i = int(len(s))

s0 = int(len(s.replace("1","")))
s1 = i-s0

print(int(2*min(s0,s1)))

Submission status: Accepted

Solution code:
S = input()
S_list = list(S)
a = S_list.count('0')
b = S_list.count('1')
print(len(S_list) - abs(a - b))

Submission status: Accepted

Solution code:
s=raw_input().strip()
pile=[s[0]]
n=len(s)
ans=0
for i in xrange(1,n):
	if pile:
		x=pile.pop()
		if s[i]!=x:
			ans=ans+2
		else:
			pile.append(x)
			pile.append(s[i])
	else:
		pile.append(s[i])
print ans

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# ABC120: C
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def debug(*args): print("DEBUG:\t", *args, file=sys.stderr)


def combine(S, i):
    if S[i] != S[i+1]:
        S
        return S[0:i] + S[i+2:]
    else:
        assert False

def main(S, answer=0, _d=False):
    S = [int(x) for x in S]
    return solve(S, answer, _d)

def solve(S, answer=0, _d=False):
    i = 0
    while i < len(S) - 1:
        #debug(S, "i=%d"% i, answer)
        if S[i] != S[i+1]:
            answer += 2
            del S[i:i+2]
            i = max(i - 1, 0)
        else:
            i += 1
    debug("answer", answer)
    return answer

def check(S, expected):
    a = main(S)
    if a != expected:
        print(a)
        print("expected %d" % expected, "but %d" % a, "for", S)

if 1==0:
    check("0011", 4)
    check("101", 2)
    check("111", 0)
    check("010", 1)
    check("0", 0)
    check("11011010001011", 12)

print(main(input().strip()))

Submission status: Accepted

Solution code:
S = str(input())
S = [int(x) for x in S]
if len(S) > 2 * sum(S):
  print(2 * sum(S))
else:
  print(2 * (len(S) - sum(S)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

res = 0
a = ""
for c in s:
    if len(a) > 0 and a[-1] != c:
        a = a[:-1]
        res += 2
    else:
        a += c
print(res)

Submission status: Accepted

Solution code:
def main():
    string = input()
    lists = list(string)
    original_len = len(lists)
    zero = lists.count('0')
    one = lists.count('1')
    print(min(zero,one)*2)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a = input()
l = len(a)
blk = a
i = 0
rem = 0
num0 = 0
num1 = 0
while i < l:
    if blk[i] == "0":
        num0 += 1
    else:
        num1 += 1
    i += 1
rem = min(num0, num1)
print(rem * 2)

Submission status: Accepted

Solution code:
st = input()
list_s = list(st)

delcount = 0
count_0 = list_s.count('0')
count_1 = list_s.count('1')
if count_0 < count_1:
    print(count_0 * 2)
else:
    print(count_1 * 2)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
def ls(): return stdin.readline()

S = ls()
num_1, num_0 = 0, 0

for s in S:

    if s == '1':
        num_1 += 1
    elif s == '0':
        num_0 += 1
print( 2 * min(num_1, num_0) )

Submission status: Accepted

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

print(min(one, zero)*2)

Submission status: Accepted

Solution code:

s = input()

n = len(s)

cnt0 = s.count('0')
cnt1 = s.count('1')

print(min(cnt0, cnt1)*2)

Submission status: Accepted

Solution code:
s = input()

s_0 = s.count('0')
s_1 = s.count('1')

print(min(s_0, s_1) * 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
s=input()
sl=len(s)
l=list(s)
nl=[l.pop(0)]
si=0
while len(l)>0:
  c=l.pop(0)
  if len(nl)>0:
    if nl[si]!=c:
      nl.pop(si)
      si=si-1
    else:
      nl.append(c)
      si=si+1
  else:
    nl=[c]
    si=0

print(sl-len(nl))

Submission status: Accepted

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

print(N-abs((S.count("1")-S.count("0"))) if N != 1 else 0)

Submission status: Accepted

Solution code:
def main():
    s = list(input())
    #s = list(s)
    #print(s)
    res = 0
    lst = []
    count = 1
    sign = 1
    for i in range(1, len(s)):
        if s[i-1] == s[i]:
            count += 1
        else:
            lst.append(count*sign)
            count = 1
            sign *= -1
    lst.append(count*sign)
    #print(lst)
    res = 0
    total = 0
    while True:
        #print(total, lst)
        try:
            curr = lst.pop(0)
        except:
            break
        if (total <= 0 and curr <= 0) or (total > 0 and curr > 0):
            pass
        else:
            res += min(abs(curr), abs(total))
            #print(min(abs(curr), abs(total)))
        total += curr
    print(res*2)
        
        
         
    

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
a=0
b=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
c_0 = 0
c_1 = 0
for i in s:
    if i == "0":
        c_0 += 1
    elif i == "1":
        c_1 += 1
print(min(c_0,c_1)*2)

Submission status: Accepted

Solution code:
cubes = [c for c in input()]

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

print(min(zero, one) * 2)

Submission status: Accepted

Solution code:
from sys import stdin


def b(input_string):
    _s = input_string
    s_length = len(_s)
    s = []
    for i in range(s_length):
        s.append(_s[i])
    count = 0
    i = 0
    while(i < len(s)-1):
        #print(s)
        #print(i)
        if s[i] != s[i+1]:
            s.pop(i)
            s.pop(i)
            count += 2
            if i != 0:
                i -= 1
        else:
            i += 1
    return count



def main():
    input_line = stdin.readline().rstrip()
    answer = b(input_line)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if s_list.count(0) < s_list.count(1):
  print(s_list.count(0) * 2)
else:
  print(s_list.count(1) * 2)

Submission status: Accepted

Solution code:
import copy

s = input()
s_sub = copy.deepcopy(s)
# # 
# tar1 = "01"
# tar2 = "10"
# tar3 = ["1010","1001","0101","0110","1100","0011",""]
# 
# while((tar1 in s )or(tar2 in s)):
# 
# 
#     # for i in range(4):
#     #     if tar3[i] in s:
#     #         s = s.replace(tar3[i],"")
# 
# 
#     if tar1 in s:
#         s = s.replace(tar1,"",1)
#     if tar2 in s:
#         s = s.replace(tar2,"",1)
# 
# 
# 
# print(len(s_sub)-len(s))

#0と1の数数えて差分が残るのでは？
l1 = s.count("0")
l2 = s.count("1")
l3 = abs(l1-l2)

print(len(s_sub)-l3)

Submission status: Accepted

Solution code:
S = input()
one = S.count('1')
zero = S.count('0')
if one > zero:
    ans = zero * 2
else:
    ans = one * 2
print(ans)

Submission status: Accepted

Solution code:
S = input()

cnt1=0
cnt0=0
for i in range(len(S)):
    if S[i]=='0':
        cnt0+=1
    elif S[i]=='1':
        cnt1+=1
if cnt1 == 0 or cnt0 == 0:
    print(0)
else:
    if cnt1>cnt0:
        print(cnt0*2)
    else:
        print(cnt1*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(raw_input())

i = 0
cnt = 0
while len(S) > 0:
    if i+1 == len(S):
        break
    if S[i] != S[i+1]:
        del S[i]
        del S[i]
        if i <= 0:
            i = -1
        else:
            i -= 2
        cnt += 2
    i += 1

print cnt

Submission status: Accepted

Solution code:
s=str(input())
ue=-1
ans=0
for i in range(len(s)):
  if(ue==-1):
    ue=int(s[i])
  elif(int(s[i])!=ue):
    ans+=2
    if(ans==i+1):
      ue=-1
print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = input()
    a = 0
    b = 0
    for c in n:
        if(c == '1'):
            a += 1
        else:
            b += 1
    if(a>b):
        print(b*2)
    else:
        print(a*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    NLIST = list(lines.pop(0))
    zero = 0
    one = 0
    for i in NLIST:
        if i == '1':
            one += 1
        else:
            zero += 1
    print(min(one,zero) * 2)
    
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
S=list(input().strip())
zero=S.count('0')
one=S.count('1')
print(min(zero,one)*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()

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

if a >= b:
	print(len(s) - a + b)
else:
	print(len(s) - b + a)

Submission status: Accepted

Solution code:
s = input()

if s.count('1') > 0 and s.count('0') > 0:
  print(min(s.count('1'), s.count('0')) * 2)
else:
  print(0)

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  S = [int(c) for c in input().strip()]
  n1 = 0
  n0 = 0
  for i in S:
    if i == 0:
      n0 += 1
    else:
      n1 += 1
  print(min(n1, n0) * 2)


if __name__ == '__main__':
  main()

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


    if len(stack) > 0:
        stack.pop()
        ss -= 1

        i+=1
        rem +=2


print(rem)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
z=0
o=0
for c in str(s):
	if c=="0":
		z+=1
	else:
		o+=1
print((z if o > z else o)*2)

Submission status: Accepted

Solution code:
S = input()

iL = len(S)
i0 = 0
for s in S:
    if s == "0":
        i0 += 1
i1 = iL - i0
print(2*min(i1,i0))

Submission status: Accepted

Solution code:
s = input()
print(min(s.count('0')*2,s.count('1')*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:
from collections import Counter
try:
  print(Counter(input()).most_common()[1][1] * 2)
except:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(map(int, list(input())))
s_len = len(S)
num_one = sum(S)
print(s_len - abs(num_one*2 - s_len))