#include <bits/stdc++.h>
#define N 1505
#define Q 11
#define pir pair<int, int>
using namespace std;
int n, q, col[N][N];
vector<pir> r[N][2], d[2][N], rd[N][N], tmp;

int idx[N * N], _index;
int ans[N];

int color(const pir &pos) {
	return col[pos.first][pos.second];
}

int f(int x, int y, const pir &pos) {
	return max(pos.first - x, pos.second - y);
}

bool cmp(int x, int y, const pir &pos1, const pir &pos2) {
	return f(x, y, pos1) < f(x, y, pos2);
}

void merge(int x, int y, const vector<pir> &a, const vector<pir> &b, vector<pir> &c) {
	c.clear();
	++_index;
	
	auto pos1 = a.begin(), pos2 = b.begin();
	while (c.size() <= q && (pos1 != a.end() || pos2 != b.end())) {
		if (pos2 == b.end() || pos1 != a.end() && cmp(x, y, *pos1, *pos2)) {
			if (idx[color(*pos1)] != _index) {
				c.push_back(*pos1);
				idx[color(*pos1)] = _index;
			}
			pos1++;
		} else {
			if (idx[color(*pos2)] != _index) {
				c.push_back(*pos2);
				idx[color(*pos2)] = _index;
			}
			pos2++;
		}
	}
}

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			scanf("%d", &col[i][j]); 

	for (int x = n; x >= 1; --x)
		for (int y = n; y >= 1; --y) {
			if (y + 1 > n) r[x][y + 1 & 1].clear();
			if (x + 1 > n) d[x + 1 & 1][y].clear(); 
			merge(x, y, r[x][y + 1 & 1], {make_pair(x, y)}, r[x][y & 1]);
			merge(x, y, d[x + 1 & 1][y], {make_pair(x, y)}, d[x & 1][y]);
			merge(x, y, rd[x + 1][y + 1], r[x][y & 1], tmp);
			merge(x, y, tmp, d[x & 1][y], rd[x][y]);
			int len = n - max(x, y) + 1;
			if (rd[x][y].size() > q) len = min(len, f(x, y, rd[x][y].back()));
			++ans[len]; 
		}
		
	for (int i = n; i; --i) ans[i] += ans[i + 1];
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);	
	return 0;
}

