#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  cout << (6 * n - 1) * k << endl;
  int t = k;
  for (int i = 0; i < n; i++) {
    cout << t << ' ' << t + 2 * k << ' ' << t + 4 * k << ' ' << t + 3 * k
         << endl;
    t += 6 * k;
  }
  return 0;
}
