#include <bits/stdc++.h>
using namespace std;
vector<int> ans[10005];
int gcd(int x, int y) {
  int z;
  while (y) {
    z = x;
    x = y;
    y = z % y;
  }
  return x;
}
int main() {
  int n, k, cnt = 0, sol = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1, j = 2; cnt < n; j += 2)
    if (j % 3)
      if (gcd(i, j) == 1 && gcd(i + 2, j) == 1 && gcd(i + 4, j) == 1) {
        ans[++cnt].push_back(i * k);
        ans[cnt].push_back((i + 2) * k);
        ans[cnt].push_back((i + 4) * k);
        ans[cnt].push_back(j * k);
        i += 6;
        sol = max((i - 2) * k, j * k);
      }
  printf("%d\n", sol);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 4; ++j) printf("%d ", ans[i][j]);
    printf("\n");
  }
  return 0;
}
