#include <bits/stdc++.h>
using namespace std;
int a[801][801], n, k, i, j, l, sum, nom;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (j = 1; j <= k - 1; j++)
    for (i = 1; i <= n; i++) {
      l++;
      a[i][j] = l;
    }
  for (i = 1; i <= n; i++)
    for (j = k; j <= n; j++) {
      l++;
      a[i][j] = l;
    }
  for (i = 1; i <= n; i++) sum += a[i][k];
  cout << sum << '\n';
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n - 1; j++) cout << a[i][j] << " ";
    cout << a[i][n] << '\n';
  }
  return 0;
}
