#include using namespace std; // Optimization stuff inline void debugMode() { #ifndef ONLINE_JUDGE freopen("debug.in", "r", stdin); #endif // ONLINE_JUDGE } inline void optimizeIt() { ios::sync_with_stdio(false); cin.tie(NULL); } // End optimization stuff inline double ABS(const int &x) { return max(x, -x); } inline bool isPrime(const long long int &x) { if(x == 1) return false; for(long long int d = 2; d * d <= x; d++) { if(x % d == 0) return false; } return true; } inline int GCD(int a, int b) { while(b) { int r = a % b; a = b; b = r; } return a; } typedef long long int ll; typedef long double ld; const int NMax = 5000 + 5; const int LIM = 1e5; const int MOD = 1e9 + 7; vector < pair < int, int > > gen; void Back(const int &lvl, const int &n, const int &noOne, const int value) { if(lvl == n) { gen.push_back({value + (1 << lvl), noOne}); return; } Back(lvl + 1, n, noOne, value); Back(lvl + 1, n, noOne + 1, value + (1 << lvl)); } inline bool cmp(const pair < int, int > &a, const pair < int, int > &b) { return (a.second > b.second); } int main(){ debugMode(); optimizeIt(); int k; cin >> k; vector < int > nums; nums.push_back(1); int ans = 1; for(int p = 1; ans < k; p++) { if(ans + (1 << p) <= k) { nums.push_back((1 << p)); ans += (1 << p); } else { Back(0, p, 0, 0); sort(gen.begin(), gen.end(), cmp); for(int i = 0; i < k - ans; i++) { nums.push_back(gen[i].first); } ans = k; } } cout << nums.size() << "\n"; for(auto const &it: nums) cout << it << " "; return 0; }