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:
def dfs(s, i, count):
    #print(f"S_len: {len(s)}")
    if len(s) > 1 and len(s) - i > 1:
        current_cube = s[i]
        tmp_ans = 0 
        if (s[i] == "0" and s[i+1] == "1") or (s[i] == "1" and s[i+1] == "0"):
            b = s[:]
            del b[i]
            del b[i]
            tmp_ans = dfs(b, 0, count + 2)
        ans = dfs(s, i+1, count)
        #print(f"ans:{ans}")
        if ans < tmp_ans:
            ans = tmp_ans
        return ans 
    else: # 要素が0のとき
        return count 


S = list(input())
#print(S)

print(dfs(S, 0, 0))

Submission status: Runtime Error

Solution code:
import re

si = input()

def count_zeroone(s, c):
  if(s.count('01') > 0 or s.count('10') > 0):
    f_l = s.count('01')
    s = re.sub('01','',s)
    f_r = s.count('10')
    s = re.sub('10','',s)
    return count_zeroone(s, (c+f_l+f_r))
  else:
    return (c)
print( (count_zeroone(si, 0) * 2 ) )

Submission status: Runtime Error

Solution code:
def crmv(c,istr):
    if len(istr)<=1:
        return c
    '''
    lidx=[]
    for i in range(len(istr)-1):
        if istr[i] != istr[i+1]:
            lidx.append(i)
    if len(lidx)==0:
        return c

    rv=0
    for i in lidx:
        tstr=istr[:i]+istr[i+1+1:]
        r=crmv(c+2,tstr)
        if r>rv:
            rv=r
    '''
    rv=-1
    for i in range(len(istr)-1):
        if istr[i] != istr[i+1]:
            tstr=istr[:i]+istr[i+1+1:]
            r=crmv(c+2,tstr)
            if r>rv:
                rv=r
    if rv == -1:
        return c
            

    return rv

istr=input()
print(crmv(0,istr))

Submission status: Runtime Error

Solution code:
s = input()
length_s = len(s)
list_s = list()
for i in range(length_s):
    list_s.append(s[:1])
    s = s[1:]
length = length_s
while(length > 2):
    for j in range(length - 1):
        if(list_s[j] != list_s[j+1]):
            del list_s[j:j+2]
            break;
        length = len(list_s)
print(length_s - len(list_s))

Submission status: Runtime Error

Solution code:
a = input()
sum = 0
for i in range(len(a)):
  if a[i] == "0" and a[i+1] == "1" and i < len(a-2):
    sum += 2
    a = a[:i] + a[i+2:]
  elif a[i] == "1" and a[i+1] == "0" and i < len(a-2):
    sum += 2
    a = a[:i] + a[i+2]
  elif a[i] == "0" and a[i+1] == "1" and i == len(a-2):
    sum += 2
    a = a[:i]
  elif a[i] == "1" and a[i+1] == "0" and i == len(a-2):
    sum += 2
    a = a[:i]
  else:
    pass
print(sum)

Submission status: Runtime Error

Solution code:
s = str(input())

num_moto = int(len(s))

for ctr in range(500)
    if 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: Runtime Error

Solution code:
S = list(input())
N = len(S)
c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
        del S[i:i+2]
        c+=2
        N-=2
        i-=1
        f=1
    i+=1
    if i+1 == N:
        i=0
        if f==0:
            break
        f=0
print(c)

Submission status: Runtime Error

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

print(L-len(S))

Submission status: Runtime Error

Solution code:
S=list(input())
count=0
N=len(S)
for j in range(N//2):
  if len(S)<=1:
    break
  if (sum(S)==0)or(sum(S)==len(S)):
    break
  i=0
  while True:
    if S[i]!=S[i+1]:
      count+=1
      del S[i:i+2]
      i-=1
    i+=1
    if i>=len(S)-1:
      break
print(2*count)

Submission status: Runtime Error

Solution code:
import sys


S_raw = sys.stdin.readline().strip()

def check_next(S):
    S = list(S)
    before_num=S[0]
    for i in range(len(S)):
        if S[i]!=before_num:
            S.pop(i-1)
            #S = list(S)
            S.pop(i-1)
            new_S = S
            return S,1
            break
    return S,0


cnt=0
N=0

while cnt<50000:
    S_raw, check_cnt = check_next(S_raw)
    N += check_cnt
    if check_cnt==0:
        break
    cnt+=1
    
print(N*2)

Submission status: Runtime Error

Solution code:
def r(s):
    bsl = len(s)
    flg = True
    while flg:
        slng = len(s)
        s = s.replace('01', '').replace('10', '')
        if slng == len(s):
            flg = False

    return bsl - len(s)


def main():
    input = sys.stdin.readline
    s = input().strip()

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
in_s = input().rstrip()
lst = list(in_s)
cur=0
while True:
    if cur >= len(lst):
        break
    if lst[cur]!=lst[cur+1]:
        del lst[cur+1]
        del lst[cur]
        cur = max(0,cur-1)
    else:
        cur+=1

print(len(in_s) - len(lst))

Submission status: Runtime Error

Solution code:
P=sum(map(int,list(raw_input())));print min(P,N-P)*2

Submission status: Runtime Error

Solution code:
S = list(input())
N = len(S)
c=0
i=0
f=0
while(1):
    if S[i] != S[i+1]:
	del S[i:i+2]
	c+=2
	N-=2
	i-=1
	f=1
    i+=1
    if i+1 == N:
	i=0
	if f==0:
            break
	f=0
print(c)

Submission status: Runtime Error

Solution code:
def r(s):
    bsl = len(s)
    flg = True
    while flg:
        slng = len(s) 
        s = s.replace('01', '').replace('10', '')
        if slng == len(s):
            flg = False
    
    return bsl - len(s)


def main():
    input = sys.stdin.readline
    s = input().strip()

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
s = input()
s = list(s)
x = 0
maxIndex = len(s) - 1
count = 0
while True:
    if maxIndex < x + 1:
        break
    if s[x] != s[x + 1]:
        s.pop(x)
        s.pop(x)
        maxIndex = len(s) - 1
        x = min(maxIndex, x - 1)
        count += 1
    else:
        x += 1
print(count * 2)

Submission status: Runtime Error

Solution code:
def extract(string, i):
    split = "".join(string.split("01")).split("10")
    i += len(split) - 1
    split_concat = "".join(split)
    if "01" in split_concat or "10" in split_concat:
        return extract(split_concat, i)
    else:
        return i * 2

S = input()
print(extract(S,0))

Submission status: Runtime Error

Solution code:
def unification(S: str) -> int:
    q = set([S])
    min_len = len(S)
    while len(q) > 0:
        t = []
        for s in q:
            min_len = len(s)
            for i, c in enumerate(s):
                if i + 1 < len(s) and c != s[i+1]:
                    t.append(s[:i] + s[i+2:])
        q = set(t)

    return len(S) - min_len


if __name__ == "__main__":
    S = input()
    answer = unification(S)
    print(answer)

Submission status: Runtime Error

Solution code:
in_s = input().rstrip()
lst = list(in_s)
cur=0
while True:
    if cur +1 == len(lst):
        break
    if lst[cur]!=lst[cur+1]:
        del lst[cur+1]
        del lst[cur]
        cur = max(0,cur-1)
    else:
        cur+=1

print(len(in_s) - len(lst))

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:

def r(s):
    bsl = len(s)
    flg = True
    while flg:
        b = s.replace('01', '').replace('10', '')
        if len(b) == len(s):
            flg = False
        else:
            s = b
    return bsl - len(s)


def main():
    input = sys.stdin.readline
    s = input().strip()

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

print(L-len(S))

Submission status: Runtime Error

Solution code:
P=sum(c=='0'for c in raw_input());print(min(P,N-P)*2)

Submission status: Runtime Error

Solution code:
def algo(s):
  if len(s) == 1:
    return 0
  elif len(s) == 2:
    if s[0] != s[1]:
      return 2
    else:
      return 0
  else:
    tmp = ""
    for i in range(1, len(s)-1):
      if s[i] != s[i+1]:
        tmp += s[0:i] + s[i+2:]
        break
    return 2 + algo(tmp)
    
x = input()
ans = algo(x)
print(ans)

Submission status: Runtime Error

Solution code:
import sys


S_raw = sys.stdin.readline().strip()

def check_next(S):
    S = list(S)
    before_num=S[0]
    for i in range(len(S)):
        if S[i]!=before_num:
            S.pop(i-1)
            #S = list(S)
            S.pop(i-1)
            new_S = S
            return S,1
            break
    return S,0


cnt=0
N=0

while cnt<10**5:
    S_raw, check_cnt = check_next(S_raw)
    N += check_cnt
    if check_cnt==0:
        break
    cnt+=1
    
print(N*2)

Submission status: Runtime Error

Solution code:
def extract(string, i):
    split = string.split("01")
    split = split.split("10")
    i += len(split) - 1
    split_concat = "".join(split)
    if "01" in split_concat or "10" in split_concat:
        return extract(split_concat, i)
    else:
        return i * 2

S = input()
print(extract(S,0))

Submission status: Runtime Error

Solution code:
def r(s):
    bsl = len(s)
    flg = True
    while flg:
        b = s.replace('01', '').replace('10', '')
        if len(b) == len(s):
            flg = False
        else:
            s = b
    return bsl - len(s)


def main():
    input = sys.stdin.readline
    s = input().strip()

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys


S_raw = sys.stdin.readline().strip()

def check_next(S):
    S = list(S)
    before_num=S[0]
    for i in range(len(S)):
        if S[i]!=before_num:
            S.pop(i-1)
            #S = list(S)
            S.pop(i-1)
            new_S = S
            return S,1
            break
    return S,0


cnt=0
N=0

while cnt<20:
    S_raw, check_cnt = check_next(S_raw)
    N += check_cnt
    if check_cnt==0:
        break
    cnt+=1
    
print(N*2)

Submission status: Runtime Error

Solution code:
import sys
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
if n > 10**5:
    sys.exit()
S = Remove(S,n)
print(n-len(S))

Submission status: Runtime Error

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

def check01(s):
    if len(s) > 1:
        for i in range(len(s)-1):
            if s[i] != s[i+1]:
                del s[i:i+2]
                return check01(s)
    return s
s2 = copy.deepcopy(s)
s2 = check01(s2)
print(len(s) - len(s2))

Submission status: Runtime Error

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

count = 0
while(True):
    old = count
    if (len(s) == 1 or len(s) == 0):
        break
    for n in range(len(s) - 1):

        if (s[n] != s[n+1]):

            s.pop(n)
            s.pop(n)
            count += 2
            n -= 1

        if (len(s) <= n + 2):
            break
    if (old == count):
        break

print(count)

Submission status: Runtime Error

Solution code:
#coding: utf-8
import math

def main():
    S = input()
    counter = 0
    while(True):
        tmp_counter, S = pull_cubes(S)
        if tmp_counter is 0:
            break
        counter += tmp_counter
    print(counter)

def pull_cubes(string):
    length = len(string)
    cube_counter = 0
    before_cube = string[0]
    index = 0

    for i in range(length):
        if index >= length:
            break
        if string[index] is not before_cube:
            string = string[0:index-1] + string[index+1:]
            length -= 2
            cube_counter += 2
            index -= 1
            before_cube = string[index]
        else:
            before_cube = string[index]
            index += 1
    return cube_counter, string

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = list(map(int, input()))
ans = 0
l = len(S)
i = 0
while len(S)-1 > i:
    if S[i] != S[i+1]:
        S.pop(i)
        S.pop(i)
        ans += 2
        i -= 2
    i += 1


print(ans)

Submission status: Runtime Error

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

def cube_cut(s, cnt):
    if "01" not in s or "10" not in s:
        print(cnt)
        exit(0)

    s2 = s.replace("01", '', 1)
    if s2 != s:
        cnt = cnt + 2
        cube_cut(s2, cnt)
    else:
        s3 = s2.replace("10", '', 1)
        if s3 != s2:
            cnt = cnt + 2
        cube_cut(s3, cnt)


cube_cut(s, cnt)

Submission status: Runtime Error

Solution code:
cubes = input()

removed_cubes_count = 0

while True:
    count01 = cubes.count('01')
    count10 = cubes.count('10')

    if count01 == 0 and count10 == 0:
        break

    removed_cubes_count += count01 + count10

    cube = cube.translate({
        '01': '',
        '10': ''
    })

print(removed_cubes_count)

Submission status: Runtime Error

Solution code:
S = list(map(int,input()))
init = int(len(S))
ans = []

def cube(S,ans):
    if not any(S) or all(S):
        ans.append(int((init-len(S))))
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            cube(S[0:i]+S[i+2:],ans)
cube(S,ans)
ans.sort()
print(ans[-1])

Submission status: Runtime Error

Solution code:
import sys
data=sys.stdin
line=[int(c) for c in data.rstrip('/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: Runtime Error

Solution code:
import numpy as np

np_int = np.frompyfunc(int,1,1)

s = np_int(np.array(list(input())))
del_num = 0

while True:
    old_s = s[:]
    del_list = np.full_like(s,False)
    for i in range(len(s) - 1):
        if (del_list[i] == True):
            continue
        if (str("".join(map(str,s[i:i + 2]))) == "01"):
            del_list[i:i + 2] = True
            for j in range(1,len(s)//2):
                if (0 <= i - j and i + j + 1 < len(s)) and ("".join([str(s[i - j]), str(s[i + j + 1])]) == "01"):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
        if (str("".join(map(str,s[i:i + 2]))) == "10"):
            del_list[i:i + 2] = True
            for j in range(1,len(s)//2):
                if (0 <= i - j and i + j + 1 < len(s)) and ("".join([str(s[i - j]), str(s[i + j + 1])]) == "10"):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
    s = np.delete(s, np.where(del_list == 1))
    del_num += np.sum(del_list)
    if (len(old_s) == len(s)):
        break

print(del_num)

Submission status: Runtime Error

Solution code:
S = input()

nums = []
for s in S:
    nums.append(int(s))

count = 0
i = 0
while i < len(nums)-1:
    if nums[i] != nums[i+1]:
        nums.pop(i+1)
        nums.pop(i)
        count += 1
        i -= 1
        continue
    i += 1

print(count*2)

Submission status: Runtime Error

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)
    S.pop(i-1)
    i-=1
  else:
    i+=1

print(L-len(S))

Submission status: Runtime Error

Solution code:
s = input()
origin = s
past = ''
cnt=0
while True:
    past = s
    s = s.replace('10','').replace('01','')
    print(s)
    print(past)
    if past==s:
        break

num = len(origin)-len(s)
print(num)

Submission status: Runtime Error

Solution code:
S = input()

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

print(2*min(c0,c1))

Submission status: Runtime Error

Solution code:
import sys
line=[int(c) for c in sys.stdin.rstrip('/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: Runtime Error

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

count = 0
for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    del S[i],S[i+1]
    count =2+count 
  else:
    if len(S)==i+1:
      print(count)
    else:
  		continue
    
print(count)

Submission status: Runtime Error

Solution code:
import sys
line=[int(c) for c in sys.stdin.rstrip()]
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:
str = input()
p = 0
count = 0
while(True):
	if p >= len(str) - 1:
		break
	if str[p] != str[p+1]:
		newstr = str[0:p] + str[p+2:]
		p -= 1
		count += 2
		str = newstr
	else:
		p += 1
print(count)

Submission status: Runtime Error

Solution code:
#coding: utf-8
import math

def main():
    S = input()
    result = pull_cubes(S)
    print(result)

def pull_cubes(string):
    length = len(string)
    cube_counter = 0
    before_cube = string[0]
    index = 0

    for i in range(length):
        if index >= length:
            break
        if string[index] is not before_cube:
            string = string[0:index-1] + string[index+1:]
            length -= 2
            cube_counter += 2
            index -= 1
            before_cube = string[index]
        else:
            before_cube = string[index]
            index += 1
    if cube_counter is 0:
        return cube_counter
    else:
        cube_counter += pull_cubes(string)
        return cube_counter

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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=i-1
  else:
    i+=1

print(L-len(S))

Submission status: Runtime Error

Solution code:
import sys
line=[int(c) for c in sys.stdin.readline() 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: Runtime Error

Solution code:
memo = {}
def solve(S):
    if len(S)<1:
        return 0
    crs = 0
    if S in memo:
        return memo[S]
    while crs + 1 < len(S):
        if S[crs] != S[crs+1]:
            memo[S] = solve(S[:crs]+S[crs+2:])+2
            return memo[S]
        crs += 1
    return 0
S = input()
print(solve(S))

Submission status: Runtime Error

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-=2
    i+=1
print(a)

Submission status: Runtime Error

Solution code:
s = input()
ls = len(s)
for i in range(ls//2):
    t = s.replace("10","").replace("01","")
    if t == s:
        break
    else:
        s = t
ans = ls - len(t)
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
S = list(S)
count = 0


for j in range(200) :
    if len(S) < 2:
        break
    
    if S[0] != S[1] :
        S.pop(0)
        S.pop(0)
        count+=2
    
    
    for i in range(1,len(S)-2) :
        print(S, i)
        if S[i] != S[i+1] :
            if S[i-1] != S[i+2] :
                S.pop(i)
                S.pop(i)
                count +=2
                break
            
print(count)

Submission status: Runtime Error

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


def cube_cut(s, cnt):
    if "01" not in s or "10" not in s:
        print(cnt)
        exit(0)

    s2 = s.replace("01", '', 1)
    if s2 != s:
        cnt = cnt + 2
    s3 = s2.replace("10", '', 1)
    if s3 != s2:
        cnt = cnt + 2
    cube_cut(s3, cnt)


cube_cut(s, cnt)

Submission status: Runtime Error

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

def df(s):
  while True:
    if '01' in s or '10' in s:
      s = s.replace('01', '')
      s = s.replace('10', '')
    else:
      break
  return s

if len(s) < 1000:
  print(l - len(df(s)))
else:
  i = l // 4
  sx = df(s[:i]) + df[i:i * 2] + df[i * 2:i * 3] + df[i * 3:]
  print(l - len(df(sx)))

Submission status: Runtime Error

Solution code:
import sys
line=[int(c) for c in sys.stdin.read()]
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:
import numpy as np

np_int = np.frompyfunc(int,1,1)

s = np_int(np.array(list(input())))
del_num = 0

while True:
    old_s = s[:]
    del_list = np.full_like(s,False)
    for i in range(len(s) - 1):
        if (del_list[i] == True):
            continue
        if (str("".join(map(str,s[i:i + 2]))) == "01"):
            del_list[i:i + 2] = True
            for j in range(1,len(s)//2):
                if ("".join([str(s[i - j]), str(s[i + j + 1])]) == "01"):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
        if (str("".join(map(str,s[i:i + 2]))) == "10"):
            del_list[i:i + 2] = True
            for j in range(1,len(s)//2):
                if ("".join([str(s[i - j]), str(s[i + j + 1])]) == "10"):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
    s = np.delete(s, np.where(del_list == 1))
    del_num += np.sum(del_list)
    if (len(old_s) == len(s)):
        break

print(del_num)

Submission status: Runtime Error

Solution code:
S = list(input().strip())
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:
import sys
line=[int(c) for c in sys.stdin.read]
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 = list(map(int, input()))

count = 0
for i in range(len(S)):
  if S[i]!=S[i+1]:
  	del S[i],S[i+1]
    count +=2
  	continue  
  elif S[len(S)]==S[len(S)+1]
  	break
  else:
  	continue
    
print(count)

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]
            i += 2
            if i >= len(S)-1:
                break

    break
print(N-len(S))

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
                break
    if counter == 0:
        break

print(ans*2)

Submission status: Runtime Error

Solution code:
import re
S = input()
l = len(S)
while True:
  if re.sub('01|10','',S) == S
  	break
  else:
    S = re.sub('01|10','',S)
print(l-len(S))

Submission status: Runtime Error

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

tmp = S
a = 0
b = 0
c = 0
count = 0
if len(tmp)-1 == b:
    a = 1
while a == 0:
    if tmp[b] != tmp[b+1]:
        if len(tmp) == 2:
            tmp = ''
            break
        else:
            count += 1
            tmp = tmp[:b] + tmp[b+2:]
            b = 0
            c += 1
    else:
        b += 1
        if len(tmp)-1 == b:
            a = 1

print(str(count*2))

Submission status: Runtime Error

Solution code:
from collection import Counter
cnt = Counter()
s = input()
for c in s:
  cnt[c] += 1
  
print(min(cnt.keys()) * 2)

Submission status: Runtime Error

Solution code:
s = input()
times = 0
is01 = s.find("01")
is10 = s.find("10")
while is01 != -1 or is10 != -1:
    times += 1
    if is01 != -1:
        s = s[:is01] + s[is01+2:]
    else :
        s = s[:is10] + s[is10+2:]
    is01 = s.find("01")
    is10 = s.find("10")
    print(s)
print(times*2)

Submission status: Runtime Error

Solution code:
s=input()
s_=list(s)
i=0
while i<=len(s_)-2:
    if s_[i]!=s_[i+1]:
        del s_[i:i+2]
        i=i-1
    else:
        i+=1
print(len(s)-len(s_))

Submission status: Runtime Error

Solution code:
s = list(map(int, input()))
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
    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
      if len(s) == i+1:
        break

print(count)

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(N)-3:
                    break


    if flag:
        continue

    nN = len(S)
    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]
            i += 2
            if i >= len(nN)-2:
                break

    break
print(N-len(S))

Submission status: Runtime Error

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

if n < 2:
    print(0)

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

    while i < n:

        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)

Submission status: Runtime Error

Solution code:
S = input()

red = 0  # 0
blue = 0 # 1
m = 0
for s in S:
	if s = '0':
		if blue != 0:
			blue -= 1
			m += 2
		else:
			red += 1
	elif s = '1':
		if red != 0:
			red -= 1
			m += 2
		else:
			blue += 1

print(m)

Submission status: Runtime Error

Solution code:
import numpy as np

s = input()
s = np.asarray(list(s))
ans = 0
i = 0
while True:
    if s[i] != s[i+1]:
        s = np.delete(s, [i, i+1])
        ans = ans + 2
        i = i - 1
        if i != -1:
            i = i - 1
    i = i+1
    if len(s) == 0 or len(s) == i+1:
        break
print(ans)