#include <bits/stdc++.h>
using namespace std;
long long a[500][500];
int n, k;
int main() {
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  cin >> n >> k;
  long long cnt = 1;
  k--;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      a[i][j] = cnt;
      cnt++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = k; j < n; j++) {
      a[i][j] = cnt;
      cnt++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i][k];
  }
  cout << ans << "\n";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
}
