#include <stdio.h>
 
#define N	1500
#define K	10
 
int min(int a, int b) { return a < b ? a : b; }
 
int main() {
	static int aa[N][N], aaa[N + 1][N + 1][K + 1], sss[N + 1][N + 1][K + 1], kk[N + 1][N + 1], ans[N + 1];
	static char used[N * N];
	int n, k_, k1, k2, k, h1, h2, i, j, s;
 
	scanf("%d%d", &n, &k_);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			scanf("%d", &aa[i][j]);
	for (i = n - 1; i >= 0; i--)
		for (j = n - 1; j >= 0; j--) {
			int *aa_ = aaa[i][j], *aa1 = aaa[i][j + 1], *aa2 = aaa[i + 1][j];
			int *ss_ = sss[i][j], *ss1 = sss[i][j + 1], *ss2 = sss[i + 1][j];
			int a, a_;
 
			k1 = kk[i][j + 1], k2 = kk[i + 1][j], k = 0, h1 = 0, h2 = 0;
			a = aa[i][j], s = 1;
			used[a] = 1, aa_[k] = a, ss_[k] = s, k++;
			while (h1 < k1 || h2 < k2) {
				if (h2 == k2 || h1 < k1 && ss1[h1] < ss2[h2])
					a_ = aa1[h1], s = ss1[h1], h1++;
				else
					a_ = aa2[h2], s = ss2[h2], h2++;
				if (i + s > n || j + s > n)
					break;
				a = aa[i + s - 1][j + s - 1];
				if (!used[a]) {
					used[a] = 1, aa_[k] = a, ss_[k] = s;
					if (k++ == k_)
						break;
				}
				s++;
				if (i + s > n || j + s > n)
					break;
				a = a_;
				if (!used[a]) {
					used[a] = 1, aa_[k] = a, ss_[k] = s;
					if (k++ == k_)
						break;
				}
				a = aa[i + s - 1][j + s - 1];
				if (!used[a]) {
					used[a] = 1, aa_[k] = a, ss_[k] = s;
					if (k++ == k_)
						break;
				}
			}
			kk[i][j] = k;
			ans[k == k_ + 1 ? ss_[k_] - 1 : min(n - i, n - j)]++;
			for (h1 = 0; h1 < k; h1++)
				used[aa_[h1]] = 0;
		}
	for (s = n - 1; s >= 1; s--)
		ans[s] += ans[s + 1];
	for (s = 1; s <= n; s++)
		printf("%d\n", ans[s]);
	return 0;
}