#include <bits/stdc++.h>
using namespace std;
int n, k, ans[10005][15], m;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  scanf("%d%d", &n, &k);
  unordered_map<int, bool> Map;
  m = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4; j++) {
      ans[i][j] = 6 * (i - 1) + j;
      if (j == 4) ans[i][j]++;
      ans[i][j] *= k;
      m = max(m, ans[i][j]);
    }
  }
  printf("%d\n", m);
  for (int i = 1; i <= n; i++)
    printf("%d %d %d %d\n", ans[i][1], ans[i][2], ans[i][3], ans[i][4]);
  return 0;
}
