#include <bits/stdc++.h>
const int modP = 1000000007;
using namespace std;
const int N = 501;
int sTable[N][N];
int main() {
  int k, n, row = 0, col = 0;
  int64_t result = 0;
  int64_t curNum;
  cin >> n >> k;
  curNum = n * n;
  while (row < n) {
    for (int i = n - 1; i >= (k - 1); --i) {
      sTable[row][i] = curNum--;
    }
    result += sTable[row][k - 1];
    row++;
  }
  row = 0;
  if (k > 1) {
    while (row < n) {
      for (int i = k - 2; i >= 0; --i) {
        sTable[row][i] = curNum--;
      }
      row++;
    }
  }
  cout << result << endl;
  for (int row = 0; row < n; ++row) {
    for (int col = 0; col < n; ++col) {
      cout << sTable[row][col] << " ";
    }
    cout << endl;
  }
  return 0;
}
