#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
bool Check(int x, int y) {
  if (gcd(x, y) > 1) return false;
  if (gcd(x + 1, y) > 1) return false;
  if (gcd(x + 2, y) > 1) return false;
  return true;
}
vector<int> ans[10010];
int main() {
  int n, k;
  cin >> n >> k;
  int x = 1;
  for (int i = 0; i < (n); i++) {
    ans[i].push_back(x * k);
    ans[i].push_back((x + 1) * k);
    ans[i].push_back((x + 2) * k);
    int y = x + 4;
    while (!Check(x, y)) y += 2;
    ans[i].push_back(y * k);
    x = y + 2;
  }
  cout << (x - 2) * k << endl;
  for (int i = 0; i < (n); i++)
    cout << ans[i][0] << " " << ans[i][1] << " " << ans[i][2] << " "
         << ans[i][3] << endl;
  return 0;
}
