def best_ss_to_expand_greedy(new_set, supersets, ruleWeights, max_mask):
    """ Returns index of the best superset to expand, given the rule
        weights and the maximum allowed mask size. -1 if none possible.
    """

    bestSuperset = None
    bestCost = float('inf')

    new_set = set(new_set)

    for superset in supersets:
        # if this merge would exceed the current mask size limit, skip it
        if len(new_set.union(superset)) > max_mask:
            continue

        # the rule increase is the sum of all rules that involve each part added to the superset
        cost = sum(ruleWeights[part] for part in new_set.difference(superset))
        if cost < bestCost:
            bestCost = cost
            bestSuperset = superset

    # if no merge is possible, return -1
    if bestSuperset == None:
        return -1

    return supersets.index(bestSuperset)