Under construction

Still being built. Things may change

Add One

Time limit2sMemory limit1024 MB

Summary
Given n integers below 2^60, merge them all by XOR while adding one to a single group exactly once. Find the largest possible final value.
Level

Medium7 of 10

Topics
Bit manipulation, Math
Solved
No attempts yet

Problem

You are given nn integers a1,a2,…,ana_1, a_2, \ldots, a_n. You must perform the following operation exactly n−1n-1 times.

  • Choose two numbers xx and yy in the sequence, remove them, and add a number with the value x⊕yx \oplus y.

This alone is boring, so at any moment you may choose one number and add one to it. You must perform this add-one operation exactly once.

Eventually only one number remains. Maximize it and print the maximum value.

Input

The first line contains a single integer nn (1≤n≤1061 \le n \le 10^6).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2600 \le a_i < 2^{60}).

Output

Print a single line containing the maximum value of the remaining number.

Hint

In the first example, the optimal strategy is:

  • Choose 1 and 2: [1, 2, 1, 2] to [1, 2, 3]
  • Choose 1 and 2: [1, 2, 3] to [3, 3]
  • Add one to the number 3: [3, 3] to [3, 4]
  • Choose 3 and 4: [3, 4] to [7]

Examples3

  1. Example 1

    Input
    4
    1 2 1 2
    
    Expected output
    7
    
  2. Example 2

    Input
    5
    1 2 3 4 5
    
    Expected output
    14
    
  3. Example 3

    Input
    6
    1 2 4 7 15 31
    
    Expected output
    47