#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int MOD = 1e9 + 7;
const int N = 0;
int n, k;
int main() {
  scanf("%d%d", &n, &k);
  printf("%d\n", k * (6 * n - 1));
  int p = 1;
  for (int i = 1; i <= n; i++) {
    printf("%d %d %d ", k * p, k * (p + 2), k * (p + 4));
    if ((p + 4) % 3 == 0)
      printf("%d\n", k * (p + 3));
    else
      printf("%d ", k * (p + 1));
    printf("\n");
    p += 6;
  }
}
