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

Submission status: Accepted

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

	print(total)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque

def unification(string):

    n = len(string)

    if n == 1:
        return 0

    q = deque()
    idx = 2
    q.appendleft(string[0])
    q.appendleft(string[1])
    count = 0

    while idx < n:
        while len(q) > 1 and q[0] != q[1]:
            q.popleft()
            q.popleft()
            count += 2

        q.appendleft(string[idx])
        idx += 1

    if len(q) > 1 and q[0] != q[1]:
        q.popleft()
        q.popleft()
        count += 2

    return count


if __name__ == "__main__":
    string = input()
    print(unification(string))

Submission status: Accepted

Solution code:
import re

S = input()

count_1 = len(re.findall('1', S))
count_0 = len(re.findall('0', S))

if(count_1 < count_0):
    print(2 * count_1)
else:
    print(2 * count_0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():

    S = input()
    N = len(S)

    count = 0
    for n in range(N):
        if S[n] == '1':
            count += 1

    print(N - abs(N - 2 * count))


main()

Submission status: Accepted

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

Submission status: Accepted

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

C0=[]
C1=[]

for n in range(N):
  if S[n]=='0':
    C0.append(n)
  elif S[n]=='1':
    C1.append(n)

C_Num=[len(C0),len(C1)]
print(2*min(C_Num))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = str(input())

count_zero = 0
count_one = 0

for i in range(len(N)):
    if int(N[i]) == 0:
        count_zero += 1
    else:
        count_one += 1
print(min(count_zero, count_one)*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys


def solve(S):
    orig_len = len(S)
    num_value = {'0': -1, '1': 1}
    status = 0

    for s in S:
        status += num_value[s]
        #if s == '0':
        #    status -= 1
        #else:
        #    status += 1
    return orig_len - abs(status)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
S = input()

red, blue = 0, 0
for s in S:
    if s=='0':
        red += 1
    else:
        blue += 1
ans = len(S) - abs(red-blue)
print(ans)

Submission status: Accepted

Solution code:
def main():
   S = str(input())
   S_0_num = S.count('0')
   S_1_num = S.count('1')
   if S_0_num > S_1_num:
       print(S_1_num*2)
   else:
       print(S_0_num*2)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

# 以下1と0の数を数える
num_1 = 0
num_0 = 0
for t in s:
    if t == '1':
        num_1 += 1
    else:
        num_0 += 1
# 文字列中に1と0が混在していたら必ず2つプロックを消すことが出来る
# よって1,0の最小の個数×2個消すことが出来る
ans = 2 * min(num_0, num_1)
print(ans)

Submission status: Accepted

Solution code:
S = input()

s0 = S.count('0')
s1 = S.count('1')

print(min(s0, s1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

# 標準入力の受取
sdi = stdin.readline().rstrip()
# a, b, c = stdin.readline().rstrip().split()
# a, b, c = [x for x in stdin.readline().rstrip().split()]
# a, b, c = [int(x) for x in stdin.readline().rstrip().split()]
l = list(sdi)
l.reverse()
start = len(l)
i = 0
while len(l) - 1 >= i + 1:
    if l[i] != l[i + 1]:
        l.pop(i + 1)
        l.pop(i)
        i = max(i - 2, 0)
        continue
    i += 1
print(start - len(l))

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

S = input()

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

print(min(zero, one) * 2)

Submission status: Accepted

Solution code:
S=input()

c0=0

for i in range(len(S)):
    if S[i]=='0':
        c0+=1

if len(S)>c0*2:
    print(2*c0)
else:
    print((len(S)-c0)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

s = list(S)

answer = 0
for i in reversed(range(1, len(s))):
    if i >= len(s):
        continue
         
    if s[i] != s[i - 1]:
        s.pop(i - 1)
        s.pop(i - 1)
        answer = answer + 2

print(answer)

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 main():
    S = input()

    zeroQue = []
    oneQue = []
    sIndex = 0
    out = 0

    for s in S:
        if s == '0':
            if len(oneQue) == 0:
                zeroQue.append(sIndex)
            else:
                out += 2
                oneQue.pop()

        else:
            if len(zeroQue) == 0:
                oneQue.append(sIndex)
            else:
                out += 2
                zeroQue.pop()

        sIndex += 1
    print(out)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
def main():
    cnt_0 = 0
    cnt_1 = 0
    for s in S:
        if s == '0':
            cnt_0 += 1
        if s == '1':
            cnt_1 += 1
    print(min(cnt_0, cnt_1)*2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
stack = []
ans = 0
for i in range(len(s)):
    if len(stack) == 0 or stack[len(stack) - 1] == s[i]:
        stack.append(s[i])
    elif stack[len(stack) - 1] != s[i]:
        stack.pop(len(stack)- 1)
        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:
a = input()

cnt_0 = 0
cnt_1 = 0

for ele in range(len(a)):
    if a[ele] == '1':
        cnt_1 += 1
    else:
        cnt_0 += 1
        
print(2 * min(cnt_0, cnt_1))

Submission status: Accepted

Solution code:
s = list(input())
s = [int(i) for i in s]
count_one = 0
count_zero = 0
for i in s:
    if i == 0:
        count_zero += 1
    else:
        count_one += 1
print(min(count_one, count_zero) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

c = 0
for i in range(len(S)):
    c += int(S[i])

print(2*min(c, len(S) - c))

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()

zeros = 0
ones =  0
for s in S:
    if s == '0':
        zeros += 1
    else:
        ones += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

s = str(input())

one = 0
zero = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
s = list(map(int, input()))
cnt = 0
zero = s.count(0)
one = s.count(1)
print(zero*2 if zero < one else one * 2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    s = input()
    num_zero, num_one = 0, 0
    for i in s:
        if i == "0":
            num_zero += 1
        else:
            num_one += 1
    num_pair = num_zero if num_zero < num_one else num_one

    print(num_pair*2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

count0=0
count1=0
for i in range(N):
  if a[i]==0:
    count0+=1
    
if count0>=N/2:
  print((N-count0)*2)
else:
  print(count0*2)

Submission status: Accepted

Solution code:
S = list(input())
n_0 = S.count("0")
n_1 = S.count("1")

print(2 * min(n_0, n_1))

Submission status: Accepted

Solution code:
a = list(input())

num_0 = a.count("0")
num_1 = a.count("1")
print(len(a) - abs(num_0 - num_1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
s = sys.stdin.read().strip()
n = len(s)
print(2 * min(s.count("0"), s.count("1")))

Submission status: Accepted

Solution code:
"""C - Unification"""
S=list(input())
num0=S.count('0')
num1=len(S)-S.count('0')
print(min(num0,num1)*2)

Submission status: Accepted

Solution code:
"""C - Unification"""
S=list(input())
print(min(S.count('0'),len(S)-S.count('0'))*2)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
count = 0
i = 0
while True:
  if i == n:
    break
  m = s[i:i+2]
  if m == '01' or m == '10':
    s = s[:i] + s[i+2:]
    count += 2
    if i != 0:
      i -= 1
  else:
    i += 1
print(count)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import deque

S = stdin.readline().rstrip()

stack = deque([])
count = 0

for s in S:
    # スタックが空なら
    if not stack:
        stack.append(s)
    # スタックの一番上がsでなければ
    elif stack[-1] != s:
        stack.pop()
        count += 2
    else:
        stack.append(s)

print(count)

Submission status: Accepted

Solution code:
from sys import stdin

S = stdin.readline().rstrip()

stack = []
count = 0

for s in S:
    # スタックが空なら
    if not stack:
        stack.append(s)
    # スタックの一番上がsでなければ
    elif stack[-1] != s:
        stack.pop()
        count += 2
    else:
        stack.append(s)

print(count)

Submission status: Accepted

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

for s in S:
    if s == "0":
        zero +=1
    elif s == "1":
        one += 1

print(min(zero, one) * 2)

Submission status: Accepted

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

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

if count_0 > 0 and count_1 > 0:
    print(2*min(count_0, count_1))
else:
    print(0)

Submission status: Accepted

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

S1 = S.count('1')
S0 = S_len - S1

if S0 < S1:
  print(S0*2)
else:
  print(S1*2)

Submission status: Accepted

Solution code:
S = list(input())

zero_S = S.count('0')
one_S = S.count('1')

print(min(zero_S, one_S) * 2)

Submission status: Accepted

Solution code:
S = list(map(str, input().strip()))
num_of_zero = S.count('0')
num_of_one = S.count('1')
if num_of_zero <=  num_of_one:
    delete_num = 2 * num_of_zero
else:
    delete_num = 2 * num_of_one
print(delete_num)

Submission status: Accepted

Solution code:
def solve(s):
    odd = 0
    even = 0
    for c in s:
        if c == "0":
            even += 1
        else:
            odd += 1
    return 2*min(even, odd)

assert solve("0011") == 4
assert solve("11011010001011") == 12
assert solve("0") == 0

s = input()
print(solve(s))

Submission status: Accepted

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
import re
S = input()

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

Submission status: Accepted

Solution code:
S = input()

zero_cnt = S.count("0")
one_cnt = S.count("1")

print( min(zero_cnt, one_cnt) * 2 )

Submission status: Accepted

Solution code:
import sys

S = list(input())
i = 0
cnt = 0

if len(S) == 1:
    print(0)
    sys.exit()

while True:
    if i == len(S) - 2:
        if S[i] != S[i+1]:
            cnt += 2
        break
    if S[i] != S[i+1]:
        cnt += 2
        S.pop(i)
        S.pop(i)
        if i > 0:
            i -= 1
    else:
        i += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
s = list(input())

cnt = np.empty(2)
for i in range(len(s)):
    cnt[int(s[i]) - 0] += 1
ans = np.min(cnt) * 2
print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
c0, c1 = 0,0
ans = 0
for ch in S:
  if c0 == 0 and ch == '1':
    c1 += 1
  elif c1 == 0 and ch == '0':
    c0 += 1
  elif ch == '1':
    ans += 2
    c0 -= 1
  else:
    ans += 2
    c1 -= 1
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
n_zero = 0
n_one = 0
for i in S:
    if i == '0':
        n_zero += 1
    else:
        n_one += 1
print(min(n_one, n_zero)*2)

Submission status: Accepted

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

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

print(2 * min(one,zero))

Submission status: Accepted

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

Submission status: Accepted

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


def solve(S: str):
    n = len(S)
    while True:
        l = len(S)
        i = 0
        while True:
            if i >= len(S) - 1:
                break
            if S[i] != S[i + 1]:
                S = S[:i] + S[i + 2:]
                i = max(i - 1, 0)
            else:
                i += 1
        if l == len(S):
            break
    print(n - len(S))
    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()
lis = [x for x in S]
Z = lis.count("0")
O = lis.count("1")
print(2*min(Z, O))

Submission status: Accepted

Solution code:
from collections import deque
sin = input()
queue = deque(maxlen=len(sin))
for s in sin:
    if len(queue)>0 and queue[-1] != s:
        queue.pop()
    else:
        queue.append(s)
#print("".join(arr))
print(len(sin)-len(queue))

Submission status: Accepted

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


def solve(s):
    ans = 0
    c = 0
    p = 0

    for v in s:
        if c == 0:
            c += 1
            p = (v == '1')
        elif p ^ (v == '1'):
            ans += 2
            c -= 1
        else:
            c += 1

    return ans



def main():
    s = input()

    print(solve(s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
S = input()
print(2*min(S.count("0"), S.count("1")))

Submission status: Accepted

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

s = input()
n = len(s)
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()

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

print(ans)

Submission status: Accepted

Solution code:
S = input()                                                                     

l = len(S)
stack = []
for i in S:
    if not stack or stack[-1] == i:
        stack.append(i)
    else:
        stack.pop()
print(l - len(stack))

Submission status: Accepted

Solution code:
s = input()
stack = []
r = 0
for c in s:
  n = int(c)
  if len(stack) > 0 and stack[-1] ^ n == 1:
    stack.pop()
    r += 2
  else:
    stack.append(n)
print(r)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(string):
    count = Counter(string)
    return str(min(count.values()) * 2) if len(count.keys()) > 1 else "0"


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
x = input()
l = len(x)
l0 = sum([1 for c in x if c == '1'])
l1 = l - l0
if l1 < l0:
    print(l - l0 + l1)
else:
    print(l - l1 + l0)

Submission status: Accepted

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

red = 0
blue = 0
for i in s:
    if i == '0':
        red += 1
    else:
        blue += 1
if red > blue:
    print(blue * 2)
else:
    print(red * 2)

Submission status: Accepted

Solution code:
#ABK=list(map(int,input().split()))
S=input()

num0=0
num1=0

for i in range(len(S)):
  if S[i]=="0":
   num0=num0+1
  else:
   num1=num1+1

print(min(num0,num1)*2)

Submission status: Accepted

Solution code:
S = list(input())

N = len(S)
index = 0
count = 0
while index < len(S) - 1:
    if S[index] != S[index + 1]:
        del S[index:index + 2]
        index = max(0, index - 1)
        count += 1
    else:
        index += 1

print(2 * count)

Submission status: Accepted

Solution code:
#coding:utf-8

if __name__ == "__main__":
    S = input()
    zero = S.count("0")
    print(2 * min(zero, len(S)-zero))

Submission status: Accepted

Solution code:
a = list(input())
if len(set(a)) == 1:
    print(0)
else:
    c = [0,0]
    for i in a:
        if i == '0':
            c[0] += 1
        else:
            c[1] += 1
    print(min(c) * 2)

Submission status: Accepted

Solution code:

S=input()
x=0
y=0
N = len(S)
for i in range(0,N): # 0,1,2,..., N-1: 
 if S[i]=="0": # S[i]=="0":
       x+=1
 else:
       y+=1

if x>=y:
      print(2*(N-x))
else:
      print(2*(N-y))

#print (S)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	S = input()
	tmp = list(S)
	
	counts = collections.Counter(tmp)
	
	ans = min(counts["0"], counts["1"])
	
	print(ans * 2)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

a = [0,0]
ans = 0
for i in range(len(S)):
  if a[1] == 0 and S[i] == '0':
    a[0] += 1
  elif a[0] == 0 and S[i] == '1':
    a[1] += 1
  elif a[1] > 0 and S[i] == '0':
    ans += 2
    a[1] -= 1
  else:
    ans += 2
    a[0] -= 1
    
print(ans)

Submission status: Accepted

Solution code:
S = raw_input()
count_zeros = sum(1 if x == '0' else 0 for x in S)
print 2 * min(count_zeros, len(S) - count_zeros)

Submission status: Accepted

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

ans = 2 * min(zero, one)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
print("{:d}".format(min(S.count('0'), S.count('1')) * 2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main120():
    import sys
    S_org = input()
    S = []

    for s in range(len(S_org)):
        S.append(S_org[s])
    S = list(map(int, S))

    cont = True
    index = 0
    count = 0

    if len(S) == 1:
        print(0)
        sys.exit()

    else:
        while(cont):
            if S[index] == S[index+1]:
                index += 1
            else:
                count += 2
                S.pop(index)
                S.pop(index)
                if index > 0:
                    index -= 1

            if index == len(S) - 2:
                if S[index] != S[index+1]:
                    count += 2
                print(count)
                sys.exit()


main120()

Submission status: Accepted

Solution code:
S = input()
i = 0
ans = 0
while i < len(S) - 1:
    if S[i] != S[i+1]:
        S = S[:i] + S[i+2:]
        ans += 2
        if i > 0:
            i -= 1
    else:
        i += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
one = s.count("1")
zero = s.count("0")
ans = 0
if one!=0 or zero!=0:
    if one > zero:
        ans = zero * 2
    else:
        ans = one * 2

print(ans)

Submission status: Accepted

Solution code:
str=input()

blue=0
red=0
for color in str:
    if color=="1":
        blue+=1
    else:
        red +=1

print(2*min(blue, red))

Submission status: Accepted

Solution code:
A = list(input())

a_count = 0
b_count = 0
for i in range(len(A)):
    if A[i] == '0':
        a_count += 1
    else:
        b_count += 1
print(min(a_count, b_count) * 2)

Submission status: Accepted

Solution code:
s = input()

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

print(2 * min(one, zero))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(2 * min(cnt0, cnt1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
N=len(S)
c0=0;c1=0
for i in range(N):
  if "0"==S[i]:
    c0=c0+1
  elif "1"==S[i]:
    c1=c1+1
print(str(2*min(c0,c1)))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
L = list(input())
cnt_0 = L.count("0")
cnt_1 = L.count("1")

print(min(cnt_0, cnt_1) * 2)

Submission status: Accepted

Solution code:
L = list(input())
L_ = []
a = L.pop(0)
cnt = 0

while True:
    if len(L) == 0:
        break
    else:
        b = L.pop(0)
    if a is not b:
        cnt += 1
        if len(L_) != 0:
            a = L_.pop()
        elif len(L) == 0:
            break  
        else:
            a = L.pop(0)
    elif a is b:
        L_.append(a)
        a = b
    # print(L_, a,  L)

print(cnt * 2)

Submission status: Accepted

Solution code:
S = input()
red = 0
blue = 0

for i in S:
    if i == "0":
        red += 1
    else:
        blue += 1

print(2*min(red, blue))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list = []
cnt = 0

for i in input():
    if list:
        if list[-1] != i:
            list.pop(-1)
            cnt += 2
        else:
            list.append(i)
    else:
        list.append(i)

print(cnt)

Submission status: Accepted

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

print(min(zero,one)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(min(r, b) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
c = Counter([s_ for s_ in s])
sums = c["0"] + c["1"]
print(sums - (max(c["0"], c["1"]) - min(c["0"], c["1"])))

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

string = input()

red_count  = string.count('0')
blue_count = string.count('1')

print(min(red_count, blue_count) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(input())
red=0
blue=0
for s in S:
    if s=="0":
        red+=1
    elif s=="1":
        blue+=1
print(min(red,blue)*2)

Submission status: Accepted

Solution code:
def solve(s):
    import collections
    l = collections.deque()

    cnt = 0
    for x in map(int,s):
        if len(l) == 0:
            l.append(x)
            continue
        y = l[-1]
        if x + y == 1:
            l.pop()
            cnt += 2
        else:
            l.append(x)

    return cnt


print(solve(input()))

Submission status: Accepted

Solution code:
S = input()

zero = 0
one = 0
for n in S:
  if n == "0":
    zero+=1
  elif n == "1":
    one+=1

print(min(zero,one)*2)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

a = ns()

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

Submission status: Accepted

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

import copy

string = [x for x in input()]

concat_string = copy.copy(string)
num_delete = 0

i = 0
j = 1
not_delete_list = []
while True:
    if j >= len(concat_string) or i < 0:
        break
    if concat_string[i] != concat_string[j]:
        num_delete += 2
        
        if i == 0:
            i = j + 1
            j = i + 1
        else:
            if len(not_delete_list) > 0:
                i = not_delete_list.pop(-1)
                j = j + 1
            else:
                i = j + 1
                j = i + 1
    else:
        not_delete_list.append(i)
        i = j
        j = i + 1


print(num_delete)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
bit_string = raw_input()
  
count_zero = bit_string.count('0')
count_one  = bit_string.count('1')
print((min(count_zero, count_one) * 2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A = input()

C0 = A.count('0')
C1 = A.count('1')
print(2*min(C0,C1))

Submission status: Accepted

Solution code:
A = input()

len0 = lenA = len(A) 
while(True):
    A = A.replace("10","").replace("01","").replace("1"*1000 + "0"*1000,"").replace("0"*1000 + "1"*1000,"")
    if lenA == len(A):
        break
    lenA = len(A)
print(len0 - lenA)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

c = 0
for i in range (0, len(s)):
    if s[i] == "0":
        c += 1

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

Submission status: Accepted

Solution code:
a=input()
print(min(a.count("0"),a.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:
S = input()

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

print(min(num_0, num_1)*2)

Submission status: Accepted

Solution code:
S = list(input())

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