#include <bits/stdc++.h>

using namespace std;

template<typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; }
template<typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; }

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<short, short> PR;
typedef vector<int> VI; 

const lod eps = 1e-9;
const lod pi = acos(-1);
const int oo = 1 << 30;
const ll loo = 1ll << 60;
const int mods = 998244353;
const int MAXN = 400005;
const int INF = 0x3f3f3f3f; //1061109567
/*--------------------------------------------------------------------*/

namespace FastIO{
	constexpr int SIZE = (1 << 21) + 1;
	int num = 0, f;
	char ibuf[SIZE], obuf[SIZE], que[65], *iS, *iT, *oS = obuf, *oT = obuf + SIZE - 1, c;
	#define gc() (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush() {
		fwrite(obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	inline void putc(char c) {
		*oS ++ = c;
		if (oS == oT) flush();
	}
	inline void getc(char &c) {
		for (c = gc(); (c < 'a' || c > 'z') && c != EOF; c = gc());
	}
	inline void reads(char *st) {
		char c;
		int n = 0;
		getc(st[++ n]);
		for (c = gc(); c >= 'a' && c <= 'z' ; c = gc()) st[++ n] = c;
	}
	template<class I>
	inline void read(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9' ; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9' ; c = gc()) x = (x << 3) + (x << 1) + (c & 15);
		x *= f;
	}
	template<class I>
	inline void print(I x) {
		if (x < 0) putc('-'), x = -x;
		if (!x) putc('0');
		while (x) que[++ num] = x % 10 + 48, x /= 10;
		while (num) putc(que[num --]);
	}
	struct Flusher_{~Flusher_(){flush();}} io_Flusher_;
}
using FastIO :: read;
using FastIO :: putc;
using FastIO :: reads;
using FastIO :: print;



int c[1505][1505], flag[1505 * 1505], Ans[1505], n, m;
PR L[1505][1505][11], U[1505][1505][11], A[1505][1505][11];
int operator - (PR x, PR y) { return max(y.fi - x.fi, y.se - x.se); }
signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
#endif
	read(n), read(m);
	for (int i = 1; i <= n ; ++ i)
		for (int j = 1; j <= n ; ++ j) read(c[i][j]);
	for (int i = 1; i <= n ; ++ i) {
		for (int j = 1, id; j <= n ; ++ j) {
			for (int k = 0; k <= m ; ++ k) L[i][j][k] = L[i][j - 1][k];
			id = m;
			for (int k = 0; k <= m ; ++ k) 
				if (c[L[i][j][k].fi][L[i][j][k].se] == c[i][j]) { id = k; break; }
			for (int k = id; k >= 1 ; -- k) L[i][j][k] = L[i][j][k - 1];
			L[i][j][0] = MP(i, j);

			for (int k = 0; k <= m ; ++ k) U[i][j][k] = U[i - 1][j][k];
			id = m;
			for (int k = 0; k <= m ; ++ k) 
				if (c[U[i][j][k].fi][U[i][j][k].se] == c[i][j]) { id = k; break; }
			for (int k = id; k >= 1 ; -- k) U[i][j][k] = U[i][j][k - 1];
			U[i][j][0] = MP(i, j);

			flag[0] = 1;
			int x = 0, y = 0, z = 0;
			for (int t = 0; t <= m ; ++ t) {
				while (x <= m && flag[c[L[i][j][x].fi][L[i][j][x].se]]) ++ x;
				while (y <= m && flag[c[U[i][j][y].fi][U[i][j][y].se]]) ++ y;
				while (z <= m && flag[c[A[i - 1][j - 1][z].fi][A[i - 1][j - 1][z].se]]) ++ z;
				if (x == m + 1 && y == m + 1 && z == m + 1) break;
				int X = (x <= m ? L[i][j][x] - MP(i, j) : INF);
				int Y = (y <= m ? U[i][j][y] - MP(i, j) : INF);
				int Z = (z <= m ? A[i - 1][j - 1][z] - MP(i, j) : INF);
				if (X <= Y && X <= Z) A[i][j][t] = L[i][j][x ++];
				else if (Y <= X && Y <= Z) A[i][j][t] = U[i][j][y ++];
				else A[i][j][t] = A[i - 1][j - 1][z ++];
				flag[c[A[i][j][t].fi][A[i][j][t].se]] = 1;
			}
			for (int t = 0; t <= m ; ++ t) flag[c[A[i][j][t].fi][A[i][j][t].se]] = 0;
			++ Ans[min(min(i, j), A[i][j][m] - MP(i, j))];
		}
	}
	for (int i = n; i >= 1 ; -- i) Ans[i] += Ans[i + 1];
	for (int i = 1; i <= n ; ++ i) print(Ans[i]), putc('\n');
	return 0;
}