def apply_stats_template(template, top_stats):   
    """Apply statistics template. Available keywords are:
    * :attr:`POST-COUNT` : The cumulative sum of posts.
    * :attr:`POST-REACTION-COUNT` : The cumulative sum of post reactions.
    * :attr:`BEST-POST-REACTION` : The posts with the highest reactions.
    * :attr:`COMMENT-COUNT` : The cumulative sum of comments.
    * :attr:`COMMENT-REACTION-COUNT` : The cumulative sum of comments reactions.
    * :attr:`BEST-COMMENT-REACTION` : The comments with the highest reactions.
    * :attr:`REPLY-COUNT` : The cumulative sum of replies.
    * :attr:`REPLY-REACTION-COUNT` : The cumulative sum of replies reactions.
    * :attr:`BEST-REPLY-REACTION` : The replies with the highest reactions.
    * :attr:`COMMENT-REPLY-COUNT` : The cumulative sum of replies and comments.
    * :attr:`REACTION-COUNT` : The cumulative sum of reactions.
    * :attr:`REACTION-AHAH` : The cumulative sum of "AHAH" reactions.
    * :attr:`REACTION-LOVE` : The cumulative sum of "LOVE" reactions.
    * :attr:`REACTION-CARE` : The cumulative sum of "CARE" reactions.
    * :attr:`REACTION-WOW` : The cumulative sum of "WOW" reactions.
    * :attr:`REACTION-SAD` : The cumulative sum of "SAD" reactions.
    * :attr:`REACTION-ANGER` : The cumulative sum of "ANGER" reactions.
    * :attr:`REACTION-LIKE` : The cumulative sum of "LIKE" reactions.

    Args:
        template (str): The template containing keywords.
        top_stats (dict): The top statistics, generated with ``get_top_stats()`` function.

    Returns:
        str
        
    Example:
        >>> template = "The best post is: <<TOP1-BEST-POST-REACTION>>, the second best comment is: <<TOP2-BEST-COMMENT-REACTION>>"
        >>> stats = get_top_stats(posts)
        >>> apply_stats_template(template, stats)
            'The best post is: Léa Ricot, the second best comment is: Jean Neymar'
    """
    for stat_category in top_stats.keys():
        for i in range(0, 3):
            try:
                stat = top_stats[stat_category][i]["user"]
            except:
                stat  = "None"
            template = template.replace(f"<<TOP{i+1}-{stat_category}>>", stat)
    return template