#include <bits/stdc++.h>
using namespace std;
int res[10004][4];
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  int n = 0, k;
  scanf("%d%d", &n, &k);
  int mx = 1, m2 = 0;
  for (int t = 0; t < n; t++) {
    res[t][0] = mx;
    mx += 2;
    res[t][1] = mx;
    mx += 2;
    res[t][2] = mx;
    mx += 2;
    if (gcd(res[t][0], res[t][0] + 3) == 1 &&
        gcd(res[t][1], res[t][0] + 3) == 1 &&
        gcd(res[t][2], res[t][0] + 3) == 1) {
      res[t][3] = res[t][0] + 1;
    } else if (gcd(res[t][0], res[t][0] + 3) == 1 &&
               gcd(res[t][1], res[t][0] + 3) == 1 &&
               gcd(res[t][2], res[t][0] + 3) == 1) {
      res[t][3] = res[t][0] + 3;
    }
  }
  mx = max(mx - 2, m2);
  printf("%d\n", mx * k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) printf("%d ", res[i][j] * k);
    printf("\n");
  }
  return 0;
}
