from typing import Tuple


def _hydra_merge_order(dotlist_entry: str) -> Tuple:
    """
    The override list needs to be ordered as the last one wins in case of
    duplicates: https://hydra.cc/docs/advanced/defaults_list#composition-order
    This function arranges the list so that _base_ is at the top, and we
    proceed with overrides from top to bottom.
    """
    key = dotlist_entry.split("=")[0]
    # presence of "@" => it is a _base_ override
    default_list_item_indicator = key.count("@")  # 1 if true, 0 otherwise
    # level in hierarchy; based on number of "."
    hierarchy_level = key.count(".")
    # multiply by -1 to keep the default list items on top
    return (-1 * default_list_item_indicator, hierarchy_level, dotlist_entry)