#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const long long inf = 0x3f3f3f3f3f;
long long a[1010][1010];
long long n, k;
int main() {
  cin >> n >> k;
  long long cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= k; j--) {
      a[i][j] = n * n - cnt;
      cnt++;
    }
  }
  long long fcnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < k; j++) {
      fcnt++;
      a[i][j] = fcnt;
    }
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) sum += a[i][k];
  cout << sum << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
