#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 500 + 5;
const int oo = 1e9 + 7;
int a[N][N];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int now = n * n;
  for (int i = n; i >= 1; i--) {
    for (int j = n; j >= k; j--) a[i][j] = now--;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = k - 1; j >= 1; j--) a[i][j] = now--;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) sum += a[i][k];
  cout << sum << "\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cout << a[i][j] << " ";
    cout << "\n";
  }
}
