#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1500 + 10;
int n, q, a[maxn][maxn];
vector<pair<int, int> > col[maxn][maxn];
bool vis[maxn * maxn];

void cal(int x, int y)
{
	vector<pair<int, int> > ve;
	ve.push_back({1, a[x][y]});
	for(auto p : col[x - 1][y]) ve.push_back({p.first + 1, p.second});
	for(auto p : col[x][y - 1]) ve.push_back({p.first + 1, p.second});
	for(auto p : col[x - 1][y - 1]) ve.push_back({p.first + 1, p.second});
	sort(ve.begin(), ve.end());
	for(auto p : ve) if(!vis[p.second])
	{
		vis[p.second] = true;
		col[x][y].push_back(p);
		if((int)col[x][y].size() == q + 1) break;
	}
	for(auto p : ve) vis[p.second] = false;
}

int res[maxn];

int main()
{
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++) scanf("%d", &a[i][j]);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++) 
		{
			cal(i, j);
			int p = min(i, j);
			if((int)col[i][j].size() - 1 >= q) p = min(p, col[i][j][q].first - 1);
			res[p] ++;
		}
	for(int i = n; i >= 1; i --) res[i] += res[i + 1];
	for(int i = 1; i <= n; i ++) printf("%d\n", res[i]);
	return 0;
}
