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