#include <bits/stdc++.h>
using namespace std;
const int Maxn = 10000 + 10;
const int Maxp = 61759 + 100;
int n, k;
vector<long long int> d[Maxn];
bool mark[Maxp];
void input();
void init();
bool gcd(long long int a, long long int b);
void output();
int main() {
  input();
  init();
  output();
  return 0;
}
void input() { cin >> n >> k; }
void init() {
  int a = 0;
  for (int i = 0; i < n; i++) {
    d[i].push_back(6 * a + 1);
    d[i].push_back(6 * a + 2);
    d[i].push_back(6 * a + 3);
    d[i].push_back(6 * a + 5);
    a++;
  }
}
bool gcd(long long int a, long long int b) {
  long long int c;
  while (a != 0) {
    c = a;
    a = b % a;
    b = c;
  }
  return (b == 1);
}
void output() {
  cout << d[n - 1][3] * k << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) cout << d[i][j] * k << " ";
    cout << endl;
  }
}
