p350.cpp
======================
#include <bits/stdc++.h>
#define endl '\n'

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

using namespace std;
template<class T, class T2>
inline void chkmax(T& x, const T2& y) {
    if(x < y) {
        x = y;
    }
}
template<class T, class T2>
inline void chkmin(T& x, const T2& y) {
    if(x > y) {
        x = y;
    }
}
const int MAXN = (1 << 10);

int m, n;
int B[MAXN], a0;

/// 2 * m = (n - 1) * n
/// n * n - n - 2 * m = 0
/// D = 1 + 8 * m
/// n = (1 + sqrt(1 + 8 * m)) / 2

void read() {
    cin >> m;
    for(int i = 0; i < m; i++) {
        cin >> B[i];
    }
    n = (1 + sqrt(1 + 8 * m)) / 2;
}

map<int, bool> L, O;

void solve() {
    for(int i = 0; i < m; i++) {
        O[B[i]] = 1;
    }

    vector<int> ans, pedo;
    ans.push_back(0);
    pedo.push_back(0);
    L[0] = 1;

    for(int i = 0; i < m; i++) {
        if(!L.count(B[i])) {
            bool ok = 1;
            for(int x = 0; x < ans.size(); x++) {
                if(!O.count(B[i] ^ ans[x])) {
                    ok = 0;
                }
            }

            if(ok) {
                for(int x = 0, SZ = pedo.size(); x < SZ; x++) {
                    L[B[i] ^ pedo[x]] = 1, pedo.push_back(B[i] ^ pedo[x]);
                }
                ans.push_back(B[i]);
            }
        }
    }

    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}

=================
statement.txt
======================
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

=================
