#include using Int = int64_t; using UInt = uint64_t; using C = std::complex; #define rep(i, n) for(Int i = 0; i < (Int)(n); ++i) #define guard(x) if( not (x) ) continue; #ifndef LOCAL_ #define fprintf if( false ) fprintf #endif const double timeLimit = 1.2; struct Timer { static const uint64_t ClocksPerSecond = 2600000000; bool valid; uint64_t beginTime; uint64_t rdtsc() { uint64_t u, l; __asm__ volatile ("rdtsc" : "=a" (l), "=d" (u)); return ((u << 32) | l); } void start() { beginTime = rdtsc(); valid = true; } double getTime() { uint64_t now = rdtsc(); return (double)(now - beginTime) / ClocksPerSecond; } void stop() { valid = false; } } globalTimer; struct Solver { Int n, m; std::vector xs; void read() { std::cin >> n >> m; xs.clear(); xs.resize(n); rep(i,n) std::cin >> xs[i]; } void gen(int seed) { std::mt19937 mt(seed); std::uniform_int_distribution<> distN(5,100000); n = distN(mt); std::uniform_int_distribution<> distM(1,n); m = distM(mt); std::uniform_int_distribution<> distX(1,1000000); std::vector checked(1000001); xs.clear(); rep(i,n) { Int x; do { x = distX(mt); } while( checked[x] ); xs.emplace_back(x); } } Int best = 0; std::vector ans; std::vector ys,zs; void solve() { for(Int i = 0; i < m; ++i) { ys.emplace_back(i); } for(Int i = m; i < n; ++i) { zs.emplace_back(i); } Int v = 0; for(Int i : ys) { v ^= xs[i]; } fprintf(stderr, "v=%ld\n", v); std::mt19937 mt(314159); std::uniform_int_distribution<> distI(0,m-1); std::uniform_int_distribution<> distK(0,n-m-1); std::uniform_real_distribution<> distP(0.0,1.0); for(Int iter = 0; ; ++iter) { if( globalTimer.getTime() > timeLimit ) break; Int i = distI(mt); Int k = distK(mt); Int nv = v ^ xs[ys[i]] ^ xs[zs[k]]; double prob = v < nv ? 1.0 : exp(-1.0/f(globalTimer.getTime()/timeLimit)); if( distP(mt) <= prob ) { v = nv; std::swap(ys[i], zs[k]); fprintf(stderr, "nv = %ld\n", nv); } if( best < v ) { ans = ys; } } } double f(double x) { double a = 1.0; return -a * x + a; } void write() { printf("%ld", xs[ans[0]]); for(Int i = 1; i < m; ++i) { printf(" %ld", xs[ans[i]]); } putchar('\n'); } }; int main() { globalTimer.start(); Solver solver; solver.read(); //solver.gen(2); solver.solve(); solver.write(); }