def _exch(pq, i, j):
    """
    Exchanges the positions of items at index i and j on the heap.
    Indices are "off-by-one" to support 1-based indexing.
    :param pq: the heap
    :param i: index of the first item
    :param j: index of the second item
    """
    pq[i - 1], pq[j - 1] = pq[j - 1], pq[i - 1]
