Problem:


Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

You are given a string S of length N. The color of the i-th cube from the bottom is red if the i-th character in S is 0, and blue if that character is 1.

You can perform the following operation any number of times: choose a red cube and a blue cube that are adjacent, and remove them. Here, the cubes that were stacked on the removed cubes will fall down onto the object below them.

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

All four cubes can be removed, by performing the operation as follows:

Remove the second and third cubes from the bottom. Then, the fourth cube drops onto the first cube.

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0



Sample input:
0011


Sample output:
4

Submission status: Time Limit Exceeded

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

while i < len(S)-1:
    if S[i] != S[i+1]:
        S = S[0:i]+S[i+2:]
        count += 1
        i = 0
    else:
        i += 1
print(count*2)

Submission status: Time Limit Exceeded

Solution code:
def remove01Pair(R):
    for i in range(len(R) - 1):
        #print(i)
        if R[i:i + 2] == '01':
            R = R[:i] + R[i + 2:]
            #print(R)
            return R
    flag[0] = 1
    return R

def remove10Pair(R):
    for i in range(len(R) - 1):
        #print(i)
        if R[i:i + 2] == '10':
            R = R[:i] + R[i + 2:]
            #print(R)
            return R
    flag[0] = 1
    return R

N = input().strip()
#print(N)
length = len(N)
#print(length)
flag = []
flag.append(0)
while flag[0] == 0:
    N = remove01Pair(N)
    #print(N)
    #time.sleep(1)
flag[0] = 0
while flag[0] == 0:
    N = remove10Pair(N)
    #print(N)
    #time.sleep(1)
#print()
#print(len(N))
print(length - len(N))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
i = 0
while True:
    before = len(s)
    s = s.replace('01', '').replace('10', '')
    after = len(s)
    if before == after:
        break
print(n - len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
N = len(S)
for _ in range(N//2):
    S = re.sub("01|10","",S)
else:
  print(N-len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()

prev = []
for i in range(len(s)):
    prev.append(s[i])
while True:
    result = []
    i = 0
    while i < (len(prev)-1):
        if prev[i] != prev[i+1]:
            i += 2
        else:
            result.append(prev[i])
            i += 1
    if i == (len(prev) - 1):
        result.append(prev[-1])
    if prev == result:
        break
    prev = result
print(len(s) - len(result))

Submission status: Time Limit Exceeded

Solution code:
s = input()
l_s = []
for i in range(len(s)):
    l_s.append(s[i])

b = True
if len(l_s) == 1:
    print(0)
    exit()

while len(l_s) > 0 and b == True:
    for i in range(len(l_s) - 1):
        if l_s[i] != l_s[i+1]:
            del l_s[i:i+2]
            break
        if i == len(l_s) - 2:
            b = False

ans = len(s) - len(l_s)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

offset = 0
non = 0
count = 0
while non == 0 and len(S) >= 2:

    if S[offset] != S[offset + 1]:
        S = S.replace(S[offset],"",1).replace(S[offset+1],"",1)
        count += 2
        offset = -1
    offset += 1
    
    if offset >= len(S)-1:
        non = 1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()

i=0
cnt=0
while(True):
    if len(s)<2 or i+1>=len(s):
        break
    if s[i]!=s[i+1]:
        cnt+=1
        s=s[:i]+s[i+2:]
        i=0
    else:
        i+=1
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
while True:
    beore = len(S)
    S = S.replace('01', '').replace('10','')
    after = len(S)
    if beore == after:
        break
    else:
        ans += beore-after
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
ans=len(S)
l=[]
f=0
while f==0 and len(S)>=2:
    a=S.pop()
    b=S.pop()
    while a==b:
        if len(S)==0:
            l.append(a)
            l.append(b)
            f=1
            break
        l.append(a)
        a,b=b,S.pop()
    while len(l):
        S.append(l.pop())
print(ans-len(S))

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    S = input()[:-1]

    ans = 0
    flg = True
    while flg:
        flg = False
        i = 0
        while i+2<=len(S):
            if S[i:i+2] in ['01', '10']:
                S = S[:i] + S[i+2:]
                flg = True
                ans += 2
                continue
            i += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_list = [int(S[i]) for i in range(len(S))]
ans = 0
rm_list = []
for aaa in range(len(S) // 2):
    for i in range(len(S_list) - 1):
        if S_list[i] != S_list[i + 1] and i not in rm_list:
            rm_list.append(i)
            rm_list.append(i + 1)
    S_list = [S_list[i] for i in range(len(S_list)) if i not in rm_list]
    if len(rm_list) == 0:
        break
    ans += len(rm_list)
    rm_list = []
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_list = [int(S[i]) for i in range(len(S))]
ans = 0
rm_list = []
for aaa in range(len(S)//2):
    for i in range(len(S_list) - 1):
        if S_list[i] != S_list[i + 1] and i not in rm_list:
            rm_list.append(i)
            rm_list.append(i + 1)
    S_list = [S_list[i] for i in range(len(S_list)) if i not in rm_list]
    ans += len(rm_list)
    rm_list = []
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
v = s
n = 10**5
for i in range(n//2+1):
    s = s.replace('01','').replace('10','')
    if len(set(s)) <= 1:
        break

print(len(v) - len(s))

Submission status: Time Limit Exceeded

Solution code:
cube=list(input())
ans=0
while True:
      if cube ==[] or set(cube)=={"1"} or set(cube)=={"0"}:
          break
      else:
         for i in range(len(cube)-1):
           if cube[i-1]!=cube[i] :
             del cube[i]
             del cube[i-1]
             ans+=2
             break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
cube=[]
ans=0
cube = [int(x) for x in list(str(N))]
while True:
      if sum(cube)==len(cube) or sum(cube)==0 or cube ==[]:
          break
      else:
         for i in range(len(cube)-1):
           if cube[i-1]-cube[i]==1 or cube[i-1]-cube[i]==-1:
             del cube[i-1]
             del cube[i]
             ans+=2
             break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
cube=[]
ans=0
for i in range(len(N)):
    n=N[i:i+1]
    cube.append(int(n))
while True:
      if sum(cube)==len(cube) or sum(cube)==0 or cube ==[]:
          break
      else:
         for i in range(len(cube)-1):
           if cube[i-1]-cube[i]==1 or cube[i-1]-cube[i]==-1:
             del cube[i-1]
             del cube[i]
             ans+=2
             break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=input()
cube=[]
ans=0
for i in range(len(N)):
    n=N[i:i+1]
    cube.append(int(n))
while sum(cube)!=len(cube) and sum(cube)!=0 and cube !=[]:
      if sum(cube)==len(cube) or sum(cube)==0 or cube ==[]:
          break
      else:
         for i in range(len(cube)-1):
           if cube[i-1]-cube[i]==1 or cube[i-1]-cube[i]==-1:
             del cube[i-1]
             del cube[i]
             ans+=2
             break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
T = str(S)

now_size = len(T)

while True:

    T = T.replace('01','')
    T = T.replace('10','')

    if now_size == len(T):
        break
    else:
        now_size = len(T)

print(len(S) - len(T))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while(True):
  zero_one = s.count("01")
  one_zero = s.count("10")
  if(zero_one == 0 and one_zero == 0):
    break
  if(zero_one > one_zero):
    ans += zero_one
    s = s.replace('01',"")
  else:
    ans += one_zero
    s = s.replace('10',"")
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
S=[i for i in input()]
m=0
while True:
  f=0
  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'):
      S.pop(i+1)
      S.pop(i)
      m+=2
      f=1
      break
  if f==0:
    break
print(m)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
while True:
    m = len(s)
    s = s.replace('10','')
    count += m-len(s)
    n = len(s)
    s = s.replace('01','')
    count += n-len(s)
    if m == len(s):
        break
    n = len(s)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
T = S
flag = True
while(flag):
    flag = False
    for i in range(1, len(T)):
        if int(T[i-1]) ^ int(T[i]):
            flag = True
            T = T[:i-1]+T[i+1:]
            break
print(len(S)-len(T))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
A = S
flag = True
while(flag):
    T = ""
    flag = False
    for i in range(1, len(S)):
        if int(S[i-1]) ^ int(S[i]):
            flag = True
            T = S[:i-1]+S[i+1:]
            S = T
            break
print(len(A)-len(S))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int,list(input())))
c = 0
while s :
    t = len(s)
    for i in range(t-1):
        if (s[i] == 0 and s[i+1] == 1) or (s[i] == 1 and s[i+1] == 0):
            s.remove(s[i])
            s.remove(s[i])
            c += 2
            break
    else:
        print(c)
        exit()

print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
i=0
ans = 0
while i < (len(s)-1):
    if s[i] != s[i+1]:
        ans += 2
        s.pop(i)
        s.pop(i)
        i=-1
    i+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
flag = True
cnt=0

while flag:
    flag = False
    n = len(s)
    for i in range(n-1):
        k = s[i]+s[i+1]
        if (k=="01") or (k=="10"):
            del(s[i:i+2])
            flag = True
            cnt+=1
            break

print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
while True:
  n = len(S)
  S = S.replace("01", "")
  S = S.replace("10", "")
  if len(S) == n:
    break
#print(N, S)
r = N-len(S)
print(r)

Submission status: Time Limit Exceeded

Solution code:
# 2019-08-31 19:48:42
S = input()
f = True
count = 0
while f:
    b = len(S)
    S = S.replace("01", "")
    S = S.replace("10", "")
    if b != len(S):
        count = count + b - len(S)
    else:
        f = False
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
flag = True
while(flag):
    for i in range(len(s)-1):
        if s[i]!=s[i+1]:
            s = s[:i]+s[i+2:len(s)]
            break
    else:
        flag=False
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
for i in range(10,-1,-1):
    t='1'*2**i+'0'*2**i
    while t in s:
        s=s.replace(t,'')
for i in range(10,-1,-1):
    t='0'*2**i+'1'*2**i
    while t in s:
        s=s.replace(t,'')
print(n-len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

while s.find("01") != -1 or s.find("10") != -1:
    count += 2 * s.count("01")
    s = s.replace("01", "")
    count += 2 * s.count("10")
    s = s.replace("10", "")
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
while S.find("01") != -1 or S.find("10") != -1:
    if S.find("01") != -1:
        S = S.replace("01","",1)
    elif S.find("10") != -1:
        S = S.replace("10","",1)
    count += 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = list(input())

    ans = 0
    while True:
        cnt = 0
        for i in range(1,len(S)):
            if S[i] != S[i-1]:
                S.pop(i)
                S.pop(i-1)
                cnt += 2
                break
        if cnt == 0:
            break
        ans += cnt

    print(ans)



main()

Submission status: Time Limit Exceeded

Solution code:
def unification(n,s,count):
    if n < 1:
        return count

    for i in range(n-1):
        if s[i] !=  s[i+1]:
            s.pop(i)
            s.pop(i)
            return unification(n-2,s,count+2)

    return count

if __name__ == '__main__':
    s = raw_input()
    n = len(s)
    _s = [i for i in s]

    print unification(n,_s,0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
l = len(s)
i = 0
while True:
    if len(s)-1 <= i:
        break
    if s[i] == '0' and s[i+1] == '1' or s[i] == '1' and s[i+1] == '0':
        del s[i:i+2]
        i = 0
    else:
        i += 1

print(l-len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
cnt=0
f1=False
f2=False
while(1):
  f1=False
  f2=False
  x1=s.find('10')
  if x1==-1:
    f1=True
  x2=s.find('01')
  if x2==-1:
    f2=True
  if f1 and f2:
    break
  elif f1:
    x=x2
  elif f2:
    x=x1
  else:
    x=min(x1,x2)
  s=s[:x]+s[x+2:]
  cnt+=1
print(cnt*2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

char = S
last_len = 0
while len(char)!=last_len:
    last_len = len(char)
    char = char.replace("01","").replace("10","").replace("01","").replace("10","").replace("01","").replace("10","")
print(len(S)-len(char))

Submission status: Time Limit Exceeded

Solution code:
S = input()
def del_01(char):
    char_1 = char.replace("01","").replace("10","")
    return char_1

char = S
last_len = 0
while len(char)!=last_len:
    last_len = len(char)
    char = del_01(char)
print(len(S)-len(char))

Submission status: Time Limit Exceeded

Solution code:
s = input()
res = 0
opes = [True]
while any(opes):
	opes = []
	for x in ['01', '10']:
		r = s.split(x)
		res += len(r) - 1
		opes.append(len(r)!=1)
		s = ''.join(r)

print(res * 2)

Submission status: Time Limit Exceeded

Solution code:

S = input()
s = S

before_len = 0
while True:
    s = s.replace('0011', '').replace('1100', '').replace('0101', '').replace('1010', '').replace('01', '').replace('10', '')
    lens = len(s)
    if before_len == lens:
        break

    before_len = lens


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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ls = len(s)
while True:
    f = False
    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[0:i] + s[i+2:]
            f = True
            break
    if f == False:
        break
print(ls-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, list(input())))
ls = len(s)
while True:
    f = False
    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:i+2]
            f = True
            break
    if f == False:
        break
print(ls-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, list(input())))
ls = len(s)
while True:
    f = False
    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[i], s[i+1] = '', ''
            f = True
    while '' in s:
        s.remove('')
    if f == False:
        break
print(ls-len(s))

Submission status: Time Limit Exceeded

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

Data = list(S)
Data = list(map(int,Data))

delnum = 1

while delnum != 0:
    i = 0
    delnum = 0
    while i < N:
        while i < N and Data[i] == -1:
            i += 1
        if i >= N:
            break

        c = Data[i]
        #
        c1_pos = i
        j = i + 1
        c1_count = 1 
        while j < N and (Data[j] == c or Data[j]==-1):
            if Data[j] == c:
                c1_count += 1
            j += 1
        #
        c2_pos = j
        c2_count = 0
        k = j
        while k < N and (Data[j] == (1-c) or Data[j] == -1):
            if Data[k] == 1-c:
                c2_count += 1
            k += 1

        i = k

        delnum = min(c1_count,c2_count)
        d = 0
        ii = 0

        while d < delnum:
            if Data[c1_pos+ii] == c:
                Data[c1_pos+ii]= -1
                d += 1
            ii += 1
        d = 0
        ii = 0
        while d < delnum:
            if Data[c2_pos+ii] == 1-c:
                Data[c2_pos+ii] = -1
                d += 1
            ii += 1
        
ans = 0
for n in Data:
    if n == -1:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

c = 0
l = len(S)
for i in range(l):
  c += S.count('01')
  S = S.replace('01','')
  c += S.count('10')
  S = S.replace('10','') 

print(c*2)

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0
while True:
  f0 = S.find("01")
  f1 = S.find("10")
  if f0 >= 0:
#    print ("01", f0, S[:f0], S[f0+2:])
    S = S[:f0] + S[f0+2:]
    cnt += 2
  elif f1 >= 0:
#    print ("10", f1, S[:f1], S[f1+2:])
    S = S[:f1] + S[f1+2:]
    cnt += 2
  else:
    break
print (cnt)

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
c=len(s)

for _ in range(10000):
        s=s.replace('01','')
        s=s.replace('10','')
        d=s.count('01')
        e=s.count('10')
        if d==0 and e==0:
                break
print(c-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
c=len(s)

for _ in range(10000):
        s=s.replace('01','')
        s=s.replace('10','')
print(c-len(s))

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
c=len(s)

for _ in range(10**5):
        s=s.replace('01','')
        s=s.replace('10','')
print(c-len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()

s2 = s
for i in range(len(s)):
    s2 = s2.replace('10', '')
    s2 = s2.replace('01', '')
    if len(s) == len(s2):
        break

print(len(s) - len(s2))

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_length = len(s);
count = 0;

for i in range(int(s_length/2)):
    for j in range(int(len(s))):
        if j+1 < int(len(s)) and s[j] != s[j+1]:
            s = s[:j] + s[j+2:len(s)]
            count = count + 1

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
# 0 のとき赤色、1 のとき青色
stack=[]
for s in S:
    stack.append(s)
# print(stack)
cnt=0 #消せた数
while "1" in stack and "0" in stack:
    for i in range(len(stack)-1):
        # print(stack)
        # print(i)
        if stack[i] != stack[i+1]:
            if len(stack) >= 2:
                stack.pop(i)
                stack.pop(i)
                cnt += 2
                break
            # else:
            #     stack.pop(i)
            #     cnt += 2
            #     break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())


def f():
    global S
    cnt = 0
    pre = ''
    pre_idx = -1
    for i, s in enumerate(S):
        if not s: continue

        if pre and s != pre:
            cnt += 2
            S[i] = ''
            S[pre_idx] = ''
            pre = ''
        else:
            pre = s
            pre_idx = i
    S = [s for s in S if s]
    return cnt


res = 0
while 1:
    tmp = f()
    if not tmp: break
    res += tmp

print(res)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())


def f():
    cnt = 0
    pre = ''
    pre_idx = -1
    for i, s in enumerate(S):
        if not s: continue

        if pre and s != pre:
            cnt += 2
            S[i] = ''
            S[pre_idx] = ''
            pre = ''
        else:
            pre = s
            pre_idx = i
    return cnt


res = 0
while 1:
    tmp = f()
    if not tmp: break
    res += tmp

print(res)

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input()))
an=0
i=0

if len(s) < 2:
    print("0")
    exit()

while 1:
    if s[i]+s[i+1]==1:
        an+=2
        del s[i:i+2]
        i=0
    else:
        i+=1
    if i+1 == len(s) or len(s)==0:
        print(an)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import copy

s = input().split()[0]

def get_kouho_list(box_list):
    kouho_list = []
    for i, color in enumerate(box_list[:-1]):
        if box_list[i] != box_list[i+1]:
            kouho_list.append((i, i+1))
    return kouho_list

def tansaku(now_box_list, koremade_step):
    kouho_list = get_kouho_list(now_box_list)
    for kouho in kouho_list:
        next_box_list = copy.copy(now_box_list)
        del next_box_list[kouho[0]:kouho[1]+1]
        tansaku(next_box_list, koremade_step + 1)
    global max_step
    if koremade_step > max_step:
        max_step = koremade_step
    return

max_step = 0
tansaku(list(s), 0)
print(max_step * 2)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	s = input()
	ans=len(s)
	flag = True
	while flag:
		flag=False
		for i in range(len(s)-1):
			if(s[i]!=s[i+1]):
				s = s[:i] + s[i+2:]
				flag=True
				break
	print(ans-len(s))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
count = 0
T = ""
while S != T:
  S = S.replace("01","a").replace("10","a")
  T = S
  count += S.count("a") * 2
  S = S.replace("a","")
  
print(count)

Submission status: Time Limit Exceeded

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

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

_n = len(s)

print(n - _n)

Submission status: Time Limit Exceeded

Solution code:
# ABC 120 C

import re

S = input()

base = len(S)

l = len(S)

while True:
    tmp = l
    S = re.sub('01', '', S)
    if l != len(S):
        l = len(S)

    S = re.sub('10', '', S)
    if l != len(S):
        l = len(S)

    if tmp == l:
        break

print(base - len(S))

Submission status: Time Limit Exceeded

Solution code:
s = raw_input()
arr = [c for c in s]
done = False
while not done:
    exist01 = False
    new_arr = []
    i = 0
    while i < len(arr)-1:
        if arr[i] != arr[i+1]:
            i += 2
            exist01 = True
        else:
            new_arr.append(arr[i])
            i += 1
    if i < len(arr):
        new_arr.append(arr[i])
    arr = new_arr
    if not exist01:
        done = True
print len(s)-len(arr)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
old_length=-1
for i in range(n):
  if old_length==len(s):
    break
  old_length=len(s)
  s=s.replace('01','').replace('10','').replace('01','').replace('10','')
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
old_length=-1
for i in range(n):
  if old_length==len(s):
    break
  old_length=len(s)
  s=s.replace('0101','').replace('1010','').replace('01','').replace('10','')
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
old_length=-1
for i in range(n):
  if old_length==len(s):
    break
  old_length=len(s)
  s=s.replace('01','').replace('10','')
print(n-len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
for i in range(n):
  if '01' not in s and '10' not in s:
    break
  s=s.replace('01','')
  s=s.replace('10','')
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
for i in range(n):
  s=s.replace('01','')
  s=s.replace('10','')
print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for _ in range(500000):
    temp1 = s.count("01")
    ans += temp1
    s = s.replace("01", "")
    temp2 = s.count("10")
    ans += temp2
    s = s.replace("10", "")
    if temp1 == 0 and temp2 == 0:
        break
    
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
while 1:
    
    temp1 = s.count("01")
    ans += temp1
    s = s.replace("01", "")
    temp2 = s.count("10")
    ans += temp2
    s = s.replace("10", "")
    if temp1 == 0 and temp2 == 0:
        break
    
print(ans*2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()

start = now = len(s)
while True:
    s = s.replace('01','').replace('10','')
    if now == len(s):
        break
    now = len(s)
print(start - now)

Submission status: Time Limit Exceeded

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

import re

S = input()

s = S
ans = 0
while 1:
    s, t = re.subn("01|10", "", s)
    ans += t * 2
    if t == 0:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
pattern = re.compile('01|10')

def remove(tower, count):
  m = pattern.split(tower)
  operation = len(m) - 1
  print(count * 2) if operation == 0 else remove(''.join(m), count + operation)  

count = 0
remove(input(), count)

Submission status: Time Limit Exceeded

Solution code:
import re

pattern = re.compile(r'01|10')

def remove(tower, count):
  target = len(pattern.findall(tower))
  if target:
    remove(pattern.sub('', tower), count + target)
  else:
    print(count * 2)

count = 0
remove(input(), count)

Submission status: Time Limit Exceeded

Solution code:
import re

pattern = re.compile(r'01|10')

def remove(tower, count):
  target = len(pattern.findall(tower))
  if target:
    tower = pattern.sub('', tower)
    remove(tower, count + target)
  else:
    print(count * 2)

count = 0
remove(input(), count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

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