#include <bits/stdc++.h>
using namespace std;
int grid[600][600];
int main() {
  int n, k;
  cin >> n >> k;
  int z = n * n - (n - k + 1) * n + 1, q = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = k; j <= n; j++) {
      grid[i][j] = z++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k - 1; j++) {
      grid[i][j] = q++;
    }
  }
  long long ret = 0;
  for (int i = 1; i <= n; i++) {
    ret += grid[i][k];
  }
  cout << ret << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
