#include <bits/stdc++.h>
using namespace std;
long long int i, n, j;
int main() {
  int ans[510][510], t, cnt = 0;
  int n, k;
  cin >> n >> k;
  t = n * n;
  for (i = 1; i <= n; i++) {
    for (j = n; j >= k; j--) {
      ans[i][j] = t;
      if (j == k) cnt += t;
      t--;
    }
  }
  t = 1;
  for (i = n; i > 0; i--) {
    for (j = 1; j < k; j++) {
      ans[i][j] = t;
      t++;
    }
  }
  cout << cnt << endl;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) cout << ans[i][j] << " ";
    cout << endl;
  }
  return 0;
}
