#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> result;
  long long temp;
  int i;
  for (i = 0; i < n; i++) {
    temp = 6 * i + 1;
    result.push_back(temp * k);
    temp = 6 * i + 2;
    result.push_back(temp * k);
    temp = 6 * i + 3;
    result.push_back(temp * k);
    temp = 6 * i + 5;
    result.push_back(temp * k);
  }
  cout << result[result.size() - 1] << "\n";
  for (i = 0; i < result.size(); i++) {
    if (i % 4 == 0 && i != 0) cout << "\n";
    cout << result[i] << " ";
  }
  cout << "\n";
  return 0;
}
