#include <bits/stdc++.h>
using namespace std;
int main() {
  float n, k;
  cin >> n >> k;
  long long r = (pow(n, 2) - (n - 1) / 2) * n - (n - k) * n * (0.5 + n / 2);
  cout << r << endl;
  int o = pow(n, 2) - (n - k + 1) * (n) + 1;
  for (int j = 0; j < n; j++) {
    for (int i = 1; i <= n; i++) {
      if (i < k)
        cout << i + (k - 1) * j << " ";
      else
        cout << o + i - k + (n - k + 1) * j << " ";
    }
    cout << endl;
  }
  return 0;
}
