#include <bits/stdc++.h>
int a[501][501];
int main() {
  int n, k, i, j, s;
  while (~scanf("%d%d", &n, &k)) {
    s = n * n;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n - k + 1; j++) {
        a[i][j] = s--;
      }
    }
    for (i = 1; i <= n; i++) {
      for (j = n - k + 2; j <= n; j++) {
        a[i][j] = s--;
      }
    }
    for (s = 0, i = 1; i <= n; i++) s += a[i][n - k + 1];
    printf("%d\n", s);
    for (i = 1; i <= n; i++) {
      for (j = n; j >= 1; j--) {
        printf("%d ", a[i][j]);
      }
      puts("");
    }
  }
  return 0;
}
