#include <bits/stdc++.h>
using namespace std;
int n, k;
struct node {
  int a[4];
  node() {}
  node(int w, int x, int y, int z) {
    a[0] = w;
    a[1] = x;
    a[2] = y;
    a[3] = z;
  }
};
vector<node> v;
int m = k, ans;
int main() {
  cin >> n >> k;
  m = k;
  for (int i = 0; i < n; i++) {
    v.push_back(node(m, k + m, 2 * k + m, 4 * k + m));
    ans = 4 * k + m;
    m = 5 * k + m;
    if (m % 2 == 0) m += k;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) cout << v[i].a[j] << " ";
    cout << endl;
  }
  return 0;
}
