#include <bits/stdc++.h>
int main() {
  int n, k, b = 1;
  scanf("%i %i", &n, &k);
  printf("%i\n", (n * 6 - 1) * k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) printf("%i ", b * k), b += 2;
    if (b % 3)
      printf("%i\n", (b - 3) * k);
    else
      printf("%i\n", (b - 1) * k);
  }
  return 0;
}
