def version_sum(packet: dict) -> int:
    """
    Recursively calculate the sum of version numbers in packet.
    """
    return packet["version"] + sum(version_sum(sub) for sub in packet["subpackets"])