Problem:


Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0



Sample input:
0011


Sample output:
4

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5-10**4*2)
S = list(input())
n = len(S)

def f(flist,count):
    if len(count) == 0:
        return flist
    else:
        del flist[count[0]]
        del count[0]
        count = list(map(lambda x: x-1,count))
        return f(flist,count)

def Remove(binList,lenList):
    count = []
    count.clear()
    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"):
            count += [i,i+1]

    count = list(set(count))
    binList = f(binList,count)
    lenList = len(binList)

    if len(count) == 0:
        return binList
    else:
        return Remove(binList, lenList)

S = Remove(S,n)
print(n-len(S))

Submission status: Wrong Answer

Solution code:
S = input()

num0 = S.count("0")
num1 = len(S)-1

print(min(num0,num1)*2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

S = sys.stdin.readline()

num0 = S.count("0")
num1 = len(S)-num0

print(min(num0,num1)*2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

S = sys.stdin.readline()

num0 = S.count("0")
num1 = len(S)-1

print(min(num0,num1)*2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

num0 = S.count("0")
num1 = len(S)-1

print(min(num0,num1)*2)

Submission status: Wrong Answer

Solution code:
S=list(input())

X=0
index=0


while index!=1:
    if len(S)<=3:
        break
    if S[index]=="1" and S[index+1]=="0":
        S.pop(index)
        S.pop(index+1)
        X+=2

    elif S[index]=="0" and S[index+1]=="1":
        S.pop(index)
        S.pop(index+1)
        X+=2

    else:
        index+=1

S.append('2')
#[0112] [012]
index=0
if S[index]=="1" and S[index+1]=="0":
    S.pop(index)
    S.pop(index+1)
    X+=2

elif S[index]=="0" and S[index+1]=="1":
    S.pop(index)
    S.pop(index+1)
    X+=2

elif S[index+1]=="1" and S[index+2]=="0":
    S.pop(index+1)
    S.pop(index+1)
    X+=2

elif S[index+1]=="0" and S[index+2]=="1":
    S.pop(index+1)
    S.pop(index+1)
    X+=2



print(X)

Submission status: Wrong Answer

Solution code:
S = list(input())
print(min(S.count('0'), S.count('1')) ** 2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    c = Counter(S)
    if len(c) != 0:
        return 0
    return min(c.values()) * 2


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    c = Counter(S)
    return min(c.values()) * 2


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = input()
zero = N.count('0')
one = N.count('1')
ans = abs(zero - one) * 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

if len(S)==1:
    print(0)
else:
    S_count = Counter(S)
    print(2*(S_count.most_common()[-1][1]))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

S = sys.stdin.readline()
S_count = Counter(S)

print(2*(S_count.most_common()[-1][1]))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

S = sys.stdin.readline().strip()
S_count = Counter(S)

print(2*(S_count.most_common()[-1][1]))

Submission status: Wrong Answer

Solution code:
s=input()

stack=[]
for si in s:
    stack.append(si)
    if len(stack) >= 2 and stack[-1] != stack[-2]:
        del stack[-2:-1]
print(len(s)-len(stack))

Submission status: Wrong Answer

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(1000):
    a = a.replace('01', '')
    a = a.replace('10', '')
print(init - len(a))

Submission status: Wrong Answer

Solution code:
s=str(input())
if s.count('1')>s.count('0'):
    print(s.count('0'))
else:
    print(s.count('1'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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に存在する0と1は必ずどこかで隣り合う。
    1と0の組み合わせは、どの順番で取り出してもmin(num(0), num(1))

"""
s = input()
count1 = s.count('1')
count0 = s.count('0')

if count0 >= count1:
    print(count0*2)
else:
    print(count1*2)

Submission status: Wrong Answer

Solution code:
s=str(input())
if s.count('1')>s.count('0'):
    print(s.count('1')-s.count('0'))
else:
    print(s.count('0')-s.count('1'))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    S = input()

    ans = f(S)
    print(ans)


def f(S):
    c = Counter(S)
    return min(c['0'], c['1'])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			del L[i:i+1]
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)

Submission status: Wrong Answer

Solution code:
cubes= list(input())
one=0
zero=0

for i in cubes:
  if i=='1':
    one+=1
  else:
    zero+=1
if one>= zero:
  print(zero)
else:
  print(one)

Submission status: Wrong Answer

Solution code:
import sys
fin = sys.stdin.readline
 
ob = [-1 if i=="0" else 1 for i in list(fin())]
print(len(ob)-abs(sum(ob)))

Submission status: Wrong Answer

Solution code:
S = input()

count = 0
index = -1

list = [s for s in S]
for i in range(len(list)) :
    if index < 0 :
        index = i
    if (list[index] == "0" and list[i - 1] == "1") or (list[index] == "1" and list[i - 1] == "0") :
        count += 2
        index = i - 2
    else :
        index = i - 1
print(count)


'''
while True :
    length = len(S)
    S = S.replace("01", "")
    S = S.replace("10", "")
    if (length == len(S)) :
        break
    count += length - len(S)
print(count)
'''

Submission status: Wrong Answer

Solution code:
# 前方から現れた0(1)の数をストックしていく
# 1(0)が現れたら、そこから連続する1(0)の数だけペアを生成する
# ストックの数 ＞ 連続する1(0)の数のとき、ストックを保持(ペアの数＝連続する1の数)
# otherwise ストックを0にして再計算(ペアの数＝スタックの数)

string = input()
length = len(string)
string = string[::-1]
stuck_zeros = 0
stuck_ones = 0
number_of_pair = 0
index = 0


def debug(target, index_of_cursor, zero_stuck, one_stuck, pair):
    print("THIS IS DEBUG DATA")
    print("0stucks : " + str(zero_stuck))
    print("1stucks : " + str(one_stuck))
    print("pair : " + str(pair))
    print(target)
    print(" " * index_of_cursor + "^")
    print("---")


while index < length:
    # debug(string, index, stuck_zeros, stuck_ones, number_of_pair)
    if string[index] == '1':
        # 1出現
        stuck_ones += 1
        index += 1
        # ペア生成開始
        if (stuck_zeros != 0):
            # 連続する1を数える
            for i in range(index, length):
                if (string[i] == '1'):
                    index += 1
                    stuck_ones += 1
                else:
                    break
            # 1の連続が少ない→0の連続が持ち越し、次の0の連続で長くなる
            if (stuck_zeros > stuck_ones):
                number_of_pair += stuck_ones
                stuck_zeros -= stuck_ones
            # 1の連続が多い→1の連続が持ち越し、次の0の連番でペア生成
            else:
                number_of_pair += stuck_zeros
                stuck_ones = 0
    else:
        # 0出現
        stuck_zeros += 1
        index += 1
        # ペア生成開始
        if (stuck_ones != 0):
            # 連続する1を数える
            for i in range(index, length):
                if (string[i] == '0'):
                    index += 1
                    stuck_zeros += 1
                else:
                    break
            # 0の連続が少ない→1の連続が持ち越し、次の1の連続で長くなる
            if (stuck_ones > stuck_zeros):
                number_of_pair += stuck_zeros
                stuck_ones -= stuck_zeros
            # 0の連続が多い→0の連続が持ち越し、次の1の連番でペア生成
            else:
                number_of_pair += stuck_ones
                stuck_zeros = 0


print(number_of_pair * 2)

Submission status: Wrong Answer

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

n = 0
X = 0
can = []

while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			can.append(i)
			n=n+1
		elif i == K-1 and len(can)==0:
			X=1
		elif i == K-1:
			for j in reversed(can):
				# print(can)
				L.pop(j)
				can=[]

# print(L)
print(n*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line=input()
while 1:
  line_1=line[:len(line)//2]
  line_2=line[((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','')
  lines=line_1+line_2
  break
line=[int(c) for c in lines]
length=len(line)
while 1:
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
  if 2 in line:
    line=[i for i in line if i!=2]
  else:
    break
print(length-len(line))

Submission status: Wrong Answer

Solution code:
# 前方から現れた0(1)の数をストックしていく
# 1(0)が現れたら、そこから連続する1(0)の数だけペアを生成する
# ストックの数 ＞ 連続する1(0)の数のとき、ストックを保持(ペアの数＝連続する1の数)
# otherwise ストックを0にして再計算(ペアの数＝スタックの数)

string = input()
length = len(string)
string = string[::-1]
stuck_zeros = 0
stuck_ones = 0
number_of_pair = 0
index = 0


def debug(target, index_of_cursor, zero_stuck, one_stuck, pair):
    print("THIS IS DEBUG DATA")
    print("0stucks : " + str(zero_stuck))
    print("1stucks : " + str(one_stuck))
    print("pair : " + str(pair))
    print(target)
    print(" " * index_of_cursor + "^")
    print("---")


while index < length:
    # debug(string, index, stuck_zeros, stuck_ones, number_of_pair)
    if string[index] == '1':
        # 1出現
        stuck_ones += 1
        index += 1
        # ペア生成開始
        if (stuck_zeros != 0):
            # 連続する1を数える
            for i in range(index + 1, length):
                index += 1
                if (string[i] == '1'):
                    stuck_ones += 1
                else:
                    break
            # 1の連続が少ない→0の連続が持ち越し、次の0の連続で長くなる
            if (stuck_zeros > stuck_ones):
                number_of_pair += stuck_ones
                stuck_zeros -= stuck_ones
            # 1の連続が多い→1の連続が持ち越し、次の0の連番でペア生成
            else:
                number_of_pair += stuck_zeros
                stuck_ones = 0
    else:
        # 0出現
        stuck_zeros += 1
        index += 1
        # ペア生成開始
        if (stuck_ones != 0):
            # 連続する1を数える
            for i in range(index + 1, length):
                index += 1
                if (string[i] == '0'):
                    stuck_zeros += 1
                else:
                    break
            # 0の連続が少ない→1の連続が持ち越し、次の1の連続で長くなる
            if (stuck_ones > stuck_zeros):
                number_of_pair += stuck_zeros
                stuck_ones -= stuck_zeros
            # 0の連続が多い→0の連続が持ち越し、次の1の連番でペア生成
            else:
                number_of_pair += stuck_ones
                stuck_zeros = 0


print(number_of_pair * 2)

Submission status: Wrong Answer

Solution code:
import numpy as np

S = np.array(list(map(int, list(input()))))

n0 = (S == 0).sum()
n1 = (S == 1).sum()

print(min(n0, n1))

Submission status: Wrong Answer

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:
                bottom_idx = next_top(top_idx)
                top_idx =  next_top(bottom_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
print(removal_count *2)

Submission status: Wrong Answer

Solution code:
cubes= list(input())
re= True
start= len(cubes)
while re:
  same=0
  if len(cubes) == 1:
    break
  for i in range(len(cubes)-1):
    if cubes[i] != cubes[i+1]:
      del cubes[i]
      del cubes[i]
      i -= 1
      max= len(cubes)-2
      break
    else:
      same+= 1
  if same == len(cubes)-1:
    break
print(start-len(cubes))

Submission status: Wrong Answer

Solution code:
s = str(input())
count0= 0
count1 = 0
for i in range(len(list(s))):
    if s[i] == '0':
        count0 += 1
    else:
        count1 += 1
if count0 > count1:
    print(count0*2)
elif count0 == count1:
    print(count1 + count0)
else:
    print(count1*2)

Submission status: Wrong Answer

Solution code:

S = input()
work=list(S)
i=0
o_cout=0
z_cout=0
for x in work:
    if(x=='1'):
        o_cout+=1
    else:
        z_cout+=1
    
if(o_cout>z_cout):
    cout=o_cout
else:
    cout=z_cout
    

print(cout*2)

Submission status: Wrong Answer

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

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

while (0 <= i and 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: Wrong Answer

Solution code:
s = input()
count = 0
while '10' in s or '01' in s:
    if '10' in s:
        s = s.lstrip('10')
    elif '01' in s:
        s = s.lstrip('01')
    count += 1

print(count * 2)

Submission status: Wrong Answer

Solution code:
def dblcnt(s):
    count = 0
    for i in range(len(s)-1):
        if(s[i] == s[i+1]):
            count += 1
    return count

ans = 0
s = list(input())
a = s.copy()
n = dblcnt(s)
while(n):
    s = list(s)
    i = 0
    while(n):
        if (s[i] == s[i+1]):
            a.pop(i)
            a.insert(i, '9')
            a.pop(i+1)
            a.insert(i+1, '9')
            n -= 1
        i += 1
    ans += a.count('9')
    s = "".join(a)
    s = s.replace('9',"")
    n = dblcnt(s)
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
i = 0
j = 1
count = 0

if len(S) != 1:
    while True:
        if S[i]=="0" and S[i+1]=="1" or S[i]=="1" and S[i+1]=="0":
            count += 1

            while i-j != -1 and i+j+1 != len(S):

                if i-j != 0 and S[i-j]=="0" and S[i+j+1]=="1" or S[i-j]=="1" and S[i+j+1]=="0":
                    count += 1
                    j += 1
                else:
                    S = S[:i-j+1] + S[i+j+1:]
                    j = 1
                    i = -1
                    break

        if i+j+1 == len(S):
            break
        
        i += 1
    
    print(count*2)
else:
    
    print(0)

Submission status: Wrong Answer

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

tmp = []
for it in range(lt-1):
	tmp.append(s[it:it+2])

while True:
	if lt == 1:
		print(0)
		break

	if "01" in tmp:
		it = tmp.index("01")
		# print(tmp.index("01"))
		tmp = tmp[:it-1]+tmp[it+2:]
	elif "10" in tmp:
		it = tmp.index("10")
		# print(tmp.index("10"))
		tmp = tmp[:it-1]+tmp[it+2:]
	else:
		print(lt-len(tmp)*2)
		break

Submission status: Wrong Answer

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

    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(len(S))

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(1000):
    if "01" in s:
        s = s.replace("01", "", 1)
        count += 2
    elif "10" in s:
        s = s.replace("10", "", 1)
        count += 2
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())

ans = 0
prev = S[0]

skip = False

prev = '2'

i=0
while i < len(S)-1:
    if not prev == S[i]:
        ans += 2
        if prev == '2':
            prev = S[i-1]
        i += 2 
    else:
        i += 1

print(ans)

Submission status: Wrong Answer

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
print(removal_count *2)

Submission status: Wrong Answer

Solution code:
import re

S = input()

count = 0

while '01' in S or '10' in S:
    #print(S)

    m = re.search('(00+)(11+)', S)
    #print(m)
    if m:
        if len(m.group(1)) > len(m.group(2)):
            num = len(m.group(2))
            S = re.sub('0{' + str(num) + '}1{' + str(num) + '}', '', S)
            count += num * 2
        else:
            num = len(m.group(1))
            S = re.sub('0{' + str(num) + '}1{' + str(num) + '}', '', S)
            count += num * 2
    m = re.search('(11+)(00+)', S)
    #print(m)
    #print(S)
    if m:
        # print('g0:' + m.group(1))
        # print('g1:' + m.group(2))
        if len(m.group(1)) > len(m.group(2)):
            num = len(m.group(2))
            S = re.sub('1{' + str(num) + '}0{' + str(num) + '}', '', S)
            count += num * 2
        else:
            num = len(m.group(1))
            S = re.sub('1{' + str(num) + '}0{' + str(num) + '}', '', S)
            count += num * 2

    #print(S)

    m = re.search('(01)+', S)
    # print(m)
    if m:
        num = len(m.group(1))
        S = re.sub('(01)+', '', S)
        count += num * 2
    m = re.search('(10)+', S)
    # print(m)
    if m:
        num = len(m.group(1))
        S = re.sub('(10)+', '', S)
        count += num * 2
    #print(S)



print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(100):
    if "01" in s:
        s = s.replace("01", "", 1)
        count += 2
    elif "10" in s:
        s = s.replace("10", "", 1)
        count += 2
    else:
        break

print(count)

Submission status: Wrong Answer

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
print(removal_count *2)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(10):
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "")
    elif "10" in s :
        count += 2 * s.count("10")
        s = s.replace("10", "")
    else:
        break

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

s = list(input())
s = np.array(s)
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] == "T"):
            continue
        if (str("".join(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") or ("".join([str(s[i - j]), str(s[i + j + 1])]) == "10")):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
        elif (str("".join(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") or ("".join([str(s[i - j]), str(s[i + j + 1])]) == "01")):
                    del_list[i - j] = True
                    del_list[i + j + 1] = True
                else:
                    break
    s = np.delete(s, np.where(del_list == "T"))
    del_num += np.sum(len(np.where(del_list=="T")[0]))
    if (len(old_s) == len(s)):
        break
 
print(del_num)

Submission status: Wrong Answer

Solution code:
s = input()
s_2 = s.replace('01', '').replace('10', '').replace('01', '').replace('10', '').replace('01', '').replace('10', '').replace('01', '').replace('10', '')
s_3 = s_2.replace('01', '').replace('10', '').replace('01', '')
print(len(s)-len(s_3))

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(10):
    if not(("01" in s) | ("10" in s)):
        break
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "")
    elif "10" in s :
        count += 2 * s.count("10")
        s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(5):
    if not(("01" in s) | ("10" in s)):
        break
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "", 1)
    elif "10" in s :
        count += 2 * s.count("10")
        s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

Solution code:
S = list(input())

def f(S):
    new_array = []
    mark = False
    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) == 2:
        if S[0] != S[1]:
            return []
        else:
            return S

    if len(S) % 3 == 1:
        if len(S) > 3:
            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: Wrong Answer

Solution code:
s = input()
s_2 = s.replace('01', '').replace('10', '').replace('01', '').replace('10', '').replace('01', '').replace('10', '').replace('01', '').replace('10', '')
print(len(s)-len(s_2))

Submission status: Wrong Answer

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(1000):
    a = a.replace('11', '')
    a = a.replace('00', '')
print(init - len(a))

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(5):
    if not(("01" in s) | ("10" in s)):
        break
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "")
    elif "10" in s :
        count += 2 * s.count("10")
        s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

Solution code:
s = input()
s_2 = s.replace('01', '').replace('10', '').replace('01', '').replace('10', '')
print(len(s)-len(s_2))

Submission status: Wrong Answer

Solution code:
s = input()
count = 0

for i in range(1000):
    if not(("01" in s) | ("10" in s)):
        break
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "")
    elif "10" in s :
        count += 2 * s.count("10")
        s = s.replace("10", "")

print(count)

Submission status: Wrong Answer

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

    break
print(N-len(S))

Submission status: Wrong Answer

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

    print(count)


if __name__ == "__main__":
    main()