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