#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const bool db = false;
int n, k;
vector<int> v;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  scanf("%d%d", &n, &k);
  int cur = 1;
  for (int i = 0; i < n; ++i) {
    v.push_back(cur);
    v.push_back(cur + 1);
    v.push_back(cur + 2);
    v.push_back(cur + 4);
    cur += 6;
  }
  cout << v.back() * k << endl;
  for (int i = 0; i < n; ++i) {
    for (int j = 4 * i; j < 4 * i + 4; ++j) {
      cout << v[j] * k << " ";
    }
    cout << endl;
  }
  cin.get();
  cin.get();
  return 0;
}
