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 = list(map(int , input()))
n = len(s)
i = 0
while True:
    try:
        if s[i] + s[i+1] == 1:
            del s[i]
            del s[i]
            i = 0
        else:
            i += 1
    except:
        break
print(n - len(s))

Submission status: Time Limit Exceeded

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

S = input().strip()
#-----

cnt=0
while (S.count("01") != 0) or (S.count("10") != 0):
    cnt += S.count("01")
    S = S.replace("01", "")
    
    cnt += S.count("10")
    S = S.replace("10", "")
    
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(len(s)-len(tmp))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while '01' in s or '10' in s:
    # print('yes')
    if '01' in s:
        s = s.replace('01', '', 1)
        ans += 2
    if '10' in s:
        s = s.replace('10', '', 1)
        ans += 2
    # print(s, ans)

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", "")
  s = s.replace("10", "")
print(l-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input().split("01")
a=len(s)-1
t="".join(s)
while True:
  s=t.split("01")
  if len(s)==1:
    while True:
      s=t.split("10")
      if len(s)==1:
        break
      a+=len(s)-1
      t="".join(s)
    break
  a+=len(s)-1
  t="".join(s)
print(2*a)

Submission status: Time Limit Exceeded

Solution code:
s=input().split("01")
a=len(s)-1
t="".join(s)
while True:
  s=t.split("01")
  if len(s)==1:
    while True:
      s=t.split("10")
      if len(s)==1:
        break
      a+=len(s)-1
    break
  a+=len(s)-1
  t="".join(s)
print(2*a)

Submission status: Time Limit Exceeded

Solution code:
S=input()
i=0
s=S
count=0
while True:
    if (i==(len(s)-1))or(len(s)==0):
        break
    if not(s[i]==s[i+1]):
        #print(s[:i],s[i+2:])
        s="".join((s[:i],s[i+2:]))
        #print(s)
        #input()
        i=0
        count=count+1
    else:
        i=i+1
print(count*2)

Submission status: Time Limit Exceeded

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

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

print(origin - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
count = 0
i = 0
while i < len(s)-1:
    if s[i] != s[i+1]:
        del s[i]
        del s[i]
        count += 2
        i = 0
    else:
        i += 1      


print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
removed = True
while removed:
    removed = False
    for i in range(1, len(s)):
        if s[i-1] != s[i]:
            s = s[0:i-1] + s[i+1:]
            removed = True
            count += 2
            break
print(count)

Submission status: Time Limit Exceeded

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

print(2 * n)

Submission status: Time Limit Exceeded

Solution code:
s = input()
sl = len(s)
while True:
  so = s
  so=so.replace("10","")
  so=so.replace("01","")
  if len(s) == len(so):
    break
  s = so

print(sl - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
sl = len(s)
s = list(s)
while True:
  flag = False
  for i in range(len(s)-1):
    if i+1 > len(s)-1 : break
    if s[i] != s[i+1]:
      s.pop(i+1)
      s.pop(i)
      flag = True
  else:
    if not flag:
      break
print(sl - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
sl = len(s)
s = list(s)
while True:
  for i in range(len(s)-1):
    if s[i] != s[i+1]:
      s.pop(i+1)
      s.pop(i)
      break
  else:
    break
print(sl - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)
m = [True] * n

result = 0
for i in range(n):
  for j in range(n):
    if s[i] != s[j] and m[i] and m[j]:
      result += 2
      m[i] = False
      m[j] = False
print(result)

Submission status: Time Limit Exceeded

Solution code:
import re

def main():
    s = input()

    hoji = len(s)

    count = len(s) // 2
    while count > 0:
        try:
            s = re.sub('01|10',"",s)
        except:
            break
        count -= 1


    print(hoji - len(s))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
bef = len(s)
ans = 0
while(1):
    s = s.replace('10', '').replace("01", "")
    now = len(s)
    if bef == now:
        break
    else:
        ans += bef-now
        bef = now
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=[i for i in input()]
leng=len(s)
flg=True
while flg:
    flg=False
    for i in range(len(s)-1):
        if s[i]!=s[i+1]:
            s.pop(i+1)
            s.pop(i)
            flg=True
            break
print(leng - len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
cnt = 0
n = input()
while True:
    cnt += len(re.findall(r"(01|10)", n))
    n = re.sub(r"(01|10)", "", n)
    m = re.search(r"(01|10)", n)
    if m is None:
        break
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
n = input()
cnt = 0
while True:
    xn = max(n.find("01"),n.find("10"))
    if xn != -1:
        cnt += 1
        n = list(n)
        n.pop(xn)
        n.pop(xn)
        n = "".join(n)
    else:
        break
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
def calculate():
    s = input()

    count = 0
    while s.count("01") > 0 or s.count("10"):
        if s.count("01") > 0:
            s = s.replace("01","",1)
            count += 1
        if s.count("10") > 0:
            s = s.replace("10", "",1)
            count += 1

    print(count*2)



calculate()

Submission status: Time Limit Exceeded

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


def divide(x):
    a = "".join(x.split("01"))
    b = "".join(a.split("10"))
    return b


def judge(x):
    return len(x.split("01")) == 1 and len(x.split("10")) == 1


while not judge(s):
    s = divide(s)

print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
si=len(s)//2+1
ns0=len(s)
ssum=0
for i in range(si):
    nsi=len(s)
#    s=s.replace("01","")
#    s=s.replace("10","")
    s=s.replace("01","").replace("10","")
    if nsi==len(s):
        break
print(ns0-nsi)

Submission status: Time Limit Exceeded

Solution code:
s=input()
si=len(s)//2+1
ns0=len(s)
ssum=0
for i in range(si):
    nsi=len(s)
    s=s.replace("01","")
    s=s.replace("10","")
    if nsi==len(s):
        break
print(ns0-nsi)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0
while ('01' in s or '10' in s and len(s) > 0):
   if ('01' in s):
      s = s.replace('01', '', 1)
   else:
      s = s.replace('10', '', 1)
   count += 2

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    ini_len = len(S)

    ind0 = 1
    ind1 = 1
    while ind0 >= 0 or ind1 >= 0:
        ind0 = S.find('01')
        if ind0 >= 0:
            S = S.replace('01', '')
        ind1 = S.find('10')
        if ind1 >= 0:
            S = S.replace('10', '')
    print(ini_len - len(S))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ls = list(map(int,list(s)))
lt = []
for i in range(len(s)-1):
  lt.append(ls[i]+ls[i+1])

ans = 0
while 1 in lt:
  flg = 1
  n = len(ls)
  for i in range(1,n):
    if flg == 1 and lt[n-i-1] == 1:
      ls.pop(n-i)
      ls.pop(n-i-1)
      ans += 2
      flg = 0
    elif flg == 0:
      flg = 1
  lt = []
  for i in range(len(ls)-1):
  	lt.append(ls[i]+ls[i+1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ls = list(map(int,list(s)))
lt = []
for i in range(len(s)-1):
  lt.append(ls[i]+ls[i+1])

ans = 0
while 1 in lt:
  flg = 1
  lf = [1]*len(ls)
  for i in range(len(lt)):
    if flg == 1 and lt[i] == 1:
      lf[i] = 0
      lf[i+1] = 0
      ans += 2
      flg = 0
    elif flg == 0:
      flg = 1
  ls = [ls[i] for i,f in enumerate(lf) if f>0]
  lt = []
  for i in range(len(ls)-1):
  	lt.append(ls[i]+ls[i+1])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
r = 0
while True:
    z = s.count('01')
    o = s.count('10')
    if z+o == 0:
        break
    elif z > o:
        s = s.replace('01', '')
        r += z
    else:
        s = s.replace('10', '')
        r += o
print(2*r)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ln = len(s)
for _ in range(100000):
    s = s.replace('10', '').replace('01', '')
#print(s)
print(ln - len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
while S.count("01") or S.count("10"):
  if S.count("01"):
    ans += S.count("01")
    S = S.replace("01", "")
  if S.count("10"):
    ans += S.count("10")
    S = S.replace("10", "")
    
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ss = s
for i in range(len(s)):
    if "10" or "01" in s:
        s = s.replace("10", "")
        s = s.replace("01", "")
print(len(ss)-len(s))

Submission status: Time Limit Exceeded

Solution code:
s =list(input())

c = 0


while True:
    if len(s) <= 1:
        break
    
    for i in range(len(s)-1):
        if len(s) <= 1:
            break
        
        k = 0
            
        if ((s[i]+s[i+1]) == '01') or ((s[i]+s[i+1]) == '10'):
            s.pop(i)
            s.pop(i)
        
            c += 2
            k += 1
            break
        
    if k == 0:
        break
    

print(c)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()

def trans_word(text):
    replacements = {'01': '', '10': ''}
    return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text)

ans = 0
flag = True

while flag:
    s_tmp = s
    s = trans_word(s)
    ans += (len(s_tmp) - len(s))
    flag = len(s_tmp) - len(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
flag = True
while flag:
    s_tmp = s
    s = s.replace('01', '')
    s = s.replace('10', '')
    ans += (len(s_tmp) - len(s))
    flag = len(s_tmp) - len(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    lengh_S = len(S)
    while True:
        if "01" in S or "10" in S:
            S = S.replace("01", "").replace("10", "")
        else:
            break
    print(lengh_S - len(S))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

def main():
    S  = list(map(int, input()))

    del_cnt = 0
    while True:
        mark = []
        now_p = 0
        now_S = len(S)
        while now_S-1 > now_p:
            if S[now_p] == S[now_p + 1]:
                now_p += 1
            else:
                mark.extend([now_p,now_p+1])
                del_cnt += 1
                now_p += 2

        S = dellist(S, mark)
        if not mark:
            break

        mark = []

    print(del_cnt * 2)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    S  = list(map(int, input()))

    del_cnt = 0
    while True:
        now_S = len(S)
        for i in range(now_S - 1):
            if S[i] != S[i+1]:
                del S[i:i+2]
                del_cnt += 1
                break
        done_S = len(S)

        if now_S == done_S:
            break

    print(del_cnt * 2)

main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
i = 0
c = 0
for _ in range(10**8):
    if len(s)==0 or i == len(s)-1:
        break
    if s[i] != s[i+1]:
        s = s[:i]+s[i+2:]
        c += 1
        i = 0
        continue
    i += 1
print(c*2)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
n=len(s)
for i in range(len(s)//2+1):
    t=''.join(s)
    if t.count('01')>0:
        del s[t.index('01'):t.index('01')+2]
    elif t.count('10')>0:
        del s[t.index('10'):t.index('10')+2]
    else:
        break
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, input().strip()))
len_s = len(s)

p = 0
count = 0

while p < len(s) - 1:
    if s[p] != s[p + 1]:
        count += 2
        first = s[:p] if p > 0 else []
        second = s[p + 2:] if p < len(s) - 2 else []
        s = first + second
        if p > 0:
            p -= 1
        else:
            p = 0
    else:
        p += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
cnt=0

while True:
    if S.find('01')!=-1:
        S=S[0:S.find('01')]+S[S.find('01')+2:]
        cnt+=2
    elif S.find('10')!=-1:
        S = S[0:S.find('10')] + S[S.find('10') + 2:]
        cnt+=2
    else:
        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
while True:
    idx = s.find("01")
    if idx != -1:
        cnt += 2
        s = s[:idx] + s[idx+2:]
    idxx = s.find("10")
    if idxx != -1:
        cnt += 2
        s = s[:idxx] + s[idxx+2:]
    if idx == -1 and idxx == -1:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
S= list(S)
switch = 0  
for i in range(len(S)):
    S[i] = int(S[i])
S_change = S
result = 0
count = 1
while len(S_change) >= 2 and count != 0:   
    S_list = S_change
    S_change = []
    count = 0
    switch = 0
    # print(S_list)
    for i in range(len(S_list)):
        if switch == 1:
            switch = 0
        elif i == len(S_list)-1:
            S_change.append(S_list[i])
        elif S_list[i] != S_list[i+1]:
            result = result +2
            count = count + 1
            switch = 1        
        else:
            S_change.append(S_list[i])
    # print(S_change)
print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()
N=len(s)
ans=0
while True:
    if s!=s.replace("10","").replace("01",""):
        s=s.replace("10","").replace("01","")
    else:
        break;
    
    

    
print(N-len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
s = str(input())

total = len(s)

while True:
    s_new = re.sub('01|10', '', s)
    if s_new == s:
        break
    s = s_new

print(total - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
#TLEになりそうな方法
while '01' in s or '10' in s:
  s = s.replace('01','')
  s = s.replace('10','')
print(l-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
init_len = len(s)
tmp_s_len = 0
while tmp_s_len != len(s):
    tmp_s_len = len(s)
    s = s.replace("01","").replace("10","")
    continue
res = init_len - tmp_s_len
print(res)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
ans = 0
N = len(S)
while True:
  S = S.replace('10', '').replace('01', '')
  if S.count('10') == 0 and S.count('01') == 0:
    break
ans = N - len(S)
print(ans)

Submission status: Time Limit Exceeded

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


def solve(S: str):
    ans = 0
    N = len(S)
    while True:
        S = S.replace('10', '').replace('01', '')
        if S.count('10') == 0 and S.count('01') == 0:
            break
    ans = N - len(S)
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = str(input())
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    ans = 0
    if S == '0':
        print(ans)
        return
    N = len(S)
    while True:
        S = S.replace('10', '').replace('01', '')
        if S.count('10') == 0 and S.count('01') == 0:
            break
    ans = N - len(S)
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = str(input())
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    ans = 0
    if S == '0':
        print(ans)
        return
    N = len(S)
    for i in range(min(S.count('0'), S.count('1'))):
        if len(S) > 0:
            S = S.replace('10', '')
            S = S.replace('01', '')
        else:
            break
        if S.count('10') == 0 and S.count('01') == 0:
            break
    ans = N - len(S)
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = str(input())
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    ans = 0
    if S == '0':
        print(ans)
        return
    N = len(S)
    for i in range(min(S.count('0'), S.count('1'))):
        if len(S) > 0:
            S = S.replace('10', '')
            S = S.replace('01', '')
        else:
            break
    ans = N - len(S)
    print(ans)
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0

flg = True
while flg:
    flg = False
    for i in range(N-1):
        if A[i] != A[i+1]:
            ans += 2
            N -= 2
            flg = True
            for j in range(i, N):
                A[j] = A[j+2] 
            break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
while "01" in S:
    ind = S.find("01")
    S = S[:ind]+S[ind+2:]
    ans += 2
while "10" in S:
    ind = S.find("10")
    S = S[:ind]+S[ind+2:]
    ans += 2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
cnt = 0
tmp = ''
hit = True
while(hit):
	hit = False
	for i in range(1, len(s)):
		if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
			tmp = s[0:i-1] + s[i+1: ]
			cnt += 2
			hit = True
			s = tmp
			break
            
print (cnt)

Submission status: Time Limit Exceeded

Solution code:
import os, sys, re, math

S = input()

count = 0
while True:
    s = S.replace('01', '').replace('10', '')
    if s == S:
        break
    count += len(S) - len(s)
    S = s

print (count)

Submission status: Time Limit Exceeded

Solution code:
import os, sys, re, math

S = input()

count = 0
while True:
    i = S.find('01')
    if i >= 0:
        S = S[:i] + S[i+2:]
        count += 2
        continue
    i = S.find('10')
    if i >= 0:
        S = S[:i] + S[i+2:]
        count += 2
        continue
    break

print (count)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
count = 0
while len(set(s)) == 2:
    for i in range(len(s)):
        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
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    t = len(list(S))
    while True:

        temp = S
        if '01' in S:
            S = S.replace('01', '')
        if '10' in S:
            S = S.replace('10', '')
        
        if temp == S:
            break
    print(t-len(list(S)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy

S = input()

len_S = len(S)

old_len_S = copy.copy(len_S)
for i in range(len_S):
    S = S.replace("10", "")
    S = S.replace("01", "")
    if old_len_S == len(S):
        break
    else:
        old_len_S = len(S)

print(len_S - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()

len_S = len(S)

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

print(len_S - len(S))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()

    count = 0

    deleted = True
    while deleted:

        deleted = False
        p = s.replace("01", "")

        if (len(s) != len(p)):
            deleted = True

        count += len(s) - len(p)
        s = p
        p = s.replace("10", "")

        if (len(s) != len(p)):
            deleted = True

        count += len(s) - len(p)
        s = p

    print(count)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import re
def print_ans(S):
    """Test Case
    >>> print_ans("0011")
    4
    >>> print_ans("11011010001011")
    12
    >>> print_ans("0")
    0
    """
    flg = True
    ans = 0
    while flg:
        tmp = re.sub(r"01|10", "", S)
        if len(tmp) == len(S):
            flg = False
            break
        else:
            ans += len(S) - len(tmp)
            S = tmp
    print(ans)
        


if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
import re
def print_ans(S):
    """Test Case
    >>> print_ans("0011")
    4
    >>> print_ans("11011010001011")
    12
    >>> print_ans("0")
    0
    """
    flg = True
    ans = 0
    while flg:
        tmp = re.search(r"01|10", S)
        if tmp == None:
            flg = False
        else:
            S = S[:tmp.start()] + S[tmp.start() + 2:]
            ans += 2
    print(ans)
        


if __name__ == '__main__':
    S = input().rstrip()
    print_ans(S)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s=s0=input()
    while True:
        i=s.find('01')
        if i>=0:
            s=s[:i]+s[i+2:]
            continue
        i=s.find('10')
        if i>=0:
            s=s[:i]+s[i+2:]
            continue
        break
    print(len(s0)-len(s))

main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ss = s
leng = 1
while leng != 0:
	ollen = len(s)
	s = s.replace('01','')
	s = s.replace('10','')
	nwlen = len(s)
	if ollen != nwlen:
		leng = abs(ollen - nwlen)
	else:
		leng = 0

print (len(ss)-len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
ans = 0
while True:
  st1 = re.split("10|01",s)
  if len(st1)==1:
    break
  ans += len(st1)-1
  s = "".join(st1)
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while True:
  st1 = s.split("01")
  st2 = ("".join(st1)).split("10")
  if len(st1)==1 and len(st2)==1:
    break
  ans += len(st1)-1+len(st2)-1
  s = "".join(st2)
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
n = len(s)

pattern = "(01)+|(10)+"
old_n = len(s)+1
while len(s)<old_n:
  old_n=len(s)
  s = re.sub(pattern,"", s)

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()

i = -1
while True:
  i += 1
  if '01' in S:
    S = S.replace('01', '', 1)
  elif '10' in S:
    S = S.replace('10', '', 1)
  else:
    break

print(i*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
while True:
    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:]
            ans += 2

    if s.count("1") == 0 or s.count("0") == 0:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

s = S
index = 0
ans = 0
while index < len(s)-1:
    c = s[index]
    next_c = s[index+1]
    if c != next_c:
        s = s[:index] + s[index+2:]
        index = 0
        ans += 2
    else:
        index += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(l1):
    if '01' in s or '10' in s:
        s = s.replace('01', '')
        s = s.replace('10', '')
    else:
        break
        
print(l1 - len(s))

Submission status: Time Limit Exceeded

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

for i in range(l1):
    if '01' in s:
        s = s.replace('01', '')
    elif '10' in s:
        s = s.replace('10', '')
    else:
        break
        
print(l1 - len(s))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
list1 = list(input())
del list1[-1]
ans = 0
def func(flist):
    i = 0
    flag = 0
    global ans
    while len(flist)>i+1:
        if flist[i] != flist[i+1]:
            flag = 1
            del flist[i],flist[i]
            ans += 1
        else:
            i+=1
    if not flag:
        return False
    else:
        return True
if __name__ == "__main__":
    while True:
        if not func(list1):
            break
    print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
t = ''
for i in range(len(S)):
    if t == '':
        t += S[i]
    elif t[-1] != S[i]:
        t = t[:-1]
    else:
        t += S[i]
print(len(S)-len(t))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
c=0
while True:
    t=s.replace('01','').replace('10','')
    r=len(s)-len(t)
    if r==0:
        break
    else:
        c+=r
        s=t
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

while len(S) >= 2 and S != '1' * len(S) and S != '0' * len(S):
    #前から２つ組にして抜いて判定する
    new_S = ''
    for i in range(len(S)//2):
        if S[2*i:(2*i)+2] == '10' or S[2*i:(2*i)+2] == '01':
            count += 1
        else:
            new_S += S[2*i:(2*i)+2]
    #len(S)が奇数の時は最後が抜ける
    if len(S) % 2 == 1:
        new_S += S[-1]
    else:
        pass
    S = new_S

    if len(S) < 2 or S == '1' * len(S) or S == '0' * len(S):
        print(count * 2)
        break
    else:
        #頭一つずらして２つ組にして判定する
        new_S = S[0]
        for i in range((len(S)-1)//2):
            if S[2*i+1:(2*i)+3] == '10' or S[2*i+1:(2*i)+3] == '01':
                count += 1
            else:
                new_S += S[2*i+1:(2*i)+3]
        #len(S)が偶数の時は最後が抜けるから足してやる
        if len(S) % 2 == 0:
            new_S += S[-1]
        else:
            pass
        S = new_S
else:
    print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
InitL = len(S)
for i in range(len(S)):
    if S.count("01")+S.count("10")==0:
        break
    S = S.replace("01", "")
    S = S.replace("10", "")
print(InitL - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
InitL = len(S)
while S.count("01")+S.count("10")>0:
    S = S.replace("01", "")
    S = S.replace("10", "")
print(InitL - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
ans = 0
while True:
    S = S.replace("01", "R")
    S = S.replace("10", "L")
    if S.count("R") + S.count("L") > 0:
        ans +=(S.count("R") + S.count("L"))*2
        S = S.replace("R", "")
        S = S.replace("L","")
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
og_l = len(s)
diff = 1
while diff > 0:
  cur_l = len(s)
  s = s.replace("01", '').replace("10", '')
  diff = cur_l - len(s)
print(og_l - len(s))

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
c=0
l=["01", "10"]
while len(S)>1:
    before=len(S)
    for i in range(before-1):
        #if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
        if S[i]+S[i+1] in l:
            c+=2
            #S.pop(i)
            #S.pop(i)
            del S[i:i+2]
            break
    if before==len(S):
        break
print(c)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
c=0
while len(S)>1:
    before=len(S)
    # 双方向から見ればループ回数は半分になる？
    for i in range(before//2):
    #for i in range(before-1):
        if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
            c+=2
            #S.pop(i)
            #S.pop(i)
            del S[i:i+2]
            break
        if S[-i-1]+S[-i-2]=="10" or S[-i-1]+S[-i-2]=="01":
            c+=2
            if i==0:
                del S[-i-2:]
            else:
                del S[-i-2:-i]
            break
    if before==len(S):
        break
print(c)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
c=0
while len(S)>1:
    before=len(S)
    for i in range(before-1):
        if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
            c+=2
            #S.pop(i)
            #S.pop(i)
            del S[i:i+2]
            break
    if before==len(S):
        break
print(c)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
c=0
while len(S)>1:
    before=len(S)
    for i in range(len(S)-1):
        #print(S[i]+S[i+1])
        if S[i]+S[i+1]=="01" or S[i]+S[i+1]=="10":
            c+=2
            S.pop(i)
            S.pop(i)
            break
    after=len(S)
    if before==after:
        break

#print(S)
print(c)