#include <bits/stdc++.h>

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

vector<pair<int, int>> dp[1505][1505];

int main()
{
	#ifdef TurnRed
		freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, q;
	cin >> n >> q;
	vector<vector<int>> a(n, vector<int>(n));
	for (auto &i : a)
		for (auto &j : i)
			cin >> j;

	for (int i = 0; i < n; ++i)
	{
		dp[0][i] = { { 0, a[0][i] } };
		dp[i][0] = { { 0, a[i][0] } };
	}

	vector<pair<int, int>> v;
	vector<int> mp(n * n + 1, n);
	auto get = [&](int i, int j)
	{
		for (auto &k : dp[i][j])
		{
			int l, x;
			tie(l, x) = k;
			if (mp[x] != n) continue;
			v.push_back({ l + 1, x });
			mp[x] = l + 1;
		}
	};

	vector<vector<pair<int, int>>> rc(n + 1);
	auto upd_rc = [&](int p, pair<int, int> x)
	{
		auto &vec = rc[p];
		int del = -1;
		for (auto &i : vec)
		{
			if (i.S == x.S)
				del = &i - &vec[0];
			++i.F;
		}
		if (del != -1) vec.erase(vec.begin() + del);
		vec.insert(vec.begin(), x);
		if (vec.size() > q + 1)
			vec.pop_back();
	};

	auto join = [&](vector<pair<int, int>> w, int lim)
	{
		vector<pair<int, int>> tmp;
		for (auto &i : w)
			if (i.F <= lim && i.F < mp[i.S])
			{
				mp[i.S] = i.F;
				tmp.push_back(i);
			}
		w.swap(tmp);
		tmp.clear();
		for (auto &i : v)
			if (mp[i.S] == i.F)
				tmp.push_back(i);
		v.swap(tmp);
		tmp.resize(v.size() + w.size());
		merge(v.begin(), v.end(), w.begin(), w.end(), tmp.begin());
		v.swap(tmp);
	};

	for (int i = 1; i < n; ++i)
	{
		rc[n].clear();
		for (int j = 1; j < n; ++j)
		{
			upd_rc(j, { 1, a[i - 1][j] });
			upd_rc(n, { 1, a[i][j - 1] });
			v = { { 0, a[i][j] } };
			mp[a[i][j]] = 0;
			get(i - 1, j - 1);
			join(rc[j], min(i, j));
			join(rc[n], min(i, j));
			for (auto &i : v)
				mp[i.S] = n;
			if (v.size() > q + 1)
				v.resize(q + 1);
			dp[i][j] = v;
		}
	}

	vector<int> ans(n + 1);
	ans[0] = n * n;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			if (dp[i][j].size() <= q)
				--ans[min(i, j) + 1];
			else
				--ans[dp[i][j][q].F];
		}

	partial_sum(ans.begin(), ans.end(), ans.begin());
	ans.pop_back();
	for (auto &i : ans)
		cout << i << "\n";

	return 0;
}
