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:
s = str(input())
n = len(s)
ans = 0
b = [0 for i in range(n)]
for i in range(n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            nowl = i
            nowr = i+1
            while flag:
                if nowl < 0 and nowr > n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                elif b[nowl] == 1 and b[nowr] == 0:
                    nowl -= 1
                elif b[nowl] == 0 and b[nowr] == 1:
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False
for i in range(1,n-1):
    if s[i] != s[i+1]:
        if b[i] == 0 and b[i+1] == 0:
            b[i] = 1
            b[i+1] = 1 
            ans += 2
            flag = True
            nowl = i-1
            nowr = i
            while flag:
                if nowl < 0 and nowr > n-1:
                    flag = False
                if b[nowl] == 1 and b[nowr] == 1:
                    nowl -= 1
                    nowr += 1
                elif b[nowl] == 1 and b[nowr] == 0:
                    nowl -= 1
                elif b[nowl] == 0 and b[nowr] == 1:
                    nowr += 1
                else:
                    if s[nowl] != s[nowr]:
                        ans += 2
                        b[nowl] += 1
                        b[nowr] += 1
                        nowl -= 1
                        nowr += 1
                    else:
                        flag = False
print(ans)

Submission status: Runtime Error

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

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

while (i <= len(S_array) -2):
    if S_array[i] != S_array[i+1]:
        del S_array[i:i+2]
        i -= 1
        answer += 2
    else:
        i += 1
        
print(answer)

Submission status: Runtime Error

Solution code:
"""
    S：長さNの文字列
    if S[i] = '0':
        color = 'red'
    elif S[i] = '1':
        color = 'blue'
    
    I can remove set of boxes which put together red and blue box.

    output : How many can I remove box?
"""
s = input()
count = 0

while len(s) > 0:
    i = 0

    while i < len(s):
        if i == len(s)-1:
            break
        if (s[i+1] == '0' and s[i+2] =='1') or (s[i+1] == '1' and s[i+2] =='1'):
            s = s[:i+1]+s[i+3:]
            count += 1
            break
        i += 1
    if i == len(s)-1:
            break

print(count*2)

Submission status: Runtime Error

Solution code:
a = input()
s = list(a)
s_int = [int(i) for i in s ]
t = len(s_int)
i = 0
while 0 in s_int and 1 in s_int and i < len(s_int):
    if s_int[i] == 0 and s_int[i+1] == 1:
        s_int.pop(i)
        s_int.pop(i)
    elif s_int[i] == 1 and s_int[i+1] == 0:
        s_int.pop(i)
        s_int.pop(i)
    else:
        i += 1
print(t - len(s_int))

Submission status: Runtime Error

Solution code:
S=input()
if S.count(1)>=S.count(0):
  print(S.count("0")*2)
else:
  print(S.count("1")*2)

Submission status: Runtime Error

Solution code:
S=input()

if len(S)==1:
  print(0)

print(min(S[::2].count(0), S[1::2].count(1)) + min(S[::2].count(1), S[1::2].count(0)))

Submission status: Runtime Error

Solution code:
S = input()

def recur_del(s):
  s = s.replace('01','A')
  s = s.replace('10','A')
  lst = s.split('A')
  s2 = ''.join(lst) 
  if len(s) == len(s2):
    return s 

  return recur_del(s2)

res = recur_del(S)

if res is None:
  c = ""
else:
  c = res
print(len(S) - len(c))

Submission status: Runtime Error

Solution code:
S=input()
if S.count(1)>=S.count(0):
  print(S.count(0)*2)
else:
  print(S.count(1)*2)

Submission status: Runtime Error

Solution code:
import sys

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

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

Submission status: Runtime Error

Solution code:
a=input()
size=len(a)
a=int(a)
num=[]
b=0
for j in range(size):
  if(a%10==1):
    num.insert(0,1)
  else:
    num.insert(0,0)
  a=int(a/10)
count=0
d=0
i=0
while(d==0):
  if(len(num)==0): break
  if(len(num)==1): break
  if(i==len(num)-1): break
  if(num[i]!=num[i+1]):
    num.pop(i)
    num.pop(i)
    i=-1
    count+=2
  i+=1
print(count)

Submission status: Runtime Error

Solution code:
def next_top(idx):
    jump = 1
    if idx + jump == l:
            return -1
    while(exist[idx+jump]==0):
        jump = jump +1
        if idx + jump == l:
            return -1
    return idx + jump

def next_bottom(idx):
    jump = 1
    while(exist[idx+jump]==0):
        jump = jump -1
        if idx - jump == -1:
            return -1
    return idx + jump

# 文字列の入力
s = input()
l = len(s)
exist = [1]*l
removal_count = 0
max_removal = l // 2
8
top_idx = 1
bottom_idx = 0

while removal_count != max_removal:
    if s[bottom_idx] != s[top_idx]:
        removal_count = removal_count +1
        exist[bottom_idx] = 0
        exist[top_idx] = 0
        if next_top(top_idx) < 0:
            break
        elif next_bottom(bottom_idx) < 0:#双方上へずらす
            if next_top(next_top(top_idx))>=0:          
                top_idx =  next_top(next_top(top_idx))
                bottom_idx = next_top(top_idx)
            else:
                break
        else:
            top_idx = next_top(top_idx)
            bottom_idx = next_bottom(bottom_idx)
    else:
        if next_top(next_top(top_idx))>=0:  
            bottom_idx = next_top(top_idx)
            top_idx =  next_top(bottom_idx)
        else:
            break
return removal_count *2

Submission status: Runtime Error

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

S = list(map(int, list(sys.stdin.readline())))
base_S_length = len(S)
check(S)

Submission status: Runtime Error

Solution code:
s = input()
s2 = s
while "01" in s2 or "10"in s2::
    if "01" in s2:
        s2 = s2.replace("01", "")
    elif "10" in s2:
        s2 = s2.replace("10", "")

print(len(s) - len(s2))

Submission status: Runtime Error

Solution code:
buffer = list(input())
S = list(map(int, buffer))
N = len(S)
i = 0
count = 0
while(1):
    if(S == [] or N == 1):
        break
    elif((S[i] + S[i + 1]) == 1):
        S.pop(i)
        S.pop(i)
        i = i - 1
        count += 2
        N = len(S)
    else:
        i += 1
        if(i == (N - 1)):
            break
print(count)

Submission status: Runtime Error

Solution code:
line=input()
length=len(line)
while 1:
  line_1=line[:len(line)//2]
  line_2=[len(line)//2+1:len(line)]
  if line_1.count(1)>line_1.count(0):
    line_1.replace('1','')
    line_2.replace('0','')
  else:
    line_2.replace('1','')
    line_1.replace('0','')
  line=line_1+line_2
print(length-len(line))

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

    break
print(N-len(S))

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)
        counter += tmp_counter
        if tmp_counter is 0 or len(S) is 0 or len(S) is 1:
            break
    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:
            if index is not length-1:
                string = string[0:index-1] + string[index+1:]
            else:
                cube_counter += 2
                string = string[0:index-1]
                break
            length -= 2
            cube_counter += 2
            index -= 1
            if len(string) is 0 or len(string) is 1:
                break
            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 = input()
count = 0
while '10' in s:
    s = s.replace('10', '', 1)
    count += 1
    print(s)

while '01' in s:
    s = s.replace('01', '', 1)
    count += 1
print(count * 2)

Submission status: Runtime Error

Solution code:

S = input()
work=list(S)
i=0
cout=0
while(True):
    if(i==len(work)-1):
        break
    if(work[i]==work[i+1]):
        i+=1
    else:
        cout+=2
        del work[i]
        del work[i]
        i=0

    

print(len(S)-len(work))

Submission status: Runtime Error

Solution code:
S = list(input())

def f(S):
    new_array = []
    mark = False
    if len(S) == 2:
        if S[0] != S[1]:
            return []
        else:
            return S

    for i in range(0, len(S) - 2):
        if i % 3 == 0:
            if S[i] == S[i + 1] and S[i + 1] == S[i + 2]:
                new_array += [S[i], S[i+1], S[i+2]]
            elif S[i] != S[i + 1]:
                new_array += [S[i+2]]
                if mark == False:
                    mark = True
            elif S[i + 1] != S[i + 2]:
                new_array += [S[i]]
                if mark == False:
                    mark = True
    
    if len(S) % 3 == 1:
        if S[-2] != S[-1]:
            new_array.pop(-1)
        else:
            new_array += [S[-1]]
    elif len(S) % 3 == 2:
        if S[-2] == S[-1]:
            new_array += [S[-2], S[-1]]

    if mark == True:
        return f(new_array)
    else:
        return new_array


print(len(S) - len(f(S)))

Submission status: Runtime Error

Solution code:
s = list(map(int,input()))
cnt = 0
def func(s):
    for i, a in enumerate(zip(s, s[1:])):
        if a[0]^a[1] == 1:
            global cnt
            cnt += 2
            s.pop(i)
            s.pop(i)
            return func(s)

func(s)
print(cnt)

Submission status: Runtime Error

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

def dfs(S):
    slen = len(S)
    for i in range(slen -1 ):
        if S[i] != S[i+1]:
            del S[i:i+2]
            dfs(S)
            break;
    End_len = len(S)
    ans = S_len - End_len
    return ans

if __name__ == '__main__':
    print(dfs(S))

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 len(s) - 1 == x:
        break
    if s[x] != s[x + 1]:
        s.pop(x)
        s.pop(x)
        count += 1
        x -= 1
    else:
        x += 1
print(count * 2)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

a =input()
N=list(a)

count=[]
def search(x):
    n=len(N)
    if(x+1>=n):
        return 
    
    if(N[x]=="0" and N[x+1]=="1"):
        #print(N)
        del N[x]
        del N[x+1]
        #print(N)
        count.append(0)
        x=0
    if(N[x]=="1" and N[x+1]=="0"):
        #print(N)
        del N[x]
        del N[x+1]
        #print(N)
        count.append(0)
        x=0    
        
    search(x+1)
ans=search(0)
#print(N)
if(len(count)!=0):
    print(len(count)*2+2)
else:
    print(0)

Submission status: Runtime Error

Solution code:
def saiki(S, count):
	if "01" in S:
		S = S.replace("01", "", 1)
		count += 2
	if "10" in S:
		S = S.replace("10", "",1)
		count += 2
	if  "01" not in S and "10" not in S:
		print(count)
	elif "01" in S or "10" in S:
		saiki(S, count)
	elif "01" == S or "10" == S:
		print(count+2)
	
S = input()
count = 0
ans = saiki(S, count)

Submission status: Runtime Error

Solution code:
def crmv(c,istr):
    if len(istr)<=1:
        return c
    if not('1' in istr):
        return c

    rv=0
    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
    return rv

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

Submission status: Runtime Error

Solution code:
import sys
import numba


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

@numba.jit
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:
S = list(input())
S_len = len(S)

for i in range(S_len-1):
    S[i+1]
def dfs(S):
    slen = len(S)
    for i in range(slen -1 ):
        if S[i] != S[i+1]:
            del S[i:i+2]
            dfs(S)
            break;
    End_len = len(S)
    ans = S_len - End_len
    return ans

if __name__ == '__main__':
    print(dfs(S))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
%%time

import re

dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

l = str(input())
cnt = 0

while "10" in l or "01" in l:
    dels = [i.start() for i in re.finditer("10", l)]
    dels.extend(list(map(lambda x: x+1, dels)))
    # print(dels)
    cnt += len(dels)
    # print(len(dels))
    l = "".join(dellist(list(l), dels))

    dels = [i.start() for i in re.finditer("01", l)]
    dels.extend(list(map(lambda x: x+1, dels)))
    # print(dels)
    cnt += len(dels)
    # print(len(dels))
    l = "".join(dellist(list(l), dels))

print(cnt)

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
        if i>=1:
            i-=2
        else:
            i-=1
    i+=1
    #print(i,N,S,f)                                                                      
    if i+1 == N or N < 2:
        break
print(c)

Submission status: Runtime Error

Solution code:
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    for i in range(l-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            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()
res1,res2=0
for i in range(1000):
  S=S.replace("10","3")
  S=S.replace("01","3")
  res1+=S.count("3")*2
  S=S.replace("3","")
for j in range(1000):
  S=S.replace("10","3")
  S=S.replace("01","3")
  res2+=S.count("3")*2
  S=S.replace("3","")
if res1>res2:
  print(res2)
else:
  print(res1)

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 r(s):
    bsl = len(s)
    flg = True
    while flg:
        if '01' in s or '10' in s:
            s = s.replace('01', '')
            s = s.replace('10', '')
        else:
            flg = False

    return bsl - len(s)


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

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def pickup(S,ans):
    l = len(S)
    if l<2:
        return ans
    for i in range(l-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            ans += pickup(S,ans)
            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 r(s):
    bsl = len(s)
    flg = True
    while flg:
        if '01' in s or '10' in s:
            s = s.replace('01', '')
            s = s.replace('10', '')
        else:
            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:
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
        if i>=1:
            i-=2
        else:
            i-=1
    i+=1
    #print(i,N,S,f)                                                                      
    if i+1 == N:
        break
print(c)

Submission status: Runtime Error

Solution code:
s = str(input())
i = 0
score = 0
str_length = len(s)
while True:
    str_length = len(s)
    if str_length == 2:
        if int(s[0]) ^ int(s[1]) == 1:
            score += 2
            print(score)
            exit()
        else:
            print(score)
            exit()
    i = 0
    while True:
        j = i + 1
        cur_num = int(s[j])
        prev_num = int(s[j-1])
        next_num = int(s[j+1])
        if (cur_num ^ prev_num) == 1:
            score += 2
            s = s[:j-1] + s[j+1:]
            break
            
        elif (cur_num ^ prev_num) == 1:
            score += 2
            s = s[:j] + s[j+2:]
            break
        else :
            i += 1
            if i == str_length:
                print(score)
                exit()

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


    if flag:
        continue

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

    break
print(N-len(S))

Submission status: Runtime Error

Solution code:
s = list(input())

def check_pair(array,ans=0):
    if len(array) < 2:
        return ans
    for i, a in enumerate(array[:-1]):
        if (a=='0' and array[i+1]=='1') or (a=='1' and array[i+1]=='0'):
            del array[i:i+2]
            ans += 2
            return check_pair(array, ans)
    return ans

s = check_pair(s)

print(s)

Submission status: Runtime Error

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

while a == 0:
    S.strip("01")
    S.strip("10")
    if "01" in S & "10" in S:
        a = 0
    else:
        a = 1

print(str(N - len(S))

Submission status: Runtime Error

Solution code:
def remove_box(s,removed_box_num):
    for i in range(len(s)-1):
        if s[i] + s[i+1]==1:
            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:
cmax=0
def crmv(c,istr):
    if len(istr)<=1:
        return c
    if not('1' in istr) or not('0' in istr):
        return c

    rv=0
    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
    return rv

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

Submission status: Runtime Error

Solution code:
import sys 

sys.setrecursionlimit(1000000)
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:
# -*- coding: utf-8 -*-
s = input()
s = list(s)
x = 0
maxIndex = len(s) - 1
count = 0
while True:
    if len(s) <= x:
        break
    if s[x] != s[x + 1]:
        s.pop(x)
        s.pop(x)
        maxIndex = len(s) - 1
        count += 1
    else:
        x += 1
print(count * 2)

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)
        counter += tmp_counter
        if tmp_counter is 0 or len(S) is 0 or len(S) is 1:
            break
    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]
            length -= 2
            cube_counter += 2
            index -= 1
            if len(string) is 0 or len(string) is 1:
                break
            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:
# -*- coding: utf-8 -*-
from copy import copy
a = list(map(int,input()))
cur_min = 100001
def remove_max(cubes):
    global cur_min
    for i in range(len(cubes)-1):
        if cubes[i] != cubes[i+1]:
            z = copy(cubes)
            z.pop(i)
            z.pop(i)
            if len(z) == 0:
                cur_min=0
            if len(z) <= cur_min:
                cur_min = len(z)
                remove_max(z)
remove_max(a)
if cur_min==100001:
    print(0)
else:
    print(len(a) - cur_min)

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import pandas as pd
import torch


s = list(str(input()))

escape = False
begin = len(s)

def rem(s):
    for i in range(1,len(s)):
        # print(s)
        if s[i-1] != s[i]:
            s.pop(i)
            s.pop(i-1)
            break
    return s


for i in range(10**4):
    s = rem(s)

end = len(s)
print(begin-end)

Submission status: Runtime Error

Solution code:

def r(s):
    bsl = len(s)
    flg = True
    while flg:
        if '01' in s or '10' in s:
            s = s.replace('01', '')
            s = s.replace('10', '')
        else:
            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:

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]:
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
                break

            if S[ix] == S[ix+1] and S[ix+1] == S[ix+2]:
                del S[ix+1]
    if counter == 0:
        break

print(ans*2)

Submission status: Runtime Error

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

def pre():
    global s
    n = 0
    while '1100' in s:
        s=s.replace('1100', '10', 1)
        n+=2

    while '0011' in s:
        s=s.replace('0011', '01', 1)
        n+=2
    
    while '10101' in s:
        s=s.replace('10101', '101', 1)
        n+=2
    
    while '01010' in s:
        s=s.replace('01010', '010', 1)
        n+=2

    return n

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

ans=pre()
print(func(s, ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from copy import copy
a = list(input())
cur_min = 100001
def remove_max(cubes):
    global cur_min
    for i in range(len(cubes)-1):
        if cubes[i] != cubes[i+1]:
            z = copy(cubes)
            z.pop(i)
            z.pop(i)
            if len(z) == 0:
                cur_min=0
            if len(z) <= cur_min:
                cur_min = len(z)
                remove_max(z)
remove_max(a)
if cur_min==100001:
    print(0)
else:
    print(len(a) - cur_min)

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
    if N<2:
        break
    i+=1
    if i+1 == N:
        i=0
        if f==0:
            break
        f=0
print(c)

Submission status: Runtime Error

Solution code:
s = input()
s = list(s)
i = 0
j = 0
flg =0

if len(s) >1:
    while(1):
        for i in range(len(s)+1):
            if s[i] != s[i+1]:
                s.pop(i+1)
                s.pop(i)
                j+=2
                break
            elif len(s) == 2:
                flg = 1
                break
        
        if len(s) ==0 or flg==1:
            break
        
print(j)

Submission status: Runtime Error

Solution code:
S=input()
S=S.replace("10","3")
S=S.replace("01","3")
res=0
res+=S.count(3)
print(S.replace("3",""))

Submission status: Runtime Error

Solution code:
S = [] 
def f1():
    global S
    i = 1
    while i < (len(S) - 1):
        if S[i] != S[i + 1]:
            if S[i - 1] != S[i + 2]:
                del S[i:i + 2]
                return True

        i += 1
    
    return False

def f2():
    global S
    i = 1
    while i < (len(S) - 1):
        if S[i] != S[i + 1]:
            del S[i:i + 2]
            return True

        i += 1
    
    return False


def f3():
    global S
    if 2 <= len(S):
        if S[0] != S[1]:
            del S[0:2]
            return True
    
    return False

def f4():
    global S
    if 2 <= len(S):
        b = len(S) - 1
        if S[b] != S[b - 1]:
            del S[b - 1:]
            return True
    
    return False


n = 0
S = list(input().rstrip())
while 0 < len(S):
    result = f1()
    if result:
        n += 1
        continue

    result = f2()
    if result:
        n += 1
        continue

    result = f3()
    if result:
        n += 1
        continue

    result = f4()
    if result:
        n += 1
        continue

    break


print(n * 2)

Submission status: Runtime Error

Solution code:
S=input()
def union(s):
    answer_str = s
    for i in range(len(s)-1):
        if s[i]!=s[i+1]:
            if i!=len(s)-2:
                return union(s[:i]+s[i+2:])
            else:
                return union(s[:i])
    
    return answer_str
 
print(len(S)-len(union(S)))

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)
        counter += tmp_counter
        if tmp_counter is 0 or len(S) is 0:
            break
    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]
            length -= 2
            cube_counter += 2
            index -= 1
            if len(string) is 0:
                break
            before_cube = string[index]
        else:
            before_cube = string[index]
            index += 1

    return cube_counter, string

if __name__ == "__main__":
    main()