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

ct = 0
while True:
    ct += S.count('01')
    S = S.replace('01', '')
    ct += S.count('10')
    S = S.replace('10', '')
    if not S.count('01') and not S.count('10'):
        break

print(ct*2)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N, ans, i = len(S), 0, 0
while i < N:
    if S[i+1:i+2] != '' and S[i:i+1] != S[i+1:i+2]:
        S = S[0:i] + S[i+2:N]
        ans, i, N = ans + 2, 0, N - 2
    else:
        i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
A=len(S)
for i in range(int(A/2)):
    S=S.replace("01","").replace("10","")
print(A-len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
t = True
nex = 0
while t:
    s = S
    for i in range(len(S)-1):
        if nex == 1:
            nex = 0
            continue
        if S[i:i+2] == '01' or S[i:i+2] == '10':
            s = s[:i] + '--' + s[i+2:]
            nex = 1
    #print('s',s)
    s = s.replace('-','')
    if s == S:
        print(l-len(S))
        exit()
    if len(s) == 0:
        print(l)
        exit()
    S = s

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()

match_101 = re.compile('101')
match_010 = re.compile('010')
match_1100 = re.compile('1100')
match_0011 = re.compile('0011')
match_111000 = re.compile('111000')
match_000111 = re.compile('000111')

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    prev_s = cs
    ci = i
    prev_ci = ci
    while True:
        cs = match_101.sub('1', cs)
        cs = match_010.sub('0', cs)
        cs = match_1100.sub('10', cs)
        cs = match_0011.sub('01', cs)
        cs = match_111000.sub('10', cs)
        cs = match_000111.sub('01', cs)
        cs = cs[2:] if cs.startswith('10') else cs
        cs = cs[2:] if cs.startswith('01') else cs
        cs = cs[:-2] if cs.endswith('10') else cs
        cs = cs[:-2] if cs.endswith('01') else cs
        ci += len(prev_s) - len(cs)
        if prev_ci == ci:
            return (cs, ci)
        prev_s = cs
        prev_ci = ci
S_2, i_2 = pre_remove(S, 0)
print(i_2)

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()

match_101 = re.compile('101')
match_010 = re.compile('010')
match_1100 = re.compile('1100')
match_0011 = re.compile('0011')

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    prev_s = cs
    ci = i
    prev_ci = ci
    while True:
        cs = match_101.sub('1', cs)
        cs = match_010.sub('0', cs)
        cs = match_1100.sub('10', cs)
        cs = match_0011.sub('01', cs)
        cs = cs[2:] if cs.startswith('10') else cs
        cs = cs[2:] if cs.startswith('01') else cs
        cs = cs[:-2] if cs.endswith('10') else cs
        cs = cs[:-2] if cs.endswith('01') else cs
        ci += len(prev_s) - len(cs)
        if prev_ci == ci:
            return (cs, ci)
        prev_s = cs
        prev_ci = ci

#def search_removable_point(s):
#    if s.find('0') >= 0 and s.find('1') >= 0:
#        return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]
#    else:
#        return []

# def remove_target_point(s, i):
#     return s[:i] + s[i+2:]

#def max_removed_point(s, i):
#    removable_points = search_removable_point(s)
#    if removable_points:
#        return max([
#            max_removed_point(remove_target_point(s, point), i + 2)
#            for point in removable_points
#        ])
#    else:
#        return i

S_2, i_2 = pre_remove(S, 0)
print(i_2)

Submission status: Time Limit Exceeded

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

match_101 = re.compile('101')
match_010 = re.compile('010')
match_1100 = re.compile('1100')
match_0011 = re.compile('0011')

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    prev_s = cs
    ci = i
    prev_ci = ci
    while True:
        cs = match_101.sub('1', cs)
        cs = match_010.sub('0', cs)
        cs = match_1100.sub('10', cs)
        cs = match_0011.sub('01', cs)
        cs = cs[2:] if cs.startswith('10') else cs
        cs = cs[2:] if cs.startswith('01') else cs
        cs = cs[:-2] if cs.endswith('10') else cs
        cs = cs[:-2] if cs.endswith('01') else cs
        ci += len(prev_s) - len(cs)
        if prev_ci == ci:
            return (cs, ci)
        prev_s = cs
        prev_ci = ci

def search_removable_point(s):
    if s.find('0') >= 0 and s.find('1') >= 0:
        return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]
    else:
        return []

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))

Submission status: Time Limit Exceeded

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

match_101 = re.compile('101')
match_010 = re.compile('010')
match_1100 = re.compile('1100')
match_0011 = re.compile('0011')

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    prev_s = cs
    ci = i
    prev_ci = ci
    while True:
        cs = match_101.sub('1', cs)
        cs = match_010.sub('0', cs)
        cs = match_1100.sub('10', cs)
        cs = match_0011.sub('01', cs)
        ci += len(prev_s) - len(cs)
        if prev_ci == ci:
            return (cs, ci)
        prev_s = cs
        prev_ci = ci

def search_removable_point(s):
    if s.find('0') >= 0 and s.find('1') >= 0:
        return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]
    else:
        return []

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))

Submission status: Time Limit Exceeded

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

match_101 = re.compile('101')
match_010 = re.compile('010')
match_1100 = re.compile('1100')
match_0011 = re.compile('0011')

def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    prev_s = cs
    ci = i
    prev_ci = ci
    while True:
        cs = match_101.sub('1', cs)
        cs = match_010.sub('0', cs)
        cs = match_1100.sub('10', cs)
        cs = match_0011.sub('01', cs)
        ci += len(prev_s) - len(cs)
        if prev_ci == ci:
            return (cs, ci)
        prev_s = cs
        prev_ci = ci

def search_removable_point(s):
    return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))

Submission status: Time Limit Exceeded

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


def pre_remove(s, i):
    '''
    101 -> 1
    010 -> 0
    この並びの場合は順番にかかわらず削除しても良い
    0011 -> 01
    1100 -> 10
    この並びの時は順番にかかわらず短縮しても良い
    '''
    cs = s
    ci = i
    while True:
        find_101 = cs.find('101')
        find_010 = cs.find('010')
        find_1100 = cs.find('1100')
        find_0011 = cs.find('0011')
        if find_101 > 0:
            cs = remove_target_point(cs, find_101)
            ci += 2
        elif find_010 > 0:
            cs = remove_target_point(cs, find_010)
            ci += 2
        elif find_1100 > 0:
            cs = remove_target_point(cs, find_1100 + 1)
            ci += 2
        elif find_0011 > 0:
            cs = remove_target_point(cs, find_0011 + 1)
            ci += 2
        else:
            return (cs, ci)

def search_removable_point(s):
    return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 2)
            for point in removable_points
        ])
    else:
        return i

S_2, i_2 = pre_remove(S, 0)
print(max_removed_point(S_2, i_2))

Submission status: Time Limit Exceeded

Solution code:
S = input()

def search_removable_point(s):
    return [i for i, (i1, i2) in enumerate(zip(s[:-1], s[1:])) if i1 != i2]

def remove_target_point(s, i):
    return s[:i] + s[i+2:]

def max_removed_point(s, i):
    removable_points = search_removable_point(s)
    if removable_points:
        return max([
            max_removed_point(remove_target_point(s, point), i + 1)
            for point in removable_points
        ])
    else:
        return i

print(max_removed_point(S, 0) * 2)

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()
count = 0
flag = True
while(flag):
    if '01' in S:
        S = S.replace('01','',1)
        count += 2
        continue
    elif '10' in S:
        S = S.replace('10','',1)
        count += 2
        continue                                                                                                    
    flag = False
print count

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()
count = 0
flag = True
while(flag):
    if '01' in S:
        S = S.replace('01','',1)
        count += 2                                                                                                  
    elif '10' in S:
        S = S.replace('10','',1)
        count += 2
    else:
        flag = False
print count

Submission status: Time Limit Exceeded

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

counter = 0
i = 0
while(True):
    if not '0' in S or not '1' in S or S == '':
        break
    if S[i:i+2] == '01' or S[i:i+2] == '10':
        S_list = list(S)
        S_list.pop(i)
        S_list.pop(i)
        S_str = ''
        for j in S_list:
            S_str += j
        S = S_str
        counter += 2
        i -= 1
    else:
        i += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys
import re


def my_sub(m):
    len1 = len(m.group(1))
    len2 = len(m.group(2))
    if len1 > len2:
        return m.group(1)[0] * (len1 - len2)
    return m.group(2)[0] * (len2 - len1)


def solve(S):
    orig_len = len(S)
    while True:
        t = re.sub(r'(0+)(1+)', my_sub, S)
        t = re.sub(r'(1+)(0+)', my_sub, t)
        if t == S:
            break
        S = t
    return orig_len - len(S)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys
import re


def my_sub(m):
    len1 = len(m.group(1))
    len2 = len(m.group(2))
    if len1 > len2:
        return m.group(1) * (len1 - len2)
    return m.group(2) * (len2 - len1)


def solve(S):
    orig_len = len(S)
    while True:
        t = re.sub(r'01', '', S)
        t = re.sub(r'10', '', t)
        if t == S:
            break
        S = t
    return orig_len - len(S)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
def remove(s):
    r = None
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            r = s[0:i] + s[i+2:]
            break
    return r


def calc(s):
    count = 0
    c = s
    while True:
        t = remove(c)
        if t == None:
            break
        count += 2
        c = t
    return count


s = input()
print(calc(s))

Submission status: Time Limit Exceeded

Solution code:
S=list(input())

c=0
cc=3
tmp=[]
while c!=cc:
    cc=c
    for i in range(len(S)-1):
        if S[i]!=S[i+1] and S[i]!='2':
            S[i]='2'
            S[i+1]='2'
            c+=2

    while S:
        e=S.pop()
        if e!='2':
            tmp.append(e)
    while tmp:
        S.append(tmp.pop())

print(c)

Submission status: Time Limit Exceeded

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

for i in range(int(len(S)/2)):
  zero_i = S.find("01")
  one_i = S.find("10")
  if zero_i > -1:
    S = S[:zero_i] + S[zero_i+2:]
  elif one_i > -1:
    S = S[:one_i] + S[one_i+2:]
  else:
    break

print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:


#c=list(map(int, input().split()))
#str = "11011010001011"


S = input()
c=list(S)

rm_list = []
i = 0
num = len(c)
while(True):
    try:
        while(True):
            
            #print("-------------")
            #print(i)
            #print(c)
            #print("c[{}]:{}".format(i,c[i]))
            #print("c[{}]:{}".format(i+1,c[i+1]))
            if c[i] != c[i+1]:
                #print("けしたよ")
                c.pop(i+1)
                c.pop(i)
                
                i = 0
                break
            i +=1
    except:
        break
#print("================================")
#print(c)
print(num - len(c))

Submission status: Time Limit Exceeded

Solution code:
S=input()


S=[s for s in S]

count=0
i=0
while(i<len(S)-1):
#	print(i,S)
	if(int(S[i])+int(S[i+1])==1):
		count+=2
		if(i<=len(S)-3):
			S=S[:i]+S[i+2:]
		elif(i==len(S)-2):
			break
				
		if(i>0):
			i-=1
	else:
		i+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = S

while s.count('01') or s.count('10'):
    s = ''.join(s.split('01')) if s.count(
        '01') > s.count('10') else ''.join(s.split('10'))


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

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = S

while s.count('01') or s.count('10'):
    s = ''.join(s.split('01')) if s.count('01') > s.count('10') else ''.join(s.split('10'))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
s = list(map(int, input()))
cnt = 0
while len(set(s)) > 1:
    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):
            cnt += 2
            del s[i:i+2]
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8
s = list(map(int, input()))
cnt = 0
while len(set(s)) > 1:
    for i in range(len(s)-1):
        if s[i] == 1 and s[i+1] == 0:
            cnt += 2
            del s[i:i+2]
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
s = sys.stdin.read().strip()
n = len(s)

while len(re.findall("10|01", s)) > 0:
    s = re.sub("10|01", "", s)
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
n = len(s)
while len(re.findall("10|01", s)) > 0:
    s = re.sub("10|01", "", s)
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()








count = 0
while True:
    index = s.find("01")
    if index == -1:
        index = s.find("10")
    if index == -1:
        break
    else:
        # s = s.replace(s[index: index + 2], "")
        s = s[:index] + s[index + 2:]
        count += 2


print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import re

S = stdin.readline().rstrip()

before_S = S

while(True):
    #after_S = S.replace("01", "").replace("10", "")
    after_S = re.sub("(01)+|(10)+", "", S)
    if len(after_S) != len(S):
        S = after_S
    else:
        break

print(len(before_S) - len(S))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

S = stdin.readline().rstrip()

beforeS = S

while(True):
    after_S = S.replace("01", "").replace("10", "")
    if len(after_S) != len(S):
        S = after_S
    else:
        break

print(len(beforeS) - len(S))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

S = stdin.readline().rstrip()

count = 0
prev_S = ""
while(True):
    if S == prev_S or S == "":
        break
    prev_S = S
    S = S.replace("01", "").replace("10", "")
    count += len(prev_S) - len(S)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

DEBUG = 0

def to_s(lis):
    return "".join(map(str, lis))

def erase(lis, cnt):
    if DEBUG==1:   
        print("try")
    
    i = 0
    this_cnt = 0
    while(i < len(lis)-1):
        #if DEBUG==1:
            #print ("in while loop")
            
        if lis[i] != lis[i+1]:
            del lis[i]
            del lis[i]
            this_cnt += 1
            cnt += 1
            if DEBUG==1:
                print(cnt, to_s(lis))
        else:
            i+=1
            
    if DEBUG==1:
        print("cnt so far: ", cnt, "this_cnt: ", this_cnt)

    if this_cnt > 0:
        erase(lis, cnt)

    return lis

        
def main():
    string = input()
    lis = [int(v) for v in string]

    if DEBUG==1:
        print("start: ")
        print(to_s(lis))

    
    erase(lis, 0)
    #print(cnt, to_s(lis))
    ans = len(string)-len(lis)
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

DEBUG = 0

def to_s(lis):
    return "".join(map(str, lis))

def erase(lis, cnt):
    if DEBUG==1:   
        print("try")
    
    i = 0
    this_cnt = 0
    while(i < len(lis)-1):
        #if DEBUG==1:
            #print ("in while loop")
            
        if lis[i] != lis[i+1]:
            del lis[i]
            del lis[i]
            this_cnt += 1
            cnt += 1
            if DEBUG==1:
                print(cnt, to_s(lis))
        else:
            i+=1
            
    if DEBUG==1:
        print("cnt so far: ", cnt, "this_cnt: ", this_cnt)

    if this_cnt > 0:
        erase(lis, cnt)
    else:
        return cnt 

        
def main():
    string = input()
    lis = [int(v) for v in string]

    if DEBUG==1:
        print("start: ")
        print(to_s(lis))

    
    erase(lis, 0)
    #print(cnt, to_s(lis))
    ans = len(string)-len(lis)
    print(ans)
main()

Submission status: Time Limit Exceeded

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

while True:
    cur_len = len(S)
    S = S.replace("01", "")
    S = S.replace("10", "")
    if len(S) == cur_len:
        print(init_len - cur_len)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()

cnt = 0
while True:
  s = re.sub('01|10', '', S, 1)
  if s != S:
    S = s
    cnt += 2
  else:
    print(cnt)
    exit()

Submission status: Time Limit Exceeded

Solution code:
S = input()
len_org = len(S)
while True:
    len_before = len(S)
    S = S.replace("10","").replace("01","")
    len_after = len(S)
    if len_before == len_after:
        break

print(len_org - len_after)

Submission status: Time Limit Exceeded

Solution code:
S = input()
len_org = len(S)
while True:
    len_before = len(S)
    S = S.replace("10","").replace("01","").replace("11110000","").replace("00001111","")
    len_after = len(S)
    if len_before == len_after:
        break

print(len_org - len_after)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count = 0
while S.find('01')!=-1:
    S_list=list(S)
    i_pop = S.find('01')
    S_list.pop(i_pop)
    S_list.pop(i_pop)
    S = ''.join(S_list)
    count +=2
while S.find('10')!=-1:
    S_list=list(S)
    i_pop = S.find('10')
    S_list.pop(i_pop)
    S_list.pop(i_pop)
    S = ''.join(S_list)
    count +=2
print(count)

Submission status: Time Limit Exceeded

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


def solve(S: str):
    n = len(S)
    while True:
        l = len(S)
        for i in range(len(S) - 1):
            if S[i] != S[i + 1]:
                S = S[:i] + S[i + 2:]
                break
        if l == len(S):
            break
    print(n - len(S))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
sin = input()
arr = []
for s in sin:
    if len(arr)>0 and arr[-1] != s:
        arr = arr[:-1]
    else:
        arr.append(s)
print(len(sin)-len(arr))

Submission status: Time Limit Exceeded

Solution code:
x = input()
l = len(x)
for _ in range(l):
    x = x.replace('01', '')
    x = x.replace('10', '')
print(l - len(x))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8-*-

s = input()
n = len(s)
flag = True
while flag:
    flag = "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 = input()
#s = '11011010001011'
count = 0
while True:
	if s.count('01') > 0:
		s.replace("01","")
		count += 1
	if s.count('10') > 0:
		s.replace("10","")
		count += 1
	if s.count('01') == 0 and s.count('10') == 0:
		break
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
s = input()
n = 0
while True:
  if s.find('01') != -1:
    s = s.replace('01', '', 1)
    n += 1
  elif s.find('10') != -1:
    s = s.replace('10', '', 1)
    n += 1
  else : break
print(n*2)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
s = input()
n = 0
while ('01' in s or '10' in s):
  if s.find('01') != -1:
    s = s.replace('01', '', 1)
    n += 1
  elif s.find('10') != -1:
    s = s.replace('10', '', 1)
    n += 1
  else : break
print(n*2)

Submission status: Time Limit Exceeded

Solution code:
def main120():
    import sys
    S_org = input()
    S = []

    for s in range(len(S_org)):
        S.append(S_org[s])
    S = list(map(int, S))

    cont = True
    index = 0
    count = 0

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

    else:
        while(cont):
            if S[index] == S[index+1]:
                index += 1
            else:
                count += 2
                S.pop(index)
                S.pop(index)
                index = 0
    
            if index == len(S) - 2:
                if S[index] != S[index+1]:
                    count += 2
                print(count)
                sys.exit()


main120()

Submission status: Time Limit Exceeded

Solution code:
s = input()

complete = False
ans = 0

while complete == False:
    complete = True
    i = 0
    while i < len(s) - 1:
        if s[i] != s[i+1]:
            s = s[:i] + s[i+2:]
            ans = ans + 2
            complete = False
        i = i + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
S = str(input().split())
n = len(S)
count = 0
while(True):
    l_ = len(S)
    S = re.sub('01', '', S)
    S = re.sub('10', '', S)
    l = len(S)
    if l == l_:
        break
print(n-len(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()

count = 0

def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str
 
string = s
can_remove = True
while can_remove:
  new_text = ''
  search_count_10 = string.count('10')
  if search_count_10 > 0:
    new_text = string.replace('10', '', search_count_10)
    count += search_count_10 * 2
    string = new_text

  search_count_01 = string.count('01')
  if search_count_01 > 0:
    new_text = string.replace('01', '', search_count_01)
    count += search_count_01 * 2
    string = new_text
  
  if search_count_01 == 0 and search_count_10 == 0:
    can_remove = False

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

idx = 0
pick = 0
while(("0" in S) and ("1" in S)):
#    print("S = " + S)
    if(S[idx] != S[idx + 1]):
#        print("idx = {} : S[:idx] = {}, S[idx + 2:] = {}, new str = {} ".format(idx, S[:idx], S[idx + 2:], S[:idx] + S[idx + 2:]))
        S = S[:idx] + S[idx + 2:]
        pick = pick + 2
    else:
        idx = idx + 1

    if(idx > len(S) - 2):
        idx = 0

print(pick)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
for _ in range(N//2):
    S = S.replace('01','').replace('10','')
    S = S.replace('10','').replace('01','')
    if S.count('01') == 0 and S.count('10') == 0:
        break
print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
for _ in range(N//2):
    S = S.replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','')

    if S.count('01') == 0 and S.count('10') == 0:
        break
print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
for _ in range(N//2):
    S = S.replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','').replace('01','').replace('10','')

    if S.count('01') == 0 and S.count('10') == 0:
        break
print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
for _ in range(N):
    S = S.replace('01','').replace('10','')
    if S.count('01') == 0 and S.count('10') == 0:
        break
print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
#print(N)
for _ in range(N//2):
    S = S.replace('01','').replace('10','')
    if S.count('01') == 0 and S.count('10') == 0:
        #print("break")
        break
print(N - len(S))

Submission status: Time Limit Exceeded

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

cnt = 0
idx = 1
prv = S[0]
while idx < len(S):
	if S[idx] != prv:
		cnt += 2
		del S[idx]
		del S[idx-1]
		if len(S) > 0:
			idx = 1
			prv = S[0]
		else:
			break
	else:
		prv = S[idx]
		idx += 1
		
print(cnt)

Submission status: Time Limit Exceeded

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

while True:
    if '111000' in s:
        count += s.count('111000') * 6
        s = s.replace('111000','')
    if '000111' in s:
        count += s.count('000111') * 6
        s = s.replace('000111','')
    if '1100' in s:
        count += s.count('1100') * 4
        s = s.replace('1100','')
    if '0011' in s:
        count += s.count('0011') * 4
        s = s.replace('0011','')
    if '10' in s:
        count += s.count('10') * 2
        s = s.replace('10','')
    elif '01' in s:
        count += s.count('01') * 2
        s = s.replace('01','')
    else:
        break

print(count)

Submission status: Time Limit Exceeded

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

while True:
    if '10' in s:
        count += s.count('10') * 2
        s = s.replace('10','')
    elif '01' in s:
        count += s.count('01') * 2
        s = s.replace('01','')
    else:
        break

print(count)

Submission status: Time Limit Exceeded

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

while True:
    if '10' in s:
        s = s.replace('10','',1)
        count += 2
    elif '01' in s:
        s = s.replace('01','',1)
        count += 2
    else:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
l = [int(x) for x in list(s)]

count = 0
flag = True

while flag == True:
    flag = False
    for i in range(n-1):
        if l[i] != l[i+1]:
            l = l[:i] + l[i+2:]
            count += 2
            n -= 2
            flag = True
            break

print(count)