Problem:


Score : 300 points

Problem Statement

There are N cubes stacked vertically on a desk.

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

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

At most how many cubes can be removed?

Constraints

1 \leq N \leq 10^5

|S| = N

Each character in S is 0 or 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of cubes that can be removed.

Sample Input 1

0011

Sample Output 1

4

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

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

Remove the first and second cubes from the bottom.

Sample Input 2

11011010001011

Sample Output 2

12

Sample Input 3

0

Sample Output 3

0



Sample input:
0011


Sample output:
4

Submission status: Time Limit Exceeded

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

n = 0
X = 0
while X<1:
	K = len(L)-1
	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(n*2)

Submission status: Time Limit Exceeded

Solution code:
import sys

data= sys.stdin.readline()

a = data.count("01")
b = data.count("10")
c = 0
while not (a == 0 and b == 0):
    if a > b:
        c += a * 2
        data = data.replace("01", "")
        a = data.count("01")
        b = data.count("10")
        
    else:
        c += b * 2
        data = data.replace("10", "")
        a = data.count("01")
        b = data.count("10")
    
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
c = l

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

    if(len(S) == c):
        break

    c = len(S)

print(l - len(S))

Submission status: Time Limit Exceeded

Solution code:
import re
s = input()
s = s.replace('01','10')
cnt=0
t = re.subn('10','',s)
while t[1]!=0:
    a = t[0].replace('01','10')
    cnt += t[1]
    t = re.subn('10','',a)
print(int(cnt*2))

Submission status: Time Limit Exceeded

Solution code:
buffer = list(input())
S = list(map(int, buffer))
N = len(S)
i = 0
count = 0
while(1):
    if(S == [] or N == 1):
        break
    elif((S[i] + S[i + 1]) == 1):
        S.pop(i)
        S.pop(i)
        i = 0
        count += 2
        N = len(S)
    else:
        i += 1
        if(i == (N - 1)):
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

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

l = str(input())
cnt = 0

while "10" in l or "01" in l:
    dels = [i.start() for i in re.finditer("10", l)]
    dels.extend(list(map(lambda x: x+1, dels)))
    # print(dels)
    cnt += len(dels)
    # print(len(dels))
    l = "".join(dellist(list(l), dels))

    dels = [i.start() for i in re.finditer("01", l)]
    dels.extend(list(map(lambda x: x+1, dels)))
    # print(dels)
    cnt += len(dels)
    # print(len(dels))
    l = "".join(dellist(list(l), dels))

print(cnt)

Submission status: Time Limit Exceeded

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

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 = []

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        return
    count += 2
    max_removes = []
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        max_removes.append(len(get_removals(s1)))
        ss.append(s1)
    max_remove = max(max_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:
import re
s=input()
N=len(s)
while True:
    n = len(s)
    s = s.replace("10", "")
    s = s.replace("01", "")
    if n == len(s):
        print(N-n)
        break

Submission status: Time Limit Exceeded

Solution code:
[s] = [i for i in input().split()]
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

while True :
    length = len(S)
    S = S.replace("01", "")
    S = S.replace("10", "")
    if (length == len(S)) :
        break
    count += length - len(S)
print(count)

Submission status: Time Limit Exceeded

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

S = input()
cnt = 0

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=input()
n=len(s)

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

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
import sys

data= sys.stdin.readline()

a = data.count("01")
b = data.count("10")
c = 0
while not (a == 0 and b == 0):
    if a > 0:
        c += a * 2
        data = data.replace("01", "")
        a = data.count("01")
        b = data.count("10")
        
    if b > 0:
        c += b * 2
        data = data.replace("10", "")
        a = data.count("01")
        b = data.count("10")
    
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s = list(s)
i = 0
j = 0
flg =0

if len(s) >1:
    while(1):
        for i in range(0,len(s)):
            if i == len(s)-1:
                flg = 1
                break
            elif s[i] != s[i+1]:
                s.pop(i+1)
                s.pop(i)
                j+=2
                break
            elif len(s) == 2:
                flg = 1
                break
            
        if len(s) ==0 or flg==1:
            break
        
print(j)

Submission status: Time Limit Exceeded

Solution code:
buffer = list(input())
S = [int(n) for n in buffer]
N = len(S)
i = 0
count = 0
while(1):
    if(S == [] or N == 1):
        break
    elif((S[i] + S[i + 1]) == 1):
        S.pop(i)
        S.pop(i)
        i = 0
        count += 2
        N = len(S)
    else:
        i += 1
        if(i == (N - 1)):
            break
print(count)

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:
        if '01' in s or '10' in s:
            s = s.replace('01', '')
            s = s.replace('10', '')
        else:
            flg = False

    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=list(map(int,input()))
count=0
N=len(S)
for j in range(N//2):
  if (sum(S)==0)or(sum(S)==len(S)):
    break
  i=0
  while True:
    if S[i]!=S[i+1]:
      count+=1
      del S[i:i+2]
      i-=1
    i+=1
    if i>=len(S)-1:
      break
print(2*count)

Submission status: Time Limit Exceeded

Solution code:
cubes = input()

removed_cubes_count = 0

while True:
    count01 = cubes.count('01')
    count10 = cubes.count('10')

    if count01 == 0 and count10 == 0:
        break

    removed_cubes_count += count01 + count10

    cubes = cubes.translate({
        '01': '',
        '10': ''
    })



print(removed_cubes_count)

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()
    S_length = len(S) - 1
    for i in range(S_length):
        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:
#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input().rstrip()

Nblock = 0

while '0' in S and '1' in S:
    s = S.split('0011')
    Nblock += (len(s)-1)*4
    S = ''.join(s)
    t = S.split('1100')
    Nblock += (len(t)-1)*4
    S = ''.join(t)
    s = S.split('1010')
    Nblock += (len(s)-1)*4
    S = ''.join(s)
    t = S.split('0101')
    Nblock += (len(t)-1)*4
    S = ''.join(t)
    s = S.split('10')
    Nblock += (len(s)-1)*2
    S = ''.join(s)
    t = S.split('01')
    Nblock += (len(t)-1)*2
    S = ''.join(t)

print(Nblock)

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 = []

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        return
    count += 2
    max_removes = []
    for removal in removals:
        s1 = remove(s, removal)
        max_removes.append(len(get_removals(s1)))
    max_remove = max(max_removes)
    for removal in removals:
        s1 = remove(s, removal)
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

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

Submission status: Time Limit Exceeded

Solution code:
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_b -d test-b
oj test -d test-c -c "python abc116c.py"
oj test -d test-b -c "python abc116b.py" test-b/sample-3.in
"""

from collections import defaultdict
import sys
import math
import time
import itertools

def deco(func):
    def wrapper(*args, **kwargs):
        s = time.time()
        #print('--start--')
        ret = func(*args, **kwargs)
        logging.debug('--end in %f --' % (time.time() - s) )
        return ret
    return wrapper



def str_del(str,i, j):
    str = str[:i]+str[j+1:]
    return str

#@deco
def sol(S):
    a = 0
    i = 0
    sz = len(S)
    while sz > 0 or i > sz:
        if i >= sz: break
        if i > 0:
            #print(S, i, i-1)
            if S[i] != S[i-1]:
                a += 2
                S = str_del(S, i-1, i)
                i = 0
                sz = len(S)
            else:
                i += 1
        else:
            i += 1
    return a





import logging
#logging.basicConfig(level=logging.DEBUG, format="%(message)s")
logging.basicConfig(level=logging.ERROR, format="%(message)s")
do_submit = True
#do_submit = False
def input_parse(input_str):
    # lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    # parsed_lines = [list(map(int, line.split())) for line in lines]
    # S = parsed_lines[0][0]
    # S = parsed_lines[1]
    # return (n, S)
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    #print(lines)
    S = lines[0]
    return (S)

#do_submit = False
do_submit = True

if not do_submit:
    # n, S= input_parse("""
    # 4
    # 1 2 2 1
    # """)
    S= input_parse("""
    0011
    """)
    print(sol(S))

    S= input_parse("""
    11011010001011
    """)
    print(sol(S))

    S= input_parse("""
    0
    """)
    print(sol(S))

else:
    # a, b, c = list(map(int, input().split()))
    # print(sol(a, b, c))
    # n = int(input())
    # S = list(map(int, input().split()))
    # print(sol(S, n))
    # n, a, b, c = list(map(int, input().split()))
    # S = []
    # for i in range(n):
    #     S.append(int(input().strip()))
    # print(sol(n, a, b, c, S))
    S = input()
    print(sol(S))

Submission status: Time Limit Exceeded

Solution code:

# -*- coding: utf-8 -*-
# 整数の入力
# a = int(input())
s = input()
# s = '11011010001011'
# スペース区切りの整数の入力
# a, b, k = map(int, input().split())

counter = 0
while s.find('01') != -1 or s.find('10') != -1:
    if s.find('01') != -1:
        s = s.replace('01', '', 1)
        counter += 2
    if s.find('10') != -1:
        s = s.replace('10', '', 1)
        counter += 2

# 出力
print("{}".format(int(counter)))

Submission status: Time Limit Exceeded

Solution code:
S=input()
res=0
for i in range(1000000):
  S=S.replace("10","3")
  S=S.replace("01","3")
  res+=S.count("3")*2
  S=S.replace("3","")
print(res)

Submission status: Time Limit Exceeded

Solution code:
def dp(st):
    ref = ""
    count = 0
    pos = []
    ans = []
    for n,s in enumerate(st):
        if ref=="":
            ref = s
        else:
            if ref != s:
                pos.append(n-1)
            else:
                count = 0
            ref = s
    # print(pos)
    if pos:
        p = pos[0]
        ans.append(dp(st[:p]+st[p+2:])+1)
    else:
        return 0
    return max(ans)



s = input()
ans = dp(s)
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
buffer = list(input())
S = [int(n) for n in buffer]
N = len(S)
i = 0
count = 0
while(1):
    
    if(S == [] or N == 1):
        break
    elif(S[i] != S[i + 1]):
        S.pop(i)
        S.pop(i)
        i = 0
        count += 2
        N = len(S)
    else:
        i += 1
        if(i == (N - 1)):
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
data = input()
score = 0
size = len(data)

def get_score(data):
    global score
    for i in range(0, size-1):
        ab = data[i:i+2]

        if ab == '10' or ab =='01':
            score += 2
            data = data[:i] + data[i+2:]
            break

    if data == '' or set(data) == {'1'} or set(data) == {'0'}:
        return
    get_score(data)

get_score(data)
print(score)

Submission status: Time Limit Exceeded

Solution code:
def dp(st):
    ref = ""
    count = 0
    pos = []
    ans = []
    for n,s in enumerate(st):
        if ref=="":
            ref = s
        else:
            if ref != s:
                pos.append(n-1)
            else:
                count = 0
            ref = s
    # print(pos)
    if pos:
        for p in pos:
            ans.append(dp(st[:p]+st[p+2:])+1)
    else:
        return 0
    return max(ans)



s = input()
ans = dp(s)
print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
def remove_01_10(S):
	N = len(S) 
	while True:
		if '01' in S or '10' in S:
			S = S.replace('10', '')
			S = S.replace('01', '')
		else:
			return(N - len(S))	

print(remove_01_10(input()))

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

while ("01" in s) | ("10" in s):
    count += 2 * s.count("01")
    s = s.replace("01", "")
    count += 2 * s.count("10")
    s = s.replace("10", "")
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ss = s
for i in range(int(50)):
	ss = ss.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', '').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', '')
    
print(len(s)-len(ss))

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
pattern = "(01)|(10)"
count = 0
diff = 1

while diff:
    ssub = re.sub(pattern, "", s)
    diff = len(s) - len(ssub)
    count += diff
    s = ssub


print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

while ("01" in s) | ("10" in s):
    if "01" in s:
        count += 2 * s.count("01")
        s = s.replace("01", "")
    else:
        count += 2 * s.count("10")
        s = s.replace("10", "")
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = c = 0
while True:
    n += S.count("01")
    S = S.replace("01","")
    n += S.count("10")
    S = S.replace("10","")
    if c == n:
        break
    else:
        c = n
print(n*2)

Submission status: Time Limit Exceeded

Solution code:
import re
s = str(input())
cnt=0
while len(s) >1:
    if '10' in s:
        cnt+=2 * s.count('10')
        s=re.sub('10', '',s) 
        cnt+=2 * s.count('01')
        s=re.sub('01', '',s) 
        
    elif '01' in s:
        cnt+=2 * s.count('01')
        s=re.sub('01', '',s) 
        
        cnt+=2 * s.count('10')
        s=re.sub('10', '',s) 
    else:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
line=[int(c) for c in s]
length=len(line)
while 1:
  for i in range(len(line)-1):
    if line[i]!=2 and line[i]!=line[i+1]:
      line[i]=2
      line[i+1]=2
  if 2 in line:
    line=[i for i in line if i!=2]
  else:
    break
print(length-len(line))

Submission status: Time Limit Exceeded

Solution code:
#ABC120C-Unification.py

from sys import stdin

input = stdin.readline

S = input().rstrip()

Nblock = 0

while '0' in S and '1' in S:
    s = S.split('10')
    Nblock += (len(s)-1)*2
    S = ''.join(s)
    t = S.split('01')
    Nblock += (len(t)-1)*2
    S = ''.join(t)


print(Nblock)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ss = s
for i in range(int(100)):
	ss = ss.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', '').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', '')
    
print(len(s)-len(ss))

Submission status: Time Limit Exceeded

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

while True:
  if '01' in s or '10' in s:
    s = s.replace('01', '')
    s = s.replace('10', '')
  else:
    break

print(l - len(s))

Submission status: Time Limit Exceeded

Solution code:
s=input()
line=[int(c) for c in s]
length=len(line)
while 1:
  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
  if 2 in line:
    line=[i for i in line if i!=2]
  else:
    break
print(length-len(line))

Submission status: Time Limit Exceeded

Solution code:
import copy

if __name__ == "__main__":
    s = input()
    n = len(s)
    check = ""
    ans = 0 
    while s != check and s != "": 
        check = copy.copy(s)
        i = 0 
        while i + 1 < len(s) - 1 and s[i] == s[i + 1]: 
            i += 1
        if i == len(s) - 2:
            if s[i] != s[i + 1]: 
                s = copy.copy(s[0:i] + s[i + 1:len(s)])
                s = copy.copy(s[0:i] + s[i + 1:len(s)])
                ans += 2
            else:
                break
        elif i == 0 and len(s) <= 1:
            break
        else:
            s = copy.copy(s[0:i] + s[i + 1:len(s)])
            s = copy.copy(s[0:i] + s[i + 1:len(s)])
            ans += 2
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
S = list(S)
count_p = 0
count = 0

mark = 1
if len(S) <= 1:
    print(0)
    mark = 0
while mark:
    i = 0
    while i < len(S)-1:
        if int(S[i])+int(S[i+1]) == 1:
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        else:
            i += 1
    if count == count_p:
        print(count)
        break
    else:
        count_p = count
        S = [e for e in S if e!='2']

Submission status: Time Limit Exceeded

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

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

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]
    #S = list(filter(lambda a: a != 2, S))
    check(S)

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

Submission status: Time Limit Exceeded

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

S = input()
cnt = 0

# O(N^2)は不可。
# 010がある時、01と10を取り除くパターンを作る？
s = S
while True:
    ls = len(s)
    s1 = s.replace("01", "")
    s2 = s.replace("10", "")
    ls1 = len(s1)
    ls2 = len(s2)
    if ls == ls1 and ls == ls2:
        break
    elif ls1 <= ls2:
        cnt += (ls - ls1)
        s = s1
    else:
        cnt += (ls - ls2)
        s = s2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def remove_01_10(S):
	S = S.replace('10', '')
	S = S.replace('01', '')
	return S	

S = input()
N = len(S)
while True:
	if '01' in S or '10' in S:
		S = remove_01_10(S)
	else:
		print(N - len(S))
		exit()

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=int(len(S))
for _ in range(N):
    A=S
    S=S.replace("10","")
    S=S.replace("01","")
    if A==S:
        break
print(N-int(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)
    s2 = s2.replace("0000011111", "").replace("1111100000", "")
    s2 = s2.replace("000111", "").replace("111000", "")
    s2 = s2.replace("01", "").replace("10", "")
    len_2 = len(s2)
    if len_1 == len_2:
        break
print(len(s) - len(s2))

Submission status: Time Limit Exceeded

Solution code:
import re

tmp = raw_input()

length = len(tmp)


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


length2 = len(tmp)

division = length - length2

print(division)

Submission status: Time Limit Exceeded

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

ans = 0
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 += 1
  return s, ans

while True:
  l = len(s)
  s, ans = kesu(s, ans)
  if len(s) == l:
    print(ans*2)
    break

Submission status: Time Limit Exceeded

Solution code:
s=[int(i) for i in input()]
n=len(s)
updated=True
while updated:
    updated=False
    for i in range(len(s)-1):
        if i not in range(len(s)-1):
            break
        while i in range(len(s)-1) and s[i] != s[i+1]:
            del s[i]
            del s[i]
            updated=True

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

num_moto = int(len(s))

for ctr in range(5000):
    if int(len(s)) == 0:
        break
    s = s.replace('10','')
    s = s.replace('01','')
    
num_kekka = int(len(s))
print(num_moto - num_kekka)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(min(s.count("0"), s.count("1"))):
  s = s.replace("01", "")
for i in range(min(s.count("0"), s.count("1"))):
  s = s.replace("10", "")
  
#print(s)
print(n - len(s))

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_li = list(S)
count = 0
flag = False
i = 0
while True:
  if i == len(S_li) or len(S_li) == 0:
    break
  if S_li[i-1] == "0" and S_li[i] == "1" and i-1 >= 0:
    flag = True
  elif S_li[i-1] == "1" and S_li[i] == "0" and i-1 >= 0:
    flag = True
  if flag == True:
    del S_li[i-1:i+1]
    count += 2
    i = 0
    flag = False
  else:
    i += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

while ("01" in s) | ("10" in s):
    if "01" in s:
        s = s.replace("01","", 1)
    else:
        s = s.replace("10","", 1)
    count += 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

def func(s):
    s = list(s)
    for idx in range(1, len(s)):
        if s[idx] == s[idx - 1]:
            continue
        else:
            del s[idx-1:idx+1]
            break
    return ''.join(s)

n = 0
while(1):
    if '01' not in S:
        if '10' not in S:
            break
    
    S = func(S)
    n += 2

print(n)

Submission status: Time Limit Exceeded

Solution code:
import sys

data= sys.stdin.readline()

a = data.count("01")
b = data.count("10")
c = 0
while True:
    if a > 0:
        c += a * 2
        data = data.replace("01", "")
        a = data.count("01")
        b = data.count("10")
        continue
        
    if b > 0:
        c += b * 2
        data = data.replace("10", "")
        a = data.count("01")
        b = data.count("10")
        continue

    break

print(c)

Submission status: Time Limit Exceeded

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

tmp = S
a = 0
b = 0
c = 0
count = 0
if len(tmp)-1 == b:
    a = 1

while a == 0:
    if tmp[b] != tmp[b+1]:
        count += 1
        #print('取り除くもの')
        #print(tmp[b:b+2])
        tmp = tmp[:b] + tmp[b+2:]
        #print('取り除いた後')
        #print(tmp)
        b = 0
        c += 1
        if len(tmp)-1 == b or len(tmp) == 0: 
            a = 1

    else:
        b += 1
        if len(tmp)-1 == b or len(tmp) == 0: 
            a = 1

print(str(count*2))

Submission status: Time Limit Exceeded

Solution code:
import re
s=input()
s=s.replace('01','10')
cnt=0
while re.subn('10','',s)[1]!=0:
  t=re.subn('10','',s)
  s=t[0].replace('01','10')
  cnt+=t[1]
print(int(cnt*2))

Submission status: Time Limit Exceeded

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