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:
#import sys
#input = sys.stdin.readline
import random
import bisect
#from statistics import mean, median, variance, stdev

#template input

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)
def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val
def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

"""ここからメインコード"""

def daruma(s, cou):
    i = 0
    new_s = ""
    while i+1 <= len(s):
        if i+1 == len(s):
            new_s += s[i]
            i += 1
        else:
            if s[i] == s[i+1]:
                i += 1
                new_s += s[i]
            else:
                i += 2
                cou += 2

    #print(new_s)
    return new_s, cou

def main():

    s = input()
    cou = 0
    while True:
        s, cou = daruma(s, cou)
        if s.count("1") == len(s) or s.count("0") == len(s):
            print(cou)
            break









main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt=0
 
for i in range(len(s)//2):
    if '10' in s:
        cnt+=2 * s.count('10')
        s=s.replace('10', '') 
    elif '01' in s:
        cnt+=2 * s.count('01')
        s=s.replace('01', '') 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A,B,K = [int(x) for x in input().split()]
S = input()

def hoge(input):
    new = []
    i = 0
    remove = False
    while i < len(input) - 1:
        if input[i] != input[i+1]:
            i = i + 2
            remove = True
        else:
            i = i + 1
            new.append(input[i])
    if i == len(input) - 1:
        new.append(input[-1])
    return new,remove

input = S
while True:
    input, remove = hoge(input)
    if not remove:
        break
print(len(S) - len(input))

Submission status: Time Limit Exceeded

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

S = input()
N = len(S)

while True:
  n = len(S)
  S = S.replace('10','')
  S = S.replace('01','')
  if n == len(S):
    break
print(N-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
s_len = len(S)
ahead = len(S)
now = len(S)
while(True):
    S = S.replace('01', '').replace('10', '')
    ahead = now
    now = len(S)
    if(ahead == now):
        break
print(s_len - len(S))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import re

def _main():
    text = input()
    count = 0

    while True:
        new_text = re.sub(r'01|10', '', text)

        if text == new_text:
            break
        else:
            count += len(text) - len(new_text)
            text = new_text

    print(count)



if __name__ == '__main__':
    _main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while '10' in s:
    ind = s.find('10')
    temp = []
    temp.append(str(s[0:ind]))
    temp.append(str(s[ind + 2:len(s)]))
    #print(s)
    s = "".join(temp)
    cnt = cnt + 2

while '01' in s:
    ind = s.find('01')
    # print(ind)
    temp = []
    temp.append(str(s[0:ind]))
    temp.append(str(s[ind + 2:len(s)]))
    s = "".join(temp)
    #print(s)
    cnt = cnt + 2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = 0
while True:
  if "10" in s:
    k += s.count("10")*2
    s = s.replace("10","")
  elif "01" in s:
    k += s.count("01")*2
    s = s.replace("01","")
  else:
    print(k)
    break

Submission status: Time Limit Exceeded

Solution code:
S = input()
n=0
while True:
    f = S.find("01")
    if f != -1:
        S = S[:f]+S[f+2:]
        n += 1
    ff = S.find("10")
    if ff != -1:
        S = S[:ff]+S[ff+2:]
        n += 1

    if f==-1 and ff==-1:
        break
print(n*2)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
con = 1
max = 0
while con != 0 :
    con = 0
    if (len(S) <= 1):
        break
    for x in range(len(S)-1):
        # print(S[x]+":"+S[x+1])
        if(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]
        #    print(S)
           con = 1
           break
print(max)

Submission status: Time Limit Exceeded

Solution code:
inp = input()
cnt = 0

inf = 10 ** 18
for i in range(inf):
  cnt_10 = inp.count('10')
  if cnt_10 > 0:
    cnt += cnt_10 * 2
    inp = inp.replace('10','')

  cnt_01 = inp.count('01')
  if cnt_01 > 0:
    cnt += cnt_01 * 2
    inp = inp.replace('01','')  
  
  if (cnt_01 == 0) & (cnt_10 == 0):
    break

print(cnt)

Submission status: Time Limit Exceeded

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

while True:
    if S[i:i+2] == ["0","1"] or S[i:i+2] == ["1","0"]:
        S.pop(i)
        S.pop(i)
        count += 2
        i = 0
    else:
        i+=1
    if len(S)-1 < i:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

result = 0
while True:
    if '01' in S:
        index = S.find('01')
        S = S[:index] + S[index+2:]
        result += 2
    elif '10' in S:
        index = S.find('10')
        S = S[:index] + S[index+2:]
        result += 2

    else:
        break

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i 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:
s = input()
n = len(s)
n1 = n
answer = 0
while 1:
  s = s.replace("01","")
  s = s.replace("10","")
  if n == len(s):
    break
  else:
    n = len(s)
print(n1-len(s))

Submission status: Time Limit Exceeded

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

def main():
    s = input().split(" ")

    sl = list(s[0])
    prev = -1
    n = 0
    while True:
        # print(str(sl))
        if len(sl) < 1:
            break
        kita = False
        for i, c in enumerate(sl):
            if i == 0 and prev != -1:
                break
            if (prev == 0 and c == '1') or (prev == 1 and c == '0'):
                kita = True
                # print("remove", i, prev, c)
                del sl[i]
                del sl[i-1]
                n += 2
                prev = -1
                break
            else:
                kita = True
                prev = int(c)

        if not kita:
            break

    print(n)

main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
len_ini_S = len(S)
tmp_len_rep_S = len_ini_S

while True:
  rep_S = S.replace('01','').replace('10','')
  len_rep_S = len(rep_S)
  if tmp_len_rep_S == len_rep_S:
    break
  else:
    tmp_len_rep_S = len_rep_S
    S = rep_S
    

print(len_ini_S - len_rep_S)

Submission status: Time Limit Exceeded

Solution code:
S=input()
ans=0

while True:
    befere_S=S
    S=S.replace('10','').replace('01','')
    ans+=len(befere_S)-len(S)
    if befere_S == S:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = [i for i in str(input())]

count = 0

while True:
        if len(s) != 0 and sum([int(i) for i in s]) != 0 and sum([int(i) for i in s]) != len(s):
                for i in range(int(len(s))):
                        if s[i] != s[i+1]:
                                s.pop(i)
                                s.pop(i)
                                count += 2
                                break
        else:
                print(count)
                break

Submission status: Time Limit Exceeded

Solution code:
s=str(input())

p1 = '01'
p2 = '10'
s = s[::-1]
c = 0
flag = True
while flag:
  flag = False
  for i in range(len(s)):
    if s[i:i+4] in ('0011','1100','1010','0101','1001','0110'):
      s = s[:i] + s[i+4:]
      c += 4
      flag = True
      break
    
    
    if s[i:i+2] in (p1,p2):
      s = s[:i] + s[i+2:]
      c += 2
      flag = True
      break
print(c)

Submission status: Time Limit Exceeded

Solution code:
string = input()
# string = "1" * 50000 + "0" * 50000
start_length = len(string)


while len(string) > 0:
  if "10" in string or "01" in string:
    string = string.replace("1111111100000000", "")
    string = string.replace("11111110000000", "")
    string = string.replace("111111000000", "")
    string = string.replace("1111100000", "")
    string = string.replace("11110000", "")
    string = string.replace("111000", "")
    string = string.replace("1100", "")
    string = string.replace("0000000011111111", "")
    string = string.replace("00000001111111", "")
    string = string.replace("0000011111", "")
    string = string.replace("00001111", "")
    string = string.replace("000111", "")
    string = string.replace("0011", "")
    string = string.replace("10", "")
    string = string.replace("01", "")
  else:
    break

print(start_length - len(string))

Submission status: Time Limit Exceeded

Solution code:
n = str(input())
motononagasa = len(n)
while '01' in n:
  n = n.replace('01', '')
while '10' in n:
  n = n.replace('10', '')
atononagasa = len(n)
#print(n)
print(motononagasa-atononagasa)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input()

Nblock = 0

while '0' in S and '1' in S:
    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

print(Nblock)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline())
count = 0
f = False
while True:
    p1 = s.find("01")
    p2 = s.find("10")
    if p1 == -1 and p2 == -1:
        i = None
    elif p1 == -1:
        i = p2
    elif p2 == -1:
        i = p1
    else:
        i = p1 if p1 < p2 else p2

    if i is not None:
        count += 2
        s = s[:i] + s[i + 2:]
        continue

    break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main() -> None:
    S = list(input())
    m = len(S)
    pre = len(S)
    while len(S) > 0:
        for i in range(len(S) - 1):
            if S[i] != S[i+1]:
                S.remove(S[i])
                S.remove(S[i])
                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:
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(0, len(S) - 1, 2):
			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(1, len(S) - 1, 2):
			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()
flag=1
length=len(s)
while flag:
    l=len(s)
    if l<=1:
        break
    for i in range(1,l):
        if s[i-1]!=s[i]:
            s=s[:i-1]+s[i+1:]
            break
        elif i==l-1:
            flag=0
print(length-len(s))

Submission status: Time Limit Exceeded

Solution code:
s_origin = str(input())

s = s_origin.replace("00000000001111111111", "")
s = s.replace("11111111110000000000", "")
s = s.replace("000000000111111111", "")
s = s.replace("111111111000000000", "")
s = s.replace("0000000011111111", "")
s = s.replace("1111111100000000", "")
s = s.replace("00000001111111", "")
s = s.replace("11111110000000", "")
s = s.replace("000000111111", "")
s = s.replace("111111000000", "")
s = s.replace("0000011111", "")
s = s.replace("1111100000", "")
s = s.replace("00001111", "")
s = s.replace("11110000", "")
s = s.replace("000111", "")
s = s.replace("111000", "")
s = s.replace("0011", "")
s = s.replace("1100", "")
s = s.replace("01", "")
s_aft = s.replace("10", "")

s_bef = s_origin
while len(s_bef) > len(s_aft):
    s_bef, s_aft = s_aft, s_aft.replace("01", "").replace("10", "")

print (len(s_origin) - len(s_aft))

Submission status: Time Limit Exceeded

Solution code:
s=[i for i in input()]
cnt=0
for i in range(100000000000000000):
    l=len(s)
    if l==0 or s.count("0")==l or s.count("1")==l:
        break
    else:
        for i in range(l):
            try:
                if int(s[i])+int(s[i+1])==1:
                    cnt+=2
                    s=s[0:i]+s[i+2:]
            except:
                pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

s = input()

n = len(s)

check = [False]*n


rem = 0

# 0 search
for i in range(n):
    if s[i]== '1':
        continue


    # 1 search
    for j in range(n):
        if s[j] == '0':
            continue

        if check[j]:
            continue

        check[i], check[j] = True, True
        rem += 2
        break

print(rem)

Submission status: Time Limit Exceeded

Solution code:
# /user/bin/python
# -*- coding: utf-8 -*-
import sys
 
s = str(input())
s_bef = ""
s_aft = s

while(s_bef != s_aft):
  s_bef = s_aft
  s_aft = s_aft.replace("01", "")
  s_aft = s_aft.replace("10", "")

print(len(s) - len(s_aft))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
s = input()
count = 0

while True:
    if s.count("01") != 0:
        num = s.count("01")
        s = s.replace("01", "")
        count += 2*num
    elif s.count("10") != 0:
        num = s.count("10")
        s = s.replace("10", "")
        count += 2*num
    else:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())

count=0
# print(S)

bExists = True

while(bExists):
	bExists = False
	for n in range(len(S)-1):
		# 最初に見つかったものから抜いていく
		if S[n] != S[n+1]:
			del S[n:n+2]
			# print(S)
			count += 2
			bExists = True
			break


print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
S=input()
sx=list(str(S))
s=list(map(int,sx))
#print(s)
cnt=0
while(1):
    t=copy.deepcopy(s) 
    for i in range(len(s)-1):
        if s[i]+s[i+1]==1:
            s.pop(i+1)
            s.pop(i)
            cnt+=2
            break
    if s==t:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy

s = input()

tmp = ""
count = 0
while(True):
    flag = False
    for i in range(len(s)-1):
        if(flag == True): flag = False
        elif(s[i] != s[i+1]):
            count += 2
            flag = True
        else: tmp += s[i]

    if(flag == False and len(s) != 0): tmp += s[len(s)-1]
    if(s == tmp): break

    s = copy.deepcopy(tmp)
    tmp = ""

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
answer = 0
while 1:
  c_01 = s.count("01")
  answer += c_01*2
  s = s.replace("01","")
  
  c_10 = s.count("10")
  answer += c_10*2
  s = s.replace("10","")
  
  if c_01 == 0 and c_10 == 0:
    break
print(answer)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0
while True:
    flg = True
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S = S[:i] + S[i+2:]
            flg = False
            cnt += 1
            break
    
    if flg:
        break

print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import re

def _main():
    text = input()
    count = 0

    while True:
        new_text = re.sub(r'01|10', '', text, 1)

        if text == new_text:
            break
        else:
            count += 2
            text = new_text

    print(count)



if __name__ == '__main__':
    _main()

Submission status: Time Limit Exceeded

Solution code:


def remove_data(data, ind_pre, ind_after):
    if ind_pre == 0:
        data_pre = ''
    else:
        data_pre = data[:ind_pre]
    if ind_after == len(data) - 1:
        data_after = ''
    else:
        data_after = data[ind_after + 1:]
    data_remove = data_pre + data_after
    return data_remove


def calc_data(data):
    flg = 1
    while flg:
        flg = 0
        for i in range(len(data) - 1):
            if data[i] != data[i + 1]:
                data = remove_data(data, i, i+1)
                flg = 1
                break
    return len(data)

def main():
    data = input()
    length = len(data)
    final_length = calc_data(data)
    print(length - final_length)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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 = 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 == "01" or mid == "10":
            if (l == "0" and r == "1") or (l == "1" and r == "0"):
                S = S[:i] + S[i+2:]
                flag = True
                break

    if flag:
        continue

    for i in range(0, len(S)-1):
        mid = S[i:i+2]
        if mid == "01" or mid == "10":
            S = S[:i] + S[i+2:]

    break
print(N-len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while '10' in s:
    ind = s.find('10')
    s = str(s[0:ind]) + str(s[ind + 2:len(s)])
    #print(s)
    cnt = cnt + 2

while '01' in s:
    ind = s.find('01')
    # print(ind)
    s = str(s[0:ind]) + str(s[ind + 2:len(s)])
    #print(s)
    cnt = cnt + 2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while True:
    pos_0 = s.find('01')
    pos_1 = s.find('10')
    if pos_0==-1 and pos_1==-1:
        break
    pos = max(pos_0,pos_1)
    s = s[:pos]+s[pos+2:]
    ans+=2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
while True:
    S=S.replace("01","z")
    S=S.replace("10","z")
    count+=S.count("z")*2
    if S.count("z")==0:
        print(count)
        break
    S=S.replace("z","")

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=0
b=[s[0]]
for i in range(1,len(s)):
    if b==[]:
        b.append(s[i])
    elif not b[-1]==s[i]:
        a+=2
        b=b[:(len(b)-1)]
    else:
        b.append(s[i])
print(a)

Submission status: Time Limit Exceeded

Solution code:
import re


S = input()
L = len(S)

while True:
    T = S[:]
    S = re.sub('(10)+', '', S)
    S = re.sub('(01)+', '', S)
    if S == T:
        break

print(L - len(S))

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=len(s)
b=10**5+1
while True:
    b=len(s)
    s=s.replace("10","")
    c=len(s)
    if c==b:
        break
while True:
    b=len(s)
    s=s.replace("01","")
    c=len(s)
    if c==b:
        break
print(a-c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt=0

for i in range(len(s)//2):
    try: 
        if '10' in s:
            cnt+=2 * s.count('10')
            s=s.replace('10', '') 
    except:
        pass
    try: 
        if '01' in s:
            cnt+=2 * s.count('01')
            s=s.replace('01', '') 
    except:
        pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = list(input())
queue = deque()
res = 0
count = 0
for c in s:
    queue.append(c)
    count += 1
    if count >= 2:
        if "0" == queue[-1] and "1" == list(queue)[-2] or "0" == queue[-2] and "1" == list(queue)[-1]:
             res += 2
             count -= 2 
             queue.pop()
             queue.pop()
print(res)

Submission status: Time Limit Exceeded

Solution code:
import copy

s = input()
s_sub = copy.deepcopy(s)

tar1 = "01"
tar2 = "10"

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



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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
s = list(input())
c = 0
b = 100
flag = 1
while flag == 1:
    flag = 0
    for i, n in enumerate(s):
        if (b == "0" and n == "1") or (b == "1" and n == "0"):
            c += 2
            b = 2
            flag = 1
            break
        else:
            b = n
    if flag == 1:
        for j in range(2):
            del s[i-1]
print(c)

Submission status: Time Limit Exceeded

Solution code:
class Solver:

    def __init__(self):
        pass

    def solve(self, s):
        s0 = s
        while True:
            snew = s.replace('01','').replace('10','')
            if snew == s:
                return (len(s0) - len(snew))
            s = snew

if __name__ == '__main__':

    solver = Solver()

    s = input()

    n = solver.solve(s)
    print(n)

Submission status: Time Limit Exceeded

Solution code:
s=str(input())

p1 = '01'
p2 = '10'
s = s[::-1]
c = 0
flag = True
while flag:
  flag = False
  for i in range(len(s)):
    if s[i:i+2] in [p1,p2]:
      s = s[:i] + s[i+2:]
      c += 2
      flag = True
      break
print(c)

Submission status: Time Limit Exceeded

Solution code:
S=raw_input()
A=[s for s in S]

while True:
    A_new=[]
    i=0
    while i<len(A):
        if i<len(A)-1:
            if A[i]!=A[i+1]:
                i+=2
            else:
                A_new.append(A[i])
                i+=1
        else:
            A_new.append(A[i])
            i+=1
    if A==A_new:
        break
    else:
        A=A_new[:]
print len(S)-len(A)

Submission status: Time Limit Exceeded

Solution code:
S = input()
t = S

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

print(len(S) - len(t))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while True:
    pos_0 = s.find('01')
    pos_1 = s.find('10')
    if pos_0==-1 and pos_1==-1:
        break
    pos = max(pos_0,pos_1)
    s = s.replace(s[pos:pos+2],'',1)
    ans+=2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import defaultdict

#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

#A, B, K = map(int, input().split())  #
S = input()
S_list = list()
for i in range(len(S)):
    S_list.append(S[i])
#print(len(S_list))

flag = True
cnt = 0
while flag:
    flag = False
    #print(S_list)
    for i in range(len(S_list)-1):
        #print(i+1)
        if S_list[i] != S_list[i+1]:
            #print(i, i+1)
            S_list.pop(i)
            S_list.pop(i)
            cnt += 2
            flag = True
            break
        pass
    pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

S=input()
N=len(S)

buf = []
ans = 0
for s in S:
    if buf:
        if buf[-1] != s:
            buf = buf[:-1]
            ans += 2
        else:
            buf += s
    else:
        buf += s

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt=0
while True:
    for i in range(len(s)//2):
        try: 
            if '10' in s:
                cnt+=2 * s.count('10')
                s=s.replace('10', '') 
        except:
            pass
        try: 
            if '01' in s:
                cnt+=2 * s.count('01')
                s=s.replace('01', '') 
        except:
            pass
    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = 0
while True:
  if "10" in s:
    i = s.index("10")
    s = list(s)
    s.pop(i)
    s.pop(i)
    s = "".join(s)
    k += 2
  elif "01" in s:
    i = s.index("01")
    s = list(s)
    s.pop(i)
    s.pop(i)
    s = "".join(s)
    k += 2
  else:
    print(k)
    break

Submission status: Time Limit Exceeded

Solution code:
n=input()
ans=0
chk=""
for i in n:
    if chk=="" or chk[-1]==i:
        chk+=i
    else:
        chk=chk[:-1]
        ans+=2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline())
count = 0
f = False
while True:
  for i in range(len(s)-1):
    if s[i] == '0' and s[i+1] == '1':
      count += 2
      s = s[:i] + s[i+2:]
      f = True
      break 
    if s[i] == '1' and s[i+1] == '0':
      count += 2
      f = True
      s = s[:i] + s[i+2:]
      break 
  if f:
    f = False
    continue
  break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re


S = input()
L = len(S)

while True:
    T = S[:]
    S = re.sub('10', '', S)
    S = re.sub('01', '', S)
    if S == T:
        break

print(L - len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
import re
cnt = 0

while '01' in s or '10' in s:
    s = re.sub(r'01|10','', s, 1)
    cnt += 2
    continue

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
answer = 0
while 1:
  answer += s.count("01")*2
  s = s.replace("01","")
  answer += s.count("10")*2
  s = s.replace("10","")
  if n == len(s):
    break
  else:
    n = len(s)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = list(input())
queue = deque()
res = 0
for c in s:
    queue.append(c)
    if len(queue) >= 2:
        if "0" in list(queue)[-2:] and "1" in list(queue)[-2:]:
             res += 2
             queue.pop()
             queue.pop()
print(res)

Submission status: Time Limit Exceeded

Solution code:
import collections as co
S = co.deque(input())
prev = 0
cnt = 0
while prev != len(S):
    prev = len(S)
    for i, s in enumerate(S):
        if i == 0:
            continue
        if s != S[i-1]:
            del(S[i-1])
            del(S[i-1])
            cnt += 2
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
str = list(input())
last = str[0]
check = 0
ans = 0
while True:
    check = 0
    last = str[0]
    for j in range(len(str) - 1):
        if last != str[j + 1]:
            str.pop(j)
            str.pop(j)
            check = 1
            ans += 2
            break
        last = str[j+1]
    if check == 0:
        break
    if str == []:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt=0
while True:
    for i in range(len(s)//2):
        try: 
            if '10' in s:
                s=s.replace('10', '',1) 
                cnt+=2
        except:
            pass
        try: 
            if '01' in s:
                s=s.replace('01', '',1) 
                cnt+=2
        except:
            pass
    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
S = input()
S_list = list(S)
flag = 1

if len(S) < 2:
    print(0)
    sys.exit()

while flag:
    if len(S_list) == 0:
        break
    tmp = S_list[0]
    count = 0
    for i in range(1, len(S_list)):
        if S_list[i] == tmp and i == len(S_list)-1:
            flag = 0
            break
            
        elif S_list[i] == tmp:
            tmp = S_list[i]
        else:
            S_list.pop(i-1)
            S_list.pop(i-1)
            count += 1
            break

print(len(S)-len(S_list))