#include <bits/stdc++.h>
using namespace std;
int maps[550][550];
int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    int tot = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j < k; j++) maps[i][j] = ++tot;
    int num = n * n;
    for (int i = 1; i <= n; i++) {
      for (int j = n; j >= k; j--) maps[i][j] = num--;
    }
    int sum = 0;
    for (int i = 1; i <= n; i++) sum += maps[i][k];
    printf("%d\n", sum);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (j == 1)
          printf("%d", maps[i][j]);
        else
          printf(" %d", maps[i][j]);
      }
      puts("");
    }
  }
  return 0;
}
