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