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

s_list=[]
for i in range(len(S)):
    s_list.append(S[i])

num=0
judge=1
N=len(s_list)
while judge==1:
    judge=0
    for i in range(N):
        if i+1 < len(s_list):
            if s_list[i] != s_list[i+1]:
                #print(i,len(s_list),s_list,s_list[i],s_list[i+1])
                del s_list[i:i+2]
                num+=2
                judge=1
        else:
            break
    N = len(s_list)
print(num)

Submission status: Time Limit Exceeded

Solution code:
N = input()

ans = 0
while(True):
    changeFlg = False
    for a in range(len(N)-1):
        if N[a] != N[a + 1]:
            N = N[0:a] + N[a+2 : len(N)]
            ans += 2
            changeFlg = True
            break
    if  changeFlg == False:
        break

print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

cnt01 = s.count('01')
cnt10 = s.count('10')

while cnt01 != 0 or cnt10 != 0:
    if cnt01 >= cnt10:
        s = s.replace('01', '')
        cnt += cnt01
    else:
        s = s.replace('10', '')
        cnt += cnt10

    cnt01 = s.count('01')
    cnt10 = s.count('10')

print(cnt * 2)

Submission status: Time Limit Exceeded

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


cnt = 0

idx01 = s.find('01')
idx10 = s.find('10')
cnt01 = s.count('01')
cnt10 = s.count('10')

while idx01 != -1 or idx10 != -1:
    if idx01 == -1 and idx10 == -1:
        print(cnt)
        exit()
    if idx01 == -1:
        idx01 = 1000000
    if idx10 == -1:
        idx10 = 1000000
    if cnt01 >= cnt10:
        s = s.replace('01', '', cnt01)
        cnt += cnt01
    else:
        s = s.replace('10', '', cnt10)
        cnt += cnt10

    idx01 = s.find('01')
    idx10 = s.find('10')
    cnt01 = s.count('01')
    cnt10 = s.count('10')

print(cnt * 2)

Submission status: Time Limit Exceeded

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


cnt = 0

idx01 = s.find('01')
idx10 = s.find('10')
cnt01 = s.count('01')
cnt10 = s.count('10')

while idx01 != -1 or idx10 != -1:
    if idx01 == -1 and idx10 == -1:
        print(cnt)
        exit()
    if idx01 == -1:
        idx01 = 1000000
    if idx10 == -1:
        idx10 = 1000000
    if idx01 <= idx10:
        s = s.replace('01', '', cnt01)
        cnt += cnt01
    else:
        s = s.replace('10', '', cnt10)
        cnt += cnt10

    idx01 = s.find('01')
    idx10 = s.find('10')
    cnt01 = s.count('01')
    cnt10 = s.count('10')

print(cnt * 2)

Submission status: Time Limit Exceeded

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


cnt = 0

idx01 = s.find('01')
idx10 = s.find('10')

while idx01 != -1 or idx10 != -1:
    if idx01 == -1 and idx10 == -1:
        print(cnt)
        exit()
    if idx01 == -1:
        idx01 = 1000000
    if idx10 == -1:
        idx10 = 1000000
    if idx01 <= idx10:
        s = s.replace('01', '', 1)
    else:
        s = s.replace('10', '', 1)
    cnt += 1
    idx01 = s.find('01')
    idx10 = s.find('10')

print(cnt * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
origin = len(s)
le = 0
while len(s) != le:
    le = len(s)
    s = s.replace('10','').replace('01','')
    
print(origin-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
a = 0
while True:
    if "0" in S and "1" in S:
        S.pop(S.index("0"))
        S.pop(S.index("1"))
        a += 2
    else:
        break
print(a)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

#print(s)
print(count)


"""
s = input()

count = 0
while True:
    s0 = s
    s = s.replace("10","",1)
    if s0 != s:
        count += 2
        #print(s)
    else:
        s1 = s
        s = s.replace("01","",1)
        if s1 != s:
            count += 2
            #print(s)
        else:
            break

#print(s)
print(count)
"""

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
while True:
    s0 = s
    s = s.replace("10","",1)
    if s0 != s:
        count += 2
        #print(s)
    else:
        s1 = s
        s = s.replace("01","",1)
        if s1 != s:
            count += 2
            #print(s)
        else:
            break

#print(s)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
s = list(input())
ans = 0
s.append('n')
while 'n' in s:
    s = [i for i in s if i != 'n']
    for i in range(len(s)):
        if s[i:i+2]==['1', '0'] or s[i:i+2]==['0', '1']:
            ans += 2
            s[i:i+2] = ['n','n']
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

p = len(s)
cnt = 0
temp = 0

while True:
    s = s.replace("01","")
    s = s.replace("10","")
    
    cnt = len(s)
    
    if temp == cnt:
        break
    temp = cnt
    
print(p - cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
temp = 0

while True:
    cnt += s.count("01") * 2
    s = s.replace("01","")
    
    cnt += s.count("10") * 2
    s = s.replace("10","")
    
    if temp == cnt:
        break
    temp = cnt
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
orig = len(s)
while True:
    s = list(s)
    for i in range(1, len(s)):
        if s[i] == '0' and s[i-1] == '1':
            s[i] = 'x'
            s[i-1] = 'x'
        elif s[i-1] == '0' and s[i] == '1':
            s[i] = 'x'
            s[i-1] = 'x'
    s = ''.join(s)
    if s == s.replace('x', ''):
        break
    s=s.replace('x', '')
print(orig-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
c=0
n=1
while n>0 or m>0:
  n=s.count('01')
  s=s.replace('01','')
  c=c+n
  m=s.count('10')
  s=s.replace('10','')
  c=c+m
print(c*2)

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()

trimmed = 0

while True:
    tmp = re.split("01|10", S)
    if len(tmp) == 1:
        break
    else:
        trimmed = trimmed + len(tmp) - 1
        S = "".join(tmp)

print(trimmed * 2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(str(S))
cubes = [int(i) for i in list(S)]

first_comb = [0]
second_comb = [0]
while len(first_comb) > 0 or len(second_comb) > 0:
  length = len(cubes)
  first_comb = []
  second_comb = []
  for i in range(length - 1):
    if (cubes[i] == 0 and cubes[i + 1] == 1) or (cubes[i] == 1 and cubes[i + 1] == 0):
      if i + 2 <= length - 1 and i - 1 >= 0:
        if (cubes[i + 2] == 0 and cubes[i - 1] == 1) or (cubes[i + 2] == 1 and cubes[i - 1] == 0):
          first_comb.append([i, i + 1])
        else: 
          second_comb.append([i, i + 1])
      else: 
        second_comb.append([i, i + 1])

  if len(first_comb) > 0:
    cubes.pop(first_comb[0][0])
    cubes.pop(first_comb[0][1] - 1)
  elif len(second_comb) > 0:
    cubes.pop(second_comb[0][0])
    cubes.pop(second_comb[0][1] - 1)

print(N - len(cubes))

Submission status: Time Limit Exceeded

Solution code:
S = input()
def co(s):
    l = list(s)
    cnt = True
    for i in range(len(s))[:0:-1]:
        if l[i] != l[i-1]:
            del l[i]
            del l[i-1]
            cnt = False
            break
    if cnt:
        return s
    if not cnt:
        return co(''.join(l))
print(len(S)-len(co(S)))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
S = stdin.readline().rstrip()
ans = 0
while(S.count('01') != 0 or S.count('10') != 0):
    # print(S)
    ans += S.count("01")
    S = S.replace('01','')
    ans += S.count('10')
    S = S.replace('10','')
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

ans = len(S)
for i in range(len(S)):
  if len(S) == len(S.replace("01","")) and len(S) == len(S.replace("10","")):
    break
  else:
    S = S.replace("01","")
    S = S.replace("10","")

print(ans-len(S))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			cnt+=S.count('10')
			S=S.replace('10','')
			chk=1
		if '01' in S:
			cnt+=S.count('01')
			S=S.replace('01','')
			chk=1
	print(cnt*2)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		if '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		elif '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		elif '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)

resolve()

Submission status: Time Limit Exceeded

Solution code:
data = input()
data_list = [c for c in data]
#print(data_list)
count = 1
delete_count = 0
while ('0' in data_list) and ('1' in data_list):
    if data_list[count - 1] != data_list[count]:
        del data_list[count - 1: count + 1]
        delete_count += 2
        count = 1
    else:
        count += 1

print(delete_count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ans = 0
while(True):
    if s.find("01") != -1:
        s = s.replace("01","",1)
        ans += 2
    elif s.find("10") != -1:
        s = s.replace("10","",1)        
        ans += 2
    else:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input();
l = len(s)
while ('01' in s) or ('10' in s): 
	s=s.replace('01', '').replace('10', '')
print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)):
    null = 0
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    else:
        null +=1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
    else:
        null += 1
    if null == 2:
        break
print(2*counter)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)//2):
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
print(2*counter)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)):
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
print(2*counter)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
s=len(S)
#while any((S[i]== '0' and S[i+1]=='1') or (S[i]== '1' and S[i+1]=='0')for i in range(len(S)-1)

while any((S[i]== '0' and S[i+1]=='1') or (S[i]== '1' and S[i+1]=='0')for i in range(len(S)-1)):
    for j in range(len(S)-1):
        if j+1<len(S) and ((S[j]== '0' and S[j+1]=='1') or (S[j]== '1' and S[j+1]=='0')):
            S.pop(j)
            S.pop(j)

print(s-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

while True:
	if S.count('01') != 0:
		cnt += S.count('01')
		S=S.replace('01' , '')
	if S.count('10') != 0:
		cnt += S.count('10')
		S=S.replace('10' , '')

	if S.count('01') == 0 and S.count('10') == 0:
		print(cnt*2)
		exit()

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain


def f(s):
    l = s.split('01')
    for i in range(len(l)):
        l[i] = l[i].split('10')
    l = list(chain.from_iterable(l))
    return l


s = input().rstrip()

count = 0
while True:
    l = f(s)
    if len(l) == 1:
        break
    count += (len(l) - 1) * 2
    s = ''.join(l)

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain
import sys
sys.setrecursionlimit(99999)

s = input().rstrip()

def f(s):
    l = s.split('01')
    for i in range(len(l)):
        l[i] = l[i].split('10')
    l = list(chain.from_iterable(l))
    if len(l) == 1:
        return 0
    else:
        r = (len(l) - 1) * 2
        return r + f(''.join(l))

print(f(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while True:
    a = s.count('01')
    ans += 2*a
    s = s.replace('01', '')
    
    b = s.count('10')
    ans += 2*b
    s = s.replace('10', '')

    if not a and not b:
        break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
while True:
    if S.count("01") == 0 and S.count("10") == 0:
        break

    if S.count("01") > 0:
        ans += S.count("01")*2
        S = S.replace("01", "")

    if S.count("10") > 0:
        ans += S.count("10")*2
        S = S.replace("10", "")

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

work = S
unfinished = True
cnt = 0
lenlog = 0

while unfinished:
    work = work.replace('01', '').replace('10', '')
    cnt = len(S) - len(work)

    if lenlog == len(work):
        unfinished = False
        print(cnt)
        quit()

    lenlog = len(work)

Submission status: Time Limit Exceeded

Solution code:
#1,0が隣り合ったところを取り出していく　

L = [int(i) for i in list(input())]
N = len(L)
count = 0
flag = 0

k = 0
while 1:
  flag = 0
  i = N - 1
  while (i != 0) and (i > 0) :
    if (((L[i - 1] == 1) and (L[i] == 0)) or ((L[i - 1] == 0) and (L[i] == 1))):
      del L[i - 1:i + 1]
      N = N - 2
      count += 2
      i -= 1
      flag = 1
    i -= 1

  if flag == 0:
    break

print(count)

Submission status: Time Limit Exceeded

Solution code:

def check(S, Flag, counter):
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S = S[:i] + S[i+2:]
            #print(S)
            counter += 2
            break
        else:
            continue
    return S, Flag, counter

S = list(input())
Flag = True
counter = 0

while Flag:
    S, Flag, counter = check(S, Flag, counter)
    if S.count('1') == len(S) or S.count('0') == len(S):
        Flag = False
print(counter)

Submission status: Time Limit Exceeded

Solution code:

def check(S, Flag, counter):
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S = S[:i] + S[i+2:]
            #print(S)
            counter += 2
            break
        else:
            continue
        if S.count('1') == len(S) or S.count('0') == len(S):
            Flag = False
    return S, Flag, counter

S = list(input())
Flag = True
counter = 0

while Flag:
    S, Flag, counter = check(S, Flag, counter)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
def check(S, Flag, counter):
    for i in range(len(S)-1):
        if S[i] != S[i+1]:
            S = S[:i] + S[i+2:]
            #print(S)
            counter += 2
            break
        else:
            continue
        if i == len(S) - 2:
            Flag = False
    #print(S)
    return S, Flag, counter

S = list(input())
Flag = True
counter = 0

while Flag:
    S, Flag, counter = check(S, Flag, counter)
    if S.count('1') == len(S) or S.count('0') == len(S):
        Flag = False
print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()

begginingLength = len(S)

while "01" in S:
    S = S.replace("01","")

while "10" in S:
    S = S.replace("10","")

endLength = len(S)

ans = begginingLength - endLength
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = [int(i) for i in input()]
size = len(s)

def operation(strings):
    rest = []
    count = 0

    for i in range(len(strings)-1) :
        if strings[i] != strings[i+1] and count - 1  != i :
            rest.extend(strings[count:i])
            count = i + 2

    rest.extend(strings[count:])
    return rest 


while True :
    
    s = operation(s)
    if sum(s)  == len(s)  or sum(s)== 0:
        break
    else : continue
    
    
ans = size - len(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = raw_input();

cnt = 0;

while True:
	for i in range(len(S)):
		tmp = S.replace('01', '', 1);
		if S != tmp:
			cnt += 2;
			S = tmp;
			break;

		tmp = S.replace('10', '', 1);
		if S != tmp:
			cnt += 2;
			S = tmp;
			break;

	if len(set(S)) <= 1:
		break;

print(cnt);

Submission status: Time Limit Exceeded

Solution code:
def main():
  S = input()
  n = len(S)

  while True:
    tmp = S
    S = S.replace('01', '')
    S = S.replace('10', '')
    if tmp == S:
      break

  print(n - len(S))


if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
total = 0

while '01' in s or '10' in s:

  s = s.replace('01', 'x').replace('10', 'x')
  total += s.count('x') * 2
  s = s.replace('x', '')
  
print(total)

Submission status: Time Limit Exceeded

Solution code:
s = input()
total = 0

while '01' in s or '10' in s:
  total += s.count('01') * 2
  s = s.replace('01', '')
  total += s.count('10') * 2
  s = s.replace('10', '')

print(total)

Submission status: Time Limit Exceeded

Solution code:
s = input()
total = 0

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

while '10' in s:
  total += s.count('10') * 2
  s = s.replace('10', '')

print(total)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    S = str(input())
    N = len(S)

    answer = 0
    for i in range(0, N):
        index_00 = S.find('01')
        if index_00 != -1:
            answer += 2
            S = S[:index_00] + S[index_00+2:]
            continue
        index_11 = S.find('10')
        if index_11 != -1:
            answer += 2
            S = S[:index_11] + S[index_11+2:]
            continue
        if S.find('01') == -1 and S.find('10') == -1:
            break

    print(answer)

Submission status: Time Limit Exceeded

Solution code:
s = t = input()

ans = 0
flag = True
while flag:
    s = s.replace('01','').replace('10','')
    if len(s) == len(t):
        flag = False
    else:
        ans += len(t) - len(s)
        t = s

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
int_S=[]
for i in range(0,len(S)):
    int_S.append(int(S[i]))
global_count=0
count=1
while(count!=0):
    new_list=[]
    count=0
    i=0
    while(i<len(S)):
        if (i==len(S)-1):
            new_list.append(S[i])
            i+=1

        elif(S[i]!=S[i+1]):
            global_count+=2
            i+=2
            count+=1
        else:
            new_list.append(S[i])
            i+=1
    S=new_list
print(global_count)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
int_S=[]
for i in range(0,len(S)):
    int_S.append(int(S[i]))
global_count=0
count=1
while(count!=0):
    new_list=[]
    count=0
    i=0
    while(i<len(S)):
        if (i==len(S)-1):
            new_list.append(S[i])
            i+=1

        elif(S[i]!=S[i+1]):
            global_count+=2
            i+=2
            count+=1
        else:
            new_list.append(S[i])
            i+=1
    S=new_list
 
print(global_count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
i, ans = (0, 0)
while i>=0 and i<len(S)-1:
    if S[i]!=S[i+1]:
        S = S[:i]+S[i+2:] if i+2<len(S) else S[:i]
        ans += 2
        i = max(0, i-1)
    else:
        i+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
import copy
s=input()
sr,ss=copy.deepcopy(s),""
while ss!=sr:
    sr,ss=ss,re.sub("01|10","",ss if sr!=s else s)
print(len(s)-len(ss))

Submission status: Time Limit Exceeded

Solution code:
l=list(input())
c=0
while "1" in l and "0" in l:
  for i in range(1,len(l)):
    if (l[i-1]=="0" and l[i]=="1") or (l[i-1]=="1" and l[i]=="0"):
      del l[i-1]
      del l[i-1]
      c+=2
      break
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
l = len(s)
while '01' in s or '10' in s:
    s = s.replace('01', '').replace('10', '')
print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

l = len(s)
for st in ['01', '10']:
    while st in s:
        s = s.replace('01', '').replace('10', '')

print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

l = len(s)
for st in ['01', '10']:
    while st in s:
        s = s.replace(st, '')

print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ans = 0 

for st in ['01', '10']:
    while st in s:
        for i in range(len(s)):
            if s[i:i+2] == st:
                s = s[:i] + s[i+2:]
                ans += 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ans = 0 

for st in ['01', '10']:
    while st in s:
        for i in range(len(s)):
            if s[i:i+2] == st:
                if i > 0 and i + 2 < len(s):
                    s = s[:i] + s[i+2:]
                elif i == 0:
                    s = s[i+2:]
                elif i + 2 == len(s):
                    s = s[:i]
                ans += 2

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()
ls = list(S)
ls = [int(x) for x in ls]
offset = 0
count = 0
while len(ls) >= 2:
    if ls[offset] != ls[offset +1]:
        del ls[offset:offset +2]
        count += 2
        offset = 0
    elif offset + 2 == len(ls):
        break
    else:
        offset += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

slength = len(s)
for _ in range(5000):
    s = s.replace("01", "").replace("10", "")
print(slength-len(s))

Submission status: Time Limit Exceeded

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

s = [int(c) for c in s]

c = 0
while True:
    i = 0
    while i < len(s) - 1:
        if s[i] != s[i + 1]:
            s[i] = s[i + 1] = -1
            i += 2
            c += 2
        i += 1
    s = [c for c in s if c >= 0]
    l = len([c for c in s if c == 0])
    if l == 0 or l == len(s):
        break

print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

while(1):
    before = len(S)
    S = S.replace("01","")
    S = S.replace("10","")
    after = len(S)
    if before - after  == 0:
        break
    else:
        ans += before - after




print(ans)

Submission status: Time Limit Exceeded

Solution code:
#120 C
S =input()
min_=min(S.count('0'),S.count('1'))
cnt=0
for i in range(min_):
    if S.count('01')>0:
        S=S.replace('01','',1)
        cnt+=2
    if  S.count('10')>0:
        S=S.replace('10','',1)
        cnt+=2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#120 C
S =input()
cnt=0
for i in range(len(S)):
    if S.count('01')>0:
        S=S.replace('01','',1)
        cnt+=2
    if  S.count('10')>0:
        S=S.replace('10','',1)
        cnt+=2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)
pos = 0
cnt = 0

while pos != n - 1 and n != 0:
    if s[pos] != s[pos + 1]:
        del s[pos]
        del s[pos]
        pos = 0
        n -= 2
        cnt += 2
    else:
        pos += 1

print(cnt)

Submission status: Time Limit Exceeded

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

#print(S)

while '01' in S or '10' in S:
  S = S.replace('01', '')
  S = S.replace('10', '')
  #print(S)

print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_len = len(S)
ans = 0
while(S.count("01") != 0 or S.count("10") != 0):
    S = S.replace("01","")
    S = S.replace("10","")
    count = S_len - len(S)
    ans += count
    S_len = len(S)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
Smae = S
while True:
    S = S.replace('01', '')
    S = S.replace('10', '')
    if '01' not in S and '10' not in S:
        break
print(len(Smae) - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

s = S

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

print(len(S) - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
while True:
    n = len(s)
    ints = sum(map(int, s))
    if n == 0 or ints == 0 or ints == n:
        break
    sn = s + '\n'
    for i in range(n):
        if sn[i-1] + sn[i] == '10' or sn[i-1] + sn[i] == '01':
            s = sn[:i-1] + sn[i+1:n]
            count += 1
            break

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
while True:
    n = len(s)
    if n == 0 or all(c == '0' for c in s) or all(c == '1' for c in s):
        break
    sn = s + '\n'
    for i in range(n):
        if sn[i-1] + sn[i] == '10' or sn[i-1] + sn[i] == '01':
            s = sn[:i-1] + sn[i+1:n]
            count += 1
            break

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
while True:
    sn = s + '\n'
    for i in range(len(s)):
        if sn[i-1] + sn[i] == '10' or sn[i-1] + sn[i] == '01':
            s = sn[:i-1] + sn[i+1:len(sn)-1]
            count += 1
            break
    if len(s) == 0 or all(c == '0' for c in s) or all(c == '1' for c in s):
        break

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

def del_cube(s, i):
    s = s[:i] + s[i+2:]
    return s

s = S
while True:
    flag = True
    for i in range(len(s) - 1):
        if s[i] == '0' and s[i+1] == '1' or s[i] == '1' and s[i+1] == '0':
            flag = False
            s = del_cube(s, i)
            break
            
    if flag == True:
        break
        
print(len(S) - len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

remove_count = 0
while(True) :
    S = S.replace("10","X").replace("01","X")
    current_count = S.count("X")
    if (current_count == 0) :
        break
    remove_count += current_count
    S = S.replace("X","")

print(remove_count * 2)

Submission status: Time Limit Exceeded

Solution code:
count = 0

daruma = list(map(int, list(input())))

flag = len(daruma)

while flag != 0:
    try:
        for i in range(0, len(daruma)):
            if daruma[i] + daruma[i+1] == 1:
                daruma = daruma[:i]+daruma[i+2:]
                count +=2
        flag -= 1
    except:
        flag -= 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()
S = str(S)

counter = 0


while True:
    killer = 0

    killer += int(S.count('10'))
    S = S.replace('10','')

    killer += int(S.count('01'))
    S = S.replace('01','')

    counter += int(killer)

    if killer == 0:
        break
print counter * 2

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

count = 0
T = ""
while((len(S) >= 1) and ("0" in S) and ("1" in S)):
    if (S[0:2] == "01") or (S[0:2] == "10"):
        count += 2
        S = S[2:]
        T += S
        S = T
        T = ""
    else:
        T += S[0]
        S = S[1:]
print(count)

Submission status: Time Limit Exceeded

Solution code:
k = input()
ol = pl = len(k)
l = 0
while l != pl:
  pl = l
  k = k.replace("01", "").replace("10", "")
  l = len(k)
print(ol - l)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
s1 = len(s)
a = len(s)
b = 0

while a != b:
    a = len(s)
    s = s.replace('01','')
    s = s.replace('10','')

    b = len(s)

print(s1-b)

Submission status: Time Limit Exceeded

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

count = 0
flag = True

while flag:
  for i in range(len(s) - 1):
    if not s[i] == s[i+1]:
      del s[i:i+2]
      count += 2
      break
  else :
    flag = False

print(count)

Submission status: Time Limit Exceeded

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

while len(S) > 1:
    no_01 = True
    before_s = S[0]
    for i, s in enumerate(S):
        if before_s != s:
            no_01 = False
            newS = S[:i-1] + S[i+1:]
            S = newS
            break
    if no_01:
        break
print(init_count - len(S))