#include <bits/stdc++.h>
using namespace std;
int II() {
  int q;
  scanf("%d", &q);
  return q;
}
long long LII() {
  long long q;
  scanf("%lld", &q);
  return q;
}
void solve() {
  long long N, M;
  cin >> N >> M;
  vector<long long> v;
  for (long long i = 0; i < 35; i++) {
    if (((1LL << i) & N)) v.push_back(i);
  }
  vector<long long> pa;
  long long cnt = 1;
  for (auto it : v) {
    long long q = it;
    while (q--) pa.push_back(cnt);
    cnt += M + 1;
  }
  for (long long i = 0; i < v.size(); i++) {
    pa.push_back(cnt);
    cnt += M + 1;
  }
  cout << pa.size() << endl;
  for (auto it : pa) {
    cout << it << " ";
  }
  cout << endl;
}
int32_t main() {
  long long tt;
  tt = 1;
  long long cas = 1;
  while (tt--) {
    solve();
  }
}
