#include <bits/stdc++.h>
using namespace std;
queue<long long> q;
int main() {
  long long n, k, i, j;
  while (scanf("%lld %lld", &n, &k) != EOF) {
    long long odd = -1, ans;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= 4; j++) {
        if (j == 2) {
          q.push(odd + 1);
        } else {
          odd += 2;
          q.push(odd);
          ans = odd;
        }
      }
    }
    printf("%lld\n", ans * k);
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= 4; j++) {
        long long x = q.front();
        q.pop();
        if (j > 1) printf(" ");
        printf("%lld", x * k);
      }
      printf("\n");
    }
  }
  return 0;
}
