Friendship Test

0

0 votes
Medium
Problem

Sunpriya and Pranjali are best friends. But a guy called Bharti ji has some doubt on their friendship. He wanted to test them. So he designed a problem which states that there are N numbers, they can choose a pair of two numbers and apply AND operation on two numbers. They need to tell the maximum sum of ANDs possible by selecting distinct (by index) pairs. For example numbers are [10, 10, 20] the possible distinct pairs are {10(first position),10(second position)}, {10(first position), 20}, {10(second position),20} and maximum sum of ANDs possible is 10 by selecting first pair only.
If they tell the correct answer Bharti ji will give them that many choclates. Since they are best friends they will only accept choclates if they can divide it between themselves, like in above example they will accept 10 choclates, otherwise not.

Input
The first line of input consists of the integer N. 
The second line contains N numbers.

Output
First line - maximum sum possible.
Second line - "YES" if Sunpriya and Pranjali can divide the choclates otherwise "NO".   

Constraints
1 <= N <= 10^5
0 <= value of each number <= 10^6

Note :- Pairs are unordered.

Sample Input
5
1 2 3 4 5 
Sample Output
9
NO
Time Limit: 1
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?