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:
import sys
from operator import itemgetter
import collections


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


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

    print(r(s))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
l=list(S)
ilength=len(l)
recon=True
while(recon):
  recon=False
  indeces=[]
  jump=False
  for i in range(len(l)-1):
    if(int(l[i])+int(l[i+1])==1 and not(jump)):
      indeces.append(i)
      indeces.append(i+1)
      i+=1
      recon=True
      jump=True
    else:
      jump=False
  sl=[]
  for i in range(len(l)):
    if(not(i in indeces)): sl.append(l[i])
  l=sl[:]
flength=len(l)
print(ilength-flength)

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):
        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:
import sys, itertools
s = sys.stdin.readline().strip()
l = n1 = len(s)
while True:
    n = l
    skip = False
    _s = ""
    for i, j in itertools.zip_longest(s[:], s[1:]):
        if skip:
            skip = False
            continue
        if i != j and j != None:
            skip = True
        else:
            _s += i
    s = _s
    l = len(s)
    if l != 0 and n != l:
        continue
    else:
        break
print(n1 - len(s))

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 = 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:
# from sys import stdin
# S = stdin.readline().rstrip().split()
S = input()
S = list(S)
# print(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 S[i] == '0' and S[i+1] == '1':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        elif S[i] == '1' and S[i+1] == '0':
            S[i] = '2'
            S[i+1] = '2'
            count += 2
            i += 2
        else:
            i += 1
        # print(S)
    if count == count_p:
        print(count)
        break
    else:
        count_p = count
        A = []
        for i in range(len(S)):
            if S[i] != '2':
                A.append(S[i])
        S = A
        # print(S)
        # if len(S) == 2:
        #     if S[0] == '0'
        #      and (S == ['0', '1'] or ['1', '0']):
        #     count += 2
        #     print(count)
        #     break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
data = list(input())
removed_block = 0
i = 1
log = data[0]
while i < (len(data) + 1):
    try:
        if data[i] != log:
            data.pop(i)
            data.pop(i - 1)
            removed_block += 2
            i = 1
            log = data[0]
        else:
            i += 1
    except:
        break
print(removed_block)

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("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:
S = input()
len_s = len(S)
import re
def f(S):
    if ((not "01" in S) and (not "10" in S)):
        return S
    S = re.sub('01|10',"",S)
    return f(S)
print(len_s - len(f(S)))

Submission status: Time Limit Exceeded

Solution code:
s = input()
s2 = s
s = list(s)
s2 = list(s2)
count = 0
s_leng = len(s)
while s_leng >= 2:
    for i in range(1, s_leng):
        i0 = s[i-1]
        i1 = s[i]
        if i0 != i1:
            s2.pop(i)
            s2.pop(i-1)
            count += 2
            s_leng -= 2
            s = s2
            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()
n = c = 0
while True:
    S = S.replace("01","2")
    S = S.replace("10","2")
    n += S.count("2")
    S = S.replace("2","")

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

Submission status: Time Limit Exceeded

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

print(N - len(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('01')
    Nblock += (len(s)-1)*2
    S = ''.join(s)
    t = S.split('10')
    Nblock += (len(t)-1)*2
    S = ''.join(t)


print(Nblock)

Submission status: Time Limit Exceeded

Solution code:
s = input()
length_s = len(s)
list_s = list()
for i in range(length_s):
    list_s.append(s[:1])
    s = s[1:]
for i in range(length_s):
    length = len(list_s)
    if (length < 2):
        break
    for j in range(length - 1):
        if(list_s[j] != list_s[j+1]):
            del list_s[j:j+2]
            break;
print(length_s - len(list_s))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
Quve = S
count = 0
flag = 0
Quve.append("")
while(flag ==0):
    tmp = count
    for i in range(len(Quve)-1):
        if ((Quve[i]=="0") & (Quve[i+1]=="1")) | ((Quve[i]=="1") & (Quve[i+1]=="0")):
            del Quve[i]
            del Quve[i]
            count += 2
            break
    if (tmp == count):
        flag = 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == '__main__':
    S = stdin.readline().rstrip()
    c = 0
    while(1):
        a = S.count('01')
        if a > 0:
            S = S.replace("01", "")
        b = S.count('10')
        if b > 0:
            S = S.replace("10", "")
        num = a+b
        if num == 0:
            print(c*2)
            exit()
        c += num

Submission status: Time Limit Exceeded

Solution code:
# その時点で消せる分を消す
import sys

S = input()  # str

def destroy_step(charst):
    if len(charst) == 1:
        return charst, False
    initial = len(charst)
    dst = ""
    next = True

    for i in range(initial-1):

        if next:
            a = charst[i]
            b = charst[i+1]
            if a != b:
                next = False
            else:
                dst+=a
                next = True
                if i == initial-2:
                    dst+=b
        else:
            next = True
        if i == initial-3:
            if next is False:
                dst+=charst[-1]

    last = len(dst)
    flag = True
    if initial - last == 0:
        flag = False
    return dst, flag
dst = S
flag = True
while flag:
    dst, flag = destroy_step(dst)
print(len(S)-len(dst))
sys.exit()

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
    for removal in removals:
        s1 = remove(s, removal)
        process(s1, count)

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

Submission status: Time Limit Exceeded

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

S = input()
stack = []
ans = 0
for ch in S:
    if len(stack) == 0 or stack[-1] == ch:
        stack.append(ch)
    else:
        ans += 2
        stack = stack[:-1]
print(ans)

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 s[i] != s[i+1]:
            del s[i]
            del s[i]
            updated=True
            break

print(n-len(s))

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
l = len(S)
r = re.compile('01|10')
while True:
  S_ = r.sub('',S)
  if S_ == S:
  	break
  else:
    S = S_ 
print(l-len(S))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
pattern = "(01)|(10)"
count = 0
f = True
while f:
    l = re.findall(pattern,s)
    count += len(l)*2
    s = re.sub(pattern, "", s)
    f = len(l)


print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
  
while len(set(s)) == 2:
  
  count += s.count("10")*2
  s = s.replace("10","")
  count += s.count("01")*2
  s = s.replace("01","")

print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

tmp = raw_input()

length = len(tmp)


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


length2 = len(tmp)

division = length - length2

print(division)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count =0

while True:
    if '01' not in S and '10' not in S:
        break
    if '01' in S:
        a = S.count('01')
        S = S.replace('01','',a)
        count += a
        #print(S)
    if '10' in S:
        b = S.count('10')
        S = S.replace('10','',b)
        count += b
        #print(S)

#print(S)
print(count*2)

Submission status: Time Limit Exceeded

Solution code:
import re

def extract(string, i):
    split = re.split('01|10', string)
    i += len(split) - 1
    split_concat = "".join(split)
    if "01" in split_concat or "10" in split_concat:
        return extract(split_concat, i)
    else:
        return i * 2

S = input()
print(extract(S,0))

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 = s.count("01")
    c2 = s.count("10")
    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())
ss = s
for i in range(int(1000)):
	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', '')
	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', '')
	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))

Submission status: Time Limit Exceeded

Solution code:
S=list(input())
count=0
N=len(S)
for j in range(N//2):
  if len(S)<=1:
    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:
# -*- coding: utf-8 -*-

s = list(input())

# print(S)

i = 0
count = 0
s_sum = len(s)

while i + 1 < len(s):
    if s[i] != s[i + 1]:
        s.pop(i)
        s.pop(i)
        i = 0
        count += 1
    else:
        i += 1

print(count * 2)

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("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:
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 += 2
  return s, ans

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
S=input()
N=int(len(S))
for _ in list(S):
    A=S
    S=S.replace("0110","")
    S=S.replace("0101","")
    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()
flag=1
length=len(s)
s_flag=[1 for _ in range(length)]
while flag:
    l=sum(s_flag)
    if l<=1:
        break
    comp=0
    while s_flag[comp]==0:
        comp+=1
    # print(s_flag,comp)
    for i in range(comp+1,length):
        if s_flag[i]:
            if s[comp]!=s[i]:
                s_flag[comp]=0
                s_flag[i]=0
                break
            else:
                comp=i
                if i==length-1:
                    flag=0
print(length-sum(s_flag))

Submission status: Time Limit Exceeded

Solution code:
S=input()
L=len(S)
for i in range(50000):
    S=S.replace("01","").replace("10","")
L2=len(S)
print(L-L2)

Submission status: Time Limit Exceeded

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

S = input()
N = len(S)
cnt = 0

# O(N^2)は不可。
# 010がある時、01と10を取り除くパターンを作る？
s = S
while True:
    c1 = s.count("01")
    c2 = s.count("10")
    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


# 時間超過
# s = set()
# s.add(S)
# while True:
#     #print(s)
#     s2 = set()
#     for d in s:
#         for i in range(len(d)-1):
#             if d[i] != d[i+1]:
#                 ns = None
#                 if i+2 < len(d):
#                     ns = d[:i]+d[i+2:]
#                 else:
#                     ns = d[:i]
#                 if ns is not None and len(ns) > 0:
#                     s2.add(ns)
#     if len(s2) > 0:
#         cnt += 2
#         s = s2
#     else:
#         break
#

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
pattern = "(01)|(10)"
count = 0
while re.search(pattern,s):
    l = re.findall(pattern,s)
    count += len(l)*2
    s = re.sub(pattern, "", s)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, itertools
s = sys.stdin.readline().strip()
l = n1 = len(s)
while True:
    n = l
    skip = False
    _s = ""
    for i, j in itertools.zip_longest(s[:], s[1:]):
        if skip:
            skip = False
            continue
        if i == j or j == None:
            _s += i
        else:
            skip = True
    s = _s
    l = len(s)
    if l == 0 or n == l:
        break
print(n1 - len(s))

Submission status: Time Limit Exceeded

Solution code:
s = input()
origin = s
past = ''
cnt=0
while True:
    past = s
    s = s.replace('10','').replace('01','')
#    print(s)
#    print(past)
    if past==s:
        break

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def extract(string, i):
    import re
    split = re.split('01|10', string)
    i += len(split) - 1
    split_concat = "".join(split)
    if "01" in split_concat or "10" in split_concat:
        return extract(split_concat, i)
    else:
        return i * 2

S = input()

print(extract(S,0))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
cnt = 0
while len(set(s)) == 2:
  for i in range(len(s)):
    if s[i] != s[i+1]:
      cnt += 1
      s = s[:i] + s[i+2:]
      break

print(cnt * 2)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
S=input()
N=int(len(S))
for _ in list(S):
    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:

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
                break
    if counter == 0:
        break

print(ans*2)

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), 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("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
s=input()
m=0
s1 = re.compile(r'01|10')
l1 = re.compile(r'0000011111|1111100000|00001111|11110000|000111|111000')
for i in range(len(s)//2):
  dst = re.sub(s1, "", s)
  dst = re.sub(l1, "", dst)
  if dst == s:
    break
  m += len(s) - len(dst)
  s=dst
print(m)

Submission status: Time Limit Exceeded

Solution code:
import sys


S_raw = sys.stdin.readline().strip()

def check_next(S):
    S = list(S)
    before_num=S[0]
    for i in range(len(S)):
        if S[i]!=before_num:
            S.pop(i-1)
            #S = list(S)
            S.pop(i-1)
            new_S = S
            return S,1
            break
    return S,0


cnt=0
N=0

while cnt<10**5:
    S_raw, check_cnt = check_next(S_raw)
    N += check_cnt
    if not S_raw:
        break
    cnt+=1
    
print(N*2)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    S = input()
    c = 0
    while(1):
        a = 2 * S.count('01')
        if a > 0:
            S = S.replace("01", "")
        b = 2 * S.count('10')
        if b > 0:
            S = S.replace("10", "")
        num = a+b
        if num == 0:
            print(c)
            exit()
        c += num

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int, input()))
ans = 0
l = len(S)
i = 0
while len(S)-1 > i:
    if S[i] != S[i+1]:
        S.pop(i)
        S.pop(i)
        ans += 2
        i = -1
    i += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

num_moto = int(len(s))

while True:
    if s.find('10') == -1 and s.find('01') == -1:
        break
    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 = list(input())

def check_pair(array):
    if len(array) < 2:
        return False
    for i, a in enumerate(array[:-1]):
        if (a=='0' and array[i+1]=='1') or (a=='1' and array[i+1]=='0'):
            del array[i:i+2]
            return array
    return False

ans = 0
while True:
    s = check_pair(s)
    if s == False:
        break
    else:
        ans += 1

print(ans*2)

Submission status: Time Limit Exceeded

Solution code:
s=input()
flag=1
length=len(s)
s_flag=[1 for _ in range(length)]
while flag:
    l=sum(s_flag)
    if l<=1:
        break
    comp=0
    while s_flag[comp]==0:
        comp+=1
    for i in range(comp+1,length):
        if s_flag[i]:
            if s[comp]!=s[i]:
                s_flag[comp]=0
                s_flag[i]=0
                break
            elif i==length-1:
                flag=0
print(length-sum(s_flag))

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ss = s
for i in range(int(1000)):
	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))

Submission status: Time Limit Exceeded

Solution code:
import re
S = input()
l = len(S)
while True:
  if re.sub('01|10','',S) == S:
  	break
  else:
    S = re.sub('01|10','',S)
print(l-len(S))

Submission status: Time Limit Exceeded

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

while "01" in s or "10" in s:
    s2 = s.replace("01", '', 1)
    if s2 != s:
        cnt = cnt + 2
    s3 = s2.replace("10", '', 1)
    if s3 != s2:
        cnt = cnt + 2
    s = s3

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
inp = input()
len_1st = len(inp)

inf = 10 ** 5
for i in range(inf):
  inp = inp.replace('10','')  
  inp = inp.replace('01','')  
  
  if i%100 == 0: 
    cnt_01 = inp.count('01')
    cnt_10 = inp.count('10')
    if (cnt_01 == 0) & (cnt_10 == 0):
      break
  
len_after = len(inp)
print(len_1st - len_after)

Submission status: Time Limit Exceeded

Solution code:
s = input()
slen = len(s)
ans = 0

for i in range(len(s)):
  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:
sent = str(input())
tmpsent = sent
lis = []
ss = ""
ss2 = ""
prev = [""]
for i in range(int(len(sent) / 2)):
    pv = []
    for p in prev:
        ss = "0" + p + "1"
        ss2 = "1" + p + "0"
        pv.append(ss)
        pv.append(ss2)
        lis.append(ss)
        lis.append(ss2)
    prev = pv

lis.reverse()
loop = True
while loop:
    loop = False
    for l in lis:
        if tmpsent != tmpsent.replace(l, ''):
            tmpsent = tmpsent.replace(l , '')
            loop = True
            break
print(len(sent) - len(tmpsent))

Submission status: Time Limit Exceeded

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

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

if len(s) < 1000:
  print(l - len(df(s)))
else:
  i = l // 4
  sx = df(s[:i]) + df(s[i:i * 2]) \
         + df(s[i * 2:i * 3]) + df(s[i * 3:])
  print(l - len(df(sx)))

Submission status: Time Limit Exceeded

Solution code:
S = input()
count =0

while True:
    if '01' not in S and '10' not in S:
        break
    if '01' in S:
        S = S.replace('01','',1)
        count += 1
        #print(S)
    if '10' in S:
        S = S.replace('10','',1)
        count += 1
        #print(S)

#print(S)
print(count*2)

Submission status: Time Limit Exceeded

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

ans = 0
def kesu(s, ans):
  for ni in range(n-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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
s=input()
m=0
s1 = re.compile(r'01|10')
l1 = re.compile(r'000111|111000|00001111|11110000|0000011111|1111100000')
for i in range(len(s)//2):
  dst = re.sub(s1, "", s)
  dst = re.sub(l1, "", dst)
  if dst == s:
    break
  m += len(s) - len(dst)
  s=dst
print(m)

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)
for i in range(N):
	if len(S) == len(remove_01_10(S)):
		print(N - len(S))
		exit()
	else:
		S = remove_01_10(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
 
for i in range(N):
    fn = len(S)
    S = S.replace('01', '').replace('10', '').replace('01', '').replace('10', '').replace('01', '').replace('10', '')
    if fn == len(S):
        break
 
print(N - len(S))

Submission status: Time Limit Exceeded

Solution code:
import re
S = (input())
advance = len(S)
ans = 0
while True:  
    count = re.findall("01",S)
    S = S.replace("01","")
    ans+=len(count)*2
    count = re.findall("10",S)
    S = S.replace("10","")
    ans+=len(count)*2
    if advance==len(S):
        break
    advance = len(S)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
pattern = "(01)|(10)"
count = 0
while re.search(pattern,s):
    count += 2
    s = re.sub(pattern, "", s,1)

print(count)

Submission status: Time Limit Exceeded

Solution code:
sent = str(input())
tmpsent = sent
lis = []
ss = ""
ss2 = ""
prev = [""]
for i in range(int(len(sent) / 2)):
    pv = []
    for p in prev:
        ss = "0" + p + "1"
        ss2 = "1" + p + "0"
        pv.append(ss)
        pv.append(ss2)
        lis.append(ss)
        lis.append(ss2)
    prev = pv

lis.reverse()
loop = True
while loop:
    loop = False
    for l in lis:
        if tmpsent != tmpsent.replace(l, ''):
            tmpsent = tmpsent.replace(l , '')
            loop = True
print(len(sent) - len(tmpsent))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = S
res = True
while res == True:
    s = s.replace('01','')
    s = s.replace('10','')
    res0 = s.find('01')
    res1 = s.find('10')
    if res0 == -1 and res1 == -1:
        res = False
print(len(S) - len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    lines = sys.stdin.readlines()[0]
    s = lines.rstrip('\n')
    size = len(s)
    pat0 = '01'
    pat1 = '10'
    while(True):
        if pat0 in s:
            parts = s.split(pat0)
        elif pat1 in s:
            parts = s.split(pat1)
        else:
            break
        s = ''.join(parts)
    print(size - len(s))
        
        


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = S
res = True
while res == True:
    s = s.replace('01','',1)
    s = s.replace('10','',1)
    res0 = s.find('01')
    res1 = s.find('10')
    if res0 == -1 and res1 == -1:
        res = False
print(len(S) - len(s))

Submission status: Time Limit Exceeded

Solution code:
in_s = input().rstrip()
s_old = in_s
while True:
    s_new = s_old.replace("10","").replace("01","")
    if s_new == s_old:
        break
    s_old = s_new
print(len(in_s) - len(s_new))

Submission status: Time Limit Exceeded

Solution code:
inp = input()
len_1st = len(inp)

inf = 10 ** 5
for i in range(inf):
  inp = inp.replace('10','')  
  inp = inp.replace('01','')  
  
  cnt_01 = inp.count('01')
  cnt_10 = inp.count('10')
  if (cnt_01 == 0) & (cnt_10 == 0):
    break
  
len_after = len(inp)
print(len_1st - len_after)

Submission status: Time Limit Exceeded

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

count = 0
while(True):
    old = count
    if (len(s) == 1 or len(s) == 0):
        break

    for n in range(len(s) - 1):

        k = s[n]
        l = s[n + 1]

        if (k != l):

            s.pop(n)
            s.pop(n)

            count += 2
            break

    if (old == count):
        break

print(count)