#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e4 + 10;
vector<ll> v[maxn];
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  ll t = 1;
  for (int i = 0; i < n; ++i) {
    ll tt = t;
    for (; t < tt + 3; ++t) {
      v[i].push_back(t * k);
    }
    t++;
    v[i].push_back(t * k);
    t += 2;
  }
  cout << v[n - 1][3] << endl;
  for (int i = 0; i < n; ++i) {
    for (ll j : v[i]) {
      cout << j << " ";
    }
    cout << endl;
  }
  return 0;
}
