#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1.0);
using namespace std;
const double EPS = 1e-9;
const int N = 505 + 9;
int n, k, c, sum, a[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k - 1; j++) a[i][j] = ++c;
  for (int i = 1; i <= n; i++)
    for (int j = k; j <= n; j++) a[i][j] = ++c;
  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;
  }
  return 0;
}
