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