#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1.0);
int cs = 1, test;
vector<int> v[509];
int main() {
  int i, n, j, k, x, y, z, len, mx = -1;
  scanf("%d %d", &n, &k);
  int num = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j < k; j++) {
      v[i].push_back(num);
      num++;
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = k; j <= n; j++) {
      v[i].push_back(num);
      num++;
    }
  }
  int sum = 0;
  for (i = 1; i <= n; i++) {
    sum += v[i][k - 1];
  }
  printf("%d\n", sum);
  for (i = 1; i <= n; i++) {
    for (j = 0; j < n; j++) printf("%d ", v[i][j]);
    printf("\n");
  }
  return 0;
}
