#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int a[10007][4];
int main() {
  int n, k;
  cin >> n >> k;
  int m = 0;
  for (int i = 0; i < n; i++) {
    a[i][0] = m + 1;
    a[i][1] = m + 2;
    a[i][2] = m + 3;
    a[i][3] = m + 5;
    m = m + 6;
  }
  cout << (m - 1) * k << endl;
  for (int i = 0; i < n; i++)
    cout << a[i][0] * k << " " << a[i][1] * k << " " << a[i][2] * k << " "
         << a[i][3] * k << endl;
  return 0;
}
