AtCoder Beginner Contest 120 - Unification

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-----
0011

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


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


A = list(input())
ans = 0
print(2 * min(A.count('0'), A.count('1')))


s = input()
l = list(s)
a = l.count('0')
b = l.count('1')
ans = 2 * min(a, b)
print(ans)


s = input()
zero = 0
one = 0
for i in s:
	if i == '0':
		zero += 1
	else:
		one += 1
ans = min(one, zero)
print(ans << 1)


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


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


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


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


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


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


S = input()
c0 = 0
c1 = 0
for i in range(len(S)):
	if S[i] == '0':
		c0 += 1
	else:
		c1 += 1
ans = len(S) - abs(c0 - c1)
print(ans)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	S = readline().strip()
	red = S.count('0')
	blue = len(S) - red
	print(min(red, blue) * 2)
	return

def __starting_point():
	main()
__starting_point()


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


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


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


S = str(input())
print(len(S) - abs(S.count('0') - S.count('1')))


from collections import Counter
import sys
S = input()
c = Counter(S)
print(len(S) - abs(c['0'] - c['1']))


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


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


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


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

def __starting_point():
	main2()
__starting_point()


N = str(input())
one = N.count('1')
zero = N.count('0')
print(min(one, zero) * 2)


s = list(input())
t = len(s)
a = s.count('0')
b = t - a
print(min(a, b) * 2)


n = input()
b = n.count('0')
print(min(b, len(n) - b) * 2)


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


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
s = ns()
n = len(s)
b = s.count('0')
r = n - b
print(2 * min(b, r))


S = input()
a = S.count('0')
b = S.count('1')
print(len(S) - abs(a - b))


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


s = str(input())
a = s.count('0')
print(min(a, len(s) - a) * 2)


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


S = input()
cnt_0 = S.count('0')
min_cnt_01 = min(cnt_0, len(S) - cnt_0)
print(min_cnt_01 * 2)


print(2 * min(list(map(input().count, '10'))))


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


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


S = input()
z = S.count('0')
o = S.count('1')
print(len(S) - abs(z - o))


a = list(input())
temp1 = 0
temp0 = 0
for i in range(len(a)):
	if a[i] == '0':
		temp0 += 1
	else:
		temp1 += 1
print(min(temp0, temp1) * 2)


s = input()
k0 = s.count('0')
k1 = s.count('1')
print(2 * min(k0, k1))


s = input()
a = s.count('0')
b = len(s) - a
print(min(a, b) * 2)


s = input()
red = s.count('0')
blue = s.count('1')
print(min(red, blue) * 2)


S = str(input())
x = len(S)
if '0' in S:
	y0 = S.count('0')
else:
	y0 = 0
if '1' in S:
	y1 = S.count('1')
else:
	y1 = 0
d = abs(y0 - y1)
print(x - d)


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


s = input()
o = s.count('1')
z = s.count('0')
print(2 * min(o, z))


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


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


S = list(input())
a = S.count('0')
print(min(a, len(S) - a) * 2)


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


s = input()
n = len(s)
c = s.count('1')
print(2 * min(c, n - c))


s = input()
r = s.count('0')
b = s.count('1')
print(min(r, b) * 2)


s = input()
zero = s.count('0')
one = s.count('1')
print(min(zero, one) * 2)


S = input()
s_lis = list(S)
r_cout = s_lis.count('1')
w_cout = s_lis.count('0')
print(2 * min(r_cout, w_cout))


import sys
input = sys.stdin.readline

def main():
	S = input().rstrip()
	stack = []
	count = 0
	if S == '0':
		print('0')
		return
	for s in S:
		if len(stack) == 0:
			stack.append(str(s))
		elif s != stack[-1]:
			count += 1
			stack.pop()
		else:
			stack.append(str(s))
	print(2 * count)

def __starting_point():
	main()
__starting_point()


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


import collections
S = list(str(input()))
cc = collections.Counter(S)
ans = min(cc['0'], cc['1'])
print(ans * 2)


a = list(input())
count = 0
num = 0
while a != []:
	if num == -1:
		num += 1
		continue
	if num == len(a) or len(a) == 1 or (num == len(a) - 1 and a[-1] == a[-2]):
		break
	if a[num] == '0' and a[num + 1] == '1' or (a[num] == '1' and a[num + 1] == '0'):
		a.pop(num)
		a.pop(num)
		count += 2
		num -= 1
	else:
		num += 1
print(count)


S = input()
z = 0
o = 0
for c in S:
	if c == '0':
		z += 1
	else:
		o += 1
print(min([z, o]) * 2)


s = input()
print(min((s.count(c) for c in '01')) * 2)


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)


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


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


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


s = input()
n = len(s)
S = s.count('0')
print(n - abs(S - n + S))


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


S = input()
c = S.count('0')
l = len(S)
print(l - abs(c - (l - c)))


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


s = input()
ans = s.count('0')
print(min(ans, len(s) - ans) * 2)


s = [c for c in input()]
print(min(s.count('0'), s.count('1')) * 2)


from collections import Counter

def main():
	S = input()
	cs = Counter(S)
	ans = min(cs['0'], cs['1']) * 2
	print(ans)

def __starting_point():
	main()
__starting_point()


S = input()
a = S.count('0')
b = len(S) - a
print(min(a, b) * 2)


s = list(input())
n = len(s)
t = []
while s:
	c = s.pop()
	if t and t[-1] != c:
		t.pop()
	else:
		t.append(c)
print(n - len(t))


s = input()
n = len(s)
a = s.count('1')
b = s.count('0')
if a >= b:
	print(b * 2)
else:
	print(a * 2)


n = input()
print(len(n) - abs(n.count('1') - n.count('0')))


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


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


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


s = input()
z = s.count('0')
o = s.count('1')
print(len(s) - abs(z - o))


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


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


s = input()
n0 = s.count('0')
print(2 * min(n0, len(s) - n0))


s = list(map(int, input()))
print(min(len(s) - sum(s), sum(s)) * 2)


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


S = input()
N = len(S)
cnt = 0
for s in S:
	if s == '0':
		cnt += 1
print(2 * min(cnt, N - cnt))


S = input()
List = list(S)
zeroNum = List.count('0')
oneNum = List.count('1')
res = min(zeroNum, oneNum)
print(res * 2)


s = input()
c = s.count('0')
print(2 * min(c, len(s) - c))


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


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


s = input()
x = s.count('0')
print(2 * min(x, len(s) - x))


S = list(input())
N = len(S)
len0 = S.count('0')
len1 = S.count('1')
rm = min(len0, len1)
print(2 * rm)


from collections import deque
S = input()
d = deque()
cnt = 0
for s in S:
	if d:
		if d[-1] != s:
			d.pop()
			cnt += 2
		else:
			d.append(s)
	else:
		d.append(s)
print(cnt)


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


s = input()
z = s.count('0')
print(min(z, len(s) - z) * 2)


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


S = list(input())
print(len(S) - abs(S.count('0') - S.count('1')))


from collections import Counter
num_dict = Counter(input())
if num_dict.get('0') is not None and num_dict.get('1') is not None:
	if num_dict.get('0') > num_dict.get('1'):
		print(num_dict.get('1') * 2)
	else:
		print(num_dict.get('0') * 2)
else:
	print(0)


S = input()
d = [0, 0]
for i in S:
	d[int(i)] += 1
print(min(d) * 2)


S = input()
n = S.count('1')
print(2 * min(n, len(S) - n))


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


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


S = input()
o = 0
i = 0
for j in S:
	if j == '0':
		o += 1
	else:
		i += 1
print(min(o, i) * 2)


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


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


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


s = input()
r = s.count('0')
print(min(r, len(s) - r) * 2)


S = input()
na = S.count('0')
nb = len(S) - na
print(min(na, nb) * 2)


s = input()
from collections import Counter
count = Counter(s)
c0 = count['0']
c1 = count['1']
print(min(c0, c1) * 2)


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


S = list(map(int, list(input())))
N = len(S)
cnt = [0, 0]
for i in S:
	cnt[i] += 1
print(2 * min(cnt))


s = input()
s0 = s.count('0')
s1 = s.count('1')
print(min(s0, s1) * 2)


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


s = list(input())
length = len(s)
r = s.count('0')
b = s.count('1')
print(length - abs(r - b))


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


from collections import Counter
S = str(input())
c = Counter(S)
d = c.most_common()
if len(d) == 2:
	ans = d[1][1] * 2
	print(ans)
else:
	print(0)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LS():
	return input().split()

def resolve():
	S = SS()
	ans = 0
	stk = []
	for i in S:
		if stk and stk[-1] != i:
			stk.pop()
			ans += 2
		else:
			stk.append(i)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


s = input()
n = len(s)
cnt_r = 0
cnt_b = 0
for c in s:
	if c == '0':
		cnt_r += 1
cnt_b = n - cnt_r
print(2 * min(cnt_r, cnt_b))


S = input()
zero = S.count('0')
one = S.count('1')
if zero != 0 and one != 0:
	print(min(zero, one) * 2)
else:
	print(0)


S = str(input())
zero = S.count('0')
one = S.count('1')
ans = min(zero, one)
print(ans * 2)


s = input()
a = s.count('1')
print(2 * min(a, len(s) - a))


import collections
s = list(map(str, input()))
ans = 0
a = collections.Counter(s)
if len(a) == 1:
	print(0)
else:
	print(min(a.values()) * 2)


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


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


S = input()
zero_count = S.count('0')
one_count = S.count('1')
ans = 2 * min(int(zero_count), int(one_count))
print(ans)


S = list(map(int, input()))
N = len(S)
x = sum(S)
print(2 * min(x, N - x))


import os
import sys

def main():
	S = input()
	if S.count('0') < S.count('1'):
		print(S.count('0') * 2)
	else:
		print(S.count('1') * 2)

def __starting_point():
	main()
__starting_point()


s = input()
red = 0
blue = 0
for i in s:
	if i == '0':
		red += 1
	else:
		blue += 1
print(red + blue - abs(red - blue))


s = input()
r = s.count('0')
b = s.count('1')
print(r + b - abs(r - b))


L = input()
A = L.count('0')
B = L.count('1')
print(2 * min(A, B))


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


b = input()
A = b.count('1')
B = b.count('0')
print(min(2 * A, 2 * B))


l = list(input())
a = l.count('0')
b = l.count('1')
print(min(a, b) * 2)


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


import math
from collections import Counter
s = list(input())
s = list(map(int, s))
dict_s = Counter(s)
print(min(dict_s[0], dict_s[1]) * 2)


S = list(input())[::-1]
que = []
N = len(S)
ans = 0
while len(S) > 0:
	que.append(S.pop(-1))
	if len(que) > 1:
		if que[-1] == '1' and que[-2] == '0' or (que[-1] == '0' and que[-2] == '1'):
			que.pop(-1)
			que.pop(-1)
			ans += 2
print(ans)


S = input()
a = S.count('1')
print(2 * min(a, len(S) - a))


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


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


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


s = input()
num = s.count('0')
print(2 * min(num, len(s) - num))


import sys
cubes = list(input())
stack = []
count = 0
for cube in cubes:
	if not stack:
		stack.append(cube)
	elif stack[-1] != cube:
		count += 2
		stack.pop()
	else:
		stack.append(cube)
print(count)