def rules_cidrs_and_security_groups(rules):
    """
    Return a dict with keys "cidrs" and "sgids" 
    from a list of security group rules.

    :param rules: list of security group rules
    :type rules: list
    :return: Dict with keys "cidrs" and "sgids"
    :rtype: dict
    """
    cidrs = set(
        ip_range["CidrIp"]
        for rule in rules
        for ip_range in rule["IpRanges"]
    )
    sgids = set(
        group_pair["GroupId"]
        for rule in rules
        for group_pair in rule["UserIdGroupPairs"]
    )
    return {"cidrs": cidrs, "sgids": sgids}