Costliest Data Plan
Practice
2.9 (7 votes)
Bit manipulation
Basic programming
Bit manipulation
Basics of bit manipulation
Bitmask
Problem
87% Success 1318 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Pawan has a finite number of friends, each friend has a unique non-negative number associated with him. (0, 1, 2..)
Pawan plans to host a party and has to send notifications to his friends.
A friend attends the party if he receives at least 1 notification from Pawan.
To send notifications, Pawan buys data plans 
Pawan can send notifications using data plan \(X\) in the following way:
Let's say Data plan \(X\) costs \(Y\).
Then a friend associated with the number \(i\) will receive a notification if and only if the \(i^{th}\) bit in \(Y\) is set.
Now Pawan wonders if he can cut costs. Let him know the maximum cost that he can cut by removing at most 1 data plan and still being able to invite all the friends he could invite earlier

 

Input

Each test contains multiple test cases. The first line contains a single integer t (1≤t≤100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer \(N\) -  the number of data plans 

The second line of each test case contains \(N\) integers a1,a2,…,an — the cost of data plans array.

It is guaranteed that the sum of \(N\) over all test cases does not exceed \(10^5\)

Output

For each test case, print a line containing a single integer – the maximum possible money that Pawan can save (print 0 if no data plan can be removed)

Constraints

\(1 <= T <= 100\)

\(1 <= N <= 10^5\)

\(0<=a_i<=10^9\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
6 votes
Tags:
Basics of Input/OutputBit ManipulationBasic ProgrammingInput/OutputBasics of Bit Manipulation
Points:50
2 votes
Tags:
MathematicsHardOpenApproved
Points:30
17 votes
Tags:
Easy