#include <bits/stdc++.h>
using namespace std;
int N, K;
int ans[505][505];
int main() {
  cin >> N >> K;
  int s = (K - 1) * N + 1;
  for (int i = 1; i <= N; i++)
    for (int j = K; j <= N; j++) {
      ans[i][j] = s;
      s++;
    }
  s = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j < K; j++) {
      ans[i][j] = s;
      s++;
    }
  long long sum = 0;
  for (int i = 1; i <= N; i++) sum += ans[i][K];
  cout << sum << endl;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) cout << ans[i][j] << ' ';
    cout << endl;
  }
  return 0;
}
