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