#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v;
  long long int j = 1;
  while (v.size() < 3 * n) {
    v.push_back(j);
    j += 2;
  }
  cout << v[v.size() - 1] * k << "\n";
  long long int cur = 2;
  long long int t1, t2, t3;
  for (int i = 0; i < v.size(); i += 3) {
    cout << v[i] * k << " " << v[i + 1] * k << " " << v[i + 2] * k << " "
         << (v[i] + 1) * k << "\n";
  }
}
