#include <bits/stdc++.h>
using namespace std;
int a[510][510];
int main() {
  int n, k;
  cin >> n >> k;
  long long s = 0;
  int num = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < k; j++) {
      a[i][j] = num;
      num++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = k; j <= n; j++) {
      a[i][j] = num;
      num++;
      if (j == k) {
        s += a[i][j];
      }
    }
  }
  printf("%lld\n", s);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) printf("%d ", a[i][j]);
    printf("\n");
  }
}
