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