#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
  x = 0;
  Tp f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = x * f;
}
template <typename Tp>
inline void write(Tp x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 | 48);
}
int n, k;
int main() {
  read(n), read(k);
  write((6 * n - 1) * k);
  puts("");
  int cur = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4; j++) {
      printf("%d ", cur * k);
      if (j == 1)
        cur++;
      else if (j == 2)
        cur++;
      else
        cur += 2;
    }
    printf("\n");
  }
  return 0;
}
