#include <bits/stdc++.h>
using namespace std;
long long n, k, num[10010][110], Min;
int main() {
  num[1][0] = 1;
  num[1][1] = 2;
  num[1][2] = 3;
  num[1][3] = 5;
  scanf("%I64d%I64d", &n, &k);
  for (int i = 2; i <= n; i++) {
    num[i][0] = num[i - 1][3] + 2;
    num[i][1] = num[i][0] + 1;
    num[i][2] = num[i][1] + 1;
    num[i][3] = num[i][2] + 2;
  }
  cout << num[n][3] * k << endl;
  for (int i = 1; i <= n; i++) {
    cout << num[i][0] * k << ' ' << num[i][1] * k << ' ' << num[i][2] * k << ' '
         << num[i][3] * k << endl;
  }
  return 0;
}
