#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[10000][5];
int odd, even;
int v;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
bool check(int i) {
  int t = even * 2;
  for (int j = 1; j < 4; ++j)
    if (gcd(t, a[i][j]) > 1) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < 4; ++j) {
      ++odd;
      a[i][j] = odd * 2 - 1;
    }
    do {
      ++even;
      if (check(i)) {
        a[i][0] = even * 2;
        break;
      }
    } while (1);
    for (int j = 0; j < 4; ++j) v = max(v, a[i][j]);
  }
  printf("%d\n", v * k);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 4; ++j) printf("%d ", a[i][j] * k);
    puts("");
  }
  return 0;
}
