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