p350.ans1
======================
94 64 77 28

=================
p350.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int m, n;
vector<int> b;

void read() {
    cin >> m;
    b.resize(m);
    cin >> b;
    n = (1 + (int)sqrt(1 + 8 * m)) / 2;
}

void solve() {
    // B holds all M = n(n-1)/2 pairwise XORs of the unknown set A. Since any
    // pairwise XOR is unchanged by XOR-ing every element of A with the same
    // constant, we may fix the first reconstructed element to 0.
    //
    // - present = the multiset of values that appear in B (any reconstructed
    //   pairwise XOR must be one of these).
    //
    // - ans = the elements we have committed to (starting with 0), and span =
    //   the set of XORs of all subsets of ans (its linear span over GF(2)),
    //   used to detect when a new value is XOR-dependent on chosen ones.
    //
    // We scan the B values in order. We accept a candidate value v only when
    // it is not already in span (otherwise it would create a zero-XOR subset)
    // and v ^ a is a value present in B for every a already in ans, i.e. the
    // new pairwise XORs it introduces are all consistent with B. On accepting
    // v we extend span by XOR-ing v into every current span element and append
    // v to ans.

    set<int> present;
    for(int x: b) {
        present.insert(x);
    }

    vector<int> ans = {0}, span = {0};
    set<int> in_span = {0};

    for(int i = 0; i < m; i++) {
        if(in_span.count(b[i])) {
            continue;
        }

        bool ok = true;
        for(int a: ans) {
            if(!present.count(b[i] ^ a)) {
                ok = false;
            }
        }

        if(ok) {
            int sz = span.size();
            for(int x = 0; x < sz; x++) {
                int val = b[i] ^ span[x];
                span.push_back(val);
                in_span.insert(val);
            }

            ans.push_back(b[i]);
        }
    }

    cout << ans << '\n';
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p350.in1
======================
6
30 19 66 13 92 81

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

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