#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long d = n - k;
  long long sum = 0;
  long long a[n][n];
  memset(a, 0, sizeof(a));
  long long x = n * n;
  for (long long i = 0; i < n; i++) {
    for (long long j = n - 1; j >= k - 1; j--) a[i][j] = x--;
  }
  x = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < k - 1; j++) a[i][j] = x++;
  }
  for (long long i = 0; i < n; i++) sum += a[i][k - 1];
  cout << sum << "\n";
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) cout << a[i][j] << " ";
    cout << "\n";
  }
}
