#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000LL * 1000000LL * 1000000LL;
int n, k;
int tyl, l, sum;
int T[1000][1000];
int main() {
  scanf("%d %d", &n, &k);
  tyl = n * n;
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= k; j--) {
      T[i][j] = tyl;
      tyl--;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j == k) {
        sum += T[i][j];
      }
      if (T[i][j] == 0) {
        l++;
        T[i][j] = l;
      }
    }
  }
  printf("%d\n", sum);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      printf("%d ", T[i][j]);
    }
    printf("\n");
  }
}
