#include <bits/stdc++.h>
using namespace std;
int conversion(string p) {
  int o;
  o = atoi(p.c_str());
  return o;
}
string toString(int h) {
  stringstream ss;
  ss << h;
  return ss.str();
}
string toStringLong(long long h) {
  stringstream ss;
  ss << h;
  return ss.str();
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * (b / gcd(a, b))); }
int main() {
  int n, k;
  cin >> n >> k;
  int tam[4];
  memset(tam, 0, sizeof tam);
  tam[0] = k;
  cout << 5 * k + (6 * k) * (n - 1) << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 4; j++) {
      if (j == 1) {
        tam[j] = tam[j - 1] + k * 2;
      } else {
        tam[j] = tam[j - 1] + k;
      }
    }
    cout << tam[0] << " " << tam[1] << " " << tam[2] << " " << tam[3] << endl;
    tam[0] = tam[3] + k * 2;
  }
}
