def remove(h, i):
    """Remove the item at position i of the heap."""
    n = h.size() - 1
    if n != i:
        h.swap(i, n)
        down(h, i, n)
        up(h, i)

    return h.pop()
Remove the item at position i of the heap.