#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
int majid;
int main() {
  int a = 0, b;
  int n, m;
  cin >> n >> m;
  b = m;
  cout << (6 * (n - 1) + 5) * m << endl;
  cout << m << " " << (2 * m) << " " << (3 * m) << " " << (5 * m) << endl;
  for (int i = 1; i <= n - 1; i++) {
    cout << (6 * i + 1) * m << " " << (6 * i + 2) * m << " " << (6 * i + 3) * m
         << " " << (6 * i + 5) * m;
    cout << endl;
  }
}
