# C. K-special Tables【构造】水

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 1000100
#define MOD 1000000007

int n,m;
int a[550][550];

int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t,C = 1;
//scanf("%d",&t);
while(scanf("%d%d",&n,&m) != EOF)
{
int pos1 = 1,pos2 = (m-1)*n+1;
int ans = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
if(j == m)
ans += pos2;
if(j >= m)
a[i][j] = pos2++;
else
a[i][j] = pos1++;
}
printf("%d\n",ans);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
printf("%d ",a[i][j]);
printf("\n");
}
}
return 0;
}


#### CodeForces 625 C. K-special Tables（水~）

2016-02-25 16:52:34

#### K-special Tables

2018-02-08 23:23:06

#### CF#342(2) C. K-special Tables 贪心

2017-05-20 10:09:54

#### cf 625 C. K-special Tables （打表+规律）

2016-03-02 23:27:06

#### CodeForces 625C K-special Tables

2016-02-20 17:32:39

#### CodeFOrces 625C - K-special Tables

2016-03-15 22:58:08

#### Codeforces 625C - K-special Tables

2016-03-08 19:30:12

#### coderforces342C. K-special Tables

2016-02-07 20:18:55

#### 053-707

2013-12-15 22:20:30