#include <bits/stdc++.h>
using namespace std;
int dp[505][505];
int main() {
  int l = 1, n, k, i, j, s = 0;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; i++) {
    for (j = 1; j < k; j++) {
      dp[i][j] = l++;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = k; j <= n; j++) {
      dp[i][j] = l++;
    }
  }
  for (i = 1; i <= n; i++) s += dp[i][k];
  printf("%d\n", s);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      printf("%d ", dp[i][j]);
    }
    printf("\n");
  }
  return 0;
}
