#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int an[40005];
void init() {
  for (int i = 0; i < 10000; i++) {
    an[4 * i + 0] = 6 * i + 1;
    an[4 * i + 1] = 6 * i + 3;
    an[4 * i + 2] = 6 * i + 5;
    an[4 * i + 3] = 6 * i + 2;
  }
}
int main() {
  int n, k;
  init();
  while (~scanf("%d%d", &n, &k)) {
    printf("%d\n", an[4 * n - 2] * k);
    for (int i = 0; i < n; i++) {
      int tp = 4 * i;
      printf("%d %d %d %d\n", an[4 * i] * k, an[4 * i + 1] * k,
             an[4 * i + 2] * k, an[4 * i + 3] * k);
    }
  }
  return 0;
}
