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: Runtime Error

Solution code:
sent = str(input())
tmpsent = sent
lis = []
ss = ""
ss2 = ""
for i in range(int(len(sent) / 2)):
    ss = "0" + ss + "1"
    ss2 = "1" + ss2 + "0"
    lis.append(ss)
    lis.append(ss2)
lis.reverse()
loop = True
while loop:
    loop = False
    for l in lis:
        if tmpsent != tmpsent.replace(l, ''):
            tmpsent = tmpsent.replace(l , '')
            loop = True
print(len(sent) - len(tmpsent))

Submission status: Runtime Error

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

def Remove(binList,lenList):
    for i in range(0,lenList-1):
        if (binList[i] == "0" and binList[i+1] == "1") or (binList[i] == "1" and binList[i+1] == "0"):
            del binList[i:i+2]
            return Remove(binList,lenList - 2)
    return binList
S = Remove(S,n)
print(n-len(S))

Submission status: Runtime Error

Solution code:
#%%
def c(s):
    n = len(s)

    if n < 2:
        print(0)

    else:
        ans, i = 0, 0
        rem = []

        while i < n:
            print(rem,s[0:i],s[i:])

            if not rem:

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

#%%
s = input()

c(s)

Submission status: Runtime Error

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

S = list(input())
N = len(S)
while True:
    flag = False
    for i in range(1, len(S)-2):
        l = S[i-1]
        mid = S[i:i+2]
        r = S[i+2]
        if mid == ["0", "1"] or mid == ["1", "0"]:
            if (l == "0" and r == "1") or (l == "1" and r == "0"):
                del S[i:i+2]
                i += 2
                flag = True
                if i >= len(S)-3:
                    break


    if flag:
        continue

    for i in range(0, len(S)-1):
        mid = S[i:i+2]
        if mid == ["0", "1"] or mid == ["1", "0"]:
            del S[i:i+2]
            if i >= len(S)-2:
                break

    break
print(N-len(S))

Submission status: Runtime Error

Solution code:
import sys

def parse(inp):
    S=list(map(int,list(next(inp))))
    return S

def main(inp):
    S = inp
    ones = sum(S)
    zeros = len(S) - ones
    return 2*min(ones,zeros)
  
print(main(parse(sys.stdin)))

Submission status: Runtime Error

Solution code:
S = str(input())
cnt = 0
S.replace('01','')
i=0
while S.count('01')>0 or S.count('10')>0:
    if S.count('01')>0:
        i = S.find('01')
        if i==0:
            S = S[2:]
        elif i+1==N-1:
            S = S[:N-2]
        else:
            S = S[:i]+S[i+2:]
        cnt+=2
    else:
        i = S.find('10')
        if i==0:
            S = S[2:]
        elif i+1==N-1:
            S = S[:N-2]
        else:
            S = S[:i]+S[i+2:]
        cnt+=2
print(cnt)

Submission status: Runtime Error

Solution code:

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                print(S)
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
    if counter == 0:
        break

print(ans*2)

Submission status: Runtime Error

Solution code:
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    check_dif = False
    #print(S)
    for i in range(l-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            #print(S)
            check_dif = True
            ans += pickup(S,ans)
            break
    if check_dif:
        ans+=2
    return ans   
S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
print(pickup(S_list,ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

S = list(input())
N = len(S)
while True:
    flag = False
    for i in range(1, len(S)-2):
        l = S[i-1]
        mid = S[i:i+2]
        r = S[i+2]
        if mid == ["0", "1"] or mid == ["1", "0"]:
            if (l == "0" and r == "1") or (l == "1" and r == "0"):
                del S[i:i+2]
                i += 2
                flag = True
                if i >= len(S)-3:
                    break


    if flag:
        continue

    for i in range(0, len(S)-1):
        mid = S[i:i+2]
        if mid == ["0", "1"] or mid == ["1", "0"]:
            del S[i:i+2]

    break
print(N-len(S))

Submission status: Runtime Error

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

if s != [0]:
  ans = 0
  def kesu(s, ans):
    for ni in range(n-1):
      if ni+1 >= len(s):
        return 0, ans
      if s[ni] != s[ni+1]:
        del s[ni:ni+2]
        ans += 2
        return s, ans

  while True:
    s, ans = kesu(s, ans)
    if s == 0:
      print(ans)
      break
else:
  print(0)

Submission status: Runtime Error

Solution code:
def f(s, c):
    num = 2 * s.count('01')
    s = s.replace("01", "")
    num += 2 * s.count('10')
    s = s.replace("10", "")
    if num == 0:
        return c
    return f(s, c+num)


    # for i in range(1, n):
    #     if s[i-1] != s[i]:
    #         c += 2
    #         return f(s[:i-1] + s[i + 1:], n - 2, c)


if __name__ == '__main__':
    S = input()
    c = 0
    print(f(S, c))

Submission status: Runtime Error

Solution code:
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    check_dif = False
    #print(S)
    for i in range(l-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            #print(S)
            check_dif = True
            ans += pickup(S,ans)
            break
    if not check_dif:
        return ans
    else:
        return ans+2
    
S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
print(pickup(S_list,ans))

Submission status: Runtime Error

Solution code:
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    check_dif = False
    #print(S)
    for i in range(l-1):
        if i+1
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            #print(S)
            check_dif = True
            ans += pickup(S,ans)
            break
    if not check_dif:
        return ans
    else:
        return ans+2
    
S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
print(pickup(S_list,ans))

Submission status: Runtime Error

Solution code:
S=input()
L=len(S)
L1=len(S)
L2=0
while L1!=L2:
    L1=len(S)
    S=S.replace("01","")
    S=S.replace("10","")
    print(S)
    L2=len(S)
print(L2)
print(L-L2)

Submission status: Runtime Error

Solution code:
s = list(input())
n = n0 = len(s)
nn = 0
while n > 1 and n != nn:
  n = len(s)
  for i in range(n-1, 1, -1):
    if s[i] != s[i-1]:
      s.pop(i)
      s.pop(i-1)
      i -= 1
  nn = len(s)
print(n0 - nn)

Submission status: Runtime Error

Solution code:
s = list(input())
n = n0 = len(s)
nn = 0
while n > 1 and n != nn:
  n = len(s)
  for i in range(n-1, 1, -1):
    if s[i] != s[i-1]:
      s.pop(i)
      s.pop(i-1)
      i -= 1
  nn = len(s)
print(n0 - len(nn))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.input
def check(S, cnt):
    if len(S) < 2:
        print(cnt)
        sys.exit()
    for i in range(len(S) - 1):
        if S[i] != S[i + 1]:
            S = S[:i] + S[i + 2:]
            cnt += 2
            check(S, cnt)
    print(cnt)
    sys.exit()

S = list(map(int, list(input())))
check(S, cnt=0)

Submission status: Runtime Error

Solution code:
import sys
def check(S, cnt):
    stop = True
    if len(S) < 2:
        print(cnt)
        sys.exit()
    for i in range(len(S) - 1):
        if S[i] != S[i + 1]:
            S = S[:i] + S[i + 2:]
            cnt += 2
            check(S, cnt)
    print(cnt)
    sys.exit()

S = list(map(int, list(input())))
check(S, cnt=0)

Submission status: Runtime Error

Solution code:
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    check_dif = False
    #print(S)
    for i in range(l-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            #print(S)
            check_dif = True
            ans += pickup(S,ans)
            break
    if not check_dif:
        return ans
    else:
        return ans+2
    
S=input()
S_list = []
l = len(S)
for i in range(l):
    S_list.append(S[i])
ans =0
print(pickup(S_list,ans))

Submission status: Runtime Error

Solution code:
import copy
S = list(input())

flag = True
total = len(S)

S_ = S

while flag:
  S = S_
  S_ = copy.copy(S)
  j = 0
  carsor = 0
  while carsor < len(S)-1:
    if S[carsor] != S[carsor+1]:
      del S_[j]
      del S_[j]
      j -= 2
      carsor += 1
    j += 1
    carsor += 1
  if carsor == j:
    flag = False
      
print(total - len(S))

Submission status: Runtime Error

Solution code:
s = [int(i) for i in str(input())]
 
count = 0
l = len(s)
su = sum(s)

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

Submission status: Runtime Error

Solution code:
import copy as copy
s = input()
dic={}

def func(val, n):
    if val in dic:
        return dic[val]

    if not ('1' in val):
        return n
    elif not ('0' in val):
        return n
    a=0
    b=0    
    if '01' in val:
        a = func(val.replace('01', '', 1), n+2)
    if '10' in val:
        b = func(val.replace('10', '', 1), n+2)
    
    ans=max(a, b, n)

    dic[val]=ans

    return ans

print(func(s, 0))

Submission status: Runtime Error

Solution code:
S = list(raw_input())

i = 0
cnt = 0
while len(S) > 0:
    if i+1 == len(S):
        break
    if S[i] != S[i+1]:
        del S[i]
        del S[i]
        i -= 2
        cnt += 2
    i += 1

print cnt

Submission status: Runtime Error

Solution code:
S=list(input())
red=len(list(filter(lambda e:e=='0', S)))
blue=len(list(filter(lambda e:e=='1', S)))
d=abs(red-bule)
print(red+bule-d)

Submission status: Runtime Error

Solution code:
a,b,c = map(int,input().split())
count = int(0)
i = int(0)

if (a == 0) or (b == 0):
    i = 0
else:
    for i in range(1,100):
            if ((a % i) == 0) and ((b % i) == 0):
                count += 1
                if count >= c:
                   break

print(i)

Submission status: Runtime Error

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

count = 0
l = len(s)
su = sum(s)
        
while True:
        if 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: Runtime Error

Solution code:
import re
s=input()
m=0
for i in range(len(s)//2):
  dst = re.sub(r'01|10', "", s)
  dst = re.sub(r'000000111111', "", dst)
  if dst == s:
    break
  m += len(s) - len(dst)
  s=dst
print(m

Submission status: Runtime Error

Solution code:
#c

S = input()

def clean(seq):
#     print("seq: ", seq)
    if len(seq) == 1:
        return seq
    
    def get_removee_left(cand_seq):
        if len(cand_seq) == 1:
            return -1
        for idx, s in enumerate(cand_seq[:-1]):
            if int(s) + int(cand_seq[idx+1]) == 1:
                return idx
        return -1
        
    ans = seq
    
    left = get_removee_left(seq)
#     print("left: ",left)
    if left > 0:
#         print("give:",seq[:left]+seq[left+2:])
        give = seq[:left]+seq[left+2:]
        ans = clean(give)
    elif left == 0:
#         print("give:", seq[left+2:])
        ans = clean(seq[left+2:])
    else:
        pass
        
    return ans
    
    
#     cleaned_seq = []
#     remove_flag = False
#     for idx, s in enumerate(seq):
#         if remove_flag:
#             ans = clean(clean_seq)
            
#         if idx == len(seq)-1:
#             cleaned_seq.append(s)
#             break

#         this_ = int(s)
#         next_ = int(seq[idx+1])
#         if this_ + next_ == 1:
#             remove_flag = True
#         else:
#             cleaned_seq.append(s)
            
#     return cleaned_seq

# former_cleaned = []
# cleaned = S
# while(not len(cleaned) == len(former_cleaned)):
#     former_cleaned = cleaned
#     cleaned = clean(former_cleaned)
    
# print(len(S) - len(cleaned))
print(len(S) - len(clean(S)))

Submission status: Runtime Error

Solution code:
# a, b, k = map(int, input().split())
s = input()

n = len(s)


def rep(str):
    ret = str.replace('01', '')
    ret = ret.replace('10', '')

    if ret != str:
        ret = rep(ret)

    return ret


input_str = s
# ret = None
#
# while ret is None or input_str != ret:
#     ret = input_str
#     input_str = rep(input_str)

ret = rep(s)

print(n - len(ret))

Submission status: Runtime Error

Solution code:
import sys
rawdata=sys.stdin.readline()
rawdata.rstrip('\n')
rawdata2=list(rawdata)
line=list(map(int,rawdata2))
line=list(map(int,list(str(input()))))
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: Runtime Error

Solution code:
t = ['01','10']
s = input()

def count_removal(c):
  is_01 = c.count(t[0])
  is_10 = c.count(t[1])
  if is_01 >= is_10 and is_01 > 0:
    return count_removal(c.replace(t[0], '')) + c.count(t[0]) * 2
  elif is_01 < is_10 and is_10 > 0:
    return count_removal(c.replace(t[1], '')) + c.count(t[1]) * 2
  else:
    return 0

print(count_removal(s))

Submission status: Runtime Error

Solution code:
def solve(S,crs=0):
    if crs >= len(S) or crs <0:
        return 0
    while crs + 1 < len(S):
        if S[crs] != S[crs+1]:
            #print(S,crs)
            return max(solve(S,crs+1),solve(S[:crs]+S[crs+2:],crs-1)+2)
        crs += 1
        
    return 0
  
S = input()
print(solve(S,0))

Submission status: Runtime Error

Solution code:
import sys

def parse(inp):
    S=list(map(int,list(next(inp))))
    return S

def main(inp):
    S=inp
    i = 0
    count = 0
    while i < len(S)-1:
        if(S[i] != S[i+1]):
            del S[i:i+2]
            i=0
            count += 2
        else: i += 1
            
    return count
  
print(main(parse(sys.stdin)))

Submission status: Runtime Error

Solution code:
import sys
rawdata=sys.stdin.readline()
rawdata.rstrip('\n')
line=list(map(int,list(rawdata)))
line=list(map(int,list(str(input()))))
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: Runtime Error

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

Submission status: Runtime Error

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

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0

    i = 0
    while True:
        if len(sl) <= i:
            break

        if (prev == 0 and sl[i] == '1') or (prev == 1 and sl[i] == '0'):
            # print(str(sl))
            # print("remove", i, prev, sl[i])
            del sl[i]
            del sl[i-1]
            n += 2
            if len(sl) <= i:
                break
            else:
                prev = int(sl[i-2])
                i = i-1
        else:
            prev = int(sl[i])
            i += 1

    print(n)

main()

Submission status: Runtime Error

Solution code:
s = input()
n0 = n = len(s)
nn = 0
while s and n != nn:
  n = len(s)
  for i, c in enumerate(s):
    if s[i] != s[i+1]:
      s = s[:i] + s[i+2:]
      i -= 1
  nn = len(s)
print(n0-len(nn))

Submission status: Runtime Error

Solution code:
import sys
S = input()
S_list = list(S)
flag = 1
S_pick = []

if len(S) < 2:
    print(0)
    sys.exit()

while flag:
    if len(S_list) == 0:
        break
    tmp = S_list[0]
    count = 0
    for i in range(1, len(S_list)):
        if S_list[i] == tmp and i == len(S_list)-1:
            break
            
        elif S_list[i] == tmp:
            tmp = S_list[i]
        else:
            S_pick.append(i-1)
            S_pick.append(i)
            tmp = S_list[i+1]
    for i in range(len(S_pick)-1, -1, -1):
        S_list.pop(S_pick[i])
    if len(S_pick) == 0:
        flag = 0
    S_pick = []
    
print(len(S)-len(S_list))

Submission status: Runtime Error

Solution code:
def f(s, n, c):
    for i in range(1, n):
        if s[i-1] != s[i]:
            c += 2
            return f(s[:i-1] + s[i + 1:], n - 2, c)
    return c


if __name__ == '__main__':
    S = input()
    N = len(S)
    c = 0
    print(f(S,N,c))

Submission status: Runtime Error

Solution code:
s = [int(i) for i in s]
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]:
                        s.pop(i)
                        s.pop(i)
                        count += 2
                        break
else:
        print(count)
        break

Submission status: Runtime Error

Solution code:
import re
s=input()
m=0
for i in range(len(s)/2):
  dst = re.sub(r'01|10', "", s)
  if dst == s:
    break
  m += len(s) - len(dst)
  s=dst
print(m)

Submission status: Runtime Error

Solution code:
import sys
def check(S, cnt):
    if len(S) < 2:
        print(cnt)
        sys.exit()
    for i in range(len(S) - 1):
        if S[i] ^ S[i + 1]:
            S = S[:i] + S[i + 2:]
            cnt += 2
            check(S, cnt)
    print(cnt)
    sys.exit()

S = list(map(int, list(input())))
check(S, cnt=0)

Submission status: Runtime Error

Solution code:
import copy as copy
s = input()

def func(val, n):
    if len(val) < 2:
        return n
    a=0
    b=0    
    if '01' in val:
        a = func(copy.copy(val.replace('01', '', 1)), n+2)
    if '10' in val:
        b = func(copy.copy(val.replace('10', '', 1)), n+2)
    
    return max(a, b, n)

print(func(s, 0))

Submission status: Runtime Error

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

S = input()
N = len(S)
while True:
    flag = False
    for i in range(1, len(S)-2):
        l = S[i-1]
        mid = S[i:i+2]
        r = S[i+2]
        if mid == "01" or mid == "10":
            if (l == "0" and r == "1") or (l == "1" and r == "0"):
                S = S[:i] + S[i+2:]
                i += 2
                flag = True
                if i >= len(S)-3:
                    break


    if flag:
        continue

    for i in range(0, len(S)-1):
        mid = S[i:i+2]
        if mid == "01" or mid == "10":
            S = S[:i] + S[i+2:]

    break
print(N-len(S))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def check(S, cnt):
    if len(S) < 2:
        print(cnt)
        sys.exit()
    for i in range(len(S) - 1):
        if S[i] ^ S[i + 1]:
            S = S[:i] + S[i + 2:]
            cnt += 2
            check(S, cnt)
    print(cnt)
    sys.exit()

S = list(map(int, list(input())))
check(S, cnt=0)

Submission status: Runtime Error

Solution code:
def f(s, n, c):
    rem = s[0]
    for i in range(n):
        if s[i] != rem:
            c += 2
            s = s[:i-1] + s[i + 1:]
            return f(s, n - 2, c)
        rem = s[i]
    return c


if __name__ == '__main__':
    S = input()
    N = len(S)
    c = 0
    print(f(S,N,c))

Submission status: Runtime Error

Solution code:
def remove_box(s,removed_box_num):
    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):
            del s[i:i+2]
            removed_box_num+=2
            return remove_box(s,removed_box_num)
    return removed_box_num

s = [int(i) for i in input()]

print(remove_box(s, 0))

Submission status: Runtime Error

Solution code:
s = input()
S = [int(s[i]) for i in range(len(s))]
# print(S)
count = 0
before = 0
while 1:
    #print("S:", S)
    is_continue = False
    # print(len(S))
    deleted = False
    for i in range(before, len(S) - 1):
        #print(before, i)
        #print(S[i], S[i + 1])
        # print(S)
        if S[i] != S[i + 1]:
            # print(count)
            del S[i]
            del S[i]
            count += 2
            is_continue = True
            if deleted:
                pass
            else:
                before = i - 1
                deleted = True
            break
    if not is_continue:
        break
print(count)

Submission status: Runtime Error

Solution code:
s = input()

def func(val, n):
    if len(val) < 2:
        return n
    a=0
    b=0    
    if '01' in val:
        a = func(val.replace('01', '', 1), n+2)
    if '10' in val:
        b = func(val.replace('10', '', 1), n+2)
    
    return max(a, b, n)

print(func(s, 0))

Submission status: Runtime Error

Solution code:
in_str = input()
#input_list = list(map(int,in_str.split()))
in_str = "0b"+in_str
#print(in_str)
#print(int(in_str, 0))
int_in = int(in_str, 0)
div = 0
while(True):
  int_in = int(int_in/2)
  if(int_in==1):
    break
  div +=1
print(div)

Submission status: Runtime Error

Solution code:
s = list(input())
x = list(map(int, s))
i = 0
ans = 0
k = 0
if len(x) == 1:
    print(0)
else:
    while(True):
        if x[i] + x[i + 1] == 1:
            k += 1
            del x[i + 1], x[i]
        if i + 2 >= len(x):
            ans += k
            if k == 0 or len(x) == 0:
                break
            k = 0
            i = 0
        else:
            i += 1
    print(ans * 2)

Submission status: Runtime Error

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

S = input()
N = len(S)
while True:
    flag = False
    for i in range(1, len(S)-2):
        l = S[i-1]
        mid = S[i:i+2]
        r = S[i+2]
        if mid == "01" or mid == "10":
            if (l == "0" and r == "1") or (l == "1" and r == "0"):
                S = S[:i] + S[i+2:]
                i += 2
                flag = True
                if i > len(S)-2:
                    break


    if flag:
        continue

    for i in range(0, len(S)-1):
        mid = S[i:i+2]
        if mid == "01" or mid == "10":
            S = S[:i] + S[i+2:]

    break
print(N-len(S))

Submission status: Runtime Error

Solution code:
s = input()

def count_removal(c):
  if '01' in c:
    return count_removal(c.replace('01', '')) + c.count('01')*2
  else:
    return 0

print(count_removal(s))

Submission status: Runtime Error

Solution code:
s = list(input())
x = list(map(int, s))
i = 0
ans = 0
k = 0
while(True):
    if x[i] + x[i + 1] == 1:
        k += 1
        del x[i + 1], x[i]
    if i + 2 >= len(x):
        ans += k
        if k == 0 or len(x) == 0:
            break
        k = 0
        i = 0
    else:
        i += 1
print(ans * 2)

Submission status: Runtime Error

Solution code:
# coding=utf-8


def count_remove(cube_list):
    for i in range(len(cube_list)):
        try:
            if cube_list[i] != cube_list[i+1]:
                cube_list_n = cube_list[:i] + cube_list[i+2:]
                return 1 + count_remove(cube_list_n)
        except IndexError:
            return 0
    else:
        return 0


if __name__ == '__main__':
    S = list(map(int, input()))

    ctr = count_remove(S)
    print(ctr*2)

Submission status: Runtime Error

Solution code:
s=str(input())

p1 = '01'
p2 = '10'
s = s[::-1]
c = 0
flag = True
while flag:
  flag = False
  for i in range(len(s)):
    if s[i:i+4] == in('0011','1100','1010','0101','1001','0110'):
      s = s[:i] + s[i+4:]
      c += 4
      flag = True
      break
    
    
    if s[i:i+2] in [p1,p2]:
      s = s[:i] + s[i+2:]
      c += 2
      flag = True
      break
print(c)

Submission status: Runtime Error

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

count = 0

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

Submission status: Runtime Error

Solution code:
a = input()
count0 = 0
count1 = 0
a = int(a)
while(a > 0):
    if(a%2 ==0):
        count0 = count0 + 1
        a = a/10
    else:
        count1 = count1 + 1
        a = (a-1)/10

print(min(count0,count1)*2)

Submission status: Runtime Error

Solution code:
S=input()
count=0
for j in len(S)//2:
  i=0
  while i<=len(S):
    if S[i]!=S[i+1]:
      count+=1
      del S[i+1]
      del S[i]
      i-=1
    i+=1
print(count)

Submission status: Runtime Error

Solution code:
import sys

def f(A, c):
  n = len(A)
  B = []
  for i in range(len(A) -1):
    if A[i] != A[i+1]:
      c += 2
      B += A[i+2:]
      break
    else:
      B.append(A[i])
  if len(B) == n:
    return c
  else:
    return f(B, c)


def main():
  input = sys.stdin.readline
  S = [int(c) for c in input().strip()]
  ans = f(S, 0)
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
str = list(input())
last = str[0]
check = 0
ans = 0

while True:
    check = 0
    last = str[0]
    for j in range(len(str) - 1):
        if j >= len(str):
            break

        if last != str[j + 1 - check]:
            str.pop(j-check)
            str.pop(j-check)
            check += 1
            ans += 2

        if str == []:
            break
        last = str[j + 1 - check]

    if check == 0:
        break
    if str == []:
        break

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
S = [int(s[i]) for i in range(len(s))]
# print(S)
count = 0
before = 0
while 1:
    #print("S:", S)
    is_continue = False
    # print(len(S))
    for i in range(before, len(S) - 1):
        #print(before, i)
        #print(S[i], S[i + 1])
        # print(S)
        if S[i] != S[i + 1]:
            # print(count)
            del S[i]
            del S[i]
            count += 2
            is_continue = True
            before = i-1
            break
    if not is_continue:
        break
print(count)

Submission status: Runtime Error

Solution code:
S=list(input())
ans=0
j=0
while len(S)-1>j:
    if S[j]!=S[j+1]:
        S.pop(j)
        S.pop(j)
        ans+=2
        j-=1
        continue
    j+=1
print(ans)