#P2326. Maximum Apple Mass

    ID: 15600 Type: Default 1000ms 256MiB

Maximum Apple Mass

Maximum Apple Mass

Akn is fascinated by a catchy song and buys a bunch of apples to practice the dance moves accompanying it. He discovers that if he sings the song while colliding two complete apples (i.e. original apples), they merge into a new big apple. However, this big apple cannot participate in any further merging due to its changed internal structure.

Moreover, when two apples merge, the mass of the resulting apple becomes the bitwise AND, denoted as \(a\,\&\,b\), of the masses of the two original apples. Akn wants to gift his friend one such big apple and wishes its mass to be as high as possible. Given the masses of the apples, determine the maximum possible mass of a merged apple (obtained by applying the bitwise AND operation on a pair of distinct original apples).

inputFormat

The input consists of two lines. The first line contains a single integer \(n\) (with \(n \ge 2\)) representing the number of apples. The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) where each \(a_i\) denotes the mass of an apple.

outputFormat

Output a single integer – the maximum mass of a merged apple that can be obtained by performing the bitwise AND operation on two distinct apples.

sample

2
1 2
0