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