# slow_case.py — educational Python 3.14 example

def totals_by_tag(records):
    tags = sorted({record["tag"] for record in records})
    return {
        tag: sum(record["size"] for record in records if record["tag"] == tag)
        for tag in tags
    }


def build_records(count=4000, groups=40):
    if count < 0 or groups < 1:
        raise ValueError("count must be non-negative and groups must be positive")
    return [
        {"tag": f"tag-{i % groups:02d}", "size": (i % 5) + 1}
        for i in range(count)
    ]


if __name__ == "__main__":
    data = build_records()
    totals_by_tag(data)
