#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1111;
const int INF = 0x7f7f7f7f;
int cases;
vector<int> ans[10001];
void init() {
  int tot = 0;
  for (int i = 1; tot <= 10000; i += 6) {
    ans[tot].push_back(i);
    ans[tot].push_back(i + 1);
    ans[tot].push_back(i + 2);
    ans[tot].push_back(i + 4);
    tot++;
  }
}
int main() {
  init();
  int n, k;
  scanf("%d%d", &n, &k);
  printf("%lld\n", (long long)ans[n - 1][3] * k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      printf("%lld%c", (long long)ans[i][j] * k, j == 3 ? '\n' : ' ');
    }
  }
}
