#include <bits/stdc++.h>
using namespace std;
int a[600][600];
int main() {
  long long int happy = 100000;
  int n, k;
  cin >> n >> k;
  int p = n * n;
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= k; j--) {
      a[i][j] = p;
      p--;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = k - 1; j >= 1; j--) {
      a[i][j] = p;
      p--;
    }
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a[i][k];
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
