#include <bits/stdc++.h>
using namespace std;
long long n, k, x, i, ans[1001][1001], sum;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  x = k - 1;
  x *= n;
  for (int a = 1; a <= n; a++) {
    for (int b = k; b <= n; b++) ans[a][b] = ++x;
  }
  i = 0;
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b < k; b++) ans[a][b] = ++i;
  }
  for (int a = 1; a <= n; a++) sum += ans[a][k];
  cout << sum << endl;
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= n; b++) cout << ans[a][b] << " ";
    cout << endl;
  }
  return 0;
}
