def is_ordered(treap):
    """ Utility to check that every node in the given Treap satisfies the following:
    Rules:
     - if v is a child of u, then v.priority <= u.priority
     - if v is a left child of u, then v.key < u.key
     - if v is a right child of u, then v.key > u.key
    """
    # iterate through all nodes in the heap
    for node in treap:
        # check parent (if not root)
        if node != treap.root and (node.priority > node.parent.priority):
            print("Node {} and parent ({}) have mismatched priorities.".format(node, node.parent))
            return False
        # check left and right. All are optional, technically
        if node.left and (node.key < node.left.key):
            print("Node {} and left child ({}) have mismatched keys.".format(node, node.left))
            return False
        if node.right and (node.key > node.right.key):
            print("Node {} and right child ({}) have mismatched keys.".format(node, node.right))
            return False
    return True