import re


def handle_gutenberg(text: str) -> str:
    """Removes Project Gutenberg boilerplate from text.

    :param text: A Project Gutenberg document.
    :return: The input text document without the Gutenberg boilerplate.
    """

    # find end of front boiler plate, assuming something like:
    #     *** START OF THIS PROJECT GUTENBERG EBOOK FRANKENSTEIN ***

    # This is a "non-greedy" regex pattern, meaning it will stop looking
    # and return after the first "***" (instead of deleting some of the text
    # if it finds "***" outside of the boilerplate.
    re_start_gutenberg = re.compile(
        r"\*\*\* START OF THIS PROJECT GUTENBERG.*?\*\*\*",
        re.IGNORECASE | re.UNICODE | re.MULTILINE)
    match = re.search(re_start_gutenberg, text)
    if match:
        end_boiler_front = match.end()
        # text saved without front boilerplate
        text = text[end_boiler_front:]
    else:
        re_start_gutenberg = re.compile(
            r"Copyright.*\n\n\n", re.IGNORECASE | re.UNICODE)
        match = re.search(re_start_gutenberg, text)
        if match:
            end_boiler_front = match.end()
            # text saved without front boilerplate
            text = text[end_boiler_front:]

    # now let's find the start of the ending boilerplate
    re_end_gutenberg = re.compile(
        r"End of.*?Project Gutenberg",
        re.IGNORECASE | re.UNICODE | re.MULTILINE)
    match = re.search(re_end_gutenberg, text)
    if match:
        start_boiler_end = match.start()
        # text saved without end boilerplate
        text = text[:start_boiler_end]

    return text