#include <bits/stdc++.h>   using namespace std;   int arr[503][503];   int main() {     int n, k;     cin >> n >> k;     int p = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j < k; j++) {         arr[i][j] = p++;       }     }     for (int i = 1; i <= n; i++) {       for (int j = k; j <= n; j++) {         arr[i][j] = p++;       }     }     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += arr[i][k];     }     cout << sum << endl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << arr[i][j] <<    ;       }       cout << endl;     }     return 0;   }   