Max AND Sum of Array

Assign each element of an array to one of numSlots slots. Each slot can hold at most two elements. The value of assigning an element to a slot is the bitwise AND of the element and the slot number. Maximize the total sum.

Examples
Input: [[1,2,3,4,5,6],3]
Output: 9
Hints

Max AND Sum of Array

Assign each element of an array to one of numSlots slots. Each slot can hold at most two elements. The value of assigning an element to a slot is the bitwise AND of the element and the slot number. Maximize the total sum.