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