#include <bits/stdc++.h>
using namespace std;
int mat[505][505];
void solve() {
  int N, K;
  cin >> N >> K;
  memset(mat, -1, sizeof(mat));
  int last = N * N;
  for (int i = N; i >= K; i--) {
    int temp = last;
    for (int j = N; j >= 1; j--) {
      mat[j - 1][i - 1] = temp;
      temp -= (N - K + 1);
    }
    last--;
  }
  int num = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (mat[i][j] == -1) mat[i][j] = num++;
    }
  }
  int sum = 0;
  for (int i = 0; i < N; i++) sum += (mat[i][K - 1]);
  cout << sum << endl;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) cout << mat[i][j] << " ";
    cout << endl;
  }
  return;
}
int main() {
  solve();
  return 0;
}
