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 math
s = list(input())
s = list(map(int, s))
s_ori = s.copy()
s_len = len(s)

s_new=[]
for _ in range(200000):
    count=0
    s_len = len(s)
    if s_len ==1:
        #print('a')
        break
    for i in range(1,s_len):
        if count %2==1:
            count +=1
            if i +1==s_len:
                s_new.append(s[-1])
            continue
        if s[i] is not s[i-1]:
            count +=1
        else:
            s_new.append(s[i-1])
            if i +1==s_len:
                s_new.append(s[-1])
    #print(s_new)
    if s==s_new:
        s = s_new
        break
    s = s_new
    s_new=[]
    
#print(s_ori)    
#print(s)
print(math.floor((len(s_ori)-len(s))/2)*2)

Submission status: Time Limit Exceeded

Solution code:
import math
s = list(input())
s = list(map(int, s))
s_ori = s.copy()
s_len = len(s)

s_new=[]
for _ in range(200000000):
    count=0
    for i in range(1,len(s)):
        if count %2==1:
            count +=1
            if i +1==len(s):
                s_new.append(s[-1])
            continue
        if s[i] is not s[i-1]:
            count +=1
        else:
            s_new.append(s[i-1])
            if i +1==len(s):
                s_new.append(s[-1])     
    if s==s_new:
        s = s_new
        break
    s = s_new
    s_new=[]

#print(s_ori)    
#print(s)
print(math.floor((len(s_ori)-len(s))/2)*2)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
num = 0
m = 1
for i in range(min(s.count('1'),s.count('0'))):
    t = num
    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'):
            num += 2
            s = s[:i]+ s[i+2:]
            break
    if t == num:
        break
print(num)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
num = 0
m = 1
while m == 1:
    t = num
    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'):
            num += 2
            s = s[:i]+ s[i+2:]
            break
    if t == num:
        break
print(num)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans1=len(s)
for i in range(10**5):
	s1=s.replace('01', '').replace('10', '')
	if s==s1:
		break
	s=s1
ans2=len(s)
print(ans1-ans2)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans1=len(s)
while True:
	s1=s.replace('01', '').replace('10', '')
	if s==s1:
		break
	s=s1
ans2=len(s)
print(ans1-ans2)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s = input()
    c = 0
    while True:
        for i in range(len(s)-1):
            if s[i] != s[i+1]:
                s = s[:i] + s[i+2:]
                c += 2
                break
        if len(set(s)) == 0 or len(set(s)) == 1:
            break
    print(c)
resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
while True:
    if '0011' in S:
        ans += 2
        i = S.index('0011')
        S = S[: i + 1] + S[i+3:]
    elif '1010' in S:
        ans += 2
        i = S.index('1010')
        S = S[: i + 1] + S[i+3:]
    elif '0101' in S:
        ans += 2
        i = S.index('0101')
        S = S[: i + 1] + S[i+3:]
    elif '1100' in S:
        ans += 2
        i = S.index('1100')
        S = S[: i + 1] + S[i+3:]
    else:
        break

while True:
    if '01' in S:
        ans += 2
        i = S.index('01')
        S = S[: i] + S[i+2:]
    elif '10' in S:
        ans += 2
        i = S.index('10')
        S = S[: i] + S[i+2:]
    else:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in list(input())]
cnt=0
l=0
while 1:
  #print(s,l)
  if len(s)<2 or l ==len(s)-1:
    break
  #print(l)
  if s[l]^s[l+1]:
    s.pop(l)
    s.pop(l)
    cnt += 2
    l=0
  else:
    l += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

while True:
    p_len_s = len(s)
    for i in range(len(s)):
        if i == 0:
            pass
        else:
            if (s[i] == '0' and s[i-1] == '1') or (s[i] == '1' and s[i-1] == '0'):
                s = s[0:i-1] + s[i+1::]
                ans += 2

                if len(s) < 2:
                    print (ans)
                    exit ()

                if s == '10' or s == '01':
                    print (ans+2)
                    exit ()

                break

    a_len_s = len(s)
    if p_len_s == a_len_s:
        print (ans)
        exit ()

Submission status: Time Limit Exceeded

Solution code:
#! python3
#  solve_120_C.py

S = input()

f_len = len(S)

for i in range(len(S)):
    S = S.replace("10","")
    S = S.replace("01","")

s_len = len(S)

print(f_len - s_len)

Submission status: Time Limit Exceeded

Solution code:
s=[*input()]
n1=[*'01']
n2=[*'10']
judge=True
max_length=len(s)
while judge:
  judge = False
  length = len(s)
  for i in range(1,length):
    if s[i-1:i+1]==n1 or s[i-1:i+1]==n2:
      del s[i]
      del s[i-1]
      i+=2
      judge = True
print(max_length-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
tmp = len(S)
frag = True
while frag == True and len(S) != 0:
    i = 0
    frag = False
    while i < len(S)-1 and frag == False :
        if S[i] != S[i+1] :
            del S[i]
            del S[i]
            frag = True
        else:
            i += 1
print(tmp - len(S))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
s = len(S)
while True:
    T = re.sub("(01|10)","",S)
    if T == S:
        break
    S = T
t = len(T)
print(s-t)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

while True:
    ans += s.count("01")*2
    s = s.replace("01", "")
    ans += s.count("10")*2
    s = s.replace("10", "")
    if not (s.count("01") or s.count("10")):
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

orilen = len(s)
ans = 0

for i in range(orilen//2):
    s = s.replace("01", "")
    s = s.replace("10", "")

print(orilen - len(s))

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#S =input().strip()
*S, = input() 
count =0
flag =1
while len(S) >=2 and flag==1:
    flag =0
    l =len(S)
    for i in range(l -1):
        if S[i:i+2] ==["1","0"] or S[i:i+2] ==["0","1"]:
            #print(S[i:i+2])
            del S[i:i+2]
            #print(S,end=" ")
            count +=2
            flag =1
            #break
    #print()
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

orilen = len(s)
ans = 0

for i in range(10**5):
    s = s.replace("01", "")
    s = s.replace("10", "")

print(orilen - len(s))

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#S =input().strip()
*S, = input() 
count =0
flag =1
while len(S) >=2 and flag==1:
    flag =0
    for i in range(len(S)-1):
        if S[i:i+2] ==["1","0"] or S[i:i+2] ==["0","1"]:
            #print(S[i:2])
            del S[i:i+2]
            #print(S,end=" ")
            count +=2
            #print(count)
            flag =1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#S =input().strip()
*S, = input() 
count =0
flag =1
while len(S) >=2 and flag==1:
    flag =0
    for i in range(len(S)-1):
        if S[i:i+2] ==["1","0"] or S[i:i+2] ==["0","1"]:
            #print(S[i:2])
            del S[i:i+2]
            #print(S,end=" ")
            count +=2
            #print(count)
            flag =1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
#input = sys.stdin.readline  #文字列では使わない
#S =input().strip()
*S, = input() 
count =0
flag =1
while len(S) >=2 and flag==1:
    flag =0
    for i in range(len(S)):
        if S[i:i+2] ==["1","0"] or S[i:i+2] ==["0","1"]:
            #print(S[i:2])
            del S[i:i+2]
            #print(S,end=" ")
            count +=2
            #print(count)
            flag =1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
t = []
p = len(s)
flg = True

while flg:
    flg = False
    i = 0
    while i < len(s):
        if i < len(s)-1:
            if s[i] != s[i+1]:
                i += 2
                flg = True
            else:
                t.append(s[i])
                i += 1
        else:
            t.append(s[i])
            i += 1
    s = list(t)
    t.clear()

print(p - len(s))

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()

from functools import *

@lru_cache(None)
def rec(i, j):
    if abs(i - j) <= 1:
        return 0

    res = 0
    if S[i] != S[j - 1] and rec(i + 1, j - 1) == j - i - 2:
        res = j - i

    for m in range(i + 1, j):
        res = max(res, rec(i, m) + rec(m, j))
    return res

print(rec(0, len(S)))

Submission status: Time Limit Exceeded

Solution code:
S=input()
X=len(S)
A=S
for i in range(10**3+1):
  A=A.replace("10","").replace("01","")
  A=A.replace("10","").replace("01","")
  A=A.replace("10","").replace("01","")
if X==1:
  print(0)
else:
  print(X-len(A))

Submission status: Time Limit Exceeded

Solution code:
S=input()
X=len(S)
A=S
for i in range(10**4+1):
  A=A.replace("10","").replace("01","")
if X==1:
  print(0)
else:
  print(X-len(A))

Submission status: Time Limit Exceeded

Solution code:
S=input()
X=len(S)
A=S
for i in range(10**5+1):
  A=A.replace("10","").replace("01","")
if X==1:
  print(0)
else:
  print(X-len(A))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    s = list(input())
    ans = 0
    while(True):
        if s == [] or len(s) == 1:
            print(ans*2)
            return
        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'):
                ans += 1
                s.pop(i)
                s.pop(i-1)
                break
            if i == len(s)-1:
                print(ans*2)
                return
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
n = len(s)
while True:
    ns = s.replace("01", "").replace("10", "")
    if ns == s:
        break
    s = ns
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
c = 0
while True:
    ns = ""
    p = ""
    f = [1] * len(s)
    for i in range(len(s)):
        if f[i] > 0:
            if i == len(s)-1:
                ns += s[i]
            elif s[i] != s[i + 1]:
                c += 2
                f[i + 1] = 0
            else:
                ns += s[i]
    if ns == s:
        break
    s = ns
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = [int(i) for i in list(input())]
ans, cnt = 0, 0

for _ in range(len(s) // 2):
    for i in range(len(s) - 1):
        try:
            if s[i] + s[i + 1] == 1:
                del s[i:i + 2]
                cnt += 2
        except IndexError:
            break
    if ans == cnt:
        break
    else:
        ans = cnt

print(ans)

Submission status: Time Limit Exceeded

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

for _ in range(len(s) // 2):
    for i in range(len(s) - 1):
        try:
            if s[i] + s[i + 1] == 1:
                del s[i:i + 2]
                ans += 2
        except IndexError:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = [int(i) for i in list(input())]
l = len(s)
ans = 0

for _ in range(l//2):
    for i in range(l-1):
        try:
            if s[i] + s[i+1] == 1:
                del s[i:i+2]
                ans += 2
        except IndexError:
                break
print(ans)

Submission status: Time Limit Exceeded

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

S = input().rstrip('\n')
N = len(S)

for i in itertools.count():
    # print(S)
    S = S.replace('01', '').replace('10', '')
    if not S:
        break
    if S.count('0') == 0 or S.count('1') == 0:
        break

print(N-len(S))

Submission status: Time Limit Exceeded

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

S = list(map(int, list(input().rstrip('\n'))))
temp = S.copy()

for k in itertools.count():
    for i in range(len(temp) - 1):
        if temp[i] != temp[i + 1]:
            temp.pop(i)
            temp.pop(i)
            break
    if temp.count(0) == len(temp) or temp.count(1) == len(temp):
        break

print(len(S)-len(temp))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
n = 0
i = 0
while i < len(S):
    # print(S)
    if len(set(S[i:i+2])) == 2:
        S = S[:i]+S[i+2:]
        n += 2
        if i != 0:
            i -= 1
    else:
        i += 1
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
ans = 0

while True:
    num0 = S.count('01')
    S = re.sub('01', '', S)
    num1 = S.count('10')
    S = re.sub('10', '', S)
    ans += 2*(num0+num1)
    if num0+num1 == 0:
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    S = str(input())
    ans = 0

    while True:
        tmp1 = S.count('01')
        ans += tmp1 * 2
        S = S.replace('01', '')

        tmp2 = S.count('10')
        ans += tmp2*2
        S = S.replace('10', '')

        if tmp1 == 0 and tmp2 == 0:
            break

    print(ans)
    return
resolve()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import sys
input=sys.stdin.readline
s=input().rstrip()
d=deque([])
for i in range(len(s)):
    d.append(int(s[i]))
d.append(2)
ans=0
while 0 in d and 1 in d:
    if d[0]+d[1]==1:
        d.popleft()
        d.popleft()
        ans+=2
    else:
        d.rotate(-1)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
num=0
while num<len(s)-1:
    if s[num]!=s[num+1]:
        s=s[:num]+s[num+2:]
        num-=1
        ans+=2
    else:
        num+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=input()
    l = len(s)
    while "01" in s or "10" in s:
        s = s.replace("01", "").replace("10", "")
    print((l-len(s)))
        
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  import sys
  i=0
  L=list(input())
  N=len(L)
  if N==1:
    print(0)
    sys.exit()
  for j in range(N):
    i=0
    S=len(L)
    if S==1 or S==0:
      break
    while True:
      if L[i]!=L[i+1]:
        L.pop(i)
        L.pop(i)
        if L==[]:
          print(N)
          sys.exit()
      i+=1
      if i>len(L)-2:
        break
    if S==len(L):
      break
  print(N-len(L))
main()

Submission status: Time Limit Exceeded

Solution code:
import sys
i=0
L=list(input())
N=len(L)
if N==1:
  print(0)
  sys.exit()
for j in range(N):
  i=0
  S=len(L)
  if S==1 or S==0:
    break
  while True:
    if L[i]!=L[i+1]:
      L.pop(i)
      L.pop(i)
      if L==[]:
        print(N)
        sys.exit()
    i+=1
    if i>len(L)-2:
      break
  if S==len(L):
    break
print(N-len(L))

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
counter = 0
ans_bf = len(S)
while True:
    len_bf = len(S)
    S = re.sub(r"01","",S)
    S = re.sub(r"10","",S)
    if len_bf == len(S):
        break
print(ans_bf - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0
ans_bf = len(S)
while True:
    len_bf = len(S)
    for i in range(0,(len_bf-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:]
            break
    if len_bf == len(S):
        break
print(ans_bf - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0
ans_bf = len(S)
while True:
    S = list(S)
    len_bf = len(S)
    for i in range(0,(len_bf-1)):
        if (S[i] == '0' and S[i+1] == '1') or(S[i] == '1' and S[i+1] == '0') :
            S[i] = ""
            S[i+1] = ""
    S = "".join(S)
    if len_bf == len(S):
        break
print(ans_bf - len(S))

Submission status: Time Limit Exceeded

Solution code:
import re
def resolve():
    inp = input()
    result = inp

    while True:
        before = len(result)
        result = re.sub(r'01|10', '', result)
        after = len(result)
        if before == after:
            break

    print(len(inp)-len(result))

resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans =0
for i in range(1,10**5):
  if S.count('0') ==0 or S.count('1') ==0:
      break
  for j in range(1,10**5):
      if S[j] != S[j-1]:
          S= S[0:j-1]+S[j+1:]
          ans +=2
          break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    inp = input()
    result = inp

    while True:
        before = len(result)
        result = result.replace('01', '')
        result = result.replace('10', '')
        after = len(result)
        if before == after:
            break

    print(len(inp)-len(result))

resolve()

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    inp = input()
    orginp = inp
    while True:
        update = 0
        for i in range(len(inp)-1):
            if inp[i] != inp[i+1]:
                if len(inp) > i+1:
                    inp = inp[:i] + inp[i+2:]
                else:
                    inp = inp[:i]
                update += 1
                break
        if update == 0:
            break
    print(len(orginp)-len(inp))

resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    inp = input()
    orginp = inp
    while True:
        update = 0
        for i in range(len(inp)-1):
            if inp[i] != inp[i+1]:
                if len(inp) > i+2:
                    inp = inp[:i] + inp[i+2:]
                else:
                    inp = inp[:i]
                update += 1
                break
        if update == 0:
            break
    print(len(orginp)-len(inp))

resolve()

Submission status: Time Limit Exceeded

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

while len(set(S)) > 1:
    S = S.replace('01', '')
    S = S.replace('10', '')

print(N - len(S))

Submission status: Time Limit Exceeded

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

a=[0 if x == '0' else 1 for x in S]

while True:
    v = 0
    p = -1
    b = []
    for i in a:
        if p >= 0:
            if p == 0 or p == 1:
                if i == 0 or i == 1:
                    if p != i:
                        p = -1
                        v += 1
                        continue
            b.append(p)
        p = i
    if p >= 0:
        b.append(p)
    if v == 0:
        print(N - len(a))
        break
    a = b

Submission status: Time Limit Exceeded

Solution code:
S=input().strip()
N=len(S)
q = [S]
while q:
    s = q.pop()
    p = ''
    v = 0
    for i,c in enumerate(s):
        if (p == '0' and c == '1') or (p == '1' and c == '0'):
            q.append(s[:i-1]+s[i+1:])
            v += 1
        p = c
    if v == 0:
        print(N-len(s))
        break

Submission status: Time Limit Exceeded

Solution code:
import collections

s = raw_input()
q = 0
n = len(s)
while(True):
	s = s.replace('01','')
	s = s.replace('10','')
	if len(s)  == n:
		break
	else:
		q += n - len(s)

print q

Submission status: Time Limit Exceeded

Solution code:
import collections
i,j = 0,0 
s = raw_input()
q = collections.deque([])
while(j < len(s)):
	while(j < len(s) and s[j] == s[i]): j+=1
	q.append(j - i - 1)
	j = i

#5 6 5 1 1 4 2 1 1 1 1 1
ns = len(s)
while(len(q) > 1):
	u,v = q.popleft(), q.popleft()
	if q: q[0] += abs(u-v)
print ns - (q[0] if q else 0)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)
prev = s[0]
ans = 0
l = s
while l:
    update = False
    l = []
    i = 1
    while i<len(s):
        if s[i-1]!=s[i]:
            l.append(i-1)
            l.append(i)
            update = True
            ans += 2
            i += 2
        else:
            i += 1
    s = "".join(s[i] for i in range(len(s)) if i not in l)
    if not update:
        break
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    ss = s
    for i in range(len(s)//2):
        f = len(ss)
        ss = ss.replace("01", "").replace("10", "")
        if f == len(ss):
            break
    print(len(s)-len(ss))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    ss = s
    for i in range(len(s)//2):
        ss = ss.replace("01", "").replace("10", "")
    print(len(s)-len(ss))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
c=0
k=1
while(k!=0):
    k=0
    b=s.replace('10','')
    c+=len(s)-len(b)
    k=len(s)-len(b)
    s=b
    b=s.replace('01','')
    c+=len(s)-len(b)
    k+=len(s)-len(b)
    s=b
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = len(s)
f = 0
while f == 0: 
  s = s.replace('01', '').replace('10', '')
  if s.count('0') == 0 or s.count('1') == 0:
    f = 1 
    break
print(k - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
flag = True
ans = 0
while flag:
    flag = False
    if len(s) <= 1:
        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':
            del s[i]
            del s[i]
            ans += 2
            flag = True
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = len(s)
f = 0
while f == 0: 
  s = s.replace('01', '')
  s = s.replace('10', '')
  if s.count('0') == 0 or s.count('1') == 0:
    f =1 
    break
print(k - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
f = 0
while f == 0:
  for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
      next
    else:
      ans += 2
      s = s[:i] + s[i + 2:]
      break
  if s.count('0') == 0 or s.count('1') == 0:
    f =1 
    break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()
x = len(s)
for i in range(len(s)//2+1):
    s = s.replace('01', '')
    s = s.replace('10', '')
print(x - len(s))

Submission status: Time Limit Exceeded

Solution code:
ans=0

def br(s):
  global ans
  ns=[]
  fl=True
  i=0
  while i <len(s):
    if s[i:i+2]==["0","1"] or s[i:i+2]==["1","0"]:
      ans+=2
      i+=1
      fl=False
    else:
      ns.append(s[i])
    i+=1

  if fl or len(ns)==0:
    return 0
  else:
    br(ns)

br(list(input()))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
#11011010001011
l = len(s)
while True:
	s2 = s.replace("10","").replace("01","")
	if s == s2:
		break
	s = s2



print(l - len(s))

Submission status: Time Limit Exceeded

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

import sys
sys.setrecursionlimit(10**9)

def a(s,n1):
    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]="a"
    s=list("".join(s).replace("a",""))
    
    if len(set(s))==1 or s==[]:
        print(n1-len(s))
    else:
        a(s,n1)
a(s,n1)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

s=list(input())
n=len(s)

count=0
flag=1
while flag!=0:
    flag=0
    for i in range(n):
        if s[i]=="#":
            continue 
        for j in range(i,n):
            if s[i]!=s[j] and s[j]!="#":
                s[i]="#"
                s[j]="#"
                flag+=1
                count+=1
                break
    if flag==0:
        print(2*count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

flg = True
i = 0
cnt = 0

while flg:
    flg = False
    while i < len(s)-1:
        if s[i]+s[i+1] == '01' or s[i]+s[i+1] == '10':
            s.pop(i)
            s.pop(i)
            flg = True
            cnt += 2
        else:
            i += 1
    i = 0

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))
ans = 0
drop = False
l = 0
while l <= len(s) - 2:
    if drop == False:
        if s[l] != s[l + 1]:
            ans += 2
            del s[l:l + 2]
            drop = True
        else:
            l += 1
    while drop == True and len(s) >= 2:
        if 0 <= l:
            l -= 1
        if s[l] != s[l + 1]:
            ans += 2
            del s[l:l + 2]
        else:
            drop = False
            l += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))
ans = 0
drop = False
for r in range(1, len(s)):
    if drop == False:
        l = r - 1
        if s[l] != -1 and s[l] != s[r]:
            ans += 2
            s[l], s[r] = -1, -1
            drop = True
    elif drop == True:
        while l >= 0 and s[l] == -1:
            l -= 1
        if l == -1 or s[l] == s[r]:
            drop = False
            continue
        if s[l] != s[r]:
            ans += 2
            s[l], s[r] = -1, -1
print(ans)

Submission status: Time Limit Exceeded

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

while True:
    if s.count('0') == 0 or s.count('1') == 0:
        break
    elif 4 <= len(s):
        s = s.replace('0011', '')
        s = s.replace('1010', '')
        s = s.replace('0101', '')
        s = s.replace('1100', '')
    else:
        s = s.replace('01', '')
        s = s.replace('10', '')

print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

S = list(map(int, list(input())))
N = len(S)

dp = [[-1] * (N + 1) for i in range(N + 1)]

def rec(l, r):
    if dp[l][r] != -1:
        return dp[l][r]
    if abs(l - r) <= 1:
        return 0

    res = 0
    if S[l] != S[r - 1] and rec(l + 1, r - 1) == r - l - 2:
        res = r - l
    for i in range(l + 1, r):
        res = max(res, rec(l, i) + rec(i, r))
    dp[l][r] = res
    return res
print(rec(0, N))

Submission status: Time Limit Exceeded

Solution code:
S = input()
if not len(S):
  print(0)
else:
  N = len(S)
  ans = 0
  while 1:
    S = S.replace('10', '')
    tmp1 = N - len(S)
    N = len(S)
    S = S.replace('01', '')
    tmp2 = N - len(S)
    N = len(S)
    if not tmp1 + tmp2:
      break
    else:
      ans += tmp1 + tmp2
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
if not len(S):
  print(0)
else:
  N = len(S)
  ans = 0
  while '10' in S or '01' in S:
    S = S.replace('10', '')
    ans += N - len(S)
    N = len(S)
    S = S.replace('01', '')
    ans += N - len(S)
    N = len(S)
  print(ans)

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:
    old = S
    S = S.replace('01', '').replace('10', '')
    if old==S:
        break
print(L-len(S))