#include <bits/stdc++.h>
using namespace std;
long long ans[503][503];
int main() {
  long long n, k, i, j;
  scanf("%lld %lld", &n, &k);
  long long c = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j < k; j++) {
      ans[i][j] = c++;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = k; j <= n; j++) {
      ans[i][j] = c++;
    }
  }
  long long p = 0;
  for (i = 1; i <= n; i++) p += ans[i][k];
  printf("%lld\n", p);
  for (i = 1; i <= n; i++, printf("\n")) {
    for (j = 1; j <= n; j++) printf("%lld ", ans[i][j]);
  }
  return 0;
}
