import io
import math


def build_pretty_binary_heap(heap: list, total_width=36, fill=" ") -> str:
    """Returns a string (which can be printed) representing heap as a tree.

    To increase/decrease the horizontal space between nodes, just
    increase/decrease the float number h_space.

    To increase/decrease the vertical space between nodes, just
    increase/decrease the integer number v_space.
    Note: v_space must be an integer.

    To change the length of the line under the heap, you can simply change the
    line_length variable."""
    if not isinstance(heap, list):
        raise TypeError("heap must be an list object")
    if len(heap) == 0:
        return "Nothing to print: heap is empty."

    output = io.StringIO()
    last_row = -1
    h_space = 3.0
    v_space = 2

    for i, heap_node in enumerate(heap):
        if i != 0:
            row = int(math.floor(math.log(i + 1, 2)))
        else:
            row = 0

        if row != last_row:
            output.write("\n" * v_space)

        columns = 2 ** row
        column_width = int(math.floor((total_width * h_space) / columns))
        output.write(str(heap_node).center(column_width, fill))
        last_row = row

    s = output.getvalue() + "\n"
    line_length = total_width + 15
    s += ('-' * line_length + "\n")
    return s