#include <bits/stdc++.h>
using namespace std;
int n, k, ans, now;
int v[505][505];
int main() {
  scanf("%d%d", &n, &k);
  now = n * n;
  for (int i = n; i >= 1; i--)
    for (int h = n; h >= k; h--) v[i][h] = now--;
  now = 1;
  for (int i = 1; i <= n; i++)
    for (int h = 1; h < k; h++) v[i][h] = now++;
  for (int i = 1; i <= n; i++) ans += v[i][k];
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    for (int h = 1; h <= n; h++) cout << v[i][h] << " ";
    cout << "\n";
  }
}
