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:
from collections import deque

S = input()

ss = []
flag = True
ans = 0
for i in range(len(S)): ss.append(S[i])

while flag:
    length = len(ss)
    tmp_flag = False
    for i in range(length-1):
        if ss[i] != ss[i+1]:
            rm = i
            ans += 2
            tmp_flag = True
            break
    if tmp_flag:
        ss.pop(rm)
        ss.pop(rm)
    else:
        flag = False
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
while 1:
    l = len(S)
    S = S.replace('01', '').replace('10', '')
    l2 = len(S)
    if l==l2:
        break
print(L-l2)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ans = 0
i = 0
while len(S)>i+1:
  if S[i] != S[i+1]:
    S.pop(i)
    S.pop(i)
    ans += 2
    i = 0
  else:
    i = i+1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

t = s

while True:
    a = s.replace("01", "")
    a = a.replace("10", "")
    if (len(s) == len(a)):
        break
    s = a

print(len(t) - len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
prev = -1
while True:
    count += 2*S.count('01')
    S = S.replace('01','')
    count += 2*S.count('10')
    S = S.replace('10','')
    if count == prev:
        break
    else:
        prev = count
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
count = 0
while True:
    if '1' not in S or '0' not in S:
        break
    L = len(S)
    for i in range(L):
        if i < L-1 and (S[i] == '0' and S[i+1] == '1' or S[i] == '1' and S[i+1] == '0'):
            count += 2
            S = S[:i] + S[i+2:]
            break
print(count)

Submission status: Time Limit Exceeded

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

# check
cnt = 0
del_ind = []
append = del_ind.append

while N > 1:
    for i in range(1, N):
        if S[i - 1:i + 1] in ["01", "10"]:
            cnt += 2
            N -= 2
            S = S[:i - 1] + S[i + 1:]
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S = [int(s) for s in S]
N = len(S)
#print('S:', S)

count=0
i=1
while True:
    #print(S,i)
    if len(S)==0 or len(S)==1 or sum(S)==len(S) or sum(S)==0 :
        break

    elif S[i-1] != S[i]:
        del S[i-1]
        del S[i-1]
        count+=1
        i=1
    else:
        i+=1

print(count*2)

Submission status: Time Limit Exceeded

Solution code:
import sys
s = str(input())
p = len(s)
new = []
if p == 1:
    print("0")
    sys.exit()
while True:
    for i in range(len(s)-1):
        if i == len(s) - 2:
            if s[i] != s[i+1]:
                s = s[:i] + s[i+2:]
                print(p-len(s))
                sys.exit()
            else:
                print(p-len(s))
                sys.exit()
        elif s[i] != s[i+1]:
            s = s[:i] + s[i+2:]
            break

Submission status: Time Limit Exceeded

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

while s != prev:
    prev = s
    s = s.replace('01', '')
    s = s.replace('10', '')

print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = input()
s=S
ans=0
while True:
    s=s.replace('10','')
    s=s.replace('01','')

    cnt10=s.count('10')
    cnt01=s.count('01')
       
    if cnt10==0 and cnt01==0:
        break
print(len(S)-len(s))

Submission status: Time Limit Exceeded

Solution code:
str = input()
n = 0
cnt = 0
f = True
while f == True:
  s = list(str)
  f = False
  for i in range(len(str)-1):
#    print(len(str))
    if s[i] != s[i+1] and s[i] != "":
      s[i] = ""
      s[i+1] = ""
      cnt += 1
      f = True
  str = "".join(s)
#  print(str)
print(2*cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
cnt = 0
prev = len(s)
while len(s) > 1:
    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'):
            cnt += 2
            s = s[:i] + 'xx' + s[i + 2:]
    s = s.replace('xx', '')
    if len(s) == prev:
        break
    prev = len(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
cnt = 0
while len(s) > 1:
    for i in range(len(s) - 1):
        if s[i] != s[i + 1]:
            cnt += 2
            if i == len(s) - 1:
                break
            else:
                s = s[:i] + s[i + 2:]
                break
    else:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(S: str):
    nS = len(S)
    pS = ""
    while pS != S:
        pS = S
        S = S.replace("01", "")
        S = S.replace("10", "")
    print(nS - len(S))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  s = input()
  
  answer = 0
  
  while ("0" in s) and ("1" in s):
    answer += s.count("10")
    s = s.replace("10", "")
    answer += s.count("01")
    s = s.replace("01", "")
  
  print(answer * 2)


if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  s = input()
  
  answer = 0
  
  while ("0" in s) and ("1" in s):
    answer += s.count("10")
    s.replace("10", "")
    answer += s.count("01")
    s.replace("01", "")
  
  print(answer)


if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
p=0
c=0
while p<len(s)-1:
    if (s[p]=='0' and s[p+1]=='1') or (s[p]=='1' and s[p+1]=='0'):
        s=s[:p]+s[p+2:]
        
        c+=2
        p=0
    else:
        p+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while True:
    if '01' in s: i = s.index('01')
    elif '10' in s: i = s.index('10')
    else: break
    s = s[:i] + s[i+2:]
    ans += 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

s = input()
tmp = 0 
# まず"01"で抜きまくって、次に"10"で抜きまくる。という実装
ans = 0 
while len(s) != tmp:
    tmp = len(s)
    for i in range(len(s)-1):
        if s[i] == '0' and s[i+1] == '1':
            ans += 1
            s = s[0:i]+s[i+2:]
            #print('s =', s)
            break
tmp = 0 
while len(s) != tmp:
    tmp = len(s)
    for i in range(len(s)-1):
        if s[i] == '1' and s[i+1] == '0':
            ans += 1
            s = s[0:i]+s[i+2:]
            #print('s =', s)
            break

print(2*ans)

Submission status: Time Limit Exceeded

Solution code:
s, cont = input(), 0
while s.find("01") is not -1:    
    s = s.replace("01", "", 1)
    cont += 1    
while s.find("10") is not -1:
    s = s.replace("10", "", 1)
    cont += 1
print(cont * 2)

Submission status: Time Limit Exceeded

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

map_list = [int(i) for i in s]
ans=0
while True:
    flag=True
    for i in range(n-1):
        if map_list[i]==-1:
            continue
        j=i+1
        if map_list[i+1]==-1:
            for k in range(i+1,n):
                if map_list[k]!=-1:
                    j=k
                    break
        if min(map_list[i],map_list[j])>=0:
            if map_list[i]!=map_list[j]:
                map_list[i]=-1
                map_list[j]=-1
                flag=False
                ans+=2
                continue
    if flag:
        break
print(ans)

Submission status: Time Limit Exceeded

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

while True:
    new_s = []
    len_s = len(s)
    while s:
        if len(s)==1:
            new_s.append(s[0])
            break
        x=s.pop(0)
        if s[0]!=x:
            y=s.pop(0)
        else:
            new_s.append(x)
    
    s = new_s
    if len(new_s)==len_s:
        print(num_s-len_s)
        break

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
while '0' in s and '1' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
    s = s.replace('01', '')
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
while '0' in s and '1' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
def process():
    global S
    global cnt
    p = 0
    for i in range(len(S)-1):
        if S[i:i+2] == '01' or S[i:i+2] == '10':
            S=S[:i]+S[i+2:]
            p+=2
            
    cnt += p
    if p == 0:
        print(cnt)
    else:
        process()

S = str(input())
cnt = int()
process()

Submission status: Time Limit Exceeded

Solution code:
# ABC120C

s = input()
s = list(s)
count = 0
while len(s) > 1:
    found = False
    for i in range(len(s)-1):
        if (s[i] == '1' and s[i+1] == '0') or (s[i] == '0' and s[i+1] == '1'):
            #print(f"s = {s}, i, i+1, {i}, {i+1}")
            s.pop(i+1)
            s.pop(i)
            found = True
            count += 2
            break
    if found == False:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = "".join(list(input()))

ans = 0

while True:
    if S.find("10") == -1 and S.find("01") == -1:
        break
    if S.find("10") > -1:
        S = S.replace("10","",1)
        ans += 2
    elif S.find("01") > -1:
        S = S.replace("01","",1)
        ans += 2
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    cnt = 0
   
    if len(set(S)) == 1 :
        print(0)
    else:
        l_past  = None
        l_new = None
        block = list(S)

        for i in range(10**5):
            block = [ a for a in block if a != "-"]
            l_new = len(block)

            if l_past == l_new :
                break

            for i in range(len(block) - 1):
                if (block[i] == "0" and block[i+1] == "1") or (block[i] == "1" and block[i+1] == "0"):
                    cnt += 2
                    block[i] = "-"
                    block[i+1] = "-"

            l_past = l_new

        print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    cnt = 0
    l_past  = None
    l_new = None
    block = list(S)
    for i in range(10**5):
        block = [ a for a in block if a != "-"]
        l_new = len(block)

        if l_past == l_new :
            break

        for i in range(len(block) - 1):
            if (block[i] == "0" and block[i+1] == "1") or (block[i] == "1" and block[i+1] == "0"):
                cnt += 2
                block[i] = "-"
                block[i+1] = "-"

        l_past = l_new

    print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input()))
count=0
k=len(s)-2
i=0
while i<=k:
    if s[i]!=s[i+1]:
        s.remove(s[i])
        s.remove(s[i])
        k-=2
        count+=2
        if i!=0:
            i-=1
    else:
        i+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    cnt = 0
    for i in range(len(S)):
        if S.find("10") != -1 or S.find('01') != -1:
            if S.find("10") != -1:
                S = S.replace("10", "", 1)
                cnt += 1
            if S.find("01") != -1:
                S = S.replace("01", "", 1)
                cnt += 1
        else:
            break
    print(cnt*2)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = list(s)
idx = 0
blocks = 0
while idx != len(s) - 1:
    if s[idx] == '0' and s[idx+1] == '1':

        tmp1 = s[idx]
        tmp2 = s[idx+1]

        s.remove(tmp1)
        s.remove(tmp2)

        idx = 0
        blocks += 2

    elif s[idx] == '1' and s[idx+1] == '0':

        tmp1 = s[idx]
        tmp2 = s[idx+1]

        s.remove(tmp1)
        s.remove(tmp2)

        idx = 0
        blocks += 2

    else:
        idx += 1
        
    if len(s) == 0:
        break

print(blocks)

Submission status: Time Limit Exceeded

Solution code:
def myAnswer(S:list) -> int:
   counter = 0
   while True:
      for i in range(len(S)-1):
         if(S[i]!=S[i+1]):
            S.pop(i)
            S.pop(i)
            counter += 2
            break
      else:
         break
   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
for i in range(l//2):
    s = s.replace("01","").replace("10","")
print(l-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ans = 0
for _ in range(len(S)):
    check = S[0]
    tmp = ans
    for i in range(1,len(S)):
        if check != S[i]:
            count = 1
            for _ in range(len(S)):
                if i-1-count > 0 and i+count < len(S):
                    if S[i-1-count] != S[i+count]:
                        count += 1
                    else:
                        break
                else:
                    break
            ans += 2 * count
            del S[i-count:i+count]
            break
        check = S[i]
    if len(S) == 0:
        break
    if tmp == ans:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ans = 0
for _ in range(len(S)):
    check = S[0]
    tmp = ans
    for i in range(1,len(S)):
        if check != S[i]:
            ans += 2
            del S[i-1:i+1]
            break
        check = S[i]
    if len(S) == 0:
        break
    if tmp == ans:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
l = [0]*10**6
l[0] = input()
i = 1

while True:
    l[i] = l[i-1].replace("10", "").replace("01","")
    if "10" not in l[i] and "01" not in l[i]:
        print(len(l[0]) - len(l[i]))
        exit()
    i += 1

Submission status: Time Limit Exceeded

Solution code:
import re
a = input()
operations = 0
while re.search("01", a) or re.search("10", a):
    if re.search("01", a):
        a = a.replace("01", "", 1)
        operations += 2
    if re.search("10", a):
        a = a.replace("10", "", 1)
        operations += 2
print(operations)

Submission status: Time Limit Exceeded

Solution code:
import re
a = input()
operations = 0
re.search("01", a) or re.search("10", a)
i = 0
while re.search("01", a) or re.search("10", a):
    if re.search("01", a):
        a = a.replace("01", "", 1)
        operations += 2
    if re.search("10", a):
        a = a.replace("10", "", 1)
        operations += 2
print(operations)

Submission status: Time Limit Exceeded

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    cnt = 0
    flag = False
    ok = False
    while True:
        if flag:
            break
        i = 0
        while i < len(s)-1:
            ok = False
            if s[i] != s[i+1]: # 違うものが出た
                cnt += 2
                s = (s[:i] + s[i+2:] if len(s) >= 3 else s[:i])
                ok = True
                break
            i += 1
        if not ok:
            break
        if len(s) == 0:
            break
    print(cnt)


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
#print(type(s))
#s = str(s)
#print(type(s))
#print(s)


#s = int(s)
#s = str(s)

flag = 1
cont = 0


while(flag):
    flag = 0
    for x in range(0, len(s)):
        if  x+1 < len(s) and s[x] == '1' and s[x+1] == '0':
            cont = cont + 2
            flag = 1
            aux = s[:x]
            aux2 = s[x+2: len(s)]
            s = aux + aux2
        elif x+1 < len(s) and s[x] == '0' and s[x+1] == '1':
            cont = cont + 2
            flag = 1
            aux = s[:x]
            aux2 = s[x+2: len(s)]
            s = aux + aux2

print(cont)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
#print(s)


#s = int(s)
#s = str(s)

flag = 1
cont = 0


while(flag):
    flag = 0
    for x in range(0, len(s)):
        if  x+1 < len(s) and s[x] == '1' and s[x+1] == '0':
            cont = cont + 2
            flag = 1
            aux = s[:x]
            aux2 = s[x+2: len(s)]
            s = aux + aux2
            break
        elif x+1 < len(s) and s[x] == '0' and s[x+1] == '1':
            cont = cont + 2
            flag = 1
            aux = s[:x]
            aux2 = s[x+2: len(s)]
            s = aux + aux2
            break

print(cont)

Submission status: Time Limit Exceeded

Solution code:
s = input()

aux = 0

while '01' in s or '10' in s:
    if '01' in s:
        s = s.replace('01', '', 1)
        aux += 2
    if '10' in s:
        s = s.replace('10', '', 1)
        aux += 2

print(aux)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
size = len(S)
to_remove = []
last_size = len(S)
while True:
    i = 0
    while i < len(S)-1:
        if S[i] != S[i+1]:
            to_remove.append(i)
            to_remove.append(i+1)
            i+=1
        i+=1
    to_remove.reverse()
    for t in to_remove:
        del S[t]
    to_remove = []
    if last_size == len(S) or len(S) == 0:
        break
    else:
        last_size = len(S)
print(size-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
last_size = 0
size = len(S)
to_remove = []
while True:
    i = 0
    while i < len(S)-1:
        if S[i] != S[i+1]:
            to_remove.append(i)
            to_remove.append(i+1)
            i+=1
        i+=1
    to_remove.reverse()
    for t in to_remove:
        del S[t]
    to_remove = []
    if last_size == len(S) or len(S) == 0:
        break
    else:
        last_size = len(S)
print(size-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
last_size = 0
size = len(S)
while True:
    for i in range(0, len(S)-1):
        if S[i] != S[i+1]:
            del S[i+1]
            del S[i]
            break
    if last_size == len(S) or len(S) == 0:
        break
    else:
        last_size = len(S)
print(size-len(S))

Submission status: Time Limit Exceeded

Solution code:
num = input()
predicted_value = 0
finished = False
i = 1
while i < len(num):
    if num[i] != num[i-1]:
        num = num[:i-1] + num[i+1:]
        predicted_value += 2
        i = 0
    i += 1
print(predicted_value)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())   
adj=-1
op=0

while(adj==-1):
    adj=0
    for i in range(1,len(s)):
        if(s[i]!=s[i-1]):
            adj=-1
            del(s[i], s[i-1])
            op+=2
            break
         
print(op)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
for i in range(0,len(s)):
    s[i]=int(s[i])
    
adj=-1
op=0
while(adj==-1):
    adj=0
    for i in range(1,len(s)):
        if((s[i]==0 and s[i-1]==1) or (s[i]==1 and s[i-1]==0)):
            adj=-1
            s[i]=2
            s[i-1]=2
            op+=2
    while True:
        try:
            s.remove(2)
        except:
            break
            
print(op)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
stack = [s[0]]
flg = False
for i in range(1,len(s)):
        if len(stack) > 0:
            if stack[0] != s[i]:
                ans += 2
                stack.pop(0)
            else:
                stack.insert(0, s[i])
        else:
            stack.insert(0, s[i])

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
L=N
for i in range(L):
  S="".join(S.split("01"))
  S="".join(S.split("10"))
  #print(S)
  if L==len(S):
    break
  L=len(S)
  
#print(S)
print(N-L)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)
i = 0
count = 0
while i < n-1:
    if (s[i]=="0" and s[i+1]=="1") or (s[i]=='1' and s[i+1]=='0'):
        s.pop(i)
        s.pop(i)
        count += 2
        i= 0
        n = len(s)
    else:
        i += 1
    
    
print(count)

Submission status: Time Limit Exceeded

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

cnt = 0
renew=True
while S and renew:
    nextS = []
    renew = False
    lS = len(S)
    i = 0
    while (i <= lS-1):
        if i == lS-1:
            nextS.append(S[i])
            break
        a = S[i]
        b = S[i+1]
        if a != b:
            cnt += 1
            i+=2
            renew = True
        else:
            nextS.append(a)
            i+=1
    S = nextS
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
s=[]
c1=0
c0=0
for i in range(len(S)):
  s.append(S[i])
  if S[i]=='0':
    c0+=1
  else:
    c1+=1
c=0
while min(c0,c1)>0:
  for i in range(len(s)-1):
    if s[i:i+2]==['1','0'] or s[i:i+2]==['0','1']:
      c0-=1
      c1-=1
      s.remove(s[i])
      s.remove(s[i])
      c+=1
      break
print(2*c)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
s=[]
for i in range(len(S)):
  s.append(S[i])
c=0
f=True
while f:
  if s==['1']*len(s) or s==['0']*len(s) or s==[]:
    f=False
  else:
    for i in range(len(s)-1):
      if s[i:i+2]==['0','1'] or s[i:i+2]==['1','0']:
        s.remove(s[i])
        s.remove(s[i])
        c+=1
        break
print(2*c)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
s=[]
for i in range(len(S)):
  s.append(S[i])
c=0
f=True
while f:
  if s==['1']*len(s) or s==['0']*len(s):
    f=False
  else:
    for i in range(len(s)-1):
      if s[i:i+2]==['0','1'] or s[i:i+2]==['1','0']:
        s.remove(s[i])
        s.remove(s[i])
        c+=1
        break
print(2*c)

Submission status: Time Limit Exceeded

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


while True:
    t = 0
    i = 0
    while i < n - 1:
        if s[i] != s[i+1]:
            s = s[:i] + s[i+2:]
            if t == 0:
                t = 1
            n = len(s)
        else: i += 1
    if t == 0: break

print(tn - n)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = [i for i in S]
K = len(S)
i = 0
while True:    
    if i == len(L)-1 or i > K:
        break
    if L[i:i+2] == ['1','0'] or L[i:i+2] == ['0','1']:
        del L[i:i+2]
        i = 0
    else:
        i += 1
print(K-len(L))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = []
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu.append(i)
      ans += 2
      q = True
      break
  if kesu:
    p = 0
    for i in kesu:
      del slist[i-1-p:i+1-p]
      p += 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = 0
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu = i
      ans += 2
      q = True
      break
  if kesu != 0:
    del slist[kesu-1:kesu+1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
slist = [int(i)for i in s]
q = True
ans = 0
while q:
  q = False
  kesu = []
  for i in range(1,len(slist)):
    if slist[i] != slist[i-1]:
      kesu.append(i)
      ans += 2
      q = True
      break
  if kesu:
    for i in kesu:
      del slist[i-1:i+1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n_list = list(input())
n_len_o = len(n_list)
#print(n_list)
a = 0
while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(a,n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      if a != 0:
        a = i - 1
      else:
        a = 0
      flag = "ok"
      break
  if flag == "ng":
    break
#print(n_list)
print(n_len_o-len(n_list))

Submission status: Time Limit Exceeded

Solution code:
n_list = list(input())
n_len_o = len(n_list)
#print(n_list)

while(1):
  flag = "ng"
  n_len = len(n_list)
  for i in range(n_len-1):
    if n_list[i] != n_list[i+1]:
      n_list.pop(i)
      n_list.pop(i)
      flag = "ok"
      break
  if flag == "ng":
    break
#print(n_list)
print(n_len_o-len(n_list))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

cnt = 0
while True:
    if(S == []):
        break
    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'):
            S = S[:i] + S[i+2:]
            #print(S)
            cnt += 2
            break
    else:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
flag = True
while flag:
    n1 = len(s)
    s = s.replace('01', '')
    s = s.replace('10', '')
    n2 = len(s)
    if n1 > n2:
        continue
    else:
        flag = False
        break

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()

import re
#re.findall('01', s)
ans = 0
while '01' in s or '10' in s:
    ans += len(re.findall('01', s))
    s = re.sub('01', '', s)
    ans += len(re.findall('10', s))
    s = re.sub('10', '', s)

print(ans * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

ans = 0
i = 0
while i <= len(s)-2:
    if s[i] == '0' and s[i+1] == '1':
        del s[i+1]
        del s[i]
        ans += 2
        i = 0
    elif s[i] == '1' and s[i+1] == '0':
        del s[i+1]
        del s[i]
        ans += 2
        i = 0
    else:
        i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while True:
    state = False
    if len(s) == 0:
        break
    li = []
    for i in s:
        li.append(i)
    for i in range(len(li)-1):
        if li[i] == "0" and li[i+1] == "1":
            li[i] = ""
            li[i+1] = ""
            cnt+=1
            state = True
            break
        elif li[i] == "1" and li[i+1] == "0":
            li[i] = ""
            li[i+1] = ""
            cnt+=1
            state = True
            break
    if state == False:
        break
    s = ""
    for i in range(len(li)):
        s += li[i]
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while True:
    state = False
    if len(s) == 0:
        break
    li = []
    for i in s:
        li.append(i)
    for i in range(len(li)-1):
        if li[i] == "0" and li[i+1] == "1":
            li[i] = ""
            li[i+1] = ""
            cnt+=1
            state = True
        elif li[i] == "1" and li[i+1] == "0":
            li[i] = ""
            li[i+1] = ""
            cnt+=1
            state = True
    s = ""
    for i in range(len(li)):
        s += li[i]
    if state == False:
        break
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
i = 0
ans = 0
if len(S)==1:
    print(0)
    exit()
while (1):
    #print(ans, S, i)
    if (S[i]=="0" and S[i+1]=="1") or (S[i]=="1" and S[i+1]=="0"):
        del S[i:i+2]
        ans += 2
        i = 0
        if len(S)<=1:
            break
        continue
    if i>=len(S)-2:
        break
    else:
        i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
raw = len(S)
prev = len(S)
while True:
    S = re.sub(r"(10)+", "", S)
    S = re.sub(r"(01)+", "", S)
    if prev > len(S):
        prev = len(S)
    else:
        break
print(raw - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = [s for s in input()]
ans = 0
i = 1
while len(S) > 1 and i < len(S):
    if S[i] == S[i - 1]:
        i += 1
    else:
        S.pop(i)
        S.pop(i - 1)
        ans += 2
        i = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
raw = len(S)
prev = len(S)
while True:
    S = S.replace("10", "")
    S = S.replace("01", "")
    if prev > len(S):
        prev = len(S)
    else:
        break
print(raw - len(S))

Submission status: Time Limit Exceeded

Solution code:
b = list(map(int, input()))
cnt = 0
while len(b) > 1:

    if len(list(set(b))) == 1:
        break
    if b[0] != b[1]:
        b = b[2:]
        cnt += 1
        continue
    temp = b[:1]
    b = b[1:]
    b.append(*temp)
print(cnt * 2)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

b = deque(map(int, input()))
cnt = 0
while len(b) > 1:

    if len(list(set(b))) == 1:
        break
    if b[0] != b[1]:
        b.popleft()
        b.popleft()
        cnt += 1
        continue
    b.append(b.popleft())

print(cnt * 2)

Submission status: Time Limit Exceeded

Solution code:
b = list(map(int, input()))
cnt = 0
i = 0
while len(b) > 1:
    
    if len(list(set(b))) == 1:
        break
    if b[i] != b[i + 1]:
        b.pop(i)
        b.pop(i)
        cnt += 1
        i = 0
        continue
    i += 1
    
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
original = len(S)
flag = True
while flag:
    flag = False
    i = 0
    while i+1 < len(S):
        if S[i] != S[i+1]:
            flag = True
            del S[i:i+2]
        i += 1
print(original-len(S))

Submission status: Time Limit Exceeded

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

while True:
    tmp_S = S
    S = S.replace('01','').replace('10','').replace('01','').replace('10','')
    if tmp_S==S:
        break
af = len(S)
print(be-af)

Submission status: Time Limit Exceeded

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

while True:
    tmp_S = S
    for i in range(1,len(S)):
        if (S[i-1]=='0' and S[i]=='1') or (S[i-1]=='1' and S[i]=='0'):
            S[i-1], S[i] = '', ''
    S = ''.join(S)
    S = list(S)
    if tmp_S==S:
        break
af = len(S)
print(be-af)