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