n,m=gets.split.map(&:to_i) a=gets.split.map(&:to_i) def popcnt(x) x_ = x x_ = (x_ & 0x55555555) + (x_>>1 & 0x55555555); x_ = (x_ & 0x33333333) + (x_>>2 & 0x33333333); x_ = (x_ & 0x0f0f0f0f) + (x_>>4 & 0x0f0f0f0f); x_ = (x_ & 0x00ff00ff) + (x_>>8 & 0x00ff00ff); x_ = (x_ & 0x0000ffff) + (x_>>16 & 0x0000ffff); return x_ end as = a.sort_by { popcnt(_1) } h = a[0..(m / 2)] t = a[-1..(m / -2 - (m % 2))] puts (h + t) * " "