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: Time Limit Exceeded

Solution code:
s = str(input())
ss = s
for i in range(int(10000)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')
    

print(len(s)-len(ss))

Submission status: Time Limit Exceeded

Solution code:
before=input()
cnt=0
flg=0
while len(before)>1:
    after=before.replace('10','')
    after=after.replace('01','')
    sa=len(before)-len(after)
    if sa==0:
        break
    else:
        cnt+=sa
        before=after
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
length=len(s)
l = int(len(s)/2)
def erase_01_10(moji):
  moji = moji.replace('01','').replace('0011','').replace('000111','').replace('00001111','').replace('0000011111','')
  moji = moji.replace('10','').replace('1100','').replace('111000','').replace('11110000','').replace('1111100000','')
  return moji
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
print(length-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = S
res = True
while res == True:
    if s.find('01') >= 0:
        s = s.replace('01','',1)
    elif s.find('10') >= 0:
        s = s.replace('10','',1)
    res0 = s.find('01')
    res1 = s.find('10')
    if res0 == -1 and res1 == -1:
        res = False
print(len(S) - len(s))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    S = input()
    c = 0
    while(1):
        num = 2 * S.count('01')
        S = S.replace("01", "")
        num += 2 * S.count('10')
        S = S.replace("10", "")
        c += num
        if num == 0:
            print(c)
            exit()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
f = s
while True:
    s = s.replace('10', '')
    s = s.replace('01', '')
    t = list(s)
    if all(map(lambda x:x=="1", t)):
        break
    if all(map(lambda x:x=="0", t)):
        break
print(len(f)-len(s))

Submission status: Time Limit Exceeded

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

def main():
	S = list(input())
	S.pop(-1)
	flag = True
	count = 0
	while flag:
		ch = [0] * len(S)
		flag = False
		for i in range(len(S) - 1):
			if ch[i] == 0 and ch[i + 1] == 0:
				if (S[i] == '0' and S[i + 1] == '1') or (S[i] == '1' and S[i + 1] == '0'):
					ch[i] = 1
					ch[i + 1] = 1
					count += 1
					flag = True
		for i in range(len(ch))[::-1]:
			if ch[i] == 1:
				S.pop(i)
	print(count * 2)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
slen = len(s)
ans = 0

for i in range(len(s)):
  sub = s
  s = s.replace("01",'').strip()
  s = s.replace("10",'').strip()
  if sub == s:
    break
  

print(slen-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

S=list(S)

c=0
while(1):
    f=0
    for i in range(N-1):
        #print(i, S, N)                                                                  
        if S[i] != S[i+1]:
            del S[i:i+2]
            c+=2
            N-=2
            f=1
            break
    if f==0:
        break
print(c)

Submission status: Time Limit Exceeded

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

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

print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
l=list(input())
count=0
while True:
    flag=True
    for i in range(len(l)-1):
        if l[i]!=l[i+1]:
            l.pop(i)
            l.pop(i)
            flag=False
            count+=2
        if i>=len(l)-2:
            break
    if flag:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ss = s
for i in range(int(100000/2+1)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')

print(len(s)-len(ss))

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
work=S
while(len(work)>=0):
    if('01' in work):
        work = re.sub('01','',work)
    elif('10' in work):
        work = re.sub('10','',work)
    else:#01 or 10 の羅列も見つけることができなかった
        break

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

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

for ctr in range(50000):
    if s.find('10') == -1 or s.find('01') == -1 or int(len(s)) == 0:
        flag == False
    if flag == True:
        s = s.replace('10','')
        s = s.replace('01','')
        
num_kekka = int(len(s))
print(num_moto - num_kekka)

Submission status: Time Limit Exceeded

Solution code:
s = input()
res = 0
while True:
    a = s.find('01')
    b = s.find('10')
    if a != -1 or b != -1:

        if a != -1:
            if b != -1:
                if a < b:
                    s = s[:a] + s[a + 2:]
                    res += 2
                else:
                    s = s[:b] + s[b + 2:]
                    res += 2
            else:
                s = s[:a] + s[a + 2:]
                res += 2
        else:
            s = s[:b] + s[b + 2:]
            res += 2
    else: break

print(res)

Submission status: Time Limit Exceeded

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

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

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

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

        if (k != l):

            s.pop(n)
            s.pop(n)
            
            count += 2
            break

    if (old == count):
        break

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
maxilen = len(s)
ans = 0
end = True
while maxilen != 0 and end:
    for i in range(maxilen):
        if i == maxilen-1:
            end = False
            break
        elif s[i] != s[i+1]:
            del s[i:i+2]
            maxilen = len(s)
            ans += 2
            break
print(ans)

Submission status: Time Limit Exceeded

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

flag = True
total = len(S)

S_ = S

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
Quve = []
count = 0
flag = 0
for i in range(len(S)):
    if int(S[i])==0:
        Quve.append("a")#赤文字をaで表記
    else:
        Quve.append("b")
Quve.append("")
while(flag ==0):
    tmp = count
    for i in range(len(Quve)-1):
        if ((Quve[i]=="a") & (Quve[i+1]=="b")) | ((Quve[i]=="b") & (Quve[i+1]=="a")):
            del Quve[i]
            del Quve[i]
            count += 2
            break
    if (tmp == count):
        flag = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
length=len(s)
l = int(len(s)/2)
def erase_01_10(moji):
  moji = moji.replace('01','').replace('0011','').replace('000111','')
  moji = moji.replace('10','').replace('1100','').replace('111000','')
  return moji
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
print(length-len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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+1,tstr)
        if r>rv:
            rv=r
    return rv

istr=input()

print(crmv(0,istr)*2)

Submission status: Time Limit Exceeded

Solution code:
S = [int(_) for _ in input()]
length = 0
x =0
flag = True
if(len(S) == 1):
    flag = False
while(flag):
    x += 1

    if(S[x]+S[x-1] == 1):
        S.pop(x)
        S.pop(x-1)
        length += 2
        x=0
   
    if(x >= len(S)-1):
        break

print(length)

Submission status: Time Limit Exceeded

Solution code:
import copy

S = input()
cube = list(S)
cube_temp = copy.copy(cube)
while(1):
    for i in range(1, len(cube)):
        if (cube[i-1] == '1' and cube[i] == '0') or (cube[i-1] == '0' and cube[i] == '1'):
            cube_temp.pop(i-1)
            cube_temp.pop(i-1)
            break
    if cube == cube_temp:
        break
    else:
        cube = copy.copy(cube_temp)
print(len(S) - len(cube))

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)
l = [int(x) for x in list(str(S))]

count = 0
idx = 0
len_S = 0

while True:
    if len(l) <= 1:
        break
    if (l[idx] == 0 and l[idx+1] == 1) or (l[idx] == 1 and l[idx+1] == 0):
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        continue
    if idx+1 == len(l)-1:
        break
    idx += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def remove_01_10(S):
	S = S.replace('10', '')
	S = S.replace('01', '')
	return S	


S = input()
N = len(S)
while True:
	if len(S) == len(remove_01_10(S)):
		print(N - len(S))
		exit()
	else:
		S = remove_01_10(S)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
flg = 0
while '10' in s or '01' in s:
    ans += s.count('01') * 2
    s = s.replace('01', '')
    ans += s.count('10') * 2
    s = s.replace('10', '')
print(ans)

Submission status: Time Limit Exceeded

Solution code:
before=input()
cnt=0
flg=0
while len(before)>1:
    after=before.replace('10','')
    after=after.replace('01','')
    if len(before)-len(after)==0:
        break
    else:
        cnt+=len(before)-len(after)
        before=after
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
slen = len(s)
ans = 0

while(1):
  sub = s
  s = s.replace("01",'').strip()
  s = s.replace("10",'').strip()
  if sub == s:
    break
  

print(slen-len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ss = s
for i in range(int(100000)):
	ss = ss.replace('01', '')
	ss = ss.replace('10', '')

print(len(s)-len(ss))

Submission status: Time Limit Exceeded

Solution code:
in_s = input().rstrip()
s_old = in_s
while True:
    s_new = s_old.replace("10","")
    s_new = s_new.replace("01","")
    if s_new == s_old:
        break
    s_old = s_new
print(len(in_s) - len(s_new))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
s_bef = s
s_len = len(s)
for x in reversed(range(1, s_len)):
    s = s.replace("0" * x + "1" * x, "").replace("1" * x + "0" * x, "")

while len(s_bef) > len(s):
    s_bef, s = s, s.replace("01", "").replace("10", "")
 
print (s_len - len(s))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
S=input()
N=int(len(S))
for _ in list(S):
    S=S.replace("10","")
    S=S.replace("01","")
print(N-int(len(S)))

Submission status: Time Limit Exceeded

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

print(cnt * 2)

Submission status: Time Limit Exceeded

Solution code:
# This file is a "Hello, world!" in Python language by CPython for wandbox.

def checkeof(s):
    l = len(s)
    #print("1"*l)
    #print("0"*l)
    if l == 0:
        return False
    if "1"*l == s or "0"*l == s:
        return False
    else:
        return True
    

def main():
    s = input()
    c = 0
    while checkeof(s):
        tmp = s.count('01')
        if tmp:
            s = s.replace("01","")
            c += tmp
        tmp = s.count('10')
        if tmp:
            s = s.replace("10","")
            c += tmp
    print(c*2)
    
    
if __name__ == '__main__':
    main()


# CPython references:
#   https://www.python.org/

Submission status: Time Limit Exceeded

Solution code:
import re
S = (input())
ans = 0
while True:
    if "01" in S:
        count = re.findall("01",S)
        S = S.replace("01","")
        ans+=len(count)*2
    elif "10" in S:
        count = re.findall("10",S)
        S = S.replace("10","")
        ans+=len(count)*2
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
length=len(s)
l = int(len(s)/2)
def erase_01_10(moji):
  if moji.count('01')>0:
    moji = moji.replace('01','')
  elif moji.count('10')>0:
    moji = moji.replace('10','')
  return moji
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
print(length-len(s))

Submission status: Time Limit Exceeded

Solution code:
cubes = input()

removed_cubes_count = 0

while True:
    remove_index01 = cubes.find('01')
    if remove_index01 >= 0:
        cubes = cubes[:remove_index01] + cubes[remove_index01 + 2:]
        removed_cubes_count += 2


    remove_index10 = cubes.find('10')
    if remove_index10 >= 0:
        cubes = cubes[:remove_index10] + cubes[remove_index10 + 2:]
        removed_cubes_count += 2

    if remove_index01 == -1 and remove_index10 == -1:
        break

print(removed_cubes_count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
 
for _ in range(N):
    fn = len(S)
    S = S.replace('01', '').replace('10', '')
    if fn == len(S):
        break
 
print(N - len(S))

Submission status: Time Limit Exceeded

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

while "10" in l:
    idx = l.index("10")
    ll = list(l)
    ll.pop(idx+1)
    ll.pop(idx)
    l = "".join(ll)
    cnt += 1

while "01" in l:
    idx = l.index("01")
    ll = list(l)
    ll.pop(idx+1)
    ll.pop(idx)
    l = "".join(ll)
    cnt += 1

print(cnt*2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
slen = len(s)
ans = 0

while(1):
  s = s.replace("01",'').strip()
  s = s.replace("10",'').strip()
  if not("01" in s or "10" in s):
    break
  

print(slen-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
b=len(s)
while "01" in s or "10" in s:
        s=s.replace("01","")
        s=s.replace("10","")
print(b-len(s))

Submission status: Time Limit Exceeded

Solution code:
#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input().rstrip()

Nblock = 0

while True:
    for i in range(len(S)-1):
        if S[i:i+1] != S[i+1:i+2]:
            Nblock += 2
            S = S[:i] + S[i+2:]
            break
    else:
        break

print(Nblock)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

rm_count=0
rm_index=[]
while True:
    for i in range(len(s)-1):
        if i in rm_index:
            continue
        if s[i] != s[i+1]:
            rm_count=rm_count+2
            rm_index+=[i,i+1]
            #print("DEBUG: {}, {}, count: {}".format(s[i],s[i+1],rm_count))

    for i in sorted(rm_index, reverse=True):
        s.pop(i)
    rm_index=[]
    if len(set(s)) == 1 or len(s) == 0:
        break
print(rm_count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    s = tokens[0]

    return (s,)

def solve(s):
   
    current = s
    tmp = s
    while True:

        current = tmp
        for i in range(len(current) - 1):
            if current[i] == '0' and current[i+1] == '1':
                tmp = current[:i] + current[i+2:]
                break

            if current[i] == '1' and current[i+1] == '0':
                tmp = current[:i] + current[i+2:]
                break

        if len(current) == len(tmp):
            break

    return len(s) - len(current)

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

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


while ('01' in s) or ('10' in s):
    s = s.replace('10','')
    s = s.replace('01','')

print(leng-len(s))

Submission status: Time Limit Exceeded

Solution code:


s1 = input()
len_s = len(s1)
s2 = s1
while True:
    len_1 = len(s2)
    s2 = s2.replace("01", "").replace("10", "")
    len_2 = len(s2)
    if len_1 == len_2:
        break


print(len_s - len(s2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main() -> None:
    S = list(input())
    m = len(S)
    pre = len(S)
    while len(S) > 1:
        for i in range(len(S) - 1):
            if len(S) > i + 1:
                if S[i] != S[i+1]:
                    S.remove(S[i])
                    S.remove(S[i])
            else:
                break

        # 抜けなかった
        if pre == len(S):
            break
        else:
            pre = len(S)

    # 最初の数から引けば抜いた数
    print(m - len(S))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = len(a)
while ('01' in a) or ('10' in a):
    a = a.replace('01', '').replace('10', '')
print(b - len(a))

Submission status: Time Limit Exceeded

Solution code:
def main():
    string = input()
    lists = list(string)
    original_len = len(lists)
    for i in range(int(len(lists))):
        pre = 2
        for j, now in enumerate(lists):
            if(int(pre) < 2 and int(pre) != int(now)):
                del lists[j]
                del lists[j-1]
                #print(j, lists)
                break
            pre = lists[j]
    print(original_len - len(lists))
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
a = input()

l = len(a)
while True:
    a = a.replace("10", "")
    a = a.replace("01", "")
    if a.find("01") == -1 and a.find("10") == -1:
        break

print(l - len(a))

Submission status: Time Limit Exceeded

Solution code:
import copy

s = str(input())
s_origin = copy.copy(s)

while len(s) > 0:
    if "10" in s:
        s = str(s).replace("10","")
    elif "01" in s:
        s = str(s).replace("01","")
    else:
        break

print(int(len(s_origin) - len(s)))

Submission status: Time Limit Exceeded

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

s = str(input())

x = int(0)
i = int(len(s))

while "01" in s:
    s=s.replace("01","")
    s=s.replace("10","")
    x = x + i- int(len(s))
    i = int(len(s))

while "10" in s:
    s=s.replace("10","")
    x = x + i- int(len(s))
    i = int(len(s))

print(x)

Submission status: Time Limit Exceeded

Solution code:
S = (input())
ans = 0
while True:
    if "01" in S:
        S = S.replace("01","",1)
        ans+=2
    elif "10" in S:
        S = S.replace("10","",1)
        ans+=2
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
before_number = ""
counter = 0
ans = 0

while 1 == 1:
    counter1 = S.count("01")
    S = S.replace("01", "")
    ans += counter1
    counter2 = S.count("10")
    S = S.replace("10", "")
    ans += counter2
    if counter1 == 0 and counter2 == 0:
        break

print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
s=input()
line=[int(c) for c in s]
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: Time Limit Exceeded

Solution code:
a = input()
l = len(a)
blk = a
i = 0
rem = 0
while i < (l - 1):
    if(blk[i] != blk[i+1]):
        blk = blk[:i] + blk[i+2:]
        l -= 2
        rem += 2
        i = 0
    else:
        i += 1
    
print(rem)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
n = len(s)
n1 = n
answer = 0
while 1:
  s = re.sub(r"10","",re.sub(r"01","",s))
  if n == len(s):
    break
  else:
    n = len(s)
print(n1-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

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

print(count * 2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = int(len(s)/2)
def erase_01_10(moji):
  if moji.count('01')>0:
    moji = moji.replace('01','',1)
  elif moji.count('10')>0:
    moji = moji.replace('10','',1)
  return moji
count=0
for i in range(l):
  if s == erase_01_10(s):
    break
  s = erase_01_10(s)
  count+=2
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
def united(stri):
    for a in stri:
        if a != stri[0]:
            return False
    return True

while (not united(s)) and len(s) >= 2:
    k = len(s)
    if k == 2:
        if s[0] != s[1]:
            ans += 2
        break
    for i in range(0,k-1):
        if s[i] != s[i+1]:
            if i == k - 2:
                s = s[:i]
            elif i == 0:
                s = s[i+2:]
            else:
                s = s[:i] + s[i+2:]
            ans += 2
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S = [int(i) for i in S]
c = 0
while True:
    OK,flag,break_flag = 0,0,0
    LOOP = len(S)-1
    for i in range(LOOP):
        if S[i] != S[i+1] and S[i] != 9:
            S[i],S[i+1] = 9,9
            OK += 1
        else:
            flag += 1
    if flag == LOOP:
        break_flag = 1
    if OK >= 1:
        for i in range(2*OK):
            S.remove(9)
            c += 1
    if break_flag == 1 or len(S) <= 1:
        break
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
flg = 0
while flg == 0:
    ans += s.count('01') * 2
    s = s.replace('01', '')
    ans += s.count('10') * 2
    s = s.replace('10', '')
    if not ('10' in s or '01' in s):
        flg = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
S1 = S
S2 = ''
while S1 != S2:
    S2 = S1
    S1 = S1.replace('01','',-1).replace('10','',-1)
print(len(S)-len(S2))

Submission status: Time Limit Exceeded

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

s = str(input())

x = int(0)
i = int(len(s))

while "01" in s:
    s=s.replace("01","")
    x = x + i- int(len(s))
    i = int(len(s))

while "10" in s:
    s=s.replace("10","")
    x = x + i- int(len(s))
    i = int(len(s))

print(x)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
n = len(s)
n1 = n
answer = 0
while 1:
  s = s.replace("01","").replace("10","")
  if n == len(s):
    break
  else:
    n = len(s)
print(n1-len(s))

Submission status: Time Limit Exceeded

Solution code:
sent = str(input())
def search(let):
    candi = []
    for i in range(len(let) - 1):
        if let[i] != let[i+1]:
            ss = ""
            for j in range(i):
                ss += str(let[j])
            for j in range(i+2,len(let)):
                ss += let[j]
            if ss == "":
                print(len(sent))
                exit(0)
            candi.append(search(ss))
    if len(candi) == 0: ncan = [let]
    else:
        ncan = sorted(candi, key= lambda x: len(x))
    return ncan[0]

print(len(sent)-len(search(sent)))

Submission status: Time Limit Exceeded

Solution code:
def recursin_operation(S, len_init_s):
    S = list(S)
    N = len(S)
    lst = [i for i in range(N - 1) if S[i] != S[i + 1]]
    nums_of_deleted = []
    if len(lst) != 0:
        for i in lst:
            S_next = [S[j] for j in range(len(S)) if j < i or j > i + 1]
            nums_of_deleted.append(recursin_operation(S_next, len_init_s))
    else:
        nums_of_deleted.append(len_init_s - len(S))

    return max(nums_of_deleted)


def main():
    S = input()
    len_init_s = len(S)
    ans = recursin_operation(S, len_init_s)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
s = list(sys.stdin.readline().strip())
l = n1 = len(s)
while True:
    n = l
    _s = []
    skip = False
    for i in range(n):
        if skip:
            skip = False
            continue
        if i == n-1 or s[i] == s[i+1]:
            _s += s[i]
        else:
            skip = True
    s = _s
    l = len(s)
    if l == 0 or n == l:
        break
print(n1 - len(s))

Submission status: Time Limit Exceeded

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


while ('01' in s) or ('10' in s):
    s = re.sub(r'01|10','', s)

print(leng-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
con = 1
max = 0
while con != 0 :
    con = 0
    if (len(S) <= 1):
        break
    x = 0
    while True :
        if (x >= len(S)-1):
             break
        if(x <= len(S)-1 and 
            S[x] == '0' and S[x+1] == '1' or
            S[x] == '1' and S[x+1] == '0' ):
            max += 2
            del S[x:x+1+1]
            con = 1
        x += 1

print(max)

Submission status: Time Limit Exceeded

Solution code:
import copy

s = input()
s_sub = copy.deepcopy(s)
# 
tar1 = "01"
tar2 = "10"
# tar3 = ["1010","1001","0101","0110"]

while((tar1 in s )or(tar2 in s)):
    
    
    # for i in range(4):
    #     if tar3[i] in s:
    #         s = s.replace(tar3[i],"")
    

    if tar1 in s:
        s = s.replace(tar1,"",1)
    if tar2 in s:
        s = s.replace(tar2,"",1)



print(len(s_sub)-len(s))

Submission status: Time Limit Exceeded

Solution code:
a = input()
a = str(a)
l = len(a)
blk = a
i = 0
rem = 0
while i < (l - 1):
    if(int(blk[i]) + int(blk[i+1]) == 1):
        blk = blk[:i] + blk[i+2:]
        l -= 2
        rem += 2
        i = 0
    else:
        i += 1
    
print(rem)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline())
o = len(s)
for i in range(1000000000000):
    p1 = s.find("01")
    p2 = s.find("10")
    if p1 == -1 and p2 == -1:
        break
    elif p1 == -1:
        i = p2
    elif p2 == -1:
        i = p1
    else:
        i = p1 if p1 < p2 else p2

    s = s[:i] + s[i + 2:]
    
print(o - len(s))