#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (a) {
    swap(b %= a, a);
  }
  return b;
}
int n, k;
struct st {
  int el[4];
};
bool test(const st& el, int c) {
  for (int i = 0; i < c; i++) {
    if (gcd(el.el[i], el.el[c]) != 1) return false;
  }
  return true;
}
int main() {
  cin >> n >> k;
  list<int> tmp;
  int mx = 1;
  vector<st> res;
  int cur = 1;
  int last = 2;
  for (int step = 1; step <= n; ++step) {
    st el;
    el.el[0] = cur;
    cur += 2;
    el.el[1] = cur;
    cur += 2;
    el.el[2] = cur;
    mx = cur;
    cur += 2;
    while (true) {
      el.el[3] = (last);
      last += 2;
      if (test(el, 3)) {
        mx = max(mx, el.el[3]);
        break;
      }
    }
    res.push_back(el);
  }
  cout << k * mx << '\n';
  for (int i = 0; i < res.size(); i++) {
    for (int j = 0; j < 4; j++) cout << res[i].el[j] * k << ' ';
    cout << '\n';
  }
  return 0;
}
