#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, s, i, j;
  int mp[510][510];
  while (~scanf("%d%d", &n, &k)) {
    s = 1;
    for (i = 1; i <= n; i++)
      for (j = 1; j < k; j++) {
        mp[i][j] = s;
        s++;
      }
    for (i = 1; i <= n; i++)
      for (j = k; j <= n; j++) {
        mp[i][j] = s;
        s++;
      }
    int sum = 0;
    for (i = 1; i <= n; i++) sum += mp[i][k];
    printf("%d\n", sum);
    for (i = 1; i <= n; i++) {
      printf("%d", mp[i][1]);
      for (j = 2; j <= n; j++) printf(" %d", mp[i][j]);
      printf("\n");
    }
  }
}
