#include <bits/stdc++.h>
using namespace std;
int ans[10005][4];
int main() {
  int n, k, i;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    ans[i][0] = i * 6 + 1;
    ans[i][1] = i * 6 + 3;
    ans[i][2] = i * 6 + 5;
    if ((ans[i][0] + 1) % 3 == 0 && ans[i][2] % 3 == 0)
      ans[i][3] = ans[i][2] - 1;
    else
      ans[i][3] = ans[i][0] + 1;
  }
  printf("%d\n", ans[n - 1][2] * k);
  for (i = 0; i < n; i++)
    printf("%d %d %d %d\n", ans[i][0] * k, ans[i][1] * k, ans[i][2] * k,
           ans[i][3] * k);
  return 0;
}
