#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
long long N, k;
long long arr[MX];
long long ans[501][501];
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> k;
  k--;
  int now = 0, E = 1;
  while (now != k) {
    for (int j = 0; j < N; j++) {
      ans[j][now] = E;
      E++;
    }
    now++;
  }
  for (int i = 0; i < N; i++) {
    for (int j = now; j < N; j++) {
      ans[i][j] = E;
      E++;
    }
  }
  long long res = 0;
  for (int i = 0; i < N; i++) res += ans[i][k];
  cout << res << "\n";
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      if (j == N - 1)
        cout << ans[i][j] << "\n";
      else
        cout << ans[i][j] << " ";
  return 0;
}
