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