#include <bits/stdc++.h>
using namespace std;
long long n, k;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  cout << (6 * n - 1) * k << '\n';
  for (long long i = 0; i < n; ++i) {
    long long x = 1 + 6 * i;
    cout << x * k << ' ' << (x + 2) * k << ' ' << (x + 4) * k << ' ';
    if (x % 3)
      cout << (x + 3) * k << '\n';
    else
      cout << (x + 1) * k << '\n';
  }
}
