from typing import Counter


def label_sizes(pages):
    """
    pages: list(Page)

    returns: dict[str: int]

    For all labels with landings in the page list, assign each label a "size",
    from 1 to 5, based on the total number of pages with that label. (A larger
    size means the label contains more pages.)
    """

    # Note: this is basically calculating a 5-bin histogram, but I didn't want
    # to add another dependency like numpy just to do this.

    labels = [page["landing_for"] for page in pages if "landing_for" in page]
    label_counts = Counter()
    for page in pages:
        if "labels" in page:
            label_counts.update(page["labels"])

    if not label_counts:
        return {}

    total_labels = len(label_counts.keys())
    label_sizemap = {}
    size = 5
    for i, (label, count) in enumerate(label_counts.most_common()):
        if 1 - (i / total_labels) < (size - 1) / 5:
            size -= 1
        label_sizemap[label] = size

    return label_sizemap