from collections import Counter


def select_dates_by_mention_count(articles, num_dates, start_date, end_date):
    """
    Returns the most common dates mentioned in all of the the given sentences.
    
    :param articles: A list of articles to select dates from, following the standard format
    (i.e. each sentence is a dict with 'text' and 'mentioned_dates').
    :param num_dates: How many dates to return at most.
    :param start_date: The first date to consider (any dates before this are not returned).
    :param end_date: The last date to consider (any dates after this are not returned).
    :return: A list of dates.
    """

    # TODO return all dates (not just num_dates), so if during sentence selection/summarization a date has no
    #  sentences, we have substitute dates
    #  (and implement that subsitution)
    mention_count = Counter({})
    for article in articles:
        for sentence in article['sentences']:
            for mentioned_date in sentence['mentioned_dates']:
                if start_date <= mentioned_date <= end_date:
                    mention_count[mentioned_date] += 1
    return sorted([item[0] for item in mention_count.most_common()][:num_dates])
