#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 2e9 + 5;
double PI = 3.14159265358979323846;
void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  cout << (6 * (n - 1) + 5) * k << "\n";
  for (int a = 0; a < n; a++) {
    array<int, 4> x = {6 * a + 1, 6 * a + 2, 6 * a + 3, 6 * a + 5};
    for (auto xx : x) {
      cout << k * xx << " ";
    }
    cout << "\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
