#include <bits/stdc++.h>
class B {
 public:
  int gcd(int a, int b) {
    if (!b) return a;
    return gcd(b, a % b);
  }
  void solve(std::istream& in, std::ostream& out) {
    int n, k;
    in >> n >> k;
    out << (6 * n - 1) * k << "\n";
    int lastCh = 0;
    int lastNech = -1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j) {
        lastNech += 2;
        out << lastNech * k << " ";
      }
      while (true) {
        lastCh += 2;
        if (lastCh % 3 == 0) continue;
        if (gcd(lastCh, lastNech) != 1 || gcd(lastCh, lastNech - 2) != 1 ||
            gcd(lastCh, lastNech - 4) != 1)
          continue;
        out << lastCh * k << "\n";
        break;
      }
    }
  }
};
int main() {
  B solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
