<|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.

350. XOR-omania
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Professor Vasechkin had a notebook with an outstanding set of non-negative integers A1, A2,..., An. Somehow the most remarkable fact that made this set so outstanding appeared to be the impossibility to find such a subset of two or more elements, that XOR of elements in the subset would equal to zero. One day the professor managed to create a new set of integers B1, B2,..., Bn(n-1)/2 through applying the XOR operations to all pairs of elements of A set. The set B was not written in any particular order. Unfortunately due to his natural absent-mindedness professor lost the A set and now he is very confused but still obliged to ask you of a considerable favor. Please restore the set in accordance with the remaining B set.
Input
The first line describes M — the amount of numbers in B set (1 ≤ M ≤ 100, M = N x (N - 1) / 2 for some number N). The second line describes M numbers — B1, B2,..., BM (0 ≤ Bi ≤ 231 - 1).

Output
Print the A set in one line through a blank. All elements of A should be from 0 to 231 - 1 inclusively. If there are several solutions of the problem, you can choose any of them. It is guaranteed that there exists at least one A set that satisfies the condition.

Example(s)
sample input
sample output
6
30 19 66 13 92 81
94 64 77 28

<|response|>
1. Abridged Problem Statement  
You are given a multiset B of size M = n·(n–1)/2 containing all pairwise XORs Ai⊕Aj (i<j) of an unknown set A = {A1,...,An}, where the Ai are non-negative integers and no non-trivial subset of A has XOR = 0. Recover any valid A (order doesn’t matter).

2. Key Observations  
- XOR on integers is vector addition over GF(2).  
- “No subset XORs to 0” means the Ai are linearly independent vectors in GF(2)^31.  
- If {X1,...,Xn} is a basis, then all Xi⊕Xj (i<j) appear exactly once among the pairwise XORs.  
- Shifting every basis element by the same constant C (i.e., replacing Xi with Xi⊕C) does not change any pairwise XORs. In particular, we can WLOG include 0 in our reconstructed basis (we choose C = X1 to map X1→0).

3. Full Solution Approach  
a. Read M and the list B of size M.  
b. Recover n by solving n·(n–1)/2 = M, i.e. n = (1 + √(1+8M)) / 2.  
c. Insert all values of B into a hash set O for O(1) membership tests.  
d. Initialize:  
   • ans = [0]       // our basis under construction, we force 0 as the first element  
   • pedo = [0]      // list of all XORs of subsets of ans  
   • L = {0}         // set of all values reachable as XORs of a subset of ans  
e. Iterate over each b in B (in arbitrary order):  
   if b ∈ L, skip (b is already spanned).  
   else check “compatibility”: for every y in ans, (b⊕y) must be in O.  
   If the check passes, accept b as a new basis vector:  
     – For each s in the current pedo list, compute t = b⊕s; if t∉L, add t to L and append t to pedo.  
     – Append b to ans.  
   Stop once |ans| = n.  
f. Output the elements of ans. This is a valid reconstruction (it includes zero; you may optionally XOR all elements by any constant to shift away from zero).

Complexity:  
- n ≤ 15 when M ≤ 100.  
- Each candidate b tests O(n) lookups in O.  
- Maintaining pedo and L costs O(2^n·n) overall.  
- Total time is more than enough under the given constraints.

4. C++ Implementation with Detailed Comments  
```cpp
#include <bits/stdc++.h>
using namespace std;

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

    int M;
    cin >> M;
    vector<int> B(M);
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }

    // Recover n from n*(n-1)/2 = M
    int n = (1 + int(sqrt(1.0 + 8.0 * M))) / 2;

    // O: set of all given pairwise XORs, for quick membership test
    unordered_set<int> O;
    O.reserve(M * 2);
    for (int x : B) {
        O.insert(x);
    }

    // ans: our reconstructed basis, start with 0
    vector<int> ans = {0};
    // pedo: list of all XORs of subsets of ans
    vector<int> pedo = {0};
    // L: set of reachable XOR sums (initially just 0)
    unordered_set<int> L;
    L.reserve(1 << n);
    L.insert(0);

    // Try each candidate b in B
    for (int b : B) {
        // If b is already spanned by ans, skip
        if (L.count(b)) continue;

        // Check that adding b preserves known pairwise XORs
        bool valid = true;
        for (int y : ans) {
            if (!O.count(b ^ y)) {
                valid = false;
                break;
            }
        }
        if (!valid) continue;

        // Accept b as a new basis element
        int oldPedoSize = pedo.size();
        for (int i = 0; i < oldPedoSize; i++) {
            int s = pedo[i];
            int t = b ^ s;
            if (!L.count(t)) {
                L.insert(t);
                pedo.push_back(t);
            }
        }
        ans.push_back(b);
        if ((int)ans.size() == n) break;
    }

    // Output the reconstructed set A
    for (int x : ans) {
        cout << x << " ";
    }
    cout << "\n";
    return 0;
}
```

5. Python Implementation with Detailed Comments  
```python
import math
import sys

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

    # Recover n from equation n*(n-1)/2 = M
    n = (1 + math.isqrt(1 + 8*M)) // 2

    # O: set of all given pairwise XORs
    O = set(Bs)

    # ans: our reconstructed basis, force 0 as first element
    ans = [0]
    # pedo: list of XORs of all subsets of current ans
    pedo = [0]
    # L: set of values reachable by XORing a subset of ans
    L = {0}

    # Try each candidate b in Bs
    for b in Bs:
        # If already spanned, skip
        if b in L:
            continue

        # Check compatibility: for every y in ans, must have b^y in O
        valid = True
        for y in ans:
            if (b ^ y) not in O:
                valid = False
                break
        if not valid:
            continue

        # Accept b as a new basis element
        old_pedo = pedo[:]       # snapshot of current subset-XORs
        for s in old_pedo:
            t = b ^ s
            if t not in L:
                L.add(t)
                pedo.append(t)

        ans.append(b)
        if len(ans) == n:
            break

    # Print the answer (contains zero)
    print(" ".join(map(str, ans)))

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