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: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import deque

def main():
    s = IS()
    dq = deque()
    n = len(s)
    dq.append(s[0])
    cnt = 0
    idx = 1
    while idx < n:
        if not len(dq) > 0: dq.append(s[idx]); continue
        a = dq[-1]
        b = s[idx]
        if a == b:
            dq.append(b)
        else:
            dq.pop()
            cnt += 2
        idx += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
#print(s)

score=0
for i in range(len(s)):
	if s[i]=="0":
		score = score +1
	else:
		score = score -1
#	print(s[i])
print(len(s)-score)

Submission status: Wrong Answer

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()
  a = Counter(s)
  ans = min(a.values()) * 2
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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()
n = len(s)
ans = 0
for i in range(n-1):
    if s[i] != s[i-1]:
        ans += 1
print(2*ans)

Submission status: Wrong Answer

Solution code:
n_list = list(input())
#print(n_list)

while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      flag = "ok"
      break
  if flag == "ng":
    break
#print(n_list)
print(len(n_list))

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(min(r, b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
class Unification:
    def __init__(self, cube: list):
        self.cube = cube

    def calc(self):
        ans = 0
        i = 0
        while i < len(self.cube) - 1:
            if self.cube[i] != '-' and self.cube[i] != self.cube[i + 1]:
                ans += 2
                self.erase(i)
                self.erase(i + 1)
            i += 1
        print(ans)

    def erase(self, i: int):
        drop_cube = i - 2
        if drop_cube < 0:
            self.cube[i] = '-'
        else:
            self.cube[i] = self.cube[drop_cube]
    

S = list(input())
S.reverse()
cube = Unification(S)
cube.calc()

Submission status: Wrong Answer

Solution code:
class Unification:
    def __init__(self, cube: list):
        self.cube = cube

    def calc(self):
        ans = 0
        i = 0
        while i < len(self.cube) - 1:
            if self.cube[i] != self.cube[i + 1]:
                ans += 2
                self.erase(i)
                self.erase(i + 1)
            i += 1
        print(ans)

    def erase(self, i: int):
        drop_cube = i - 2
        if drop_cube < 0:
            self.cube[i] = '-'
        else:
            self.cube[i] = self.cube[drop_cube]
    

S = list(input())
S.reverse()
cube = Unification(S)
cube.calc()

Submission status: Wrong Answer

Solution code:
L = list(input())
i = 0
cnt = 0
for _ in range(len(L)):
    if ''.join(L[i:i+2]) == '01' or ''.join(L[i:i+2]) == '10':
        for j in range(i,i+2):
            L.pop(i)
            cnt += 1
        i = 0
    else:
        i += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
blk = len(s) 
while len(s) > 2:
    s = s.replace("01","")
    s = s.replace("10","")
print(blk - len(s))

Submission status: Wrong Answer

Solution code:
S = list(input())

last = S.pop(0)
stack = [last]
can_pop = True
cnt = 0
for s in S:
    if last != s and can_pop:
        stack.pop()
        can_pop = False
        # stack.append(s) 読み捨て
        cnt += 2
    else:
        stack.append(s)
        last = s
        can_pop = True

print(cnt)

Submission status: Wrong Answer

Solution code:
S=list(input())
N=len(S)
def main():
  ans=0
  i=0
  while len(S)>0 and i<N-1:
    if (S[i]==0 and S[i+1]==1) or (S[i]==1 and S[i+1]==0):
      S.remove(S[i:i+2])
      ans+=1
      i=0
    else:
      ans=ans
      i+=1
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
S=list(input())
N=len(S)
def main():
  ans=0
  i=0
  while len(S)>0 and i<N-1:
    if (S[i]==0 and S[i+1]==1) or (S[i]==1 and S[i+1]==0):
      S.remove(S[i:i+2])
      ans+=1
    else:
      ans=ans
      i+=1
  print(ans)
main()

Submission status: Wrong Answer

Solution code:
a=[100]+[int(i) for i in input()]+[100]
n=len(a)
i=1
while i<len(a)-1:
    if a[i]^1==a[i+1]:
        a.pop(i)
        a.pop(i+1)
    if a[i]^1==a[i-1]:
        a.pop(i)
        a.pop(i-1)
    else:
        i+=1
print(n-len(a))

Submission status: Wrong Answer

Solution code:
s = input()
# ans = 0
# while '01' in s or '10' in s:
#     # print('yes')
#     if '01' in s:
#         s = s.replace('01', '', 1)
#         ans += 2
#     if '10' in s:
#         s = s.replace('10', '', 1)
#         ans += 2
#     # print(s, ans)

# # print(ans)

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

Submission status: Wrong Answer

Solution code:
import numpy as np

S = str(input())

r = '01'
b = '10'

count=0
i=0
while i < (len(S)-1):
    if r == S[i:i+2]:
        S = S.replace(r,'',1)
        count+=1
        i=0
    if b == S[i:i+2]:
        S = S.replace(b,'',1)
        count+=1
        i=0
    else:
        i+=1
        
print(int(2*count))

Submission status: Wrong Answer

Solution code:
import numpy as np

S = str(input())

r = '00'
b = '11'

count=0
i=0
while i < (len(S)-1):
    if r == S[i:i+2]:
        S = S.replace(r,'',1)
        count+=1
        i=0
    if b == S[i:i+2]:
        S = S.replace(b,'',1)
        count+=1
        i=0
    else:
        i+=1
        
print(int(2*count))

Submission status: Wrong Answer

Solution code:
S = input()

S = list(S)

from collections import Counter
c = Counter(S)
keys, values = zip(*c.most_common())

print(2*min(values))

Submission status: Wrong Answer

Solution code:
from collections import Counter
c = Counter(list(input())).values()
print(2 * min(c))

Submission status: Wrong Answer

Solution code:
s = input()

print(max(s.count("1"), s.count("0")) * 2)

Submission status: Wrong Answer

Solution code:
s = input()

s0 = 0
s1 = 1

for c in s:
    if c == '0':
        s0 += 1
    else:
        s1 += 1

print(min(s0, s1)*2)

Submission status: Wrong Answer

Solution code:
s = list(input())
n = len(s)
cnt = 0

for i in range(n-1):
    if s[i] == '0' and s[i+1]:
        cnt += 2
        
print(cnt)

Submission status: Wrong Answer

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

cnt = 0
l = 0

while l < n-1:
    if ( s[l] == '0' ) and ( s[l+1] == '1' ):
        cnt += 2
        s[l:l+1]=[]
        n = len(s)
        l -= 1
        continue
    l += 1

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
l = 0

while l < n-1:
    if ( s[l] == '0' ) and ( s[l+1] == '1' ):
        cnt += 2
        s[l:l+1]=[]
        n = len(s)
        l = 0
        continue
    l += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = input()

ans = 0
update_N = N
flg = False
while set(list(update_N)) == set(['0', '1']):
    update_N = []
    for i in range(len(N) - 1):
        if flg is True:
            flg = False
            continue
        if N[i] + N[i + 1] == '10' or N[i] + N[i + 1] == '01':
            flg = True
            ans += 1
        else:
            update_N += N[i]
    if N[:-2] + N[:-1] != '10' and N[:-2] + N[:-1] != '01':
        update_N += N[-1]
    N = update_N
print(ans * 2)

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
while ('01'or'10') in s:
    ans += s.count('01')*2
    s = s.replace("01", "")
    ans += s.count('10')*2
    s = s.replace("10", "")
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
l=len(S)
print(l)
for i in range(l//2):
    S=S.replace("10", "")
    S=S.replace("01", "")
print(l-len(S))

Submission status: Wrong Answer

Solution code:
s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if nall==0:
    print(0)
elif none<=nzero:
    print(nall-none*2)
else:
    print(nall-nzero*2)

Submission status: Wrong Answer

Solution code:
s = input()
ls = list(map(int,list(s)))
lt = [0]
for i in range(1,len(s)):
  lt.append(ls[i-1]+ls[i])

ans = 0
while 1 in lt:
  flg = 1
  n = len(ls)
  for i in range(1,n):
    if flg == 1 and lt[n-i] == 1:
      ls = ls[:n-i-2] + ls[n-i:]
      ans += 2
      flg = 0
    elif flg == 0:
      flg = 1
  lt = [0]
  for i in range(1,len(ls)):
    lt.append(ls[i-1]+ls[i])
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()));print(min(s.count("0"),s.count("1")))

Submission status: Wrong Answer

Solution code:
S=input()

num0=0
num1=1

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

Submission status: Wrong Answer

Solution code:
S=input()

num0=0
num1=1

for i in range(len(S)):
    if S[i]=='0':
        num0+=1
    else:
        num1+=1
print(min(num0,num1))

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
m0 = 0
m1 = 0
for i in range(len(s)):
    if s[i]==0:
        m0+=1
    else:
        m1+=1
print(min(m0,m1)*2)

Submission status: Wrong Answer

Solution code:
s = list(map(int,input().split()))
m0 = 0
m1 = 0
for i in range(len(s)):
    if s[i]==0:
        m0+=1
    else:
        m1+=1
print(abs(m0-m1))

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
if len(set(s))==1:
    print(0)
else:
    print(min(n,n-s.count('1'))*2)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    S  = list(map(int, input()))
    o = S.count(0)
    l = S.count(1)
    print(o,l)

    print(min(o, l) * 2)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
s=input()
if len(set(s)) == 1:
  print(0)
else:
  cs=Counter()
  print(min(cs['0'],cs['1'])*2)

Submission status: Wrong Answer

Solution code:
"""a,b,c = map(int,input().split())
l =[]
for i in range(1,min(a,b)):
  if min(a,b)%i==0:
    l.append(i)

print(l[c-1])"""

s = input()
one,zero = s.count("1"),s.count("0")
if len(s)==1:
  print(0)
if len(set(s))==1:
  print(0)
else:
  print(min(one,zero)*2)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
#TLEになりそうな方法
while '00' in s or '11' in s:
  s = s.replace('00','')
  s = s.replace('11','')
print(l-len(s))

Submission status: Wrong Answer

Solution code:
s = input()
init_len = len(s)
tmp_s_len = 0
while tmp_s_len != len(s):
    tmp_s_len = len(s)
    s = s.replace("01","").replace("10","")
    if s == "":
        break
    else:
        continue
res = init_len - tmp_s_len
print(res)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
#TLEになりそうな方法
while '00' in s or '11' in s:
  s = s.strip('00')
  s = s.strip('11')
print(l-len(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
if len(s)==1:
    print(1)
else:
    print(len(s)-len(s.strip("01")))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     

def reverse_str(n):
    n = int(n)
    return str((1 - n) ** 2)

def main():
    s = S()
    dp = [(0, '') for _ in range(len(s)+1)]
    dp[0] = (1, s[0])
    for i in range(1, len(s)):
        prev_let = dp[i-1][1]
        prev_len = dp[i-1][0]
        if s[i] == prev_let:
            dp[i] = (prev_len + 1, s[i])
        else:
            dp[i] = (prev_len - 1, reverse_str(s[i]))
    print(len(s) - dp[len(s)-1][0])
    '''
    dp = [[0 for _ in range(2)] for __ in range(len(s) + 1)]
    for i in range(1, len(s)+1):
        j = int(s[i-1])
        if j == 0:
            dp[i][0] = dp[i-1][0] + 1
            dp[i][1] = dp[i-1][1] - 1
        else:
            dp[i][0] = dp[i-1][1] + 1
            dp[i][1] = dp[i-1][0] - 1
    '''
    """
    if s[i-1] == str(j):
        dp[i][j] = (dp[i-1][j] + 1)
    else:
        dp[i][reverse(j)] = (dp[i-1][reverse(j)] - 1)
    """
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque
s=input()
d=deque(s)
ans=deque([])
ans.append(d[0])
c=0
for i in range(len(s)):
    if ans==deque([]):
        ans.append(d[i])
    elif ans[-1]==d[i]:
        ans.append(d[i])
    else:
        ans.pop()
        c+=2
print(c)

Submission status: Wrong Answer

Solution code:
import collections
S = input()
c = collections.Counter(S)
print(min(c.values())*2)

Submission status: Wrong Answer

Solution code:
s=input()
cnt=0
for c in s:
  cnt+=(int(c)-0.5)*2
print(len(s)-int(cnt))

Submission status: Wrong Answer

Solution code:
S = list(input())
pop_count = 0
cont_count = 0

while True:
    for i in range(1, len(S)):
        if S[i] == "0":
            if S[i-1] == "0":
                cont_count += 1
                continue
            else:
                S.pop(i)
                S.pop(i-1)
                pop_count += 2
                break
        else:
            if S[i-1] == "1":
                cont_count += 1
                continue
            else:
                S.pop(i)
                S.pop(i-1)
                pop_count += 2
                break
    if cont_count == len(S) or len(S) == 0:
        break

print(pop_count)

Submission status: Wrong Answer

Solution code:
li = list(input())
a = li.count("0")
if a < len(li)//2:
    print(2*a)
else:
    print(2*(len(li)-a))

Submission status: Wrong Answer

Solution code:
li = list(input())
a = li.count("0")
if a < len(li):
    print(2*a)
else:
    print(2*(len(li)-a))

Submission status: Wrong Answer

Solution code:
S = input()

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

Submission status: Wrong Answer

Solution code:
s=input()
c=0
while True:
    t=s.replace('01','')
    r=len(s)-len(t)
    if r==0:
        break
    else:
        c+=r
        s=t
t=s.replace('10','')
c+=len(s)-len(t)
print(c)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
while "00" in s or "11" in s:
  c += 2 * s.count("00")
  s = s.replace("00", "")
  c += 2 * s.count("11")
  s = s.replace("11", "")
print(c)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0

while len(S) >= 2 and S != '1' * len(S) and S != '0' * len(S):
    #前から２つ組にして抜いて判定する
    new_S = ''
    for i in range(len(S)//2):
        if S[2*i:(2*i)+2] == '10' or S[2*i:(2*i)+2] == '01':
            count += 1
        else:
            new_S += S[2*i:(2*i)+2]
    S = new_S

    if len(S) == 0 or S == '1' * len(S) or S == '0' * len(S):
        break
    else:
        #頭一つずらして２つ組にして判定する
        new_S = S[0]
        for i in range((len(S)-1)//2):
            if S[2*i+1:(2*i)+3] == '10' or S[2*i+1:(2*i)+3] == '01':
                count += 1
            else:
                new_S += S[2*i+1:(2*i)+3]
        #len(S)が偶数の時は最後が抜けるから足してやる
        if len(S) % 2 == 0:
            new_S += S[-1]
        else:
            pass
        S = new_S

print(count * 2)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0

while len(S) != 0 or S != '1' * len(S) or S != '0' * len(S):
    #前から２つ組にして抜いて判定する
    new_S = ''
    for i in range(len(S)//2):
        if S[2*i:(2*i)+2] != '10' and S[2*i:(2*i)+2] != '01':
            new_S += S[2*i:(2*i)+2]
        else:
            count += 1
    S = new_S

    if len(S) == 0 or S == '1' * len(S) or S == '0' * len(S):
        break
    else:
        #頭一つずらして２つ組にして判定する
        new_S = S[0]
        for i in range((len(S)-1)//2):
            if S[2*i+1:(2*i)+3] != '10' and S[2*i+1:(2*i)+3] != '01':
                new_S += S[2*i+1:(2*i)+3]
            else:
                count += 1
        #len(S)が偶数の時は最後が抜けるから足してやる
        if len(S) % 2 == 0:
            new_S += S[-1]
        else:
            pass
        S = new_S

print(count * 2)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0

while len(S) != 0 or S != '11' or S != '00':
    #前から２つ組にして抜いて判定する
    new_S = ''
    for i in range(len(S)//2):
        judge = S[2*i:(2*i)+2]
        if judge != '10' and judge != '01':
            new_S += judge
        else:
            count += 2
    S = new_S

    if len(S) == 0 or S == '11' or S == '00':
        break
    else:
        #頭一つずらして２つ組にして判定する
        new_S = S[0]
        for i in range((len(S)-1)//2):
            judge = S[2*i+1:(2*i)+3]
            if judge != '10' and judge != '01':
                new_S += judge
            else:
                count += 2
        #len(S)が偶数の時は最後が抜けるから足してやる
        if len(S) % 2 == 0:
            new_S += S[-1]
        else:
            pass
        S = new_S

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0

while len(S) != 0 or S != '11' or S != '00':
    #前から２つ組にして抜いて判定する
    new_S = ''
    for i in range(len(S)//2):
        if S[2*i:(2*i)+2] != '10' and S[2*i:(2*i)+2] != '01':
            new_S += S[2*i:(2*i)+2]
        else:
            count += 1
    S = new_S

    if len(S) == 0 or S == '11' or S == '00':
        break
    else:
        #頭一つずらして２つ組にして判定する
        new_S = S[0]
        for i in range((len(S)-1)//2):
            if S[2*i+1:(2*i)+3] != '10' and S[2*i+1:(2*i)+3] != '01':
                new_S += S[2*i+1:(2*i)+3]
            else:
                count += 1
        #len(S)が偶数の時は最後が抜けるから足してやる
        if len(S) % 2 == 0:
            new_S += S[-1]
        else:
            pass
        S = new_S

print(count * 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())
ans = 0
while True:
    S = S.replace("01", "R")
    a = S.count("R") + S.count("10")
    if  a > 0:
        ans += a*2
        S = S.replace("R","")
        S = S.replace("10","")
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# AtCoder
S = input()

stack = []
count = 0
for e in S:
    if stack == []:
        stack.append(e)

    if stack[-1] != e:
        stack.pop(-1)
        count += 2
        continue
    else:
        stack.append(e)


print(count)

Submission status: Wrong Answer

Solution code:
S=list(input())
c=0
l=["01", "10"]
while len(S)>1:
    before=len(S)
    for i in range(before-1):
        #if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
        #if S[i]+S[i+1] in l:
        if S[i:i+2] in l:
            c+=2
            #S.pop(i)
            #S.pop(i)
            del S[i:i+2]
            break
    if before==len(S):
        break
print(c)

Submission status: Wrong Answer

Solution code:
S=list(input())
c=0
while len(S)>1:
    before=len(S)
    f=0
    # 双方向から見ればループ回数は半分になる？
    for i in range(before//2):
    #for i in range(before-1):
        if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
            c+=2
            #S.pop(i)
            #S.pop(i)
            #break
            f=1
        if S[-i-1]+S[-i-2]=="10" or S[-i-1]+S[-i-2]=="01":
            c+=2
            if i==0:
                del S[-i-2:]
            else:
                del S[-i-2:-i]
            break
        if f:
            del S[i:i+2]
            break
    if before==len(S):
        break
print(c)

Submission status: Wrong Answer

Solution code:
import math

s_L = [int(val) for val in input()]

n = len(s_L)
g = sum(s_L)

if g > n/2:
    g = g - math.ceil(n/2)
    #print(n-2*g)
    print(2*g)
elif g == n/2:
    print(n)
    exit()
elif n ==0:
    print(0)
    exit()
print(2*g)

Submission status: Wrong Answer

Solution code:
import math

s_L = [int(val) for val in input()]

n = len(s_L)
g = sum(s_L)

if g > n/2:
    g = g - math.ceil(n/2)
    print(n-2*g)
elif g == n/2:
    print(n)
    exit()
elif n ==0:
    print(0)
    exit()
print(2*g)

Submission status: Wrong Answer

Solution code:
import math

s_L = [int(val) for val in input()]

n = len(s_L)
g = sum(s_L)

if g > n/2:
    g = g - math.ceil(n/2)
elif g == n/2:
    print(n)
    exit()
elif n ==0:
    print(0)

print(n-2*g)

Submission status: Wrong Answer

Solution code:
S = input()
print(S)
stack = []
ans = 0
for c in S:
    if stack and stack[0] != c:
#         print("stack={}, c={} pop!".format(stack, c))
        stack.pop()
        ans += 2
    else:
#         print("stack={}, c={} append!".format(stack, c))
        stack.append(c)
#     print("c={0}, st={1}".format(c, stack))
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC120 C - Unification
# 2019/10/28

def main():
#     S = list(map(int, list(open(0).read())))
    S = list(map(int, list(input())))
#     print(S)
    
    cnt = 0
    i=0

    while (i<len(S)-1):
        if (S[i] == 0 and S[i+1] == 1) or (S[i] == 1 and S[i+1] == 0):
            S.pop(i)
            S.pop(i)
            cnt+=2
#             print("i={0}, S={1}, cnt={2}".format(i, S, cnt))
            i=0
        i+=1
    
    print(cnt)
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
S = input()
print(len(S) - len(re.sub("01|10|0(0)*(1)*1|1(0)*(1)*0|0(1)*(0)*1|1(1)*(0)*0","",S)))

Submission status: Wrong Answer

Solution code:
import re
S = input()
print(re.sub("01|10|0(0)*(1)*1|1(0)*(1)*0|0(1)*(0)*1|1(1)*(0)*0","",S))

Submission status: Wrong Answer

Solution code:
import re
S = input()
print(len(S)-len(re.sub("01|10|0(\d\d)*1|1(\d\d)*0","",S)))

Submission status: Wrong Answer

Solution code:
s = list(input())
if len(s)==1: print(0);exit()
ans = 0
l,r=0,1
bdr = len(s)-2
while l!=bdr:
    if s[l]!=s[r]:
        ans += 2
        s.pop(l);s.pop(l)
        l,r=0,1
    else:
        l+=1
        r+=1
    bdr = len(s)-2
print(ans + 2*(s[0]!=s[1]))

Submission status: Wrong Answer

Solution code:
from sys import stdin

S = stdin.readline()

cnt0 = 0
cnt1 = 0
for s in S:
    if s=='0':
        cnt0+=1
    else:
        cnt1+=1

print(min(cnt0,cnt1)*2)

Submission status: Wrong Answer

Solution code:
N = raw_input()
S = [] 
for i in range(0,len(N)):
  S.append(int(N[i]))
i = len(S)-1
print i
while i>0:
  print S
  print i
  if S[i] != S[i-1]:
    S.pop(i)
    S.pop(i-1)
    print S
    i = len(S)-1
  else:
    i = i -1
print len(N)-len(S)

Submission status: Wrong Answer

Solution code:
N = raw_input()
S = [] 
for i in range(0,len(N)):
  S.append(int(N[i]))
i = 0
while i<=len(S)-2:
  delete = []
  if S[i] != S[i+1]:
    delete.append(i)
    delete.append(i+1)
    i = i + 2
  else:
    i = i + 1
  if i>=len(S)-2:
    if len(delete) != 0:
      delete.reverse()
      for i in delete:
        S.pop(i)
      i = 0
      delete = []
    else:
      break
  if len(S) == 0:
    break
print len(N) - len(S)

Submission status: Wrong Answer

Solution code:
s=input()

i=0
ban_list=[]
cnt=0
while(True):
    if len(s)<2:
        break
    elif i+1>=len(s):
        s1=""
        for j in range(len(s)):
            if j not in ban_list:
                s1+=s[j]
        s=s1
        i=0
    if len(s)<2:
        break
    elif s[i]!=s[i+1]:
        cnt+=1
        ban_list.append(i)
        ban_list.append(i+1)
        i=i+2
    else:
        i+=1
print(cnt*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main(ans):
    S = input()
    S_list = [int(S[i]) for i in range(len(S))]
    rm_list = []
    for aaa in range(len(S) // 2):
        for i in range(len(S_list) - 1):
            if S_list[i] != S_list[i + 1] and i not in rm_list:
                rm_list.append(i)
                rm_list.append(i + 1)
        S_list = [S_list[i] for i in range(len(S_list)) if i not in rm_list]
        if len(rm_list) == 0:
            return
        ans += len(rm_list)
        rm_list = []


ans = 0
main(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
S_list = [int(S[i]) for i in range(len(S))]
ans = 0
rm_list = []
for aaa in range(len(S)//2):
    for i in range(len(S_list) - 1):
        if S_list[i] != S_list[i + 1] and i not in rm_list:
            rm_list.append(i)
            rm_list.append(i + 1)
    S_list = [S_list[i] for i in range(len(S_list)) if i not in rm_list]
    if (len(rm_list)):
        break
    ans += len(rm_list)
    rm_list = []
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = str(input())

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

print(len(S)-min(a, b)*2)

Submission status: Wrong Answer

Solution code:
S=[i for i in input()]
m=0
for i in range(len(S)):
  if S[i]==1:
    m+=1
  else:
    m-=1
print(len(S)-abs(m))

Submission status: Wrong Answer

Solution code:
s = input()
a_0 = s.count('0')
a_1 = s.count('1')
print(abs(a_0-a_1)*2)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
while True:
    n = len(s)
    s = s.replace('10','')
    count += n-len(s)
    s = s.replace('01','')
    count += n-len(s)
    if n == len(s):
        break
print(count)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
for i in s:
  if i == '0':
    break
  c += 1
r = list(range(len(s)))
r.reverse()
d = 0
for i in r:
  if s[i] == '1':
    break
  d += 1
zero = 0
one = 0
for i in range(c, len(s) - d):
  if s[i] == '0':
    zero += 1
  else:
    one += 1
print(min(zero, one) * 2)

Submission status: Wrong Answer

Solution code:
s = input()
c = 0
for i in s:
  if i == '0':
    break
  c += 1
r = list(range(len(s)))
r.reverse()
for i in r:
  if s[i] == '1':
    break
  c += 1
print(len(s) - c )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
cnt = 0
i = 0
n = len(s)
stack = deque()
updated = True
while updated:
    updated = False
    while i < n and len(stack) > 0 and stack[-1] == s[i]:
        # print(i, stack[-1], s[i])
        updated = True
        stack.pop()
        i += 1
        cnt += 2
    if i < n:
        updated = True
        stack.append(s[i])
    i += 1
# print(stack)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

s = input()
cnt = 0
i = 0
n = len(s)
stack = deque()
while i < n:
    stack.append(s[i])
    while len(stack) > 0 and i < n and stack[-1] == s[i]:
        stack.pop()
        i += 1
        cnt += 2
    i += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
i = 1
n = len(s)
j = 0
while i < n:
    while 0 <= j and i < n and s[j] == s[i]:
        j -= 1
        i += 1
        cnt += 2
    i += 1
    j = i - 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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