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()
LS=len(S)
l=[]
n=S[0]
cnt=0

for i,s in enumerate(S):
	if s!=n:
		l.append(cnt if n=='0' else -cnt)
		cnt=1
		n=s
	else:
		cnt+=1
	
	if i==LS-1:
		l.append(cnt if n=='0' else -cnt)

def func(l):
	if len(l)==1:
		return 0
	t=[]
	r=0
	for i in range(len(l)//2):
		a,b=l[2*i],l[2*i+1]
		if a*b<0:
			r+=2*min(abs(a), abs(b))
		t.append(a+b)
	if len(l)%2==1:
		t.append(l[-1])
	r+=func(t)
	return r

print(func(l))

Submission status: Accepted

Solution code:
S = input()

count_0 = S.count('0')
count_1 = S.count('1')

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

Submission status: Accepted

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

Submission status: Accepted

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

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

total = 0

x = 0
y = 0
for i in range(len(S)):
    if S[i] == "0": x += 1
    if S[i] == "1": y += 1

m = min(x,y)

print(2 * m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
one_count = 0
for s in S:
    if s == "1":
        one_count += 1
print(min(one_count, len(S) - one_count) * 2)

Submission status: Accepted

Solution code:
S=list(input())

N=len(S)

N0=S.count("0")
N1=N-N0

print(min(N0,N1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

total=0
count=0
for i in range(len(S)):
    if(int(S[i])==1):
        p=1
    else:
        p=-1
    if(total*p<0):
        count+=1
    total+=p

print(count*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
str = input()

count1 = str.count('1')
count0 = str.count('0')
print(2 * min(count1, count0))

Submission status: Accepted

Solution code:
s = input()
s0 = sum([1 for char in s if char == "0"])
s1 = sum([1 for char in s if char == "1"])
answer = 2 * min(s0, s1)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
s = list(s)
one = 0
zero = 0

for i in range(len(s)):
    if s[i] == '0':
        zero += 1
    else:
        one += 1
minimum = min(zero,one)
print(minimum*2)

Submission status: Accepted

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

Submission status: Accepted

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

S=input().split()
S=list(S[0])
count0=0
count1=0
for i in range(len(S)):
    if S[i]=="0":
        count0+=1
    else:
        count1+=1
print(min(count0,count1)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
count=s.count("0")


print(min(count,len(s)-count)*2)

Submission status: Accepted

Solution code:
def unification(n,s):
    rc = 0
    bc = 0

    for c in s:
        if c == '0':
            rc += 1
        elif c == '1':
            bc += 1
        else:
            break

    return min(rc,bc) * 2

if __name__ == '__main__':
    s = raw_input()
    n = len(s)
    _s = [i for i in s]

    print unification(n,_s)

Submission status: Accepted

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

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

    # 当たり前だけど全探索はTLEでアウト
    # ans = 0
    # while True:
    #    cnt = 0
    #    for i in range(1,len(S)):
    #        if S[i] != S[i-1]:
    #            S.pop(i)
    #            S.pop(i-1)
    #            cnt += 2
    #            break
    #    if cnt == 0:
    #        break
    #    ans += cnt

    #print(ans)



main()

Submission status: Accepted

Solution code:
S = input()
s = list(S)
size = len(S)
stack = []
for i in range(size):
    if len(stack) == 0 :
        stack.append(s[i])
    else :
        if stack[-1] != s[i] :
            stack.pop(-1)
        else :
            stack.append(s[i])

print("{}".format(size-len(stack)))

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = list(input())
stack = deque()
ans = 0
for i in range(len(s)):
    if len(stack) == 0:
        stack.append(s[i])
        continue
    if stack[-1] != s[i]:
        stack.pop()
        ans += 2
    else:
        stack.append(s[i])
print(ans)

Submission status: Accepted

Solution code:
s = input()
z = s.count('0')
if 2*z > len(s):
  print((len(s)-z)*2)
else:
  print(2*z)

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:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
data = list(n)

cntOne = 0
cntZero = 0

for i in range(len(data)):
    if data[i] == "0":
        cntZero += 1
    else:
        cntOne += 1

ans = int(2*min(cntOne, cntZero))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    stack = []
    count = 0
    for i in range(len(S)):
        if not stack:
            stack.append(S[i])
        else:
            if stack[-1] != S[i]:
                stack.pop()
                count += 2
            else:
                stack.append(S[i])
    return count

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import sys
import math
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
cnt=0
idx=0
while(1):
  if idx >=len(s):
    break
  if s[idx:idx+2] in ('01','10'):
    cnt+=1
    s=s[:idx]+s[idx+2:]
    idx = max(0,idx-1)
  else:
    idx+=1
print(cnt*2)

Submission status: Accepted

Solution code:
S = input()
sum = 0
for s in S:
    if s == "1":
        sum += 1
    else:
        sum -= 1
print(len(S) - abs(sum))

Submission status: Accepted

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

Submission status: Accepted

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

S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
print(2*min(S.count("0"), S.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()

m = [0]*2
for c in s:
    if c == '1':
        m[1] += 1
    else:
        m[0] += 1

ans = min(m[1], m[0]) * 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()


N = len(S)

count_0 = 0
count_1 = 0

for i in range(N):
    if S[i] == '0':
        count_0 += 1
    else:
        count_1 += 1

if count_0 > count_1:
    print(int(count_1*2))

else:
    print(int(count_0*2))

Submission status: Accepted

Solution code:
import collections

s = input()
c = collections.Counter(s)
print(min(c['1'],c['0'])*2)

Submission status: Accepted

Solution code:
from collections import Counter
C = Counter(list(input()))
print(C["0"]*2 if C["0"]<=C["1"] else C["1"]*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = input()
c = abs(s.count('1') - s.count('0'));print(len(s)-c-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
a = b = c = 0
for s in S:
    if s == "0":
        c += b > 0
        a += b == 0
        b = max(0, b-1)
    elif s == "1":
        c += a > 0
        b += a == 0
        a = max(0, a-1)
print(c*2)

Submission status: Accepted

Solution code:
S = input()

ze = 0
one = 0

for el in S:
    if el == '0':
        ze += 1
    else:
        one += 1


print(min(ze, one)*2)

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
res = Counter(s)
print(min(res['0'], res['1']) * 2)

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
n=input()

count=0
stack=[]

for s in n:
  if not stack:
    stack.append(s)
  elif stack[len(stack)-1]!=s:
    stack.pop()
    count+=2
  else:
    stack.append(s)
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

S = input()
n = len(S)

ans = 0

#消してない要素
left = []

#現在の調査位置
i = 0


for i in range(n):
    if S[i]=='0':
        if left:
            if left[-1] == '1':
                ans += 1
                left.pop()
            else:
                left.append('0')
        else:
            left.append('0')
    else:
        if left:
            if left[-1] == '0':
                ans += 1
                left.pop()
            else:
                left.append('1')
        else:
            left.append('1')
    
print(2*ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

count1 = s.count('1')
count2 = s.count('0')

print((count1+count2) - abs(count1-count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

c1 = S.count("0")
c2 = S.count("1")

if c1 >= c2:
  ans =c2*2
else:
  ans=c1*2
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())
cube = list(S)
count0 = 0
count1 = 0

for string in cube:
    if string == '0':
        count0 = count0 + 1
    else:
        count1 = count1 + 1

print(min(count0,count1) * 2)

Submission status: Accepted

Solution code:
S = input()

if len(S) == 1:
    print(0)
else:
    if S.count("0")== S.count("1"):
        print(S.count("0")*2)
    else:
        print(len(S)-(max(S.count("0"),S.count("1")) - min(S.count("0"),S.count("1"))))

Submission status: Accepted

Solution code:
s=input()
l=len(s)
a=[0 for i in range(l)]

for i in range(l):
  a[i]=int(s[i])
  
ichi=0
zero=0

for i in range(l):
  if a[i]==1:
    ichi+=1
  else:
    zero+=1
    
print(2*min(ichi,zero))

Submission status: Accepted

Solution code:
S = list(input())

ans = []
cnt = 0

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

# お約束
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*args):
    return tuple(p(v) for p, v in zip(args, input().split()))

# エントリーポイント
def main():
    S = input()
    c = [0, 0]
    for s in S:
        c[s == "1"] += 1
    print((len(S) - abs(c[0] - c[1])))

main()

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
S = input()
red = 0
blue = 0
for s in S:
  if s == '0':
    red += 1
  else:
    blue += 1
print(min(red, blue) * 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:
def solve():
    s = input()
    c0 = s.count("0")
    c1 = s.count("1")
    return 2 * min(c0, c1)


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
count_zero = 0
count_one = 0
for i in range(len(s)):
    if s[i] == '1':
        count_one += 1
    else:
        count_zero += 1

print(len(s) - abs(count_zero - count_one))

Submission status: Accepted

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

Submission status: Accepted

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

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()
n = len(S)
r = S.count('0')
b = n - r
print(2 * min([r, b]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
count_0 = s.count('0')
count_1 = s.count('1')
if len(s) == 1:
  print(0)
else:
  print(min(count_0,count_1)*2)

Submission status: Accepted

Solution code:
s = input()

count_0 = 0
count_1 = 0
for i in range(len(s)):
    if s[i] == '0':
        count_0 += 1
    else:
        count_1 += 1

print(min(count_0,count_1) * 2)

Submission status: Accepted

Solution code:
s = input()
0

count_0 = 0
count_1 = 0
for i in range(len(s)):
    if s[i] == '0':
        count_0 += 1
    else:
        count_1 += 1

print(min(count_0,count_1) * 2)

Submission status: Accepted

Solution code:
s = list(map(int, list(input())))
i = [x for x in s if x == 1]
m = sum(i)
n = len(s)-m

if n <= m:
    print(n*2)
else:
    print(m*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import collections

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s = input()

res = 0
stk = []
for c in s:
    if stk and stk[-1] != c:
        stk.pop()
        res += 2
    else:
        stk.append(c)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    
resolve()

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
S = input()
# 0 のとき赤色、1 のとき青色
stackA=[]
stackB=[]
for s in S:
    if s == "0":
        stackA.append(s)
    else:
        stackB.append(s)
print(min(len(stackA),len(stackB))*2)

Submission status: Accepted

Solution code:
S = input().rstrip()

ans = 0
cnt0 = 0
cnt1 = 0
for s in S:
    if s == '0':
        if cnt1 > 0:
            ans += 2
            cnt1 -= 1
        else:
            cnt0 += 1
    else:
        if cnt0 > 0:
            ans += 2
            cnt0 -= 1
        else:
            cnt1 += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

redCount = s.count('0')
blueCount = s.count('1')

if redCount == blueCount:
    print(len(s))
elif redCount > blueCount:
    print(blueCount * 2)
else:
    print(redCount * 2)

Submission status: Accepted

Solution code:
#from 17
s = input()
s0 = s.count("0")
s1 = s.count("1")
print(min(s0,s1)*2)

Submission status: Accepted

Solution code:
s=input()
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:
s = input()
n = len(s)
zero_count = 0
counts = [0, 0]
for c in s:
    if c == '0':
        counts[0] += 1
    else:
        counts[1] += 1
print(min(counts[0], counts[1]) * 2)

Submission status: Accepted

Solution code:
e = []
ans = 0
S = list(input())
for k in S:
    e.append(k)
    if(len(e)>1):
        if(e[-1] != e[-2]):
            ans += 2
            e.pop()
            e.pop()
print(ans)

Submission status: Accepted

Solution code:

s = input()

blue = s.count("1")
red = s.count("0")

print(2*min(blue, red))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(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:
N = input()
zeronum = N.count("0")
onenum = N.count("1")

ans = 2 * min(zeronum,onenum)
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
zero = 0
one = 0
for i in range(n):
    if s[i] == "0":
        zero += 1
    else:
        one += 1

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

Submission status: Accepted

Solution code:
s=list(input())

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

print(len(s)-len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

for s in S:
    if stack and stack[-1] != s:
        stack.pop()
        res += 2
        continue
    stack.append(s)
print(res)

Submission status: Accepted

Solution code:
S = input()

s_len = len(S)
count_0 = 0
count_1 = 0

for i in range(s_len):
    if S[i] == "0":
        count_0 += 1
    else:
        count_1 += 1

ans = min(count_0, count_1) * 2

print(ans)

Submission status: Accepted

Solution code:
s = input()
s = list(s)
s = [int(x) for x in s]
a = s.count(1)
b = s.count(0)
print(len(s)-abs(a-b))

Submission status: Accepted

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

print(2*min(a,b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

#  print(S.count('0'))
#  print(S.count('1'))

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

Submission status: Accepted

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

def main():
    s = input().strip()
    c0 = s.count("0")
    print(2 * min(c0, len(s) - c0))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
l = len(S)
T = list(S)


tmp = 0

while tmp < len(T)-1:
    if T[tmp] != T[tmp+1]: 
        T.pop(tmp)
        T.pop(tmp)
        if tmp == 0:
            tmp = 0
        else:
            tmp -= 1
    else:
        tmp += 1


k = len(T)

ans = l - k

print(ans)

Submission status: Accepted

Solution code:
S=input()
s0=S.count("0")
s1=S.count("1")

print(2*min(s0,s1))

Submission status: Accepted

Solution code:
s=input()
i=0
n=len(s)
a=0
b=0
while(i<n):
	if(s[i]=='0'):
		a+=1
	else:
		b+=1

	i+=1

print(min(a,b)*2)

Submission status: Accepted

Solution code:
s = list(input())
cnt0 = s.count('0')
cnt1 = s.count('1')

print(min(cnt0,cnt1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

s = input().split()[0]

counter = collections.Counter(list(s))
c_0 = counter['0']
c_1 = counter['1']
step = min(c_0, c_1)
print(step * 2)

Submission status: Accepted

Solution code:
S = input()


count_1 = 0
count_0 = 0

for i in range(len(S)):
  if S[i]=="1":
    count_1 = count_1 + 1
  elif S[i]=="0":
    count_0 = count_0 + 1
    

if count_1 >= count_0:
  print(count_0*2)
else:
  print(count_1*2)

Submission status: Accepted

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

n1 = sum(s)
n0 = len(s) - n1

print(min(n0, n1)*2)

Submission status: Accepted

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

def are_different(a, b):
    if (a == "0" and b == "1") or (a == "1" and b == "0"):
        return True
    else:
        return False

len_ori = len(s)
res = []
while len(s) > 0:
    # print("1")
    # print(res, s)
    while len(s) >= 2 and s[0] != s[1]:
            s.pop(0)
            s.pop(0)
    # print("2")
    # print(res, s)
    while len(s) >= 1 and len(res) >= 1 and res[-1] != s[0]:
        res.pop(-1)
        s.pop(0)
    if len(s) >= 1:
        res.append(s[0])
        s.pop(0)

    # print("3")
    # print(res, s)

print(len_ori - len(res))
# print("1")
# print(res, s)
# # if s[0] != s[1]:
# while len(s) >= 2 and s[0] != s[1]:
#         s.pop(0)
#         s.pop(0)
# res.append(s[0])
# s.pop(0)
# print("2")
# print(res, s)
# while len(s) >= 1 and len(res) >= 1 and res[-1] != s[0]:
#     res.pop(-1)
#     s.pop(0)

# print("3")
# print(res, s)

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

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

mod = 1000000007

if __name__ == "__main__":
    s = sys.stdin.readline().rstrip()
    n0 = s.count("0")
    n1 = s.count("1")

    print(min(n0,n1)*2)

Submission status: Accepted

Solution code:
S = str(input())
count_0 = S.count("0")
count_1 = S.count("1")

print(min(count_0, count_1)*2)

Submission status: Accepted

Solution code:
str_in = input()

cnt0 = 0
cnt1 = 0

for i in range(len(str_in)):
  if (int(str_in[i]) == 0):
    cnt0 += 1
  else:
    cnt1 += 1

ans = min([cnt0, cnt1]) * 2
print (ans)

Submission status: Accepted

Solution code:
x=input()

n=len(x)

one=x.count('1')
zero=n-one

res=min(one,zero)*2

print(res)

Submission status: Accepted

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

import sys
#import math

hoge = input()
n = len(hoge)

sum=0
i=0

while(1):
#	print(i)
	if(i>=n-1):
		break
	if(hoge[i]!=hoge[i+1]):
#		print("hoge:{} i:{} {} {}".format(hoge,i,hoge[i],hoge[i+1]))
		newhoge=hoge[0:i]+hoge[i+2:n]
		hoge=newhoge
		i-=1
		if(i<0):
			i=0
		n-=2
#		n=len(hoge)
		sum+=2
	else:
		i+=1


#	print(i)
#	print("---")


print(sum)

Submission status: Accepted

Solution code:
s = str(input())
count_0 = 0
count_1 = 0

for i in range(len(s)):
  if s[i] == "0":
    count_0 += 1
  else:
    count_1 += 1
print(min(count_0, count_1)*2)

Submission status: Accepted

Solution code:
s = input()

s1 = 0
s0 = 0

for i in s:
    if i == "0":
        s0 += 1
    if i == "1":
        s1 += 1

ans = min(s0, s1) * 2
print(ans)

Submission status: Accepted

Solution code:
S = input()

n0 = len([s for s in S if s == "0"])
n1 = len([s for s in S if s == "1"])
print(len(S)-abs(n0-n1))

Submission status: Accepted

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

from collections import deque  # 双方向キュー

def main():
    S = i2s()
    q = deque()
    for s in S:
        if not q:
            q.append(s)
        else:
            t = q.pop()
            if s == t:
                q.append(t)
                q.append(s)
    n = len(S) - len(q)
    print(n)

main()

Submission status: Accepted

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