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:
from __future__ import print_function
import numpy as np
import sys

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

cnt=0
S=list(input())
# eprint(S)

L=list()
L.append(S.pop())
while len(S)!=0:
    if S[-1]==L[-1]: # SのfrontとLのfrontが0と0とか一致しちゃった時だから，消せない．次のSのfrontを見よう 
        L.append(S.pop())
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))
    else: # SのfrontとLのfrontが0と1となっている場合．消す．
        S.pop()
        L.pop()
        if L==[] and S!=[]:
            L.append(S.pop())
        cnt=cnt+2
        # eprint("S: " + str(S))
        # eprint("L: " + str(L))

print(cnt)

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

Submission status: Accepted

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

b = 0
r = 0
for i in range(l):
    if S[i] == '0':
        r += 1
    else:
        b += 1

print(min(r,b) * 2)

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
num0 = 0
for i in range(n):
    if s[i]=="0":
        num0 += 1
num1 = n -num0
print(min(num0,num1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

Zero=0
One=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().strip()
o = len([1 for s in S if s == '0'])
print(min(o,len(S)-o)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

stk=[]
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

s = [int(c) for c in s]

c = 0

ss = 0

for i in range(0, len(s)):
    if s[i] == 1:
        if ss < 0:
            c += 2
        ss += 1
    else:
        if ss > 0:
            c += 2
        ss -= 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(min(one,zero)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

if len(S) == 0:
    print(0)

else:
    # 1の数
    s = 0
    for i in range(len(S)):
        s += int(S[i])

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
stack = []
removed = 0
for c in S:
    if len(stack) == 0 or stack[-1] == c:
        stack.append(c)
    else:
        stack.pop()
        removed += 2
print(removed)

Submission status: Accepted

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

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

count0 = 0
count1 = 0
for i, s in enumerate(S):
    if s == '0':
        count0 += 1
    else:
        count1 += 1

ans = min(count0, count1) * 2
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=s.count("0")
e=s.count("1")
print(len(s)-(max(t,e)-min(t,e)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

s = input()
n = len(s)
a = []
i = 0
ct = 0
for i in range(n):
    a.append(int(s[i]))
i = -1

while ct < 100000000000:
    n = len(a)
    i += 1
    if i >= n - 1: break
    if a[i] == 0 and a[i + 1] == 1:
        a.pop(i)
        a.pop(i)
        ct += 1
        i -= 2
        if i <= 1: i = -1
        continue
    elif a[i] == 1 and a[i + 1] == 0:
        a.pop(i)
        a.pop(i)
        ct += 1
        i -= 2
        if i <= 1: i = -1

print(ct * 2)

Submission status: Accepted

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

Submission status: Accepted

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

print(N - abs(S.count('0') - S.count('1')))

Submission status: Accepted

Solution code:
s = input()

red=0
blue=0

for c in s:
    if c == "0":
        red += 1
    else:
        blue += 1

print(min(red, blue) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = str(input())


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

Submission status: Accepted

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

import numpy as np

#input
#[H,W] = list(map(int,input().split()))
#[h,w] = list(map(int,input().split()))
#
#print((H-h)*(W-w))


#[N, M] = list(map(int,input().split()))
# s = str(input())

#[A, B, K] = list(map(int,input().split()))

s = str(input())

num_0 = 0

for i in range(len(s)):
    if s[i] == "1":
        num_0 += 1
    
num_1 = len(s) - num_0
print(len(s) - abs(num_0 - num_1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())
a = s.count("1")
b = s.count("0")
if a == b:
    print(2*a)
elif a > b:
    print(2*b)
elif a < b:
    print(2*a)

Submission status: Accepted

Solution code:
# C - Unification
# https://atcoder.jp/contests/abc120/tasks/abc120_c
S = raw_input()

num1 = 0
num0 = 0

for s in S:
    if s == '1':
        num1 += 1
    else:
        num0 += 1

print '{}'.format(2*min(num0, num1))

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:
hoge=input()
print(2*min(hoge.count("1"),hoge.count("0")))

Submission status: Accepted

Solution code:
S = str(input())

C0, C1 = 0, 0
for i in S:
    if i == "0":
        C0 += 1
    else:
        C1 += 1
mini = min(C0, C1)
print(2 * mini)

Submission status: Accepted

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

slen = len(s)
start = 0
count = 0

while True:
    for i in range(start, slen - 1):
        if slist[i] != slist[i+1]:
            slist.pop(i)
            slist.pop(i)
            slen -= 2
            start = max(0, i - 1)
            count += 2
            break
    else:
        break


print(count)

Submission status: Accepted

Solution code:
S = list(input())

red = 0
blue = 0
for i in range(len(S)):
    if S[i] is '0':
        red += 1
    else:
        blue += 1
n = min(red, blue)
print(n*2)

Submission status: Accepted

Solution code:
s = input()
count0 = 0
count1 = 0
for i in range(len(s)):
    if s[i] == '0':
        count0 += 1
    elif s[i] == '1':
        count1 += 1

print(2 * min(count0, count1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

zero = 0
one = 0
for s in S:
    if s == '0':
        zero += 1
    if s == '1':
        one += 1
    
print(len(S) - abs(zero - one))

Submission status: Accepted

Solution code:
s = input()

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

S = list(S)
ones = S.count("1")
zeors = S.count("0")

print(min(ones, zeors) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

a = min(zero, one)

print(2 * a)

Submission status: Accepted

Solution code:
S = list(input())

prev = ""
index = 0
ans = 0
while index < len(S):
#    print("index[{}] S[{}]".format(index, S))
    if prev == "":
        prev = S[index]
        index = index + 1
        continue

    if S[index] != prev:
        S.pop(index)
        S.pop(index - 1)
        ans = ans + 2
        if len(S) == 0:
            break

        index = index - 2 if index - 2 > 0 else 0
        prev = ""

    else:
        prev = S[index]
        index = index + 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
s = [int(i) for i in input()]
array = np.array(s)
zero = np.sum(array==0)
one = np.sum(array==1)
print(2*min(zero,one))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

C0 = S.count("0")
C1 = S.count("1")

print(2*min(C0,C1))

Submission status: Accepted

Solution code:
s=input()
a_1=s.count("1")
b_1=s.count("0")
if a_1<=b_1:
  print(2*a_1)
else:
  print(2*b_1)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
num_zero = 0
for c in S:
    if c=='0':
        num_zero += 1
print(min(num_zero, N-num_zero)*2)

Submission status: Accepted

Solution code:
s=input()
a_1=s.count("1")
b_1=s.count("0")
if a_1<=b_1:
  print(2*a_1)
else:
  print(2*b_1)

Submission status: Accepted

Solution code:
S = str(input())

s = S

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

zero_one_diff = max(zero, one) - min(zero, one)
print(len(s) - zero_one_diff)

Submission status: Accepted

Solution code:
s = input()

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

print(2 * min(zero, one))

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(len(s) - abs(a - b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
red_count = S.count("0")
ao_count = S.count("1")
if red_count > ao_count:
    print(ao_count * 2)
elif red_count < ao_count:
    print(red_count * 2)
else:
    print(red_count + ao_count)

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

remove_count = 0
# while(True) :
#     S = S.replace("10","X").replace("01","X")
#     current_count = S.count("X")
#     if (current_count == 0) :
#         break
#     remove_count += current_count
#     S = S.replace("X","")
# print(remove_count * 2)
print(min(S.count("1"), S.count("0") )* 2)

Submission status: Accepted

Solution code:
S = input()

redcount = S.count('0')
bluecount = S.count('1')

mincount = min(redcount,bluecount)
answer = mincount*2

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from collections import Counter

stdout_write = sys.stdout.write

for line in sys.stdin:
  s = Counter(list(line.strip()))
  ans = 2 * min(s['0'], s['1'])
  stdout_write('{}\n'.format(ans))

Submission status: Accepted

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

c = min(a,b)

print(2 * c)

Submission status: Accepted

Solution code:
n = list(str(input()))
a = 0
b = 0
for i in n:
    if i == "1":
        a += 1
    else:
        b += 1

c = min(a,b)

print(2 * c)

Submission status: Accepted

Solution code:
S = str(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = raw_input()
S = str(S)

S_1 = int(S.count('1'))
S_0 = int(S.count('0'))

if S_1 > S_0:
    print S_0 * 2
else:
    print S_1 * 2

Submission status: Accepted

Solution code:
S = input()
num_length = len(S)
counter_0 = 0
counter_1 = 0
for i in range(num_length):
    if S[i] == '0':
        counter_0 += 1
    if S[i] == '1':
        counter_1 += 1
if counter_0 <= counter_1:
    print(2*counter_0)
else:
    print(2*counter_1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(raw_input())
c0 = s.count('0')
c1 = len(s) - c0
print 2 * min(c0, c1)

Submission status: Accepted

Solution code:
S = str(input())

zero_num = S.count("0")

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

Submission status: Accepted

Solution code:
S = str(input())

zero_num = 0

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

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

Submission status: Accepted

Solution code:
S = str(input())

zero_num = 0
one_num = 0

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

print(2*min(zero_num, one_num))

Submission status: Accepted

Solution code:
S = input()

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

ans = min(a,b)
print(2*ans)

Submission status: Accepted

Solution code:
s = str(input())
cntz = 0
cnto = 0
for i in s:
    if i == '0':
        cntz += 1
    elif i == '1':
        cnto += 1
ans = 2*min(cnto,cntz)
print(ans)

Submission status: Accepted

Solution code:
S = input()

red = S.count('0')
blue = S.count('1')
N = 2 * min(red,blue)

print(N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	else: return y

S = raw_input()
count = [0, 0]
for i in range(0, len(S)):
	count[int(S[i])] += 1

print smaller(count[0], count[1])*2

Submission status: Accepted

Solution code:
s = input()

_1 = s.count("1")
_0 = s.count("0")

m = min(_1, _0)

print(m*2)

Submission status: Accepted

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


def solve(S: str):
    c0 = 0
    c1 = 0
    for c in S:
        if c == "0":
            c0 += 1
        else:
            c1 += 1
    print(min(c0,c1) * 2)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(s):
    pos_num, neg_num = 0, 0
    for string in s:
        if string == "1":
            pos_num += 1
        else:
            neg_num += 1

    return 2 * min(pos_num, neg_num)


def main():
    s = input()

    ans = solve(s)
    print(ans)


main()

Submission status: Accepted

Solution code:
S = list(input())

#print(S)

Red = S.count("0")
Blue = S.count("1")

#print(Red,Blue)

if Red > Blue:
    result = Blue*2
else:
    result = Red*2

print(result)

Submission status: Accepted

Solution code:
s = input()

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

print(min(cnt1,cnt2)*2)

Submission status: Accepted

Solution code:
s = input()

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

print(2 * (r if r < b else b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = str(input())

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

print(len(s) - abs(a-b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(min(cnt0,cnt1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
count0 = 0
count1 = 0
for c in S:
    if c == "0":
        count0 += 1
    else:
        count1 += 1
print(N - abs(count0 - count1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

print(min(red, blue)*2)

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    S = input()

    ans = 0
    i = 0
    while i != len(S):
        if i+1 >= len(S):
            break

        if S[i] != S[i+1]:
            # 消す
            if i == 0:
                if len(S) <= 2:
                    ans += 1
                    S = ""
                    continue
                else:
                    ans += 1
                    S = S[2:]
                    continue
            else:
                if i+2 < len(S):
                    ans += 1
                    S = S[:i] + S[i+2:]
                    i -= 1
                    continue
                else:
                    ans += 1
                    S = S[:i]
                    i -= 1
                    continue
            
        i += 1
    print(ans*2)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
s = input()
r, b = 0, 0
for c in s:
    if c == '0':
        r += 1
    else:
        b += 1
print(len(s) - abs(r-b))

Submission status: Accepted

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

Submission status: Accepted

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

tmp_i = 0
while len(S) > 1:
    no_01 = True
    before_s = None
    for i, s in enumerate(S[tmp_i:]):
        if i == 0:
            before_s = s
            continue
        if before_s != s:
            no_01 = False
            # print(S[:tmp_i + i-1], '(', S[tmp_i + i - 1], ' | ', S[tmp_i + i],  ')', S[tmp_i + i+1:])
            newS = S[:tmp_i + i-1] + S[tmp_i + i+1:]
            S = newS
            # print('newS: ', newS)
            tmp_i = tmp_i + i - 2
            if tmp_i < 0:
                tmp_i = 0
            # print(tmp_i)
            break
    if no_01:
        break
print(init_count - len(S))

Submission status: Accepted

Solution code:
S = input()

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

print(2*(min(red, blue)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N, counter_zero, counter_one = len(S), 0, 0
for i in range(N):
    if S[i:i+1] == '0':
        counter_zero += 1
    elif S[i:i+1] == '1':
        counter_one += 1
ans = 2 * min(counter_zero, counter_one)
print(ans)

Submission status: Accepted

Solution code:
S = input()

counts = [0, 0]
for s in S:
    counts[int(s)] += 1
print(2 * min(counts))

Submission status: Accepted

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

print(len(S)-abs(S.count(0)-S.count(1)))

Submission status: Accepted

Solution code:
string = input()

zeros = string.count('0')
ones = string.count('1')

print(min(zeros,ones)*2)

Submission status: Accepted

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

Submission status: Accepted

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

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()
a = s.count('0')
b = s.count('1')
c = abs(a - b)
print(len(s) - c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

# 0の数
zero = S.count('0')
one = S.count('1')
print(2 * min([zero,one]))

Submission status: Accepted

Solution code:
S = list(input())
one_num = S.count('1')
zero_num = S.count('0')

if one_num == zero_num:
    print(len(S))
else:
    print(len(S) - abs(one_num - zero_num))

Submission status: Accepted

Solution code:
from collections import Counter
c=Counter(input())
l=c.most_common()
print(l[1][1]*2 if len(l) == 2 else 0)

Submission status: Accepted

Solution code:
ss = list(input())

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

print(cnt)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    n = len(s)
    d = deque([s[0]])
    l = deque()
    for i in range(1,n):
        if d[0] != s[i]:
            l.append(d)
            d = deque(s[i])
        else:
            d.append(s[i])
    if d:l.append(d)
    while len(l) > 1:
        x = l.popleft()
        y = l.popleft()
        if x[0] == y[0]:
            for i in range(len(y)):
                x.append(y[0])
            l.appendleft(x)
        else:
            if len(x) == len(y):continue
            if len(x) > len(y):
                for i in range(len(y)):
                    x.pop()
                l.appendleft(x)
            else:
                for i in range(len(x)):
                    y.pop()
                l.appendleft(y)
    if l:
        ans = n-len(l[0])
    else:
        ans = n
    print(ans)
    return

#B
def B():
    n = I()
    h = LI()
    ans = 0
    s = deque()
    k = []
    for i in range(n):
        if h[i] == 0:
            if k:s.append(k)
            k = []
        else:k.append(h[i])
    if k:s.append(k)
    while s:
        k = s.popleft()
        if k == []:continue
        m = min(k)
        ans += m
        for i in range(len(k)):
            k[i] -= m
        l = []
        for i in range(len(k)):
            if k[i] == 0:
                if l:s.append(l)
                l = []
            else:l.append(k[i])
        if l:s.append(l)
    print(ans)
    return

#C
def C():
    n,k = LI()
    x = LI()
    ans = float("inf")
    j = bisect.bisect_left(x,0)
    if n == 1:
        print(abs(x[0]))
        quit()
    if j < n:
        if x[j] == 0:
            k -= 1
            x.pop(j)
            n -= 1
    for i in range(n):
        if i < j:
            if abs(i-j) > k:continue
            elif abs(i-j) == k:ans = min(ans,abs(x[i]))
            elif k+i-1 < n:
                ans = min(ans,abs(x[i])+x[k+i-1]-x[i])
        else:
            if abs(i-j)+1 > k:continue
            elif abs(i-j)+1 == k:ans = min(ans,x[i])
            elif i-k+1 >= 0:
                ans = min(ans,abs(x[i])+x[i]-x[i-k+1])

    print(ans)
    return

#D
def D():
    n = I()
    a = LI()
    ans = 0
    p = [1<<i for i in range(100)]
    for i in range(n):
        l = 0
        r = 100
        while r-l > 1:
            m = (l+r)//2
            if a[i]%p[m] == 0:
                l = m
            else:
                r = m
        ans += l
    print(ans)
    return

#E
def E():
    s = LI()
    s.sort()
    ans = s[2]-s[1]
    s[0] += s[2]-s[1]
    s[1] = s[2]
    if s[0]%2 != s[1]%2:
        ans += (s[1]+1-s[0])//2+1
    else:
        ans += (s[1]-s[0])//2
    print(ans)
    return

#F
def F():
    n = I()
    s = SR(n)
    for i in range(n):
        d = defaultdict(int)
        for j in range(len(s[i])):
            d[s[i][j]] += 1
            s[i][j] += str(d[s[i][j]])
    ans = set(s[0])
    for i in range(1,n):
        ans = ans&set(s[i])
    ans = list(ans)
    ans.sort()
    for i in ans:
        print(i[0],end = "")
    print()
    return

#G
def G():
    s = S()
    ans = 0
    for i in range(len(s)-1):
        if s[i] != s[i+1]:ans += 1
    print(ans)
    return

#H
def H():
    n,q = LI()
    ans = [0 for i in range(n+1)]
    for i in range(q):
        l,r = LI()
        ans[l-1] ^= 1
        ans[r] ^= 1
    for i in range(n):
        ans[i+1] ^= ans[i]
        print(ans[i],end = "")
    print()
    return

#I
def I_():
    n = I()
    a = LI()
    ans = 0
    r = 0
    for l in range(n):
        while r < n-1 and a[r+1] > a[r]:
            r += 1
        ans += r-l+1
        if l==r:r += 1
    print(ans)
    return

#J
def J():
    n = I()
    h = LI()
    dp = [float("inf") for i in range(n)]
    dp[0] = 0
    for i in range(n-1):
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
        if i < n-2:
            dp[i+2] =  min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
    print(dp[n-1])
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

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

s = input()

z = s.count("0")
o = s.count("1")

print(2*min(z,o))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    c = s.count("0")
    print(2*min(c,len(s)-c))
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Accepted

Solution code:
s = input()
red = s.count('0')
blue = s.count('1')
print((red if red < blue else blue)*2)

Submission status: Accepted

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

S2 = S[0]
count = 0
for i in range(1,N):
    S2 += S[i]
    while len(S2) > 1 and S2[len(S2)-1] != S2[len(S2)-2] :
        S2 = S2[:len(S2)-2]
        count += 2
        
print(count)

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()
zero  = 0
one   = 0
for i in S:
  if i == '0':
    zero = zero+1
  else:
    one = one + 1
print(min(one,zero)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
i = 0
total = 0
while i < len(S):
    if S[i:i+2] == '01'or S[i:i+2] == '10':
        Sa = S[:i]
        Sb = S[i+2:]
        S = Sa+Sb
        total += 1
        i -= 1
    else:
        i += 1
print(total*2)

Submission status: Accepted

Solution code:
S = input()
A = S.count('0')
B = len(S) - A
if A > B:
    print(2*B)
elif B > A:
    print(2*A)
else:
    print(A+B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
C1 = 0
C0 = 0
for i in range(len(S)):
    if S[i] == '1':
        C1 +=1
    if S[i] == '0':
        C0 +=1

print(min(C0,C1)*2)

Submission status: Accepted

Solution code:
S = input()

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

print(2 * min(zero, one))

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'), S.count('1'))*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

zeroNum = S.count('0')
oneNum = S.count('1')

print(min(zeroNum,oneNum)*2)

Submission status: Accepted

Solution code:
a=input()
count=0
for i in a:
  if i=='0':
    count+=1
  else:
    count-=1
print(len(a)-abs(count))