To compute , consider bit of mask:
If bit is in mask: submasks must also have bit . So . Nothing new to add.
If bit is in mask: submasks can have bit as or . Those with bit contribute . Those with bit contribute (flip bit off). Combined: when bit is set.