#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, x, y, n, k, m, ans, a[502][500];
  scanf("%lld", &n);
  scanf("%lld", &k);
  long long int ct = 0;
  x = n * n;
  k--;
  for (m = 0; m < n; m++) {
    for (y = n - 1; y >= k; y--) {
      a[m][y] = x;
      x--;
    }
  }
  x = 1;
  for (m = n - 1; m >= 0; m--) {
    for (y = 0; y < k; y++) {
      a[m][y] = x;
      ct++;
      x++;
    }
  }
  ans = 0;
  for (x = 0; x < n; x++) ans += a[x][k];
  printf("%lld\n", ans);
  for (x = 0; x < n; x++) {
    for (y = 0; y < n; y++) {
      printf("%lld ", a[x][y]);
    }
    printf("\n");
  }
  return 0;
}
