In the Combinatorial Lab of Prime City, the Researcher uses bitmask inclusion-exclusion to count elements satisfying at least one of several properties. Each property is represented by a bit in a mask, and the researcher iterates over all 2^k subsets of properties. "For each bitmask subset, compute the count of elements satisfying all properties in the subset," the Researcher says. "Add counts for odd-sized subsets, subtract for even-sized subsets (excluding the empty set). This gives the count of elements satisfying at least one property." Given k properties and an array of N elements where each element has a bitmask of satisfied properties, count how many elements satisfy at least one property. Each element's property mask is given as an integer. Constraints: 1 <= N <= 10^5, 1 <= k <= 20, 0 <= mask[i] < 2^k Input: 5 3 1 2 4 3 7 Output: 5 Input: 3 2 0 0 0 Output: 0
Constraints:
1 <= N <= 10^5, 1 <= k <= 20, 0 <= mask[i] < 2^k
Tags:
