<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

275. To xor or not to xor
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



The sequence of non-negative integers A1, A2, ..., AN is given. You are to find some subsequence Ai1, Ai2, ..., Aik (1 <= i1 < i2 < ... < ik <= N) such, that Ai1 XOR Ai2 XOR ... XOR Aik has a maximum value.

Input
The first line of the input file contains the integer number N (1 <= N <= 100). The second line contains the sequence A1, A2, ..., AN (0 <= Ai <= 10^18).

Output
Write to the output file a single integer number -- the maximum possible value of Ai1 XOR Ai2 XOR ... XOR Aik.

Sample test(s)

Input
3
11 9 5

Output
14
Author:	Michael R. Mirzayanov
Resource:	ACM ICPC 2004-2005, NEERC, Southern Subregional Contest
Date:	Saratov, October 7, 2004

<|response|>
1. Abridged Problem Statement  
Given N non-negative integers A₁…Aₙ (1 ≤ N ≤ 100, 0 ≤ Aᵢ ≤ 10¹⁸), choose any subsequence (i.e. any subset) of them so that the bitwise XOR of its elements is as large as possible. Output that maximum XOR value.

2. Key Observations  
- Bitwise XOR over {0,1}⁶¹ forms a vector space over GF(2).  
- Any subset XOR is a linear combination (over GF(2)) of the input bit-vectors.  
- If we extract a basis of these vectors (so that each basis vector has a unique highest set bit), then any achievable XOR is a XOR-combination of a subset of basis vectors.  
- To maximize the resulting number, we can greedily try to set high bits first by iterating through basis vectors in descending order of their highest bit.

3. Full Solution Approach  
Step A: Build a XOR-basis  
  • Maintain an array `base[0…60]`, where `base[k]` holds a basis vector whose highest set bit is k, or 0 if none.  
  • To insert a new number x:  
    – For bit k from 60 down to 0:  
      · If x’s k-th bit is 0, skip.  
      · Else if `base[k]` is 0, store `base[k] = x` and stop.  
      · Else replace x ← x XOR base[k] and continue.  
    – If x becomes 0, it is linearly dependent on the existing basis and is discarded.  

Step B: Compute the maximum subset XOR  
  • Initialize `ans = 0`.  
  • For k from 60 down to 0:  
    – If `(ans XOR base[k]) > ans`, then do `ans ^= base[k]`.  
  • At the end, `ans` is the maximum XOR one can achieve.

Time Complexity:  
  • Building the basis: O(N·B), B=61.  
  • Querying max XOR: O(B).  
  This is efficient for N ≤ 100.

4. C++ Implementation with Detailed Comments  

```cpp
#include <bits/stdc++.h>
using namespace std;

// We support 61 bits (0…60) since A_i ≤ 10^18 < 2^60.
static const int MAXB = 61;
long long baseVec[MAXB];  
// baseVec[k] will store a vector whose highest set bit is k, or 0 if none.

// Insert x into the XOR-basis
void addToBasis(long long x) {
    // Try to eliminate bits from highest to lowest
    for (int k = MAXB - 1; k >= 0 && x; --k) {
        // Check if bit k is set in x
        if ((x >> k & 1LL) == 0) 
            continue;
        // If we have no basis vector with top bit k, store x here
        if (baseVec[k] == 0) {
            baseVec[k] = x;
            return;
        }
        // Otherwise, eliminate bit k from x
        x ^= baseVec[k];
    }
    // If x reduces to 0, it is dependent and not added
}

// Compute the maximum XOR achievable from the basis
long long getMaxXor() {
    long long ans = 0;
    // Greedily try to set high bits in ans
    for (int k = MAXB - 1; k >= 0; --k) {
        if ((ans ^ baseVec[k]) > ans) {
            ans ^= baseVec[k];
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    // Read each number and add it to the basis
    for (int i = 0; i < N; ++i) {
        long long x;
        cin >> x;
        addToBasis(x);
    }

    // Output the maximum subset XOR
    cout << getMaxXor() << "\n";
    return 0;
}
```

5. Python Implementation with Detailed Comments  

```python
import sys

def add_to_basis(x, basis):
    """
    Insert integer x into the XOR-basis.
    'basis' is a dict mapping bit-position -> basis vector.
    """
    # Try to eliminate bits from 60 down to 0
    for bit in range(60, -1, -1):
        if ((x >> bit) & 1) == 0:
            continue
        # If no vector anchored at this bit, store x
        if bit not in basis:
            basis[bit] = x
            return
        # Otherwise eliminate that bit
        x ^= basis[bit]
    # If x becomes 0, it's linearly dependent and we discard it

def get_max_xor(basis):
    """
    Given the constructed basis, build the maximum possible XOR
    by greedily including basis vectors that increase the value.
    """
    ans = 0
    # Try to improve ans by XOR-ing with basis vectors from high to low
    for bit in sorted(basis.keys(), reverse=True):
        candidate = ans ^ basis[bit]
        if candidate > ans:
            ans = candidate
    return ans

def main():
    data = sys.stdin.read().split()
    n = int(data[0])
    nums = list(map(int, data[1:]))

    # Build the basis as a dict bit->vector
    basis = {}
    for x in nums:
        add_to_basis(x, basis)

    # Compute and print the result
    print(get_max_xor(basis))

if __name__ == "__main__":
    main()
```