#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, k, j = 0;
  cin >> n >> k;
  cout << (6 * n - 1) * k << "\n";
  for (int i = 1; i <= n; i++) {
    for (; j <= (3 * i - 1); j++) cout << (2 * j + 1) * k << " ";
    cout << 2 * (j - 1) * k << "\n";
  }
  return 0;
}
