#include <bits/stdc++.h>
using namespace std;
long long n, k, a[20000][6], d[6];
int main() {
  d[1] = 1;
  d[2] = 2;
  d[3] = 3;
  d[4] = 5;
  cin >> n >> k;
  for (int i = (0), _b = (n - 1); i <= _b; i++)
    for (int j = (1), _b = (4); j <= _b; j++) a[i + 1][j] = 6 * i + d[j];
  printf("%lld\n", a[n][4] * k);
  for (int i = (1), _b = (n); i <= _b; i++) {
    for (int j = (1), _b = (4); j <= _b; j++) printf("%lld ", k * a[i][j]);
    printf("\n");
  }
}
