#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
const long long SIZE = 100000;
void solve() {
  long long n, k;
  cin >> n >> k;
  long long ar[n][n];
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = 0; j < (long long)n; j++) ar[i][j] = 0;
  }
  k--;
  long long x = n * n, sum = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = n - 1; j >= k; j--) {
      ar[i][j] = x;
      if (j == k) sum += x;
      x--;
    }
  }
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = k - 1; j >= 0; j--) {
      ar[i][j] = x;
      x--;
    }
  }
  cout << sum << endl;
  for (long long i = 0; i < (long long)n; i++) {
    for (long long j = 0; j < (long long)n; j++) cout << ar[i][j] << " ";
    cout << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
