#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!a) return b;
  if (!b) return a;
  return gcd(b, a % b);
}
int n, k;
long long next(long long prev, long long a, long long b, long long c) {
  prev += 2;
  while (gcd(prev * k, a * k) != k || gcd(prev * k, b * k) != k ||
         gcd(prev * k, c * k) != k)
    prev += 2;
  return prev;
}
int main() {
  scanf("%d %d", &n, &k);
  long long a2 = 1;
  printf("%d\n", (6 * (n - 1) + 5) * k);
  long long p = 0;
  for (long long i = (0); i < (n); ++i) {
    p = next(p, a2, a2 + 2, a2 + 4);
    printf("%lld %lld %lld %lld\n", p * k, a2 * k, (a2 + 2) * k, (a2 + 4) * k);
    a2 += 6;
  }
  return 0;
}
