#include <bits/stdc++.h>
using namespace std;
long long N, M, ans;
inline void read(register long long &x) {
  x = 0;
  register char c = getchar();
  register bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (f) x = -x;
}
int main() {
  read(N);
  read(M);
  printf("%d\n", M * (6 * N - 1));
  for (int i = 1; i <= N; i++) {
    int x = (i - 1) * 6 + 1;
    printf("%d ", (x)*M);
    printf("%d ", (1 + x) * M);
    printf("%d ", (2 + x) * M);
    printf("%d\n", (4 + x) * M);
  }
}
