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 collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  s = input()
  if len(set(s)) == 1:
    print(0)
    sys.exit()
  a = Counter(s)
  ans = min(a.values()) * 2
  print(ans)
  
if __name__ == '__main__':
  main()

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

# while True:
#     flag = 1
#     for i, c in enumerate(S):
#         if pre == '':
#             pre = c
#             continue

#         if (pre == '1' and c == '0') or (pre == '0' and c == '1'):
#             if i + 1 != len(S):
#                 S = S[:i - 1] + S[i + 1:]
#             else:
#                 S = S[:i - 1]
#             ans += 2
#             flag = 0
#             break
#         pre = c
#     if flag:
#         break
a = S.count("1")
b = S.count("0")
print(min(a, b) * 2)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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 = input()
t = s.count('1')
u = s.count('0')
print(min(t,u)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = input() # 入力が1つ
# map(int, input().split()) # 入力が複数
one = 0
zero = 0
for i in s:
    if i == '1':
        one += 1
    elif i == '0':
        zero += 1
print(min(one, zero) * 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()

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

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))
 
 
S = input()
print(min(S.count('0'), S.count('1')) * 2)

Submission status: Accepted

Solution code:
import collections
s_list = list(input())
s_counter = collections.Counter(s_list)
print(2 * min(s_counter["0"], s_counter["1"]))

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

Solution code:
n_list = list(input())
n_len_o = len(n_list)
a = 0
while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(a,n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      if i != 0:
        a = i - 1
      else:
        a = 0
      flag = "ok"
      break
  if flag == "ng":
    break
print(n_len_o-len(n_list))

Submission status: Accepted

Solution code:
S = list(input())

blue = S.count('1')
red = len(S) - blue

n = min(blue,red)

print(n * 2)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
blue = s.count('1')
red = n - blue
print(2 * min(blue, red))

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
l = len(s)
c = s.count("0")
print(2*min(c,l-c))

Submission status: Accepted

Solution code:
s=sorted(list(input()))
if s[0]==s[-1]:
  print(0)
else:
  a=s.index('1')
  print(2*min(a,len(s)-a))

Submission status: Accepted

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())
    z = S.count('0')
    i = S.count('1')
    print(min(z, i) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s=input()

n=len(s)
z1=s.count("0")
z2=n-z1

print(n-abs(z1-z2))

Submission status: Accepted

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

Submission status: Accepted

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

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 = list(input())
a = s.count('0')
b = s.count('1')
print(len(s) - (max(a,b)-min(a,b)))

Submission status: Accepted

Solution code:
S = input()
x = len(S)
i = S.count('0')
k = x-i 
if i >= k:
    print(k*2)
else:
    print(i*2)

Submission status: Accepted

Solution code:
def main():
    s = input()

    c0 = s.count('0')
    c1 = s.count('1')

    print(min(c0, c1)*2)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

c0 = s.count('0')
c1 = s.count('1')

print(min(c0, c1)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
S = str(input())
SC = Counter(S)
v,c = zip(*SC.most_common())
if len(c) == 2:
  print(len(S) - abs(c[1]-c[0]))
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
ss=[]
for i in s:
    if len(ss)==0:
        ss.append(i)
    else:
        if i!=ss[-1]:
            ss.pop()
        else:
            ss.append(i)
print(len(s)-len(ss))

Submission status: Accepted

Solution code:
S = list(input())
for _ in range(len(S)):
    S[_] = int(S[_])

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

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

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

S = input()
stack = []
for c in S:
    stack.append(c)
    while len(stack) >= 2 and stack[-1] != stack[-2]:
        del stack[-2:]
print(len(S) - len(stack))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

stack = []

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    z, o = 0, 0
    for i in range(len(S)):
        if S[i] == "0": z += 1
        else: o += 1
    print(2 * min(z, o))
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

Submission status: Accepted

Solution code:
S = list(input())
now = 0
ans = 0
while now < len(S) - 1:
    if S[now] != S[now + 1]:
        for _ in range(2):
            S.pop(now)
        now = max(0, now - 1)
        ans += 2
    else:
        now += 1
print(ans)

Submission status: Accepted

Solution code:
S = input()

zero = 0
one = 0
ret = 0
for s in S:
    if s == "0":
        if one > 0:
            ret += 2
            one -= 1
        else:
            zero += 1
    elif s == "1":
        if zero > 0:
            ret += 2
            zero -= 1
        else:
            one += 1

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

S = input()
#N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = list(map(int, input().split()))

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

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

Submission status: Accepted

Solution code:
# Problem C - Unification

# input
S = list(input())

# initialization
zero_count = 0
one_count = 0

# count
for s in S:
    if s=='0':
        zero_count += 1
    else:
        one_count += 1

# output
if zero_count==0 or one_count==0:
    print(0)
elif zero_count>=one_count:
    print(one_count * 2)
else:
    print(zero_count * 2)

Submission status: Accepted

Solution code:
S = input()
red = S.count("0")
blue = S.count("1")
print(red + blue if red == blue else min(red, blue) * 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

s = input().rstrip()
n = len(s)
zero = s.count("0")
one = s.count("1")
print(n - max(zero, one) + min(zero, one))

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
s = input()

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

Submission status: Accepted

Solution code:
s = str(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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
S = input()
n = len(S)
red = S.count("0")
blue = n - red
print(n if red == blue else min(red, blue) * 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=list(input())
x=len(s)
from collections import deque
d=deque()

for i in s:
    if len(d)==0:
        d.append(i)
    elif d[-1]!=i:
        d.pop()
    elif d[-1]==i:
        d.append(i)

print(x-len(d))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem C - Unification

# input
S = list(input())

# initialization
zero_num = 0
one_num = 0

# count
for s in S:
    if s=='0':
        zero_num += 1
    else:
        one_num += 1

# output
if not zero_num>0 or not one_num>0:
    print(0)
else:
    min_ans = min(zero_num, one_num)
    print(min_ans * 2)

Submission status: Accepted

Solution code:
s=str(input())
n=len(s)
b=s.count('0')
A=[b,n-b]
print(2*min(A))

Submission status: Accepted

Solution code:
s=str(input())
n=len(s)
b=s.count('0')
A=[b,n-b]
print(min(A)+min(A))

Submission status: Accepted

Solution code:
r = 0
b = 0
for a in input():
    if a == '0':
        r += 1
    else:
        b += 1

print(min(r, b)*2)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    zero, one = 0, 0
    for i in range(len(S)):
        if S[i] == "0": zero += 1
        else: one += 1
    print(2 * min(zero, one))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = list(ns())
a = min(s.count('0'),s.count('1'))

print(a*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

S = input()
#N = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = A = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
S = [int(i) for i in list(input())]
s = ["", ""]
c = 0
for v in S:
    s.append(v)
    # print(s)
    if (s[-1], s[-2])==(0, 1) or (s[-1], s[-2])==(1, 0):
        s.pop()
        s.pop()
        c += 2

print(c)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = [int(i) * 2 - 1 for i in STR()]
ss = abs(sum(s))
l = len(s)
ans = (l - ss) // 2
print(ans * 2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
class Node:
    def __init__(self, num: str):
        self.num = num
        self.before = None
        self.next = None
    
class Linked_List:
    def __init__(self):
        self.head = None
        self.tail = None
    
    def append(self, node):
        if self.head is None:
            self.head = node
            self.tail = node
        else:
            node.before = self.tail
            self.tail.next = node
            self.tail = node

    def check(self):
        node = self.tail
        ans = 0
        while not node is self.head:
            before_node = node.before
            if node.num != before_node.num:
                ans += 2
                if before_node is self.head:
                    break
                elif node is self.tail:
                    before_node.before.next = None
                    self.tail = before_node.before
                    node = before_node.before
                else:
                    before_node.before.next = node.next
                    node.next.before = before_node.before
                    node = node.next
            else:
                node = node.before
        print(ans)

S = list(input())
cube = Linked_List()

for c in S:
    node = Node(c)
    cube.append(node)

cube.check()

Submission status: Accepted

Solution code:
# Problem C - Unification

# input
s = input()

# initialization
zero_count = 0
one_count = 0

# count
for i in range(len(s)):
    if s[i]=='0':
        zero_count += 1
    else:
        one_count += 1

# output
if zero_count>0 and one_count>0:
    if zero_count>=one_count:
        print(one_count*2)
    else:
        print(zero_count*2)
else:
    print(0)

Submission status: Accepted

Solution code:
L=input()

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    zero, one = 0, 0
    s = input().strip("\n")
    for i in range(len(s)):
        if s[i] == "0": zero += 1
        else: one += 1
    print(2 * min(zero, one))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
print(2*min(map(input().count,"01")))

Submission status: Accepted

Solution code:
#C - Unification
import collections
S = input()
S1 = [int(x) for x in list(str(S))]

c = collections.Counter(S1)
#print(c)
ans = 2*min(c[0],c[1])
print(ans)

Submission status: Accepted

Solution code:

#B
S=input()
ans=0
cnt=0
blo=-1
for s in S:
    if cnt==0:
        blo=s
        cnt+=1
        continue
    if blo==s:
        cnt+=1
    else:
        ans+=1
        cnt-=1
print(ans*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())

n = len(s)
c_0 = s.count("0")
c_1 = n - c_0

ans = min(c_0, c_1) * 2

print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
stack = deque()
for i in range(len(s)):
    if len(stack) and s[i] != stack[-1]:
        stack.pop()
    else:
        stack.append(s[i])
print(len(s) - len(stack))

Submission status: Accepted

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

tmp = []
ans = 0
for i in range(len(s)):
    if len(tmp) > 0 and tmp[-1] == '0' and s[i] == '1':
        tmp.pop()
        ans += 2
    elif len(tmp) > 0 and tmp[-1] == '1' and s[i] == '0':
        tmp.pop()
        ans += 2
    else:
        tmp.append(s[i])
print(ans)

Submission status: Accepted

Solution code:
s=input()
b=0
r=0
for ss in s:
    if ss=='1':
        b+=1
    elif ss=='0':
        r+=1
print(2*min(b,r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
s = list(s)

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    S = input()
    S = [int(c) for c in S]

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

resolve()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    s=readline().strip()
    
    res=0
    count0=0
    count1=0
    i=0
    l=len(s)
    while i<l:
        if i==l-1:
            if s[i]=="0":
                count0+=1
            else:
                count1+=1
            i+=1
        elif s[i]==s[i+1]:
            if s[i]=="0":
                count0+=1
            else:
                count1+=1
            i+=1
        else:
            res+=2
            i+=2

    print(res+min(count0,count1)*2)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
S = input()
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 = list(map(int,(input())))
c0 = S.count(0)
c1 = len(S)-c0
print(min(c0,c1)*2)

Submission status: Accepted

Solution code:
S = input()
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()
N=len(S)
st=[]

for str in S:
  #print(st,str)
  if len(st)==0:
    st.append(str)
  else:
    if str!=st[-1]:
      st.pop()
    else:
      st.append(str)
      
print(N-len(st))

Submission status: Accepted

Solution code:
s=input()

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

print(min(a,b)*2)

Submission status: Accepted

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

Submission status: Accepted

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

cnt0, cnt1 = 0, 0
for i in range(n):
    if s[i] == "0":
        cnt0 += 1
    else:
        cnt1 += 1

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

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:
list_n = list(input())
l = len(list_n)

a = list_n.count("0")
b = list_n.count("1")
ab = max(a, b) - min(a, b)

print(l-ab)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
Count = [0,0]
for i in range(N):
    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()
print(min(S.count("1"),S.count("0"))*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
red, blue = S.count('0'), S.count('1')
ret = 2 * min(red, blue)
print(ret)

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 += 1
    else:
        count_0 += 1
print(count_0 + count_1 - abs(count_0 - count_1))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()

red=0
blue=0

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

print(min(red,blue)*2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=list(input())
a=S.count("0")
b=S.count("1")
x=min([int(a),int(b)])
print(2*x)

Submission status: Accepted

Solution code:
s = list(input())

count = 0
stack = []


while(len(s) > 0):
    cube = s.pop()

    if len(stack) == 0 or stack[-1] == cube:
        stack.append(cube)
    else:    
        stack.pop()
        count += 2

print(count)

Submission status: Accepted

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

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

print(2 * min(c0, c1))

Submission status: Accepted

Solution code:
s = input()
stack = []
for i in range(len(s)):
    if not stack or stack[-1] == s[i]:
        stack.append(s[i])
    else:
        stack.pop()
print(len(s) - len(stack))

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    S = input()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

S = list(input())

tmp = Counter(S)

cnt = tmp.most_common()
cnt.append(("null", 0))

print(cnt[1][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()
zom = min(s.count("1"),s.count("0"))
if len(set(list(s))) == 1:
    zom = 0
print(zom*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

tmp = S.count("0")
print(min(tmp, len(S) - tmp) * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from collections import deque


def submit():
    s = input().strip()
    q = deque()
    ans = 0

    for c in s:
        if len(q) == 0:
            q.append(c)
        else:
            top = q.pop()
            if top != c:
                ans += 2
            else:
                q.append(top)
                q.append(c)
            
    print(ans)


if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
s = input()
c = s.count('0')

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

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
i = 0
cnt = 0
while i < n - 1:
    if n == 1:
        break
    if (s[i] == '0' and s[i + 1] == '1') or (s[i] == '1' and s[i + 1] == '0'):
        s[i:i + 2] = []
        i = max(i - 1, 0)
        cnt += 2
        n = len(s)
    else:
        i += 1

print(cnt)

Submission status: Accepted

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