#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main(void) {
  int n, k;
  cin >> n >> k;
  int quad[n][4];
  int p = 1;
  for (int i = 0; i < n; i++) {
    if (p % 2 == 0) p++;
    quad[i][0] = p++;
    int prev = p;
    quad[i][1] = p++;
    quad[i][2] = p++;
    while (gcd(p, prev) > 1 || gcd(p, prev + 1) > 1 || gcd(p, prev - 1) > 1)
      p++;
    quad[i][3] = p++;
  }
  cout << 1LL * quad[n - 1][3] * k << '\n';
  for (int i = 0; i < n; i++)
    cout << 1LL * quad[i][0] * k << ' ' << 1LL * quad[i][1] * k << ' '
         << 1LL * quad[i][2] * k << ' ' << 1LL * quad[i][3] * k << '\n';
  return 0;
}
