<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_ordered_cliques(cliques, next_cliques):
 """Order the new cliques based on the order of their ancestors in the previous iteration."""

    def sort_key(clique):
        return -len(clique[1])

    if not cliques:
        return list(sorted(
            list(next_cliques.values())[0].items(),
            key=sort_key))

    ordered_cliques = []
    for _, clique in enumerate(cliques):
        parent, _ = clique

        # If this fork continues
        if parent in next_cliques:
            # Sort the cliques in descending order of the size of the
            # clique, so that the main chain tends to the left
            ordered_cliques.extend(
                sorted(next_cliques[parent].items(), key=sort_key))

        # Else drop it

    return ordered_cliques