#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  k--;
  int m[n][n];
  int d = n * n;
  int rez = 0;
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > k; j--) {
      m[i][j] = d;
      d--;
    }
    m[i][k] = d;
    rez += d;
    d--;
  }
  for (int i = 0; i < n; i++) {
    for (int j = k - 1; j >= 0; j--) {
      m[i][j] = d;
      d--;
    }
  }
  cout << rez << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << m[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
