#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int j = n * n;
  int mat[n][n];
  for (int i = 0; i < n; i++) {
    for (int x = n - 1; x >= k - 1; x--) {
      mat[i][x] = j;
      j--;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int x = k - 2; x >= 0; x--) {
      mat[i][x] = j;
      j--;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += mat[i][k - 1];
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      printf("%d ", mat[i][j]);
    }
    printf("\n");
  }
  return 0;
}
