#include using namespace std; uint64_t rng() { static uint64_t x = 1; x ^= x << 9; return x ^= x >> 7; } int main() { clock_t start = clock(); int n, m; cin >> n >> m; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector used(n), best_used(n); int score = 0, best = 0; for (int i = 0; i < m; i++) { used[i] = true; score ^= a[i]; } best_used = used; best = score; while (clock() - start < 1.4 * CLOCKS_PER_SEC) { int x = rng() % n; for (int i = 0; i < n; i++) { int y = i; if (used[x] == used[y]) continue; swap(used[x], used[y]); score ^= a[x] ^ a[y]; if (score > best) { best_used = used; best = score; } } } int count = m; for (int i = 0; i < n; i++) { if (best_used[i]) { cout << a[i]; m--; if (m) cout << ' '; } } cout << endl; }