#include <bits/stdc++.h>
using namespace std;
long long modx(long long Base, long long exponent) {
  long long ans = 1;
  if (Base == 1) return Base;
  while (exponent) {
    if (exponent & 1) ans = (ans * Base) % 1000000007;
    Base = (Base * Base) % 1000000007;
    exponent = exponent >> 1;
  }
  return ans;
}
long long inmodx(long long num) { return (modx(num, 1000000005LL)); }
bool cmp() { return false; }
int a[509][509];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, i, j, x;
  long long ans = 0;
  cin >> n >> k;
  k = n - k + 1;
  x = n * n;
  for (i = 1; i < n + 1; i++) {
    for (j = 1; j < k + 1; j++) a[i][j] = x--;
  }
  for (i = 1; i < n + 1; i++) ans += (long long)a[i][k];
  for (i = 1; i < n + 1; i++) {
    for (j = k + 1; j < n + 1; j++) a[i][j] = x--;
  }
  cout << ans << '\n';
  for (i = 1; i < n + 1; i++) {
    for (j = n; j > 0; j--) cout << a[i][j] << " ";
    cout << '\n';
  }
  return 0;
}
