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