#include <bits/stdc++.h>
using namespace std;
const int X = 510;
int N, K;
int a[X][X];
int main() {
  cin >> N >> K;
  int cur = N * N;
  int ans = 0;
  for (int i = N; i > 0; --i) {
    for (int j = N; j >= K; --j) {
      a[i][j] = cur--;
    }
  }
  cur = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j < K; ++j) {
      a[i][j] = cur++;
    }
  }
  for (int i = 1; i <= N; ++i) ans = 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;
  }
}
