#include <bits/stdc++.h>
using namespace std;
int a[10000][4];
int main() {
  int n, k, i, j, x, y, t;
  while (~scanf("%d%d", &n, &k)) {
    x = 1, y = 2;
    for (i = 0; i < n; i++) {
      a[i][0] = x++;
      a[i][1] = x++;
      a[i][2] = x, x += 2;
      a[i][3] = x, x += 2;
    }
    printf("%d\n", (x - 2) * k);
    for (i = 0; i < n; i++)
      printf("%d %d %d %d\n", a[i][0] * k, a[i][1] * k, a[i][2] * k,
             a[i][3] * k);
  }
  return 0;
}
