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