#include <bits/stdc++.h>
using namespace std;
vector<int> ans, tmp;
int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  for (int i = 1;; i++) {
    bool ok = true;
    if (tmp.size() == 0 && i % 3 == 0) continue;
    for (int j = tmp.size() - 1; j >= 0; j--)
      if (gcd(i, tmp[j]) != 1) ok = false;
    if (ok == true) tmp.push_back(i);
    if (tmp.size() == 4) {
      for (int _ = 0; _ < 4; _++) ans.push_back(tmp[_]);
      tmp.clear();
    }
    if (ans.size() == 4 * N) break;
  }
  printf("%I64d\n", K * 1LL * ans.back());
  for (int i = 0; i < N * 4; i++) {
    for (int _ = 0; _ < 4; _++)
      printf("%I64d%c", K * 1LL * ans[i + _], " \n"[_ == 3]);
    i += 3;
  }
  return 0;
}
