#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
long long INF = 1e18;
int mas[500][500];
int main() {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> aa;
  int kek = n * (k - 1) + 1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    mas[i][k - 1] = kek;
    ans += kek;
    kek += (n - (k) + 1);
  }
  int kek2 = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k - 1; j++) {
      mas[i][j] = kek2;
      kek2++;
    }
  }
  for (int i = 0; i < n; i++) {
    int qq = mas[i][k - 1];
    for (int j = k; j < n; j++) {
      qq++;
      mas[i][j] = qq;
    }
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << mas[i][j] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
