#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int a[10010][4];
int main() {
  int n, k, cnt = 1;
  int i, j;
  for (i = 0; i < 10010; i++) {
    for (j = 0; j < 3; j++) a[i][j] = cnt++;
    a[i][j] = ++cnt;
    cnt += 2;
  }
  while (scanf("%d%d", &n, &k) != EOF) {
    cout << 1ll * a[n - 1][3] * k << endl;
    for (i = 0; i < n; i++) {
      for (j = 0; j < 4; j++) cout << 1ll * a[i][j] * k << ' ';
      cout << endl;
    }
  }
  return 0;
}
