#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class _T>
inline _T low(_T n) {
  return n & (-n);
}
template <class _T>
inline void swapp(_T &x, _T &y) {
  _T t;
  t = x, x = y, y = t;
}
template <class _T>
inline _T minn(_T i, _T j) {
  return i > j ? j : i;
}
template <class _T>
inline _T maxx(_T i, _T j) {
  return i > j ? i : j;
}
template <class _T>
inline _T gcd(_T b, _T c) {
  return b && c ? (c ? gcd(c, b % c) : b) : b | c;
}
template <class _T>
inline _T abss(_T b) {
  return b > 0 ? b : -b;
}
int a[50000][4];
int main() {
  int i, j, x, y;
  for (i = 0; i < 50000; i++)
    for (j = 0; j < 4; j++) {
      if (i == 0 && j == 0)
        a[i][j] = 1;
      else if (j == 0)
        a[i][j] = a[i - 1][j] + 6;
      else if (j == 1)
        a[i][j] = a[i][j - 1] + 2;
      else
        a[i][j] = a[i][j - 1] + 1;
    }
  int ma = 0;
  scanf("%d%d", &x, &y);
  for (i = 0; i < x; i++) {
    for (j = 0; j < 4; j++)
      if (a[i][j] > ma) ma = a[i][j];
  }
  printf("%d\n", ma * y);
  for (i = 0; i < x; i++) {
    for (j = 0; j < 4; j++) {
      if (j) printf(" ");
      printf("%d", a[i][j] * y);
    }
    printf("\n");
  }
  return 0;
}
