#include <bits/stdc++.h>
using namespace std;
const int nmax = 500;
int v[nmax + 1][nmax + 1];
int main() {
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for (int i = 1, x = 1, y = n * (k - 1) + 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (j < k) {
        v[i][j] = x;
        ++x;
      } else {
        v[i][j] = y;
        ++y;
      }
    }
    sum += v[i][k];
  }
  cout << sum << "\n";
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cout << v[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}
