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