#include <bits/stdc++.h>
using namespace std;
long n, k, bad[1 << 20];
vector<long> vec[1 << 20];
long cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    vec[i].push_back(6 * i - 4);
    vec[i].push_back(6 * i - 5);
    vec[i].push_back(6 * i - 3);
    vec[i].push_back(6 * i - 1);
  }
  cout << vec[n].back() * k << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      if (j) cout << " ";
      cout << vec[i][j] * k;
    }
    cout << endl;
  }
  cin.get();
  cin.get();
  return 0;
}
