#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long N = 2e5 + 5;
const long long INF = 1e16;
void solve() {
  long long n, k;
  cin >> n >> k;
  long long cur = 1;
  long long a[n][n];
  for (long long i = (0); i <= (n - 1); i++)
    for (long long j = (0); j <= (k - 2); j++) a[i][j] = cur++;
  for (long long i = (0); i <= (n - 1); i++)
    for (long long j = (k - 1); j <= (n - 1); j++) a[i][j] = cur++;
  long long sum = 0;
  for (long long i = (0); i <= (n - 1); i++) sum += a[i][k - 1];
  cout << sum << "\n";
  for (long long i = (0); i <= (n - 1); i++) {
    for (long long j = (0); j <= (n - 1); j++) cout << a[i][j] << " ";
    cout << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
