#B3930. Maximum Compatibility
Maximum Compatibility
Maximum Compatibility
We are given (N) ingredients numbered from (0) to (N-1). Each ingredient (i) has an associated tastiness value (a_i). When combining two different ingredients with tastiness (x) and (y), their compatibility is defined as (x ;\text{and}; y) where the operator (\text{and}) denotes the bitwise AND operation.
For example, to compute (12 ;\text{and}; 6), write them in binary as (1100) and (0110) respectively, then perform the bitwise AND to obtain (0100) which is (4) in decimal.
Your task is to find the two distinct ingredients that yield the highest compatibility value and output that value.
inputFormat
The input consists of two lines. The first line contains an integer (N) denoting the number of ingredients. The second line contains (N) integers (a_0, a_1, \dots, a_{N-1}), where (a_i) represents the tastiness of the (i)-th ingredient.
outputFormat
Output a single integer representing the maximum compatibility (bitwise AND) value that can be achieved by any pair of distinct ingredients.
sample
3
12 6 8
8