#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int> > A(n, vector<int>(n));
  int counter = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k - 1; j++) {
      A[i][j] = ++counter;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = k - 1; j < n; j++) {
      A[i][j] = ++counter;
    }
  }
  for (int i = 0; i < n; i++) {
    sum += A[i][k - 1];
  }
  cout << sum << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << A[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
