Any integer \(A\) is said to be compatible with another integer \(B\) if \(A|B=A+B\) where \(A|B\) is the Bitwise OR of \(A\) and \(B\).
You are given an array \(A\) of \(N\) integers. You are also given \(Q\) queries where each query has a single integer \(X\). For each query find the sum of all the array elements which are compatible with \(X\).
Input format
- The first line contains a single integer \(N\).
- The second line, contains \(N\) space-separated integers, the array elements.
- The third line contains a single integer \(Q\).
- The next \(Q\) lines contain a single integer each, the value of \(X\).
Output format
Print the answer for each query in a separate line — the sum of all the array elements which are compatible with \(X\).
Constraints
The array is \([1,2,3]\). There are 3 queries.
- In the first query, only \(2\) from the array is compatible with \(1\) so the answer for the first query is \(2\).
- In the second query, only \(1\) from the array is compatible with \(2\) so the answer for the second query is \(1\).
- In the third query, no element from the array is compatible with \(3\) so the answer for the third query is \(0\).
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor