#include <bits/stdc++.h>
using namespace std;
int bit[505];
int a[505][505];
int read(int idx) {
  int sum = 0;
  if (idx == 0) return 0;
  while (idx > 0) {
    sum += bit[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(int idx, int val) {
  while (idx <= 505) {
    bit[idx] += val;
    idx += (idx & -idx);
  }
}
long long multiple(long long a, long long b, long long c) {
  if (b == 0) {
    return 0;
  }
  long long ret = multiple(a, b >> 1, c);
  ret = (ret + ret) % c;
  if (b & 1) {
    ret = (ret + a) % c;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, k, value, value2 = 1;
  cin >> n >> k;
  value = n * n;
  for (int i = n; i > 0; i--) {
    for (int j = n; j >= k; j--) {
      a[i][j] = value;
      value--;
    }
    for (int j = 1; j < k; j++) {
      a[i][j] = value2;
      value2++;
    }
  }
  long long sum = 0;
  for (int i = 1; i < n + 1; i++) sum += a[i][k];
  cout << sum << endl;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) cout << a[i][j] << " ";
    cout << endl;
  }
  return 0;
}
