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

def parse(inp):
    S=list(next(inp))
    return S
  
def main(inp):
    S = inp
    zeros=0
    ones=0
    for i in range(len(S)):
        if(S[i]=='0'): zeros+=1
        else: ones+=1
            
    return 2*min(ones,zeros)
  
print(main(parse(sys.stdin)))

Submission status: Wrong Answer

Solution code:
def main():
    S = list(input())
    count = 0
    while True:
        start_count = count
        for i, val in enumerate(S):
            virtual_i = i
            while_loop = 0
            while True:
                while_loop += 1
                try:
                    if S[virtual_i] != S[virtual_i+1]:
                        S.pop(virtual_i)
                        S.pop(virtual_i)
                        virtual_i -= 1
                        count += 2
                    else:
                        break
                except IndexError:
                    break
        if start_count == count:
            break

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

S = input()
N = len(S)
L = int(S, 2)   # 2進表記の整数に変換

# O(N^2)は不可。
# 010がある時、01と10を取り除くパターンを作る？

cnt = 0
s = set()
s.add(S)
while True:
    #print(s)
    s2 = set()
    for d in s:
        for i in range(len(d)-1):
            if d[i] != d[i+1]:
                ns = None
                if i+2 < len(d):
                    ns = d[:i]+d[i+2:]
                else:
                    ns = d[:i]
                if ns is not None and len(ns) > 0:
                    s2.add(ns)
    if len(s2) > 0:
        cnt += 2
        s = s2
    else:
        break

print(cnt)

Submission status: Wrong Answer

Solution code:
S=input()
L=len(S)
for i in range(100):
    S=S.replace("0011","")
    S=S.replace("1100","")
    S=S.replace("0101","")
    S=S.replace("1010","")
    S=S.replace("1001","")
    S=S.replace("0110","")
for i in range(200):
    S=S.replace("01","")
    S=S.replace("10","")
L2=len(S)
print(L-L2)

Submission status: Wrong Answer

Solution code:
s = input()
leng = len(s)
import re

s = re.sub(r'0*011*', '', s)
s = re.sub(r'1*010*', '', s)
s = re.sub(r'0*101*', '', s)
s = re.sub(r'1*100*', '', s)

print(leng-len(s))

Submission status: Wrong Answer

Solution code:

from collections import Counter

cnt = Counter()
s = input()
for c in s:
    cnt[c] += 1

print(min(cnt.values()) * 2)

Submission status: Wrong Answer

Solution code:
# from sys import stdin
# S = stdin.readline().rstrip().split()
S = input()
S = list(S)
# print(S)
count_p = 0
count = 0
i = 0

while True:
    if len(S) == 1:
        print(0)
        break
    while i < len(S)-1:
        if S[i] == '0' and S[i+1] == '1':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2

        elif S[i] == '1' and S[i+1] == '0':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2

        else:
            i += 1
    if count == count_p:
        if S == ['0', '1'] or ['1', '0']:
            count += 2
        print(count)
        break
    else:
        count_p = count
        A = []
        for i in range(len(S)):
            if S[i] != '2':
                A.append(S[i])

Submission status: Wrong Answer

Solution code:
nums=str(input())
arr=list(map(int,nums))
l=len(arr)
a=0
i=0
while i<len(arr)-1:
    if arr[i]!=arr[i+1]:
        del arr[i:i+2]
        #print(arr)
        a+=2
        i=0
    i+=1
print(a)

Submission status: Wrong Answer

Solution code:
s = input()
ls = len(s)
for i in range(20):
    s = s.replace("10","").replace("01","")
ans = ls - len(s)
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())

num_moto = int(len(s))
flag = True

while True:
    if s.find('10') == -1 or s.find('01') == -1 or int(len(s)) == 0:
        break
    s = s.replace('10','')
    s = s.replace('01','')
        
num_kekka = int(len(s))
print(num_moto - num_kekka)

Submission status: Wrong Answer

Solution code:
S = input()
S_array = []

for i in S:
    S_array.append(i)
    
answer = 0

if len(S_array) < 2:
    print(0)
else:
    while True:
        a = 0
        for i in range(2,len(S_array)):
            if S_array[i] != S_array[i-1]:
                del S_array[i-1:i+1]
                a += 1
                answer += 2
                break
        if a == 0:
            break
    print(answer)

Submission status: Wrong Answer

Solution code:
S=input()
L=len(S)
for i in range(200):
    S=S.replace("01","")
    S=S.replace("10","")
    S=S.replace("01","")
L2=len(S)
print(L-L2)

Submission status: Wrong Answer

Solution code:
import sys
line=[int(c) for c in sys.stdin if c!='\n']
length=len(line)
while True:
  line2=[]
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
    elif line[i]!=2:
      line2.append(line[i])
  if len(line)!=0 and line[len(line)-1]!=2:
      line2.append(line[len(line)-1])
  if 2 in line:
    line=[i for i in line2]
  else:
    break
print(length-len(line))

Submission status: Wrong Answer

Solution code:
S = list(input())
SL = len(S)
L = len(S)
i = 1
while len(S)>0 and i<len(S):
  if int(S[i]) != int(S[i-1]):
    S.pop(i-1)
    S.pop(i-1)
    i=0
  else:
    i+=1

print(L-len(S))

Submission status: Wrong Answer

Solution code:
S = list(input())

ans = 0
prev = S[0]

for i in range(len(S)-1):
    if not prev == S[i+1]:
        ans += 2
    else:
        prev = S[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
class Solver:

    def __init__(self):
        pass


    def solve(self, s):
        one = 0
        zero = 0
        for ch in s:
            if ch == '1':
                one += 1
            else:
                zero += 1
        return abs(one-zero)


if __name__ == '__main__':

    solver = Solver()
    s = input()
    n = solver.solve(s)
    print(n)

Submission status: Wrong Answer

Solution code:
S=input()
L=len(S)
for i in range(500):
    S=S.replace("01","")
    S=S.replace("10","")
L2=len(S)
print(L-L2)

Submission status: Wrong Answer

Solution code:
# その時点で消せる分を消す
import sys

S = input()  # str

def destroy_step(charst):
    if len(charst) == 1:
        return charst, False
    initial = len(charst)
    dst = ""
    next = True

    for i in range(initial-1):

        if next:
            a = charst[i]
            b = charst[i+1]
            if a != b:
                next = False
            else:
                dst+=a
                next = True
                if i == initial-2:
                    print('this')
                    dst+=b
        else:
            next = True
        if i == initial-3:
            if next is False:
                dst+=charst[-1]

    last = len(dst)
    flag = True
    if initial - last == 0:
        flag = False
    return dst, flag
dst = S
flag = True
while flag:
    dst, flag = destroy_step(dst)
print(len(S)-len(dst))
sys.exit()

Submission status: Wrong Answer

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

A = input()
N = len(A)

zero_num = A.count('0')
one_num = A.count('1')

if N == 1 or zero_num == 0 or one_num == 0:
    print(0)
    exit()

if zero_num == 1 or one_num == 1:
    print(2)
    exit()

if zero_num == one_num:
    ans = one_num*2
elif zero_num > one_num:
    ans = (int(zero_num/one_num) * one_num)*2
else:
    ans = (int(one_num / zero_num) * zero_num)*2

print(ans)

Submission status: Wrong Answer

Solution code:
#C
S = input()
N = len(S)
SL = list(S)

red  = '0'
blue = '1'
cnt = 1
total = 0
while cnt != 0 and len(SL) >= 2:
    cnt = 0
    i = 1
    tmpSL = []
    while i < len(SL):
        if SL[i-1] != SL[i]:
            i += 2
            cnt += 2
            if i >= len(SL):
                tmpSL.append(SL[-1])
        else:
            tmpSL.append(SL[i - 1])
            i += 1
    SL = tmpSL
    total += cnt
print(total)

Submission status: Wrong Answer

Solution code:
S=input()
L=len(S)
for i in range(100):
    S=S.replace("01","")
    S=S.replace("10","")
L2=len(S)
print(L-L2)

Submission status: Wrong Answer

Solution code:
[s] = [i for i in input().split()]
cnt = 0

while "01" in s:
    s2 = s.replace("01", '', 1)
    if s2 != s:
        cnt = cnt + 2
    s = s2

if "10" in s:
    cnt = cnt + 2
print(cnt)

Submission status: Wrong Answer

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

def df(s):
  idx = [i for i, v in enumerate(list(s)) if v == '0']
  c = []

  if len(idx) == 0:
    c.append(len(s))
  else:
    for i in idx:
      if i < len(s) - 1:
        if s[i + 1] == '1':
          c.append(df(s[:i] + s[i + 2:]))
        elif i > 1:
          if s[i - 1] == '0':
            c.append(df(s[:i - 2] + s[i:]))
        else:
          c.append(len(s))
      else:
        c.append(len(s))
  return min(c)

print(l - df(s))

Submission status: Wrong Answer

Solution code:
string = input()
stuck_zeros = 0
number_of_pair = 0
index = 0

while index < len(string):
    if string[index] == '0':
        stuck_zeros += 1
        index += 1
    else:
        if(stuck_zeros != 0):
            number_of_continues_1 = 1
            for i in range(index + 1, len(string)):
                index += 1
                if (string[i] == '1'):
                    number_of_continues_1 += 1
                else:
                    index -= 1
                    break
            if (stuck_zeros > number_of_continues_1):
                number_of_pair += number_of_continues_1
                stuck_zeros -= number_of_continues_1
            else:
                number_of_pair += stuck_zeros
                stuck_zeros = 0
        else:
            index += 1


print(number_of_pair * 2)

Submission status: Wrong Answer

Solution code:
S = list(input())
L = len(S)
i = 1
while len(S)>0 and i<len(S)-1:
  if int(S[i]) != int(S[i-1]):
    S.pop(i-1)
    S.pop(i-1)
    i=0
  else:
    i+=1

print(L-len(S))

Submission status: Wrong Answer

Solution code:
def main():
    string = input()
    lists = list(string)
    original_len = len(lists)
    zero = lists.count('0')
    one = lists.count('1')
    print(original_len - min(zero,one)*2)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import re,sys

def nchars(s, n):
    """文字列 s に、同じ文字が n 個以上連続している部分文字列を見つける
    """
    assert n > 0
    reg = re.compile("(.)\\1{%d,}" % (n - 1))  # カンマを取ると n 個ちょうどになる
    while True:
        m = reg.search(s)
        if not m:
            break
        yield m.group(0)
        s = s[m.end():]

s = str(input())
sl = list(s)

def ltox(s):
    if(len(s) <= 1):
        return (s)
    for i in range(1, len(s)-1):
        if(s[i-1] != s[i] or s[i-1] != 'x'):
            s[i] = 'x'
    return [i for i in s if i != 'x']

bllx = len(s)
while True:
    llx = ltox(sl)
    if(len(llx) == bllx):
        if(len(llx) == 2 and llx[0] != llx[1]):
            print(len(s))
        else:
            print(len(s)-len(llx))
        sys.exit()
    else:
        bllx = len(llx)

Submission status: Wrong Answer

Solution code:
import sys
line=[int(c) for c in sys.stdin]
del line[-1]
length=len(line)
while True:
  line2=[]
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
    elif line[i]!=2:
      line2.append(line[i])
  if len(line)!=0 and line[len(line)-1]!=2:
      line2.append(line[len(line)-1])
  if 2 in line:
    line=[i for i in line2]
  else:
    break
print(length-len(line))

Submission status: Wrong Answer

Solution code:
def main():
    string = input()
    lists = list(string)
    original_len = len(lists)
    zero = lists.count('0')
    one = lists.count('1')
    print(original_len - min(zero,one)+2)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
ls = len(s)
for i in range(17):
    s = s.replace("10","").replace("01","")
ans = ls - len(s)
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
i=0
while i!=len(s) and len(s)>=2:
  if s[i:i+2]=="01" or s[i:i+2]=="10":
      s=s[:i+1]+s[i+2:]
      ans+=2
      i-=1
  else:
    i+=1
print(ans)

Submission status: Wrong Answer

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

A = input()
N = len(A)

zero_num = A.count('0')
one_num = A.count('1')

if N == 1 or zero_num == 0 or one_num == 0:
    print(0)
    exit()

if N == 3:
    if zero_num == 1 or one_num == 1:
        print(2)
        exit()

if zero_num == one_num:
    ans = one_num*2
elif zero_num > one_num:
    ans = (int(zero_num/one_num) * one_num)*2
else:
    ans = (int(one_num / zero_num) * zero_num)*2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
line=[int(c) for c in sys.stdin]
length=len(line)
while True:
  line2=[]
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
    elif line[i]!=2:
      line2.append(line[i])
  if len(line)!=0 and line[len(line)-1]!=2:
      line2.append(line[len(line)-1])
  if 2 in line:
    line=[i for i in line2]
  else:
    break
print(length-len(line))

Submission status: Wrong Answer

Solution code:
s = input()
ans = 0
flg = 0
while '10' in s and '01' 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 = list(input())

end_flg = False
ans = 0

while not end_flg:
    for i in range(len(S)-1):
        if i == len(S)-2:
            end_flg = True
            break
        if (S[i] == '1' and S[i+1] == '0') or (S[i] == '0' and S[i+1] == '1'):
            ans += 2
            S.pop(i)
            S.pop(i)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
def trim(s):
    for i in range(len(s)-1):
        if (s[i]=="0" and s[i+1]=="1") or (s[i]=="1" and s[i+1]=="0"):
            s=s[:i]+s[i+2:]
            break
    else: return False
    return s
s=input()
c=-1
while s:
    c+=1
    s=trim(s)
print(c*2)

Submission status: Wrong Answer

Solution code:
s = list(input())
for n in range(len(s)):
    s[n] = int(s[n])

count = 0
while(True):
    old = count
    if (len(s) == 1 or len(s) == 0):
        break

    for n in range(len(s) - 1):

        k = s[n]
        l = s[n + 1]

        if (k == l):
            s.pop(n)
            s.pop(n)

            count += 2
            break

    if (old == count):
        count += 2
        break

print(count)

Submission status: Wrong Answer

Solution code:
s = list(map(int, input()))
print(s)
c = 0
count = 0
while(c==0):
  for i in range(len(s)):
    if sum(s) == len(s) or sum(s) == 0:
      c=1
      break
    print(i,len(s),s)
    if i == len(s)-1:
      break
    if len(s) == 2 and sum(s) == 1:
      count+=2
      c=1
      break
    if s[i] + s[i+1] == 1:
      del s[i]
      del s[i]
      count += 2
      break
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# coding: UTF-8

S = list(input())
S = list(map(int,S))
S.append(-1)
S.insert(0,-2)
Count = 0
Before = len(S)
while True:
    L = len(S) - 2
    for i in range(L,1,-1):
        if S[i] !=  S[i+1] and S[i] != -2 and S[i+1] != -1:
            #print(S)
            S.pop(i)
            S.pop(i)
            i += 1
            if i > L:
                break
    else:
        break

#print(S)
print(Before - len(S))

Submission status: Wrong Answer

Solution code:
import sys
input  = sys.stdin.readline

S = input()
N = len(S)

c0=0
c1=0
for i in S:
  if i == '0':
    c0+=1
  else:
    c1+=1

print(2*min(c0,c1))

Submission status: Wrong Answer

Solution code:
st = input()
list_s = list(st)

delcount = 0
while True:
    if list_s.count('0') == 0 or list_s.count('1') == 0:
        break
    pre = list_s[0]
    count = 0
    for s in list_s:        
        if (pre == '0' and s == '1') or (pre == '1' and s == '0'):
            del list_s[count-1:count]
            delcount += 1
            break
        count += 1
print(delcount)

Submission status: Wrong Answer

Solution code:
#%%
s = input()
n = len(s)
rem = []

ans = 0
i = 0

if n < 2:
    print(0)

else:
    while i < n:
        if rem:
            if rem[-1] != s[i]:
                rem.pop()
                i += 1
                ans += 2
            
            else:
                if i + 1 < n:
                    if s[i] == s[i+1]:
                        rem.append(s[i])
                        i += 1

                    else:
                        i += 2
                        ans += 2

                else:
                    i += 1

        else:

            if i+1 < n and s[i] == s[i+1]:
                rem.append(s[i])
                i += 1

            else:
                i += 2
                ans += 2

print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
prv=0
while len(s)>=2:
  flag=True
  for i in range(max(0,prv-1), len(s)-1):
    if s[i:i+2]=="01" or s[i:i+2]=="10":
      s=s[:i+1]+s[i+2:]
      ans+=2
      prv=i
      flag=False
      break
  if flag:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
def ls(): return stdin.readline()

S = ls()
num_1, num_0 = 0, 0

for s in S:

    if s == '1':
        num_1 += 1
    else:
        num_0 += 1
print( 2 * min(num_1, num_0) )

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# coding: UTF-8


S = list(input())
S = list(map(int,S))
S.append(-1)
S.insert(0,-2)
Count = 0
Before = len(S)
while True:
    L = len(S) - 2
    for i in range(L,1,-1):
        if S[i] !=  S[i+1] and S[i] != -2 and S[i+1] != -1:
            #print(S)
            S.pop(i)
            S.pop(i)
            break
    else:
        break

#print(S)
print(Before - len(S))

Submission status: Wrong Answer

Solution code:
N = input()
found = True
count = 0
while found:
  found = False
  ng_list = []
  dummy = ""
  for i in range(len(N) - 1):
    if i in ng_list:
      continue
    if N[i] != N[i+1] and i not in ng_list:
      count += 2
      ng_list.append(i+1)
      found = True
      
    else:
      dummy += N[i]
      #print (dummy)
  N = dummy
  #print (N)
print(count)

Submission status: Wrong Answer

Solution code:
st = input()
list_s = []
for s in st:
    list_s.append(s)

delcount = 0
while True:
    if list_s.count('0') == 0 or list_s.count('1') == 0:
        break
    pre = list_s[0]
    count = 0
    for s in list_s:        
        if (pre == '0' and s == '1') or (pre == '1' and s == '0'):
            del list_s[count-1:count]
            delcount += 1
            break
        count += 1
print(delcount)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = input()
    a = 0
    b = 0
    for c in n:
        if(c == '1'):
            a += 1
        else:
            b += 1
    if(a>b):
        print(b)
    else:
        print(a)

Submission status: Wrong Answer

Solution code:
s = input()
cnt = 0
while '0' in s and '1' in s:
  for i in range(len(s)):
    if s[i] != s[i+1]:
      print('hoge', i)
      cnt += 1
      s = s[:i] + s[i+2:]
      break

print(cnt * 2)

Submission status: Wrong Answer

Solution code:
s = input()
s = list(s)
count = 0
for j in range(100):
    length = len(s)
    for i in range(len(s)):
        try:
            if s[i] != s[i+1]:
                s.pop(i)
                s.pop(i)
                count = count+1
        except IndexError:
            pass
    if length == len(s):
        break

Submission status: Wrong Answer

Solution code:
import copy

S = str(input())
lenS = len(S)
S2 = copy.copy(S)

flag = 0
while flag == 0:
  if S.find('10') != -1:
    S = S[:S.find('10')-1] + S[S.find('10')+1:]
  elif S.find('01') != -1:
    S = S[:S.find('01')-1] + S[S.find('01')+1:]
  else:
    flag = 1
lenS_ = len(S)

flag = 0
while flag == 0:
  if S2.find('01') != -1:
    S2 = S2[:S2.find('01')-1] + S2[S2.find('01')+1:]
  elif S.find('10') != -1:
    S2 = S2[:S2.find('10')-1] + S2[S2.find('10')+1:]
  else:
    flag = 1
lenS2_ = len(S2)

if lenS_ < lenS2_:
  print(lenS - lenS_)
else:
  print(lenS - lenS2_)

Submission status: Wrong Answer

Solution code:
s=input()
ans=0
while len(s)>=2:
  flag=True
  for i in range(len(s)-1):
    if s[i:i+2]=="01" or s[i:i+2]=="10":
      s=s[:i+1]+s[i+2:]
      ans+=2
      flag=False
      break
  if flag:
    break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = str(input())
cnt=0

while len(s) >2:
    if '10' in s:
        cnt+=2 * s.count('10')
        s=s.replace('10', '') 
    elif '01' in s:
        cnt+=2 * s.count('01')
        s=s.replace('01', '') 
print(cnt)

Submission status: Wrong Answer

Solution code:
S = input()
flag0 = False
flag1 = False
counter = 0
while True:
    idx = S.find("01")
    if idx>0:
        S = S[:idx] + S[idx+2:]
        counter += 2
    else:
        flag0 = True
    
    idx = S.find("10")
    if idx>0:
        S = S[:idx] + S[idx+2:]
        counter += 2
    else:
        flag1 = True

    if flag0 and flag1 :
        break
print(counter)

Submission status: Wrong Answer

Solution code:
S = input()

N = len(S)

count = 0
while(1):
    f=0
    for i in range(N-1):
        if S[i] != S[i+1]:
            f=1
            count += 2
            if N<=3:
                f=0
                break
            if i == 0:
                S=S[2:]
            if i == 1:
                S=S[0]+S[3:]
            if i == N-2:
                S=S[:N-2]
            N -= 2
            break
    if f == 0:
        break

print(count)

Submission status: Wrong Answer

Solution code:
s=input()
t=[]
c=0
p=0
i=0
t=""
while i<=len(s)-2:
    if p==0:
        if s[i]!=s[i+1]:
            c+=2
            i+=2
            p=1
        else:
            t+=s[i]
            i+=1
    else:
        if len(t)==0:
            p=0
        else:
            if t[-1]!=s[i]:
                c+=2
                i+=1
                t=t[:len(t)]
            else:
                p=0   
print(c)

Submission status: Wrong Answer

Solution code:
s=list(input())
n=len(s)
zero=s.count(0)
one=s.count(1)
if len(s)==1:print(0)
elif s[0]==s[-1]:print(n-2)
else:print(n-2*min(zero,one))

Submission status: Wrong Answer

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

count = 0

while True:
        l = len(s)
        su = sum(s)
        if l != 0 and su != 0 and su != l:
                for i in range(int(l)):
                        if s[i] != s[i+1]:
                                del s[i:i+1]
                                count += 2
                                break
        else:
                print(count)
                break

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input()
count = 0

if s.count("0") != 0 and s.count("1") != 0:
    if s.count("0") > s.count("1"):
        print(2*s.count("1"))
    elif s.count("1") > s.count("0"):
        print(2*s.count("0"))
    else:
        print(len(s))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
fin = sys.stdin.readline

ob = [-1 if i=="0" else 1 for i in list(fin())]
print(len(ob) - sum(ob))

Submission status: Wrong Answer

Solution code:
s=str(input())
ue=-1
ans=0
for i in range(len(s)):
  if(ue==-1):
    ue=int(s[i])
  elif(int(s[i])==ue):
    ans+=2
    if(ans==i+1):
      ue=-1
    else:
      ue=1-ue
  else:
    ue=1-ue
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
flg = 1
ans = S
if len(S) >= 2:
  while flg == 1:
      flg = 0
      for i in range(len(ans)-1):
        if ans[i]==ans[i+1]:
          ans = ans[:i]+ans[i+2:]
          flg = 1
          break
print(len(S)-len(ans))

Submission status: Wrong Answer

Solution code:
import sys

def main():
  input = sys.stdin.readline
  S = [int(c) for c in input().strip()]
  n1 = 0
  n0 = 0
  c = 0
  for i in S:
    if i == 0:
      if n1 > 1:
        c += 2
        n1 -= 1
      else:
        n0 += 1
    else:
      if n0 > 0:
        c += 2
        n0 -= 1
      else:
        n1 += 1
  print(c)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
s = input()
s = list(s)
count = 0
for j in range(100):
    for i in range(len(s)):
        try:
            if s[i] != s[i+1]:
                s.pop(i)
                s.pop(i)
                count = count+1
        except IndexError:
            pass
print(count*2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# coding: UTF-8


S = list(input())
S = list(map(int,S))
S.append(-1)
S.insert(0,-2)
Count = 0
Before = len(S)
while True:
    L = len(S) - 2
    for i in range(1,L):
        if S[i] == S[i+1]:
            #print(S)
            S.pop(i)
            S.pop(i)
            break
    else:
        break

#print(S)
print(Before - len(S))

Submission status: Wrong Answer

Solution code:
S = input()
len_s = len(S)
while(True):
    S = S.replace("01", "")
    S = S.replace("10", "")
    if not (("01" in S) and ("10" in S)):
        break
print(len_s - len(S))

Submission status: Wrong Answer

Solution code:
try:
  print(Counter(input()).most_common()[1][1] * 2)
except:
  print(0)

Submission status: Wrong Answer

Solution code:
s = input()
s = list(s)
count = 0
for j in range(10):
    for i in range(len(s)):
        try:
            if s[i] != s[i+1]:
                s.pop(i)
                s.pop(i)
                count = count+1
        except IndexError:
            pass
print(count*2)

Submission status: Wrong Answer

Solution code:
#C
S = input()
N = len(S)
SL = list(S)

red  = '0'
blue = '1'
cnt = 1
total = 0
while cnt != 0 and len(SL) >= 2:
    cnt = 0
    i = 1
    tmpSL = []
    while i < len(SL):
        if SL[i-1] == SL[i]:
            i += 2
            cnt += 2
            if i >= len(SL):
                tmpSL.append(SL[-1])
        else:
            tmpSL.append(SL[i - 1])
            i += 1
    SL = tmpSL
    total += cnt
print(total)

Submission status: Wrong Answer

Solution code:
S = input()

#print('01' in S)
#print('10' in S)

count = 0

while '01' in S or '10' in S:
    #print(S)
    #print('01' in S or '10' in S)
    if '01' in S:
        count += S.count('01')
        S = S.replace('01', '')
    if '10' in S:
        count += S.count('10')
        S = S.replace('10', '', 1)

print(count * 2)

Submission status: Wrong Answer

Solution code:
s = list(input())
res = 0
while True:
  temp = len(s)
  for i in range(temp):
    try:
      if int(s[i])+int(s[i+1]) == 1:
        s.pop(i)
        s.pop(i+1)
        res += 2
    except:
      break
  if temp == len(s):
    print(res)
    break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
0

Submission status: Wrong Answer

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

    ans = f(S)
    print(ans)


def f(S):
    """
    A,B,Cそれぞれが存在していたら終了
    存在しない場合
    diff をとる

    """
    bef = S[0]
    b = []
    a = 0
    for c in S:
        if c == '0':
            a += 1
        else:
            a -= 1
        b.append(a)

    from collections import Counter
    c = Counter(b)
    ans = 0
    for v in c.values():
        ans += v // 2 * 2

    # print(c)

    return ans


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
flg = 1
ans = S
while flg == 1:
    flg = 0
    for i in range(len(ans)-1):
      if ans[i]==ans[i+1]:
        ans = ans[:i]+ans[i+2:]
        flg = 1
        break
print(len(S)-len(ans))

Submission status: Wrong Answer

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

cnt = 0

for i in range(1, (n//2)+1):
    s = s.replace('01', '', 1)
    if len(s) < n:
      n = len(s)
      cnt += 1
      
print(2*cnt)

Submission status: Wrong Answer

Solution code:
import re

s = input()
temp = s
temp2 = ''
while len(s) != len(temp2):
    temp2 = s
    s = re.sub('00|11', '', s)

print(len(temp) - len(s))

Submission status: Wrong Answer

Solution code:
def delete(S):
    check=False
    for s in range(len(S)-1):
        if S[s]=="0" and S[s+1]=="1":
            del S[s]
            check=True
            break
        if S[s]=="1" and S[s+1]=="0":
            del S[s]
            del S[s]
            check=True
            break
    return check,S
S= [i for i in input()]
ans= 0
check=True
while check == True:
    check,S = delete(S)
    if check == False:
        break
    else:
        ans+=2
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()


N = len(S)
ind = N-1
last = S[ind]
flag = True
ans = 0
rev_rem = False
rev_rev_rem = False

while ind > 0:

	if last == S[ind-1]:
		ans += 2
		ind -= 1
		if ind-2 >= 0 and S[ind-2] != S[ind-1]:
			rev_rev_rem = rev_rem
			rev_rem = False
	elif (not rev_rem) and rev_rev_rem and last != S[ind-1]:
		ans += 2
		rev_rev_rem = False
	else:
		rev_rev_rem = rev_rem
		rev_rem = True
	ind -= 1
	last = S[ind]

print(ans)

Submission status: Wrong Answer

Solution code:
import math

s = input()
n = len(s)

cnt = 0

for i in range(1, math.floor(n/2)+1):
    s = s.replace('01', '', 1)
    if len(s) < n:
      n = len(s)
      cnt += 1
      
print(cnt)

Submission status: Wrong Answer

Solution code:

s = list(input())

k = len(s)
i = 0
j = 0

for t in range(k):
    if i+1 >= k-j or len(s)==1:
        break
    elif s[i] + s[i+1] =='01' or s[i] + s[i+1] =='10':
        del s[i]
        del s[i]
        i = 0
        j = j + 2
    else:
        i = i+1

print(j)

Submission status: Wrong Answer

Solution code:
s = input()
q = []
l = 0
o = 0
for c in s:
    q.append(c)
    l += 1
    while 2 < l and q[l-1] == q[l-2]:
        q.pop()
        q.pop()
        o += 2
        l -= 2
print(o)

Submission status: Wrong Answer

Solution code:
S = input()


N = len(S)
ind = N-1
last = S[ind]
flag = True
ans = 0
rev_rem = False
rev_rev_rem = False

while ind > 0:

	if last == S[ind-1]:
		ans += 2
		ind -= 1
		rev_rev_rem = rev_rem
		rev_rem = False
	elif (not rev_rem) and rev_rev_rem and last != S[ind-1]:
		ans += 2
		rev_rev_rem = False
	else:
		rev_rev_rem = rev_rem
		rev_rem = True
	ind -= 1
	last = S[ind]

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()

length = len(s)
past = ''
cnt=0
while s != past:
    past = s
    s = s.replace('10','',1)
    if past!=s:
        cnt+=2
#    print(past)
    past = s
    s = s.replace('01','',1)
    if past!=s:
        cnt+=2
#    print(past)

print(cnt)