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