from time import perf_counter
from random import choice


# generates random string of length size, from symbols in the given string alph
def gen_test(length, alph):
    ans = ''
    for _ in range(length):
        ans += choice(alph)
    return ans


def E_slow(s):
    index_R = s.find('R')
    if index_R < 0:
        return s, 0
    k = index_R + 1
    del_B = 0
    while k < len(s):
        if s[k] == 'B':
            s = s[:k] + s[k + 1:]
            del_B += 1
        else:
            k += 1
    return s, del_B


for size in 10, 20, 50, 100, 1000, 2000, 5000, 10000, 50000, 100000, 500000:
    s = gen_test(size, 'RB')
    start = perf_counter()
    E_slow(s)
    print(size, perf_counter() - start)