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