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 = input()

count = 0
 
def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str
 
string = s
can_remove = True
while can_remove:
  new_text = ''
  search_count = string.count('10')
  if search_count > 0:
    new_text = string.replace('10', '', search_count)
  else:
    search_count = string.count('01')
    if search_count > 0:
      new_text = string.replace('01', '', search_count)

  if new_text != string:
    string = new_text
    count += search_count * 2
    can_remove = True
  else:
    can_remove = False
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cube = s
ans = len(s)
while True:
    cube = cube.replace('01','').replace('10','')
    if ('01' not in cube) and ('10' not in cube):
        ans -= len(cube)
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = len(s)
cube = s
hight = len(s)
while True:
    cube = cube.replace('01','').replace('10','')
    if hight == len(cube):
        ans -= len(cube)
        break
    else:
        hight = len(cube)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str

def remove_cube(string):
  new_text = string.replace('10', '', 1)
  if new_text == string:
    new_text = string.replace('01', '', 1)
  return new_text

string = s
can_remove = True
while can_remove:
  removed = remove_cube(string)
  if removed != string:
    string = removed
    count += 2
    can_remove = True
  else:
    can_remove = False

print(count)

Submission status: Time Limit Exceeded

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

while s  != s.replace("01",""):
    s = s.replace("01","")

while s  != s.replace("10",""):
    s = s.replace("10","")
    
print(start-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()

s_len_init = len(s) 
while(1):
    s_len = len(s)
    s = s.replace('01','')
    if s_len == len(s):
        break
    else:
        continue
while(1):
    s_len = len(s)
    s = s.replace('10','')
    if s_len == len(s):
        break
    else:
        continue
print(s_len_init-len(s))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re
# 入力された文字列
string = input()

raw_length = len(string)

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg and len(string) != 0:
    del_flg = False
    before_length = len(string)
    string = re.sub('01|10', '', string)
    after_length = len(string)
    
    if before_length != after_length:
        del_flg = True

print((raw_length - len(string)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import re
# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

raw_length = len(string)

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False
    before_length = len(string)
    #string = string.replace('01', '').replace('10', '')
    regex = '01|10'
    string = re.sub(regex, '', string)
    after_length = len(string)
    
    if before_length != after_length:
        del_flg = True

print((raw_length - len(string)))

Submission status: Time Limit Exceeded

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

raw_length = len(string)

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False
    target = ['01', '11']
    before_length = len(string)
    string = string.replace('01', '').replace('10', '')
    after_length = len(string)
    
    if before_length != after_length:
        del_flg = True

print((raw_length - len(string)))

Submission status: Time Limit Exceeded

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

raw_length = len(string)
# 削除した文字数
del_count = 0

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False
    target = ['01', '11']
    before_length = len(string)
    string = string.replace('01', '')
    string = string.replace('10', '')
    after_length = len(string)
    
    if before_length != after_length:
        del_flg = True

new_length = len(string)
del_count = (raw_length - new_length)

print(del_count)

Submission status: Time Limit Exceeded

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

# 削除した文字数
del_count = 0

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False

    # 
    for idx in range(max):
        if idx == max or idx > max:
            break
            
        # 照合対象の文字を切り出す
        target = string[idx : idx + 2]
        
        if target == "01" or target == "10":
            # 削除文字に一致した場合、元の文字列からそれを削除しカウントを進め、
            # 削除フラグを立てる
            string = string[:idx] + string[idx + 2:]
            del_count += 2
            max -= 2
            del_flg = True

print(del_count)

Submission status: Time Limit Exceeded

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

# 削除した文字数
del_count = 0

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False

    # 
    for idx in range(max):
        # 照合対象の文字を切り出す
        target = string[idx : idx + 2]
        
        if target == "01" or target == "10":
            # 削除文字に一致した場合、元の文字列からそれを削除しカウントを進め、
            # 削除フラグを立てる
            string = string[:idx] + string[idx + 2:]
            del_count += 2
            max -= 2
            del_flg = True

print(del_count)

Submission status: Time Limit Exceeded

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

# 入力された文字列
string = input()

# 最大処理数。100000以下なら文字列長。
max = min(len(string), 100000)

# 削除した文字数
del_count = 0

# 削除があった場合True
del_flg = True

# 削除文字がなくなるまでループする
while del_flg:
    del_flg = False

    # 
    for idx in range(max):
        # 照合対象の文字を切り出す
        target = string[idx : idx + 2]
        
        if target == "01" or target == "10":
            # 削除文字に一致した場合、元の文字列からそれを削除しカウントを進め、
            # 削除フラグを立てる
            string_head = string[:idx]
            string_tail = string[idx + 2:]
            string = string_head + string_tail
            del_count += 2
            del_flg = True

print(del_count)

Submission status: Time Limit Exceeded

Solution code:
#11011010001011
#['1', '1', '0', '1', '1', '0', '1', '0', '0', '0', '1', '0', '1', '1']
#
#['1',     '1']


S=list(raw_input())
#print S

tmp_len=0
count=0
pre_len=len(S)

while tmp_len != pre_len:
    i=0
    pre_len = tmp_len
#    print S ,"<==="
    while i < (len(S)-1):
#        print i,S,"<="
        if S[i] != S[i+1]:
            S.pop(i+1)
            S.pop(i)
            count += 2
            tmp_len=len(S)
        i += 1

print count

Submission status: Time Limit Exceeded

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

import copy

string = [x for x in input()]

concat_string = copy.copy(string)
count = 0
while True:
    num_delete = 0
    flags_delete = [False] * len(string)
    
    i = 0
    j = 1
    not_delete_list = []
    while True:
        if j >= len(concat_string) or i < 0:
            break
        if concat_string[i] != concat_string[j]:
            flags_delete[i] = True
            flags_delete[j] = True
            num_delete += 2
            
            if i == 0:
                i = j + 1
                j = i + 1
            else:
                if len(not_delete_list) > 0:
                    i = not_delete_list[-1]
                    not_delete_list = not_delete_list[:-1]
                    j = j + 1
                else:
                    i = j + 1
                    j = i + 1
        else:
            not_delete_list.append(i)
            i = j
            j = i + 1
            
    if num_delete == 0:
        break
    
    count += num_delete
    concat_string = [concat_string[i] for i in range(len(concat_string)) if flags_delete[i] == False]

print(count)

Submission status: Time Limit Exceeded

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

import copy
#import random

string = [x for x in input()]
#string = [random.randint(0, 1) for _ in range(int(1e5))]

concat_string = copy.copy(string)
count = 0
while True:
    num_delete = 0
    flags_delete = [False] * len(string)
    
    i = 0
    j = 1
    while True:
        if j >= len(concat_string) or i < 0:
            break
        if concat_string[i] != concat_string[j]:
            flags_delete[i] = True
            flags_delete[j] = True
            num_delete += 2
            
            if i == 0:
                i = j + 1
                j = i + 1
            else:
                if flags_delete[i] == False:
                    i = i - 1
                    j = j + 1
                else:
                    i = j + 1
                    j = i + 1
        else:
            i = j
            j = i + 1
            
    if num_delete == 0:
        break
    
    count += num_delete
    concat_string = [concat_string[i] for i in range(len(concat_string)) if flags_delete[i] == False]

print(count)

Submission status: Time Limit Exceeded

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

import copy

string = [x for x in input()]

concat_string = copy.copy(string)
count = 0
while True:
    num_delete = 0
    flags_delete = [False] * len(string)
    
    i = 0
    while i < len(concat_string) - 1:
        if concat_string[i] != concat_string[i + 1]:
            flags_delete[i] = True
            flags_delete[i + 1] = True
            num_delete += 2
            i += 2
        else:
            i += 1
           
    if num_delete == 0:
        break
    
    count += num_delete
    concat_string = [concat_string[i] for i in range(len(concat_string)) if flags_delete[i] == False]

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = list(s)
 
def del_01(s,counter):
  for i in range(len(s)-1):
    if s[i] == '1' and s[i+1] == '0':
      s[i] ='w'
      s[i+1] = 'w'
      counter += 2
    elif s[i] == '0' and s[i+1] == '1':
      s[i] = 'w'
      s[i+1] = 'w'
      counter += 2
  s.remove('w')
  return s, counter
counter = 0
while (s.count('0') != 0) and (s.count('1') != 0) and (s != []):
  s, counter = del_01(s, counter)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import re
  
bit_string = raw_input()

replaced_count = 0
replaced_string = bit_string
while re.search('01|10', replaced_string):
  replaced_string, tmp_count = re.subn('01|10', '', replaced_string)
  replaced_count += tmp_count
print(replaced_count * 2)

Submission status: Time Limit Exceeded

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

def del_01(s,counter):
  for i in range(len(s)-1):
    if s[i] == '1' and s[i+1] == '0':
      s[i] ='w'
      s[i+1] = 'w'
      counter += 2
    elif s[i] == '0' and s[i+1] == '1':
      s[i] = 'w'
      s[i+1] = 'w'
      counter += 2
  s.remove('w')
  return s, counter
counter = 0
while (s.count('0') != 0) and (s.count('1') != 0) and (s != []):
  s, counter = del_01(s, counter)
  x = del_01(s,0)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
A = input()

len0 = lenA = len(A) 
while(True):
    A = A.replace("10","").replace("01","")
    if lenA == len(A):
        break
    lenA = len(A)
print(len0 - lenA)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = len(S)
while True:
	T = S.replace('01','').replace('10','')
	if S == T:
		break
	else:
		S = T

print(s-len(S))

Submission status: Time Limit Exceeded

Solution code:
def sakuzyo(li):
    ct = 0
    found = 1
    while found:
        found = 0
        for i in range(len(li)-1):
            if (li[i] == "0" and li[i+1] == "1") or (li[i] == "1" and li[i+1] == "0"):
                del li[i:i+2]
                ct += 2
                found = 1
                break
    return ct
li = list(input())
print(sakuzyo(li))

Submission status: Time Limit Exceeded

Solution code:
def sakuzyo(li):
    ct = 0
    found = 1
    while found:
        found = 0
        for i in range(len(li)-1):
            if (li[i] == "0" and li[i+1] == "1") or (li[i] == "1" and li[i+1] == "0"):
                li.pop(i)
                li.pop(i)
                ct += 2
                found = 1
                break
    return ct
li = list(input())
print(sakuzyo(li))

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
prev = s
while True:
    prev = s
    s = s.replace('01', '')
    s = s.replace('10', '')
    d = len(prev) - len(s)
    if d == 0:
        break
    ans += d

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int,input()))
N = len(S)
i = 0
while i < len(S)-1:
    if S[i] != S[i+1]:
        S[i:] = S[i+2:]
        i -=1
    else:
        i +=1
print(N-len(S))

Submission status: Time Limit Exceeded

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

i = 0
while i < len(S) - 1:
    if S[i] == S[i + 1]:
        i += 1
        continue
    S = S[:i] + S[i + 2:]
    if i > 0:
        i -= 1

print(N - len(S))

Submission status: Time Limit Exceeded

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

counter = 0

string = input()

while (string.find("01") != -1 ) :
    string = (string.replace("01", "", 1))
    counter += 2

while (string.find("10") != -1 ) :
    string = (string.replace("10", "", 1))
    counter += 2
    
print(counter)

Submission status: Time Limit Exceeded

Solution code:
input = input()
max = len(input)
go = True
counter =0
while(True):
  for x in range(0,max-2):
    if(input[x]!=input[x+1]):
      input = input[:x] + input[x+2:]
      max = len(input)
      counter +=2
      break
    else:
      go = False
print(counter)

Submission status: Time Limit Exceeded

Solution code:
def make_list(x,S):#x:元の配列から切り取る番号 S:リスト受け取り
    a=[]
    for i in range(0,x):#S[0]~S[x-1]までを追加
        a.append(S[i])
    if x<len(S)-2:
        for i in range(x+2,len(S)):
            a.append(S[i])
    return a
S=list(map(int,input()))
N=len(S)#S[0]~S[N-1]
count=0
j=0
while j==0 and N!=1:
    for i in range(N-1):#S[0]~S[N-2]
        if (S[i]==0 and S[i+1]==1)or(S[i]==1 and S[i+1]==0):
            count+=2
            S=make_list(i,S)#Sの書き換え
            N=len(S)#Nの書き換え
            if N==0:
                j=1
            break
        elif i==N-2:
            j=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=list(map(int,input()))
N=len(S)#S[0]~S[N-1]
count=0
j=0
def make_list(x,S):#x:元の配列から切り取る番号 S:リスト受け取り
    a=[]
    for i in range(0,x):#S[0]~S[x-1]までを追加
        a.append(S[i])
    if x<len(S)-2:
        for i in range(x+2,len(S)):
            a.append(S[i])
    return a
while j==0 and N!=1:
    for i in range(N-1):#S[0]~S[N-2]
        if (S[i]==0 and S[i+1]==1)or(S[i]==1 and S[i+1]==0):
            count+=2
            S=make_list(i,S)#Sの書き換え
            N=len(S)#Nの書き換え
            if N==0:
                j=1
            break
        elif i==N-2:
            j=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=list(map(int,input()))
N=len(S)#S[0]~S[N-1]
count=0
j=0
def make_list(x,S):#x:元の配列から切り取る番号 S:リスト受け取り
    a=[]
    for i in range(0,x):#S[0]~S[x-1]までを追加
        a.append(S[i])
    if x<len(S)-2:
        for i in range(x+2,len(S)):
            a.append(S[i])
    return a
while j==0:
    for i in range(N-1):#S[0]~S[N-2]
        if (S[i]==0 and S[i+1]==1)or(S[i]==1 and S[i+1]==0):
            count+=2
            S=make_list(i,S)#Sの書き換え
            N=len(S)#Nの書き換え
            if N==0:
                j=1
            break
        elif i==N-2:
            j=1
print(count)

Submission status: Time Limit Exceeded

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

S = input()

S = list(S)
i = 0
count = 0
while i < len(S)-1:
  i+=1
  if S[i] != S[i-1]:
    S.pop(i-1)
    S.pop(i-1)
    count +=2
    i=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

oi1000 = "0"*1000 + "1"*1000
io1000 = "1"*1000 + "0"*1000

while oi1000 in s or io1000 in s:
    while oi1000 in s:
        s = s.replace(oi1000, "", 1)
        count += 1000
    while io1000 in s:
        s = s.replace(io1000, "", 1)
        count += 1000

oi100 = "0"*100 + "1"*100
io100 = "1"*100 + "0"*100

while oi100 in s or io100 in s:
    while oi100 in s:
        s = s.replace(oi100, "", 1)
        count += 100
    while io100 in s:
        s = s.replace(io100, "", 1)
        count += 100

oi10 = "0"*10 + "1"*10
io10 = "1"*10 + "0"*10

while oi10 in s or io10 in s:
    while oi10 in s:
        s = s.replace(oi10, "", 1)
        count += 10
    while io10 in s:
        s = s.replace(io10, "", 1)
        count += 10

while "01" in s or "10" in s:
    while "01" in s:
        num = s.count("01")
        s = s.replace("01", "")
        count += num
    while "10" in s:
        num = s.count("10")
        s = s.replace("10", "")
        count += num

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

oi1000 = "0"*1000 + "1"*1000
io1000 = "1"*1000 + "0"*1000

while oi1000 in s or io1000 in s:
    while oi1000 in s:
        s = s.replace(oi1000, "", 1)
        count += 1000
    while io1000 in s:
        s = s.replace(io1000, "", 1)
        count += 1000

oi100 = "0"*100 + "1"*100
io100 = "1"*100 + "0"*100

while oi100 in s or io100 in s:
    while oi100 in s:
        s = s.replace(oi100, "", 1)
        count += 100
    while io100 in s:
        s = s.replace(io100, "", 1)
        count += 100

while "01" in s or "10" in s:
    while "01" in s:
        num = s.count("01")
        s = s.replace("01", "")
        count += num
    while "10" in s:
        num = s.count("10")
        s = s.replace("10", "")
        count += num

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
oi10 = "0"*10 + "1"*10
io10 = "1"*10 + "0"*10

while oi10 in s or io10 in s:
    while oi10 in s:
        s = s.replace(oi10, "", 1)
        count += 10
    while io10 in s:
        s = s.replace(io10, "", 1)
        count += 10

while "01" in s or "10" in s:
    while "01" in s:
        num = s.count("01")
        s = s.replace("01", "")
        count += num
    while "10" in s:
        num = s.count("10")
        s = s.replace("10", "")
        count += num

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
while "01" in s or "10" in s:
    while "01" in s:
        s = s.replace("01", "", 1)
        count += 1
    while "10" in s:
        s = s.replace("10", "", 1)
        count += 1

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
N = len(S)
C = [0] * N
L = [None] * N

C[0] = 0
L[0] = [S[0]]
for i in range(1, N):
    if len(L[i-1]) > 0 and L[i-1][-1] != S[i]:
        C[i] = C[i-1] + 2
        L[i] = L[i-1][:-1]
    else:
        C[i] = C[i-1]
        L[i] = L[i-1] + [S[i]]
print(C[-1])

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
N = len(S)
S = [None] + S + [None]
nxt = [i + 1 for i in range(N+2)]
prv = [i - 1 for i in range(N+2)]

def remove(i):
    prv[nxt[i]] = prv[i]
    nxt[prv[i]] = nxt[i]

def dump():
    print(S)
    print(nxt)
    print(prv)
    print()

count = 0
while(True):
    i = nxt[0]
    j = nxt[i]
    removed = False
    while(True):
        #print(i, j)
        #dump()
        if S[i] == None or S[j] == None:
            break
        if S[i] == S[j]:
            i = j
            j = nxt[j]
        else:
            remove(i)
            remove(j)
            removed = True
            count += 2
            i = nxt[prv[i]]
            j = nxt[i]
    if not removed:
        break
#dump()
print(count)

Submission status: Time Limit Exceeded

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

while(True):
    if len(S) <= 1:
        break

    popped = False
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S.pop(i)
            S.pop(i)
            popped = True
            break

    if not popped:
        break

print(N-len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0
while True:
    res = s.replace("10", '')
    #print(res)
    diff = len(s) - len(res)
    if diff == 0:
        break
    #print(diff)
    c += diff
    s = res
while True:
    res = s.replace("01", '')
    #print(res)
    diff = len(s) - len(res)
    if diff == 0:
        break
    #print(diff)
    c += diff
    s = res

#print(s)
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
def search(s):
    for i in range(len(s) - 1):
        if (int(s[i]) + int(s[i + 1])) % 2 == 1:
            #return s.replace(s[i]+s[i + 1], '', 1)
            s.pop(i)
            s.pop(i)
            return True
    return False

c = 0
while True:
    if not search(s):
        break
    else:
        c += 1

print(c * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
def search(s):
    for i in range(len(s) - 1):
        if (int(s[i]) + int(s[i + 1])) % 2 == 1:
            return s.replace(s[i]+s[i + 1], '', 1)
    return s

c = 0
while True:
    res = search(s)
    if s == res:
        break
    else:
        c += 1
        s = res

print(c * 2)

Submission status: Time Limit Exceeded

Solution code:
cnt = 0
s = input()
while ('01' in s)or('10' in s):
    sa = s.replace('01', '')
    sa = sa.replace('10', '')
    cnt += len(s)-len(sa)
    s = sa
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
a = 0
while True:
    fidx = s.find('10')
    if fidx==-1:
        a = 1
    cnt += s.count('10')
    s = s.replace('10', '')
    fidx = s.find('01')
    if (fidx==-1)and(a==1):
        break
    cnt += s.count('01')
    s = s.replace('01', '')
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
while '01' in s or '10' in s:
    s_next = s.replace('01', '')
    ans += len(s) - len(s_next)
    s = s_next
    s_next = s.replace('10', '')
    ans += len(s) - len(s_next)
    s = s_next
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

strings = str(input())
strings_list = []
for s in strings:
    strings_list.append(s)



flag = 1
num = 0
while flag == 1:
    flag = 0
    for i in range(len(strings_list) - 1):
        if strings_list[i] != strings_list[i + 1]:
            del strings_list[i+1]
            del strings_list[i]
            num += 2
            flag = 1
            break

print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys


strings = str(input())
strings_list = []
for s in strings:
    strings_list.append(s)

flag = 1
num = 0
while flag == 1:
    flag = 0
    for i in range(len(strings_list) - 1):
        if strings_list[i] != strings_list[i + 1]:
            del strings_list[i+1]
            del strings_list[i]
            num += 2
            flag = 1
            break

print(num)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(str, input()))
len_S_orig = len(S)
while True:
  #print('-----')
  #print(S)
  i = 1
  while i<= len(S)-1:
    #print(i)
    if S[i-1] != S[i]:
      S[i-1] = 'x'
      S[i] = 'x'
      i += 2
    else:
      i += 1
      pass

  # del all 'x's from the list 
  len_S_before = len(S)
  #print(S)
  S = [si for si in S if si != 'x']
  len_S_after = len(S)
  #print(S)
  if len_S_before == len_S_after:
    break
  
print(len_S_orig - len(S))

Submission status: Time Limit Exceeded

Solution code:
def check(P):
    for i in range(len(P)-1):
        if P[i] != P[i+1]:
            return i
    return "Non"
P = list(input())
t = check(P)
pop = 0
while t != "Non":
    P.pop(t)
    P.pop(t)
    pop+=1
    t = check(P)
print(pop*2)

Submission status: Time Limit Exceeded

Solution code:
def func(line):
    lp = 0
    res = ""
    while lp + 1 < len(line):
        if line[lp] != line[lp + 1]:
            lp += 2
        else:
            res += line[lp]
            lp += 1
    if lp == len(line) - 1:
        res += line[-1]
    return res


def main():
    line = input()
    startsize = len(line)
    while True:
        next = func(line)
        if len(line) == len(next):
            break
        line = next
    lastsize = len(line)
    print(startsize - lastsize)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
lis = [int(x) for x in s]
counter = 0
che = 1

while che:
    che = 0
    for i in range(len(lis)-1):
        if lis[i] != lis[i+1]:
            lis.pop(i)
            lis.pop(i)
            che = 1
            counter += 2
            break

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()
subS = S
cnt = 0
while True:
    flg = True
    if "01" in subS:
        flg = False
        subS = subS.replace("01", "", 1)
        cnt += 2
    if "10" in subS:
        flg = False
        subS = subS.replace("10", "", 1)
        cnt += 2
    if flg:
        break
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ans=0
flag=1
s=input()
while ans!=flag:
	flag=ans
	ans+=len(s)-len(s.replace("01",""))
	s=s.replace("01","")
	ans+=len(s)-len(s.replace("10",""))
	s=s.replace("10","")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S =input()
counter = 0
S = list(S)
q = deque([])
for i in range(len(S)):
    q.append(S[i])
for i in range(10000000):
    if q:
        s1 = q.pop()
    else:
        break
    if q:
        s2 = q.pop()
    else:
        break
    if(s1 != s2):
        counter+=2
    else:
        q.appendleft(s1)
        q.append(s2)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans=0
for i in range(len(S)//2+1):
	ans += S.count('10')
	S = S.replace('10','')
	ans += S.count('01')
	S = S.replace('01','')
print(2*ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

stack = []

ans = 0
for s in S:
    if len(stack)==0 or s==stack[-1]:
        stack.append(s)
    else:
        stack = stack[:-1]
        ans += 2

print(ans)

Submission status: Time Limit Exceeded

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

def remove(preS):
    return "".join(("".join(preS.split('01'))).split('10'))




while True:
    T = remove(S)

    if T == S:
        break
    else:
        S = T
    

print(Slength-len(T))

Submission status: Time Limit Exceeded

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

def remove01(preS):
    return "".join(preS.split('01'))

def remove10(preS):
    return "".join(preS.split('10'))



while True:
    T = remove10(remove01(S))

    if T == S:
        break
    else:
        S = T
    

print(Slength-len(T))

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
while True:
    flag = []
    S = list(S)
    for i in range(len(S)):
        if i == 0:
            pre_s = S[i]
            flag.append(0)
        else:
            if pre_s != S[i] and flag[i-1] == 0:
                flag.append(1)
                flag[i-1] = 1
                pre_s = S[i]
                S[i-1] = "a"
                S[i] = "a"
            else:
                flag.append(0)
                pre_s = S[i]
            
    if sum(flag) == 0:
        break
    else:
        count += sum(flag)

    S = "".join(S).replace("a", "")
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
while True:
    flag = []
    for i in range(len(S)):
        if i == 0:
            pre_s = S[i]
            flag.append(0)
        else:
            if pre_s != S[i] and flag[i-1] == 0:
                flag.append(1)
                flag[i-1] = 1
                pre_s = S[i]
            else:
                flag.append(0)
                pre_s = S[i]
            
    if sum(flag) == 0:
        break
    else:
        count += sum(flag)

    S = list(S)
    for i in range(len(flag)):
        if flag[i]:
            S[i] = "a"
    S = "".join(S).replace("a", "")
            
print(count)

Submission status: Time Limit Exceeded

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

cont = True
while cont==True:
    s = s.split('10')
    a = ''
    for i in s:
        a=a+i
    if s[0] == a:
        cont = False
        s = a
    else:
        s = a 
cont = True
while cont:
    s = s.split('01')
    a = ''
    for i in s:
        a=a+i
    if s[0] == a:
        cont = False
        s = a
    else:
        s = a
N2 = len(a)
print(N-N2)

Submission status: Time Limit Exceeded

Solution code:
s =input()
N = len(s)
cont = True
while cont==True:
    s = s.split('10')
    a = ''
    for i in s:
        a=a+i
    if s[0] == a:
        cont = False
        s = a
    else:
        s = a 
cont = True
while cont:
    s = s.split('01')
    a = ''
    for i in s:
        a=a+i
    if s[0] == a:
        cont = False
    else:
        s = a
N2 = len(a)
print(N-N2)

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans=len(S)
def solve(s):
    res=""
    cnt=0
    while cnt < len(s):
        if cnt == len(s)-1:
            res+=s[cnt]
            cnt+=1
        elif s[cnt] ==s[cnt+1]:
            res +=s[cnt]
            cnt+=1
        else:
            cnt+=2

    if len(s) == len(res):
        return ans-len(s)
    else:
        return solve(res)

print(solve(S))

Submission status: Time Limit Exceeded

Solution code:
def locnt(s):
    index = 0
    lopair = 0
    s = list(s)
    while(index <= len(s)-2):
        if (s[index] != s[index+1]):
            lopair += 1
            index += 2
        else :
            index += 1
    return lopair

ans = 0
s = input()
lopair = locnt(s)
while(lopair):
    i = 0
    s = list(s)
    while(lopair):
        if s[i] != s[i+1]:
            lopair -= 1
            ans += 2
            s[i] = ""
            s[i+1] = ""
            i += 2
        else:
            i += 1
    s = "".join(s)
    lopair = locnt(s)
print(ans)