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