#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class X>
void debug(vector<X>& v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
int main() {
  int i, j, k, T, cas = 0, N, M, a, b, c;
  cin >> N >> k;
  j = 1;
  cout << (5 + ((N - 1) * 6)) * k << endl;
  for (i = 1; i <= N; i++) {
    cout << j * k << " " << (j + 2) * k << " " << (j + 4) * k << " "
         << (j + 1) * k << endl;
    j += 6;
  }
  return 0;
}
