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