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

N = len(S)
l = [int(x) for x in list(str(S))]

count = 0
idx = 0
len_S = 0

while True:
    if len(l) == 1:
        break
    if l[idx] == 0 and l[idx+1] == 1:
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        if len(l) == 0:
            break
        continue
    elif l[idx] == 1 and l[idx+1] == 0:
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        if len(l) == 0:
            break
        continue
    if idx+1 == len(l)-1:
        break
    idx += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
def united(stri):
    for a in stri:
        if a != stri[0]:
            return False
    return True

while (not united(s)) and len(s) >= 2:
    k = len(s)
    if k == 2:
        if s[0] != s[1]:
            ans += 2
        break
    for i in range(0,k-2):
        if s[i] != s[i+1]:
            if i == k - 2:
                s = s[:i]
            elif i == 0:
                s = s[i+2:]
            else:
                s = s[:i] + s[i+2:]
            ans += 2
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
S=list(input().strip())

flag=True
cnt=0
i=0
f=[]
if len(S) != 1:
    while flag:
        if S[i] != S[i+1]:
            f.append(i)
            f.append(i+1)
            i+=2
        else:
            i+=1
        if i>=len(S)-1:
            cnt+=len(f)
            f.reverse()
            for k in f:
                S.pop(k)
            f=[]
            if '1' not in S or '0' not in S:
                break
            i=0
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = m = 0
c = 0
while True:
    S = S.replace("01","#")
    n += S.count("#")
    S = S.replace("#","")

    S = S.replace("10","#")
    m += S.count("#")
    S = S.replace("#","")

    if c == n + m:
        break
    else:
        c = n + m
print((n+m)*2)

Submission status: Time Limit Exceeded

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

ans = 0
status = 0
while True:
    #print (len(S))
    for i in range(len(S)):
        if i<len(S)-1 and S[i] != S[i+1]:
            S = str(S[:i]) + str(S[i+2:])
            ans += 2
            break
        if i == len(S)-1:
            status = 1
    if S == "" or status == 1:
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
rm = 0
while True:
    length = len(S)
    for i in range(length - 1):
        # print(S)
        # print(f"1){length} {i} {len(S)}")
        if (int(S[i]) + int(S[i+1])) == 1:
            rm += 2
            del(S[i:i+2])
            # print(f"2){length} {i} {len(S)} {S}")
            break
        else:
            i += 1
    # print(f"3){length} {i} {len(S)}")
    if length == len(S):
        break
    i = 0
print(rm)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = list(input())
    count = 0
    while True:
        start_count = count
        for i, val in enumerate(S):
            try:
                if S[i] != S[i+1]:
                    S.pop(i)
                    S.pop(i)
                    count += 2
            except IndexError:
                pass

        if start_count == count:
            break

    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

num = 0
while True:
    p = S.find('01')
    if p > -1:
        S = S[:p] + S[p + 2:]
        num += 2
    else:
        break
while True:
    p = S.find('10')
    if p > -1:
        S = S[:p] + S[p + 2:]
        num += 2
    else:
        print(num)
        break

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
while True :
    s=s.replace("01","").replace("10","")
    if s.find("10") == -1 and s.find("01") == -1:
        break

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
li = list(S)
ans = 0
found = 1
while found != 0:
    found = 0
    for i in range(len(li)-1):
        if li[i] != li[i+1]:
            del li[i+1]
            del li[i]
            ans += 2
            found = 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
f = s
while True:
    s = s.replace('10', '')
    s = s.replace('01', '')
    if(all(map(int, list(s)))):
        break
print(len(f)-len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()

result = 0
while re.search(r'01|10', S):
    count = len(re.findall(r'01|10', S))
    S = re.sub(r'01|10', '', S, count)
    result += 2 * count
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
S1 = S
S2 = ''
while S1 != S2:
    S2 = S1
    S1 = S1.replace('01','',-1)
    S1 = S1.replace('10','',-1)
    count += len(S2) - len(S1)
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

cnt=0

for i in range(len(s)//2):
    if '10' in s:
        cnt+=2 * s.count('10')
        s=s.replace('10', '') 
    elif '01' in s:
        cnt+=2 * s.count('01')
        s=s.replace('01', '') 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
st = input()
list_s = []
for s in st:
    list_s.append(s)

delcount = 0
while True:
    if len(list_s) < 2:
        break
    pre = list_s[0]
    count = 0
    for s in list_s:        
        if (pre == '0' and s == '1') or (pre == '1' and s == '0'):
            del list_s[count]
            del list_s[count-1]
            delcount += 1
            break
        count += 1
    if list_s.count('0') == 0 or list_s.count('1') == 0:
        break
print(delcount * 2)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def b(input_string):
    _s = input_string
    s_length = len(_s)
    s = []
    for i in range(s_length):
        s.append(_s[i])
    #print(_s)
    #print(s)
    count = 0
    flag = True
    while flag and len(s) >= 2:
        flag = False
        for i in range(s_length):
            if i < len(s)-1:
                if s[i] != s[i+1]:
                    s.pop(i)
                    #print(s)
                    s.pop(i)
                    #print(s)
                    count += 2
                    flag = True
                    break
    return count



def main():
    input_line = stdin.readline().rstrip()
    answer = b(input_line)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
cnt = 0
used = [0] * N
l , r = -1,-1
while True:
    flg = False
    for i in range(N):
        if used[i] == 0:
            if l == -1:
                l = i
            else:
                r = i
                if S[l] != S[r]:
                    used[l] = 1
                    used[r] = 1
                    l,r = -1,-1
                    flg = True
                    cnt += 1
                else:
                    l = r
    if not flg:
        break

print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline())
o = len(s)
while True:
    p1 = s.find("01")
    p2 = s.find("10")
    if p1 == -1 and p2 == -1:
        break
    elif p1 != -1 and p2 != -1:
        i = p1 if p1 < p2 else p2      
    elif p1 == -1:
        i = p2
    elif p2 == -1:
        i = p1

    s = s[:i] + s[i + 2:]
    
print(o - len(s))

Submission status: Time Limit Exceeded

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

count = 0

while True:
        l = len(s)
        su = sum(s)
        if l != 0 and su != 0 and su != l:
                for i in range(int(l)):
                        if s[i] != s[i+1]:
                                s.pop(i)
                                s.pop(i)
                                count += 2
                                break
        else:
                print(count)
                break

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter
import collections


def r(s):

    length = len(s)

    flg = True
    while flg:
        flg = False
        sl = len(s) - 1
        for i in range(sl, 0, -1):
            if not s[i] == s[i-1]:
                s = s[:i-1] + s[i+1:]
                flg = True
                break

    return length - len(s)


def main():
    input = sys.stdin.readline
    s = input().strip()

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()

result = 0
while re.search(r'01|10', S):
    S = re.sub(r'01|10', '', S, 1)
    result += 2
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()

#print('01' in S)
#print('10' in S)

count = 0

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

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

count = 0
torf = True
while torf:
    precount = count
    for i in range(len(s) - 1):
        if s[i] != s[i + 1]:
            s.pop(i)
            s.pop(i)
            count += 2
            break

    if precount == count:
        torf = False
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
while True:
    D=S.replace("10","").replace("01","")
    a=abs(len(S)-len(D))
    count+=a
    if a==0:
        print(count)
        break
    S=D

Submission status: Time Limit Exceeded

Solution code:
import re
s=input()
m=0
for i in range(len(s)//2):
  dst = re.sub(r'01|10', "", s)
  if dst == s:
    break
  m += len(s) - len(dst)
  s=dst
print(m)

Submission status: Time Limit Exceeded

Solution code:
str = list(input())
check = 0   #
ans = 0  # 取り除いた数
odd = 0

while True:
    check = 0

    if odd == 0:
        last = str[0]
        for j in range(len(str) - 1):
            if last != str[j + 1]:
                str.pop(j)
                str.pop(j)
                check = 1
                ans += 2
                break
            last = str[j + 1]
        odd = 1
    else:
        last = str[len(str)-1]
        for j in reversed(range(len(str) - 1)):
            if last != str[j]:
                str.pop(j)
                str.pop(j)
                check = 1
                ans += 2
                break
            last = str[j]
        odd = 0

    if check == 0:
        break
    if str == []:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()

l = len(a)
while True:
    a = a.replace("01", "")
    a = a.replace("10", "")
    if a.find("01") == -1 and a.find("10") == -1:
        break

print(l - len(a))

Submission status: Time Limit Exceeded

Solution code:
s = input()
origin = s
length = len(s)
past = ''
cnt=0
while s != past:
    past = s
    s = s.replace('10','').replace('01','')

num = len(origin)-len(s)
print(num)

Submission status: Time Limit Exceeded

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

S = input()
N = len(S)

while True:
  n = len(S)
  S = S.replace('110100','')
  S = S.replace('001011','')
  S = S.replace('111000','')
  S = S.replace('000111','')
  S = S.replace('1010','')
  S = S.replace('0101','')
  S = S.replace('1100','')
  S = S.replace('0011','')
  S = S.replace('10','')
  S = S.replace('01','')
  if n == len(S):
    break
print(N-len(S))

Submission status: Time Limit Exceeded

Solution code:
l=list(input())
count=0
while True:
    flag=True
    for i in range(len(l)-1):
        if l[i]!=l[i+1]:
            l.pop(i)
            l.pop(i)
            flag=False
            count+=2
            break
    if flag:
        break
print(count)

Submission status: Time Limit Exceeded

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

count = 0

while True:
        s = [int(i) for i in s]
        l = len(s)
        su = sum(s)
        if l != 0 and su != 0 and su != l:
                for i in range(int(l)):
                        if s[i] != s[i+1]:
                                s.pop(i)
                                s.pop(i)
                                count += 2
                                break
        else:
                print(count)
                break

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
N=int(len(S))
for j in range(int(len(S)/2)):
    S=S.replace("10","",1)
    S=S.replace("01","",1)
print(N-int(len(S)))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S = [int(i) for i in S]
c = 0
#print(S)
while True:
    OK = 0
    flag = 0
    break_flag = 0
    for i in range(len(S)-1):
        if S[i] != S[i+1] and S[i] != 9 and S[i+1] != 9:
            S[i] = 9
            S[i+1] = 9
            OK += 1
        else:
            flag += 1
    #print(S)
    if flag == len(S)-1:
        break_flag = 1
    if OK >= 1:
        for i in range(2*OK):
            S.remove(9)
            c += 1
    #print(S)
    #print(flag)
    if break_flag == 1 or len(S) <= 1:
        break
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()

m = 0
while True:
	a = 0
	
	a += S.count('10')
	S = S.replace('10', '')

	a += S.count('01')
	S = S.replace('01', '')

	if a!=0:
		m += a
	else:
		break

print(2*m)

Submission status: Time Limit Exceeded

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

count = 0
tmp  = 1
dst = S
while True:
    dst1 = dst.replace('01', '')
    dst2 = dst1.replace('10', '')
    if len(dst) - len(dst2) <= 0: break
    count += len(dst) - len(dst2)
    dst = dst2

print count

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = input()
s = np.asarray(list(s))
ans = 0
while True:
    delidx = []
    i = 0
    while i < len(s)-1:
        if s[i] != s[i+1]:
            delidx.append(i)
            delidx.append(i+1)
            i = i+1
            ans = ans+2
        i = i+1
    if len(delidx) == 0 or len(s) == 0:
        break
    s = np.delete(s, delidx)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main() -> None:
    S = list(input())
    m = len(S)
    pre = len(S)
    while len(S) > 0:
        for i in range(len(S) - 1):
            if len(S) > i + 1:
                if S[i] != S[i+1]:
                    S.remove(S[i])
                    S.remove(S[i])
            else:
                break

        # 抜けなかった
        if pre == len(S):
            break
        else:
            pre = len(S)

    # 最初の数から引けば抜いた数
    print(m - len(S))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_len = len(S)
while True:
    if "01"in S:
        S =S.replace("01","")
    elif "10" in S:
        S =S.replace("10","")
    else:
        break
print(S_len - len(S))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import defaultdict

#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

#A, B, K = map(int, input().split())  #
S = input()
S_list = list()
for i in range(len(S)):
    S_list.append(S[i])
#print(len(S_list))

flag = True
cnt = 0
while flag:
    flag = False
    re_list = list()
    t = True
    #print(S_list)
    for i in range(len(S_list)-1):
        #print(i+1)
        if S_list[i] != S_list[i+1] and t == True:
            re_list.append(i)
            re_list.append(i+1)
            #print(i, i+1)
            # S_list.pop(i)
            # S_list.pop(i)
            cnt += 2
            flag = True
            t = False
            #break
        else:
            t = True
        pass
    re_list.sort(reverse=True)
    for i in re_list:
        S_list.pop(i)
    pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

k = len(s)
i = 0
j = 0

for t in range(1000000000000):
    if i+1 >= k-j or len(s)==1:
        break
    elif s[i] + s[i+1] =='01' or s[i] + s[i+1] =='10':
        del s[i]
        del s[i]
        i = 0
        j = j + 2
    else:
        i = i+1


print(j)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
while True:
  temp_S = S.replace('01', '').replace('10', '')
  if temp_S == S:
    break
  S = temp_S

print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
import re


S = input()
L = len(S)

is_break = False

while len(S) > 1:
    S = re.sub('(01)+', '', S)
    S = re.sub('(10)+', '', S)
    try:
        S.find('01')
        S.find('10')
    except:
        is_break = True
    if is_break:
        break

print(L - len(S))

Submission status: Time Limit Exceeded

Solution code:
inp = input()
cnt = 0

inf = 10 ** 5
for i in range(inf):
  cnt_10 = inp.count('10')
  if cnt_10 > 0:
    cnt += cnt_10 * 2
    inp = inp.replace('10','')

  cnt_01 = inp.count('01')
  if cnt_01 > 0:
    cnt += cnt_01 * 2
    inp = inp.replace('01','')  
  
  if (cnt_01 == 0) & (cnt_10 == 0):
    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# a, b, k = map(int, input().split())
s = input()

n = len(s)


def rep(str):
    str = str.replace('01', '')
    str = str.replace('10', '')
    return str


input_str = s
ret = None

while ret is None or input_str != ret:
    ret = input_str
    input_str = rep(input_str)

print(n - len(ret))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    if len(s) == 0:
        print(0)

    fix_flag = False; fix_counts = 0
    i = 0
    while True:
        if i >= len(s) - 1:
            if not fix_flag:
                print(fix_counts)
                return
            else:
                fix_flag = False
                i = 0
                continue
        if s[i] != s[i+1]:
            fix_counts += 2
            s = s[:i] + s[i+2:]
            fix_flag = True
        i += 1

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
temp = s
temp2 = ''
while len(s) != len(temp2):
    temp2 = s
    s = re.sub('01|10', '', s)

print(len(temp) - len(s))

Submission status: Time Limit Exceeded

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

count = 0

while True:
        s = [int(i) for i in s]
        l = len(s)
        if l != 0 and sum(s) != 0 and sum(s) != l:
                for i in range(int(len(s))):
                        if s[i] != s[i+1]:
                                s.pop(i)
                                s.pop(i)
                                count += 2
                                break
        else:
                print(count)
                break

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()

result = 0
for i in range(len(S)):
    if re.search(r'01|10', S):
        result += 2
        S = re.sub(r'01|10', '', S, 1)
print(result)

Submission status: Time Limit Exceeded

Solution code:
l=list(input())
count=0
while True:
    flag=True
    for i in range(len(l)-1):
        if l[i]!=l[i+1]:
            l.pop(i)
            l.pop(i)
            flag=False
            count+=2
            break
    if flag:
        print(count)
        break

Submission status: Time Limit Exceeded

Solution code:
import re
s=input()
m=0
for i in range(len(s)):
  dst = re.sub(r'01|10', "", s)
  if dst == s:
    break
  m += len(s) - len(dst)
  s=dst
print(m)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a = list(a)
prev = '0'
i = 0
c = 0
d = True
while(d):
  if(a != []):
    if(i > 0 and a[i] != prev):
      a.pop(i-1)
      a.pop(i-1)
      c += 2
      i = 0
      continue
    prev = a[i]
    if(i == len(a) - 1):
      break
  else:
    d = False 
  i += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()

#print('01' in S)
#print('10' in S)

count = 0

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

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_len = len(S)
while True:
    if "01"in S:
        S =S.replace("01","",1)
    elif "10" in S:
        S =S.replace("10","",1)
    else:
        break
print(S_len - len(S))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
s=input()
sl=len(s)
if len(s)>1:
  while True:
    ll=len(s)
    s=s.replace('01','')
    s=s.replace('10','')
    if ll==len(s):
      break

print(sl-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
len_before = len(S)
for i in range(len_before):
  S_after = S.replace('01','').replace('10','')
  if '10' in S_after or '01' in S_after:
    S = S_after
  else:
    break
len_after = len(S_after)
print(len_before - len_after)

Submission status: Time Limit Exceeded

Solution code:
def delete(S):
    check=False
    for s in range(len(S)-1):
        if S[s]=="0" and S[s+1]=="1":
            del S[s]
            del S[s]
            check=True
            break
        if S[s]=="1" and S[s+1]=="0":
            del S[s]
            del S[s]
            check=True
            break
    return check,S
S= [i for i in input()]
ans= 0
check=True
while check == True:
    check,S = delete(S)
    if check == False:
        break
    else:
        ans+=2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
import re
n = -1
r = s
while n != 0:
    r,n = re.subn("(01|10)", "", r)
print(len(s)-len(r))

Submission status: Time Limit Exceeded

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

S = S.replace('01','').replace('10','')
len_rep_S = len(S)
tmp_len_rep_S = len_rep_S

while True:
  S = S.replace('01','').replace('10','')
  len_rep_S = len(S)
  if tmp_len_rep_S == len_rep_S:
    break
  else:
    tmp_len_rep_S = len_rep_S
    

print(len_ini_S - len_rep_S)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

def _main():
    text = input()
    count = 0

    while True:
        new_text = text.replace('01', '')
        new_text = new_text.replace('10', '')

        if text == new_text:
            break
        else:
            count += len(text) - len(new_text)
            text = new_text

    print(count)



if __name__ == '__main__':
    _main()

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
first_len = len(s)
ans = 0

while True:
    s = s.replace("01","").replace("10","")
    if not re.search('01|10',s):
        break

# print(len(s),first_len - len(s),s)
print(first_len - len(s))

Submission status: Time Limit Exceeded

Solution code:
import copy
S = list(input())
counter = 0
while(True):
    idxs = []
    flag = 0
    
    for i in range(len(S)-1):
        if flag == 1:
            flag = 0
            continue
        if S[i] != S[i+1]:
            idxs.append(i)
            idxs.append(i+1)
            flag = 1
    
    Scopy = []
    for i in range(len(S)):
        if i not in idxs:
            Scopy.append(S[i])
    S = copy.copy(Scopy)
    counter += len(idxs)
    #print(len(idxs))

    if len(idxs) == 0:
        break

print(counter)

Submission status: Time Limit Exceeded

Solution code:
s=input()
count=0
while True:
    flag=0
    f=s[0]
    for i in range(len(s)):
        if f == '-':
            f=s[i]
        elif f != s[i]:
            count += 2
            s=s[:i-1]+"--"+s[i+1:]
            flag=1
            f='-'
    s=s.replace("-","")
    if len(s)==0 or flag ==0:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
fin = sys.stdin.readline

import copy
ob = list(fin())
for i in range(len(ob)-1):
     if ob[i]=="0" and ob[i+1]=="1":
          ob[i]="1"
          ob[i+1]="0"
n = len(ob)
while True:
     ob_sub = copy.copy(ob)
     j=0
     for i in range(len(ob)-1):
          if ob[i]=="1" and ob[i+1]=="0":
               ob_sub[i],ob_sub[i+1] = "#","#"
               j+=2
     for i in range(j):
          ob_sub.remove("#")
     if ob_sub == ob:
          break
     else:
          ob = ob_sub
          
while True:
     ob_sub = copy.copy(ob)
     j=0
     for i in range(len(ob)-1):
          if ob[i]=="0" and ob[i+1]=="1":
               ob_sub[i],ob_sub[i+1] = "#","#"
               j+=2
     for i in range(j):
          ob_sub.remove("#")
     if ob_sub == ob:
          break
     else:
          ob = ob_sub

print(n-len(ob))

Submission status: Time Limit Exceeded

Solution code:
s = [i for i in str(input())]
 
count = 0

while True:
  s = [int(i) for i in s]
  
  if len(s) != 0 and sum(s) != 0 and sum(s) != len(s):
    for i in range(int(len(s))):
      if s[i] != s[i+1]:
        s.pop(i)
        s.pop(i)
        count += 2
        break
      else:
        print(count)
        break

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline())
o = len(s)
while True:
    p1 = s.find("01")
    p2 = s.find("10")
    if p1 == -1 and p2 == -1:
        break
    elif p1 == -1:
        i = p2
    elif p2 == -1:
        i = p1
    else:
        i = p1 if p1 < p2 else p2

    s = s[:i] + s[i + 2:]
    
print(o - len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

flag = True
total = len(S)

while flag:
  for i in range(len(S)-1):
    if S[i] != S[i+1]:
      del S[i]
      del S[i]
      break
  else:
    flag = False
      
print(total - len(S))

Submission status: Time Limit Exceeded

Solution code:
l = input()
l1 =l
l2 =l1
p=0
while(p!=-1):
    l1 = l1.replace("01","")
    p=l1.find("01")
p=0
while(p!=-1):
    l1=l1.replace("10","")
    p=l1.find("10")
p=0
while(p!=-1):
    l2 = l2.replace("01","")
    p=l2.find("01")
p=0
while(p!=-1):
    l2=l2.replace("10","")
    p=l2.find("10")

print(max(len(l)-len(l1),len(l)-len(l2)))

Submission status: Time Limit Exceeded

Solution code:
S = input()

def delete_cube(cube):
    new_cube = []
    cnt = 0
    i=0
    while(i < len(cube)):
        if i == len(cube)-1:
            new_cube.append(cube[i])
            i+=1
        elif (cube[i]=='0' and cube[i+1]=='1') or (cube[i]=='1' and cube[i+1]=='0'):
            cnt+=2
            i+=2
        else:
            new_cube.append(cube[i])
            i+=1
    return(new_cube, cnt)

total_cnt=0
while(True):
    S,cnt = delete_cube(S)
    if cnt==0:
        break
    total_cnt+=cnt
print(total_cnt)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
N=len(s)
n=0
while len(set(s))>1:
    if s[n]!=s[n+1]:
        del s[n+1]
        del s[n]
        n=0
    elif len(s)==2:break
    else:n+=1
print(N-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
while S.find('01') >= 0 or S.find('10') >= 0:
    S = S.replace('01', '').replace('10', '')
    S = S.replace('10', '').replace('01', '')
print(n - len(S))

Submission status: Time Limit Exceeded

Solution code:
import copy

s = input()
s_sub = copy.deepcopy(s)

tar1 = "01"
tar2 = "10"
tar3 = ["1010","1001","0101","0110"]

while((tar1 in s )or(tar2 in s)):
    for i in range(4):
        if tar3[i] in s:
            s = s.replace(tar3[i],"")
            
    if tar1 in s:
        s = s.replace(tar1,"")
    if tar2 in s:
        s = s.replace(tar2,"")



print(len(s_sub)-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
x = list(map(int, s))
i = 0
ans = 0
k = 0
if len(x) == 1:
    print(0)
else:
    while(True):
        if x[i] + x[i + 1] == 1:
            k += 1
            del x[i + 1], x[i]
        if i + 2 >= len(x):
            ans += k
            if k == 0 or len(x) <= 1:
                break
            k = 0
            i = 0
        else:
            i += 1
    print(ans * 2)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
s = input()
count = 0

for _ in range(1000000):
    if s.count("01") != 0:
        num = s.count("01")
        s = s.replace("01", "")
        count += 2*num
    elif s.count("10") != 0:
        num = s.count("10")
        s = s.replace("10", "")
        count += 2*num
    else:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(sys.stdin.readline())
count = 0
f = False
while True:
    p1 = s.find("01")
    p2 = s.find("10")
    if p1 == -1 and p2 == -1:
        break
    elif p1 == -1:
        i = p2
    elif p2 == -1:
        i = p1
    else:
        i = p1 if p1 < p2 else p2

    count += 2
    s = s[:i] + s[i + 2:]
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
line=list(map(int,list(str(input()))))
length=len(line)
while True:
  line2=[]
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
    elif line[i]!=2:
      line2.append(line[i])
  if len(line)!=0 and line[len(line)-1]!=2:
      line2.append(line[len(line)-1])
  if 2 in line:
    line=[i for i in line2]
  else:
    break
print(length-len(line))