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:
def locnt(s):
    index = 0
    lopair = 0
    s = list(s)
    while(index <= len(s)-2):
        if (s[index] != s[index+1]):
            lopair += 1
            index += 2
        else :
            index += 1
    return lopair

ans = 0
s = input()
lopair = locnt(s)
while(lopair):
    i = 0
    s = list(s)
    while(lopair):
        if s[i] != s[i+1]:
            lopair -= 1
            ans += 2
            s.pop(i)
            s.pop(i)
        else:
            i += 1
    s = "".join(s)
    lopair = locnt(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def locnt(s):
    index = 0
    lopair = 0
    while(index <= len(s)-2):
        if (s[index] != s[index+1]):
            lopair += 1
            index += 2
        else :
            index += 1
    return lopair

ans = 0
s = input()
lopair = locnt(s)
while(lopair):
    s = list(s)
    n = lopair
    i = 0
    while(n):
        if s[i] != s[i+1]:
            n -= 1
            ans += 2
            s.pop(i)
            s.pop(i)
        else:
            i += 1
    s = "".join(s)
    lopair = locnt(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def locnt(s):
    index = 0
    lopair = 0
    while(index <= len(s)-2):
        if (s[index] != s[index+1]):
            lopair += 1
            index += 2
        else :
            index += 1
    return lopair

ans = 0
s = input()
lopair = locnt(s)
while(lopair):
    s = list(s)
    n = lopair
    i = 0
    while(n):
        if s[i] != s[i+1]:
            n -= 1
            ans += 2
            s[i] = '9'
            s[i+1] = '9'
            i += 2
        else:
            i += 1
    s = "".join(s).replace('9', "")
    lopair = locnt(s)
print(ans)

Submission status: Time Limit Exceeded

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

while '01' in s or '10' in s:

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

Ls=len(s)

print(L-Ls)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

Solution code:
S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
for _ in range(int(l/2)):
    l = len(S_list)
    if l<2:
        break
    check_dif = False
    for i in range(l-1):
        if S_list[i] != S_list[i+1]:
            S_list.pop(i)
            S_list.pop(i)
            check_dif = True
            break
    if check_dif:
        ans+=2
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
while True:
    l = len(S_list)
    if l<2:
        break
    check_dif = False
    for i in range(l-1):
        if S_list[i] != S_list[i+1]:
            S_list.pop(i)
            S_list.pop(i)
            check_dif = True
            break
    if check_dif:
        ans+=2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def f(s):
    _s = s + '*'
    i = 0
    ans = 0
    while True:
        if _s[i] == '*':
            return _s[:-1], ans
        elif _s[i+1] == '*':
            i += 1
        elif _s[i] == _s[i+1]:
            i += 1
        else:
            ans += 2
            if i == 0:
                _s = _s[i+2:]
            else:
                _s = _s[:i] + _s[i+2:]


s = input()
ans = 0
while True:
    s, _ans = f(s)
    if _ans != 0:
        ans += _ans
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

while True:
  last_length = len(S)
  S = S.replace('10', '')
  S = S.replace('01', '')
  if last_length == len(S):
    break
    
print(start_length - last_length)

Submission status: Time Limit Exceeded

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

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    s = tokens[0]

    return (s,)

def solve(s):
    

    current = [int(c) for c in s]
    tmp = current
    while True:

        current = tmp
        for i in range(len(current) - 1):
            if current[i] == 1 and current[i+1] == 0:
                tmp = current[:i] + current[i+2:]
                break

            if current[i] == 0 and current[i+1] == 1:
                tmp = current[:i] + current[i+2:]
                break

        if len(current) == len(tmp):
            break

    return len(s) - len(current)

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

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

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    s = tokens[0]

    return (s,)

def solve(s):
    

    index_list = [(i, False) for i in range(len(s))]

    remained_index_list = [i for (i, removed) in index_list if not removed]

    while True:

        remained_index_list_len_before = len(remained_index_list)

        i = 0
        while i < len(remained_index_list) - 1:
#            print("i=%d" % i)
#            print("remained_index_list=%s" % remained_index_list)

            if s[remained_index_list[i]] == '0' and s[remained_index_list[i+1]] == '1':
                index_list[remained_index_list[i]] = (remained_index_list[i], True)
                index_list[remained_index_list[i+1]] = (remained_index_list[i+1], True)
                i = i + 2
            elif s[remained_index_list[i]] == '1' and s[remained_index_list[i+1]] == '0':
                index_list[remained_index_list[i]] = (remained_index_list[i], True)
                index_list[remained_index_list[i+1]] = (remained_index_list[i+1], True)
                i = i + 2
            else:
                i = i + 1

        remained_index_list = [i for (i, removed) in index_list if not removed]
        remained_index_list_len_after = len(remained_index_list)

        if remained_index_list_len_before == remained_index_list_len_after:
            break

    return len(s) - len(remained_index_list)

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
for i in range(len(s)):
    if '10' in s:
        s = s.replace('10', '', 1)
        count += 1
    elif '01' in s:
        s = s.replace('01', '', 1)
        count += 1
    else:
        pass

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
l = len(S)
mem = l
i = 0
while (1):
    M = S
    S = S.replace("01", "")
    S = S.replace("10", "")
    if (M == S):
        break

print(mem-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
l = len(S)
mem = l
i = 0
while (i < l-1):
    j = 0
    if (S[i] != S[i + 1]):
        if (i == 0):
            S = S[i + 2:]
        else:
            S = S[:i] + S[i + 2:]
        i = 0
    else:
        i += 1
    l = len(S)

print(mem-len(S))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
pattern = [['0', '1'], ['1', '0']]
count = 0
while len(s) > 1:
    found = False
    for x in pattern:
        i = 1
        while i < len(s):
            if [s[i-1], s[i]] == x:
                found = True
                s = s[:i-1]+s[i+1:] if i >= 1 else s[i+1:]
                count = count + 2
                i = 1
            else:
                i = i + 1
    if not found: break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
S_list = list(S)
N = len(S)

import sys
i = 0
count = 0
while len(S_list) > 1.5:
    try:
        #print("len(S_list) = ", len(S_list))
        if S_list[i] == S_list[i+1]:
            i +=1
            #print("Current i = ", i)
        else:
            S_list.pop(i)
            S_list.pop(i)
            #print("after pop len(S_list) = ", len(S_list))
            count+=2
            i=0
    except IndexError:
            print(count)
            sys.exit()
print(count)

Submission status: Time Limit Exceeded

Solution code:
#TLE
S = input()
flag0 = False
flag1 = False
counter = 0
while True:
    idx = S.find("01")
    if idx>=0:
        S = S[:idx] + S[idx+2:]
        counter += 2
    else:
        flag0 = True
    
    idx = S.find("10")
    if idx>=0:
        S = S[:idx] + S[idx+2:]
        counter += 2
    else:
        flag1 = True

    if flag0 and flag1 :
        break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
pattern = [['0', '1'], ['1', '0']]
count = 0
while len(s) > 1:
    founds = False
    for x in pattern:
        found = False
        for i in range(1, len(s)):
            if [s[i-1], s[i]] == x:
                found = True
                s = s[:i-1]+s[i+1:] if i >= 1 else s[i+1:]
                count = count + 2
                break
        if found:
            founds = True
            break
    if not founds: break
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(init // 2):
    a = a.replace('01', '')
    a = a.replace('10', '')
print(init - len(a))

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) or (l[idx] == 1 and l[idx+1] == 0):
        l.pop(idx)
        l.pop(idx)
        count += 2
        idx = 0
        if len(set(l)) == 1:
            break
        continue
    if idx+1 == len(l)-1:
        break
    idx += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(init):
    a = a.replace('01', '')
    a = a.replace('10', '')
print(init - len(a))

Submission status: Time Limit Exceeded

Solution code:
s=input()

stack=[]
for si in s:
    stack = stack + [si]
    if len(stack) >= 2 and stack[-1] != stack[-2]:
        del stack[-1]
        del stack[-1]
print(len(s)-len(stack))

Submission status: Time Limit Exceeded

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

n = 0
X = 0
while X<1:
	# print(L)
	K = len(L)-1
	# print(K)
	for i in range(K):
		if L[i]+L[i+1]==1:
			L.pop(i)
			L.pop(i)
			n=n+1
			break
		elif i == K-1:
			X=1

# print(L)
print(n*2)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(5000):
    a = a.replace('01', '')
    a = a.replace('10', '')
print(init - len(a))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(10000):
    a = a.replace('01', '')
    a = a.replace('10', '')
print(init - len(a))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

a = stdin.readline().rstrip()
init = len(a)
for i in range(100000):
    a = a.replace('01', '')
    a = a.replace('10', '')
print(init - len(a))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(5000)
S = input()

def recur_del(s):
  s = s.replace('01','A')
  s = s.replace('10','A')
  lst = s.split('A')
  s2 = ''.join(lst) 
  if len(s) == len(s2):
    return s2
  return recur_del(s2)

res = recur_del(S)

print(len(S) - len(res))

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
num=0
def left(S,num):
    ini=S[0]
    for i in range(len(S)):
        if i==0:
            continue
        if ini==S[i]:
            continue
        if ini!=S[i]:
            g=S[:i-1]
            h=S[i+1:]
            num+=1
            return (g+h,num)
    return ("",num)
def right(S,num):
    S=S[::-1]
    ini=S[0]
    for i in range(len(S)):
        if i==0:
            continue
        if ini==S[i]:
            continue
        if ini!=S[i]:
            g=S[:i-1]
            h=S[i+1:]
            num+=1
            return ((g+h)[::-1],num)
    return ("",num)  
for i in range(len(S)):
    S,num=left(S,num)
    if S=="":
        break
    S,num=right(S,num)
    if S=="":
        break
print(num*2)

Submission status: Time Limit Exceeded

Solution code:
cubes = input()

removed_cubes_count = 0

while True:
    removed_cubes = cubes.replace('01', '')
    removed_cubes = removed_cubes.replace('10', '')

    removed_cubes_count += len(cubes) - len(removed_cubes)

    if len(cubes) == len(removed_cubes):
        break

    cubes = removed_cubes

print(removed_cubes_count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=int(len(S))
for _ in range(N):
    A=S
    S=S.replace("01","")
    S=S.replace("10","")
    S=S.replace("01","")
    if A==S:
        break
print(N-int(len(S)))

Submission status: Time Limit Exceeded

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

a = 0
while a == 0:
    S = S.replace("0110", "")
    S = S.replace("1001", "")
    S = S.replace("01", "")
    S = S.replace("10", "")
    if "01" in S or "10" in S:
        a = 0
    else:
        a = 1

print(str(N - len(S)))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**5-10**4*2)
S = list(input())
n = len(S)
def Remove(binList,lenList):
    for i in range(0,lenList-1):
        if (binList[i] == "0" and binList[i+1] == "1") or (binList[i] == "1" and binList[i+1] == "0"):
            del binList[i:i+2]
            return Remove(binList,lenList - 2)
    return binList
if n > 10**5:
    sys.exit()
S = Remove(S,n)
print(n-len(S))

Submission status: Time Limit Exceeded

Solution code:
a=str(input())
count=0
while 1:
    before=a
    if "01" in a:
        a=a.replace("01","",1)
        count+=2
    if "10" in a:
        a=a.replace("10","",1)
        count+=2
    after=a
    if before==after:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
# s1 = input()
# len_s = len(s1)
# s2 = s1
# while True:
#     len_1 = len(s2)
#     s2 = s2.replace("01", "").replace("10", "")
#     len_2 = len(s2)
#     if len_1 == len_2:
#         break
#
# print(len_s - len(s2))

s = input()
s2 = s
# for i in range(len(s) // 2, 0, -1):
#     # print("i", i)
#     # print("s2", s2)
#     m1 = "1" * i + "0" * i
#     m2 = "0" * i + "1" * i
#     s2 = s2.replace(m1, "").replace(m2, "")

while True:
    len_1 = len(s2)

    a1 = "000111"
    a2 = "111000"
    if a1 in s2:
        s2 = s2.replace(a1, "")
    if a2 in s2:
        s2 = s2.replace(a2, "")

    a3 = "0011"
    a4 = "1100"
    if a3 in s2:
        s2 = s2.replace(a3, "")
    if a4 in s2:
        s2 = s2.replace(a4, "")

    a5 = "01"
    a6 = "10"
    if a5 in s2:
        s2 = s2.replace(a5, "")
    if a6 in s2:
        s2 = s2.replace(a6, "")

    len_2 = len(s2)
    if len_1 == len_2:
        break

print(len(s) - len_2)

Submission status: Time Limit Exceeded

Solution code:
l = raw_input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

ones = 0
zeros = 0
for num in s:
    if num == '0':
        ones += 1
    if num == '1':
        zeros += 1
max_candidate = min(ones, zeros) * 2

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        if count == max_candidate:
            print(max_candidate)
            exit()
        return
    count += 2
    max_remove = 0
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        ss.append(s1)
        num_removes = len(get_removals(s1))
        if max_remove < num_removes:
            max_remove = num_removes
    for s1 in set(ss):
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

process(s, 0)
print(max(num_removals))

Submission status: Time Limit Exceeded

Solution code:
s = input()
slen = len(s)
while(1):
  sub = s
  s = s.replace("01","")
  s = s.replace("10","")
  if sub == s:
    break
print(slen-len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
while True:
  S_ = S.replace('01','').replace('10','')
  if S_ != S:
  	S = S_
  else:
    break
print(l-len(S))

Submission status: Time Limit Exceeded

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

a = 0
while a == 0:
    S = S.replace("01", "")
    S = S.replace("10", "")
    if "01" in S or "10" in S:
        a = 0
    else:
        a = 1

print(str(N - len(S)))

Submission status: Time Limit Exceeded

Solution code:
# s1 = input()
# len_s = len(s1)
# s2 = s1
# while True:
#     len_1 = len(s2)
#     s2 = s2.replace("01", "").replace("10", "")
#     len_2 = len(s2)
#     if len_1 == len_2:
#         break
#
# print(len_s - len(s2))

s = input()
s2 = s
# for i in range(len(s) // 2, 0, -1):
#     # print("i", i)
#     # print("s2", s2)
#     m1 = "1" * i + "0" * i
#     m2 = "0" * i + "1" * i
#     s2 = s2.replace(m1, "").replace(m2, "")

while True:
    len_1 = len(s2)

    a1 = "000111"
    a2 = "111000"
    if a1 in s2:
        s2 = s2.replace(a1, "")
    if a2 in s2:
        s2 = s2.replace(a2, "")

    a5 = "01"
    a6 = "10"
    if a5 in s2:
        s2 = s2.replace(a5, "")
    if a6 in s2:
        s2 = s2.replace(a6, "")

    a3 = "0011"
    a4 = "1100"
    if a3 in s2:
        s2 = s2.replace(a3, "")
    if a4 in s2:
        s2 = s2.replace(a4, "")

    len_2 = len(s2)
    if len_1 == len_2:
        break

print(len(s) - len_2)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**5)
S = list(input())
n = len(S)
def Remove(binList,lenList):
    for i in range(0,lenList-1):
        if (binList[i] == "0" and binList[i+1] == "1") or (binList[i] == "1" and binList[i+1] == "0"):
            del binList[i:i+2]
            return Remove(binList,lenList - 2)
    return binList
if n > 10**5:
    sys.exit()
S = Remove(S,n)
print(n-len(S))

Submission status: Time Limit Exceeded

Solution code:
import re
txt = input()
cnt = 0
while True:
    if re.findall('10',txt):
        a = re.subn('10', '', txt)
        txt = a[0]
        cnt += a[1]
    else:
        if re.findall('01', txt):
            a = re.subn('01', '', txt)
            txt = a[0]
            cnt += a[1]
        else:
            break;
print(int(cnt*2))

Submission status: Time Limit Exceeded

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

if 0 not in S:
    print(0)
elif 1 not in S:
    print(0)

else:
    while True:
        if 0 not in S:
            after = len(S)
            break
        elif 1 not in S:
            after = len(S)
            break
        
        for i in range(before - 2):
            if S[i] == 1 and S[i + 1] == 0:
                S.pop(i)
                S.pop(i)
                break
            elif S[i] == 0 and S[i + 1] == 1:
                S.pop(i)
                S.pop(i)
                break
    print(before - after)

Submission status: Time Limit Exceeded

Solution code:
import sys
def check(S):
    stop = True
    if len(S) < 2:
        print(base_S_length - len(S))
        sys.exit()
    for i in range(len(S) - 1):
        if (S[i] + S[i + 1]) == 1:
            S[i] = S[i + 1] = 2
            stop = False    
    if stop:
        print(base_S_length - len(S))
        sys.exit()
    S = [i for i in S if i < 2]
    check(S)

S = list(map(int, list(input())))
base_S_length = len(S)
check(S)

Submission status: Time Limit Exceeded

Solution code:
S = input()

def operate_one(S):
  S = list(S)
  c = 0
  for i in range(len(S) - 1):
    if S[i] != S[i+1] and S[i] != "_":
      c += 2
      S[i] = "_"
      S[i+1] = "_"
  return "".join(S).replace("_",""),c

res = 0
while True:
  S_prev = S
  S,c = operate_one(S)
  res += c
  if S_prev == S:
    break
    
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
import math

def main():
    S = input()
    counter = 0
    while(True):
        tmp_counter, S = pull_cubes(S)
        counter += tmp_counter
        if tmp_counter is 0 or len(S) is 0 or len(S) is 1:
            break
    print(counter)

def pull_cubes(string):
    length = len(string)
    cube_counter = 0
    before_cube = string[0]
    for i in range(length):
        if string[i] is not before_cube:
            if i is length-1:
                string = string[0:i-1]
                cube_counter += 2
                break
            string = string[0:i-1] + string[i+1:]
            cube_counter += 2
            break
        before_cube = string[i]
    return cube_counter, string

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
i = 0
while "01" in s or "10" in s:
    if "01" in s:
        s = s.replace("01","",1)
        i+=2
    if "10" in s:
        s = s.replace("10","",1)
        i+=2
print (i)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
#table = str.maketrans({'01':'','10':''})
while True:
  S_ = S.replace('01','').replace('10','')
  if S_ != S:
  	S = S_
  else:
    break
print(l-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = 0
flg01, flg10 = True, True
while(1):
    if '01' in S:
        count = S.count('01')
        n += 2 * count
        S = S.replace('01', '')
    else:
        flg01 = False

    if '10' in S:
        count = S.count('10')
        n += 2 * count
        S = S.replace('10', '')
    else:
        flg10 = False
    
    if flg01 == False:
        if flg10 == False:
            break

print(n)

Submission status: Time Limit Exceeded

Solution code:
a = list(input().strip())
# print(a)
i = 0
ans = 0
while True:
    if len(a) < 2:
        break
    if a[i] != a[i + 1]:
        ans += 1
        a.pop(i + 1)
        a.pop(i)
    # print(len(a))
    # print(a)
    i += 1
    if i >= len(a) - 2:
        i = 0
    if len(list(set(a))) == 1 or len(a) == 0:
        break
print(ans * 2)

Submission status: Time Limit Exceeded

Solution code:
import sys
S = list(input())

if len(S) == 1:
  print(0)
  sys.exit()

cnt = 0
while True:
  o = True
  i=0
  while i < len(S)-1:
    s=S[i]
    if s != S[i+1]:
      S.pop(i)
      S.pop(i)
      o = False
      cnt += 2
      break
    i+=1
  if o:
    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
while '10' in s or '01' in s:
    if '10' in s:
        s = s.replace('10', '', 1)
    elif '01' in s:
        s = s.replace('01', '', 1)
    count += 1

print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

cubes = list(input())
cubes = list(map(int, cubes))

def removeCubes(cubeList, cnt):
    cubeArray = np.array(cubeList)
    originalList = copy.deepcopy(cubeList)
    max = 0
    resultList = []
    for i in range(0, len(cubeArray) - 1):
        if cubeArray[i] != cubeArray[i + 1]:
            cubeList.pop(i)
            cubeList.pop(i)
            resultList.append(removeCubes(cubeList, cnt + 1))
            cubeList = copy.deepcopy(originalList)
    if len(resultList) == 0:
        return cnt
    elif len(resultList) == 1:
        return resultList[0]
    else :
        maxRet = 0
        for j in range(0, len(resultList)):
            if maxRet < resultList[j]:
                maxRet = resultList[j]
        return maxRet

print(removeCubes(cubes, 0) * 2)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = list(s)
count = 0
s_leng = len(s)
while s_leng >= 2:
    k = 1
    for i in range(1, s_leng):
        i0 = s[s_leng-k]
        i1 = s[s_leng-k-1]
        if i0 != i1:
            s.pop(s_leng-k)
            s.pop(s_leng-k-1)
            count += 2
            s_leng -= 2
            k += 1
        k += 1
        if s_leng-k < 0 or s_leng-k-1 < 0:
            break
    try:
        pk = [0, 1]
        pk.pop(int(s[0]))
        ik = str(pk[0])
        if ik not in s:
            break
    except:
        pass
    
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s2 = s
while "01" in s2 or "10" in s2:
    if "01" in s2:
        s2 = s2.replace("01", "")
    elif "10" in s2:
        s2 = s2.replace("10", "")

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

Submission status: Time Limit Exceeded

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

S = input()
cnt = 0

# O(N^2)は不可。
# 010がある時、01と10を取り除くパターンを作る？

# 時間超過
s = S
while True:
    c1, c2 = 0, 0
    ls = len(s)
    for i in range(ls-1):
        if s[i] == "0" and s[i+1] == "1":
            c1 += 1
        elif s[i] == "1" and s[i+1] == "0":
            c2 += 1
    if c1 == 0 and c2 == 0:
        break
    elif c1 >= c2:
        s = s.replace("01", "")
        cnt += c1*2
    else:
        s = s.replace("10", "")
        cnt += c2*2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
cnt=0
while '10' in s or '01' in s:
    cnt+=s.count('10')
    s=s.replace('10', '') 
    cnt+=s.count('01')
    s=s.replace('01', '') 
print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
num = 0
i = 0
while "1" in s and "0" in s:
    if (s[i] == "0" and s[i + 1] == "1") or (s[i] == "1" and s[i + 1] == "0"):
        del s[i]
        del s[i]
        num += 2
        i = 0
    else:
        i += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
s=list(map(str,input()))
c=0
while "1" and "0" in s:
    for i in range(1,len(s)):
        if s[i-1] != s[i]:
            del s[i-1]
            del s[i-1]
            c+=2
            break
        else:
            pass
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
count = 0
flag = True
while flag:
    if  len(s) < 2:
        flag = False
        break
    for i in range(len(s)-1):
        if (s[i] == "0" and s[i+1] == "1") or (s[i] == "1" and s[i+1] == "0"):
            s.pop(i)
            s.pop(i)
            count += 2
            break
        elif i == len(s)-2:
            flag = False
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
s = str(input())
cnt=0
while '10' in s or '01' in s:
    cnt+=s.count('10')
    s=re.sub('10', '',s) 
    cnt+=s.count('01')
    s=re.sub('01', '',s) 

print(cnt*2)

Submission status: Time Limit Exceeded

Solution code:
S=input()
res=0
a=1
re=0
while a!=0:
  S=S.replace("10","3")
  S=S.replace("01","3")
  res+=S.count("3")*2
  S=S.replace("3","")
  a=re-res
  re=res
print(res)

Submission status: Time Limit Exceeded

Solution code:
# s1 = input()
# len_s = len(s1)
# s2 = s1
# while True:
#     len_1 = len(s2)
#     s2 = s2.replace("01", "").replace("10", "")
#     len_2 = len(s2)
#     if len_1 == len_2:
#         break
#
# print(len_s - len(s2))

s = input()
s2 = s
# for i in range(len(s) // 2, 0, -1):
#     # print("i", i)
#     # print("s2", s2)
#     m1 = "1" * i + "0" * i
#     m2 = "0" * i + "1" * i
#     s2 = s2.replace(m1, "").replace(m2, "")

while True:
    len_1 = len(s2)
    a1 = "0000011111"
    a2 = "1111100000"
    if a1 in s2:
        s2 = s2.replace(a1, "")
    if a2 in s2:
        s2 = s2.replace(a2, "")

    a3 = "000111"
    a4 = "111000"
    if a3 in s2:
        s2 = s2.replace(a3, "")
    if a4 in s2:
        s2 = s2.replace(a4, "")

    a5 = "01"
    a6 = "10"
    if a5 in s2:
        s2 = s2.replace(a5, "")
    if a6 in s2:
        s2 = s2.replace(a6, "")
    # print(s2)

    len_2 = len(s2)
    if len_1 == len_2:
        break


print(len(s) - len_2)

Submission status: Time Limit Exceeded

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

while True :
    s = s.replace("01","")
    if not("01" in s ): break

while True :
    s=s.replace("10","")
    if not ("10" in s): break

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
count = 0
Olength = len(S)
previousCount = 0

while(1) :
    S = re.sub("(01|10)", "", S)
    count = count + (Olength - len(S))
    Olength = len(S)
    
    if previousCount == count :
        break
    previousCount = count
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
while '10' in s:
    s = s.replace('10', '', 1)
    count += 1

while '01' in s:
    s = s.replace('01', '', 1)
    count += 1
print(count * 2)

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter
import collections


def r(s):
    bsl = len(s)
    flg = True
    while flg:
        flg = False
        if '01' in s:
            s = s.replace('01', '')
            flg = True
        if '10' in s:
            s = s.replace('10', '')
            flg = True

    return bsl - len(s)


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

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
s2 = s
while True:
    if "01" in s2:
        s2 = s2.replace("01", "")
    elif "10" in s2:
        s2 = s2.replace("10", "")
    elif not "01" in s2 and not "10"in s2:
        break

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

Submission status: Time Limit Exceeded

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

def kesu(s, ans):
  for ni in range(len(s)-1):
    if ni+1 >= len(s):
      return s, ans
    if s[ni] != s[ni+1]:
      del s[ni:ni+2]
      ans += 2
  return s, ans

l = len(s)
s, ans = kesu(s, 0)
while len(s) < l:
  l = len(s)
  s, ans = kesu(s, ans)

print(ans)