#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first)
    return a.first > b.first;
  else
    return a.second > b.second;
}
long long pow(long long base, long long x) {
  long long ans = 1;
  for (long long i = 1; i <= x; i++) ans *= base;
  return ans;
}
long long ar[501][501];
int main() {
  long long n, k;
  cin >> n >> k;
  long long a = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j < k; j++) ar[i][j] = a++;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = k; j <= n; j++) ar[i][j] = a++;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = k; j <= k; j++) ans += ar[i][k];
  }
  cout << ans << "\n";
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) cout << ar[i][j] << ' ';
    cout << "\n";
  }
  return 0;
}
