#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

#define rep( i, a, b ) for( int i = (a) ; i <= (b) ; i ++ )
#define per( i, a, b ) for( int i = (a) ; i >= (b) ; i -- )

typedef pair<int, int> Color;

const int MAXN = 1.5e3 + 5, MAXC = MAXN * MAXN, MAXQ = 15;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MIN( const _T a, const _T b )
{
	return a < b ? a : b;
}

vector<Color> hor[2][MAXN], ver[2][MAXN], tmp;

int ans[MAXN];
int C[MAXN][MAXN];
int N, M, Q;
bool app[MAXC];

void Merge( const vector<Color> &a, const vector<Color> &b, vector<Color> &ret )
{
	ret.clear();
	int i = 0, j = 0, la = a.size(), lb = b.size();
    while( i < la || j < lb )
	{
		if( i < la && ( j == lb || a[i].first < b[j].first ) )
		{
            if( ! app[a[i].second] ) ret.push_back( a[i] );
            app[a[i ++].second] = true;
		}
		else
		{
			if( ! app[b[j].second] ) ret.push_back( b[j] );
			app[b[j ++].second] = true;
		}
		if( ( int ) ret.size() == Q + 1 ) break;
	}
	rep( i, 0, ( int ) ret.size() - 1 ) app[ret[i].second] = false;
}

int main()
{
	int res;
	read( N ), read( Q );
	rep( i, 1, N ) rep( j, 1, N ) read( C[i][j] );
	int nw = 0;
    rep( i, 1, N )
    {
    	nw ^= 1;
    	rep( j, 0, N ) hor[nw][j].clear(), ver[nw][j].clear();
    	rep( j, 1, N )
		{
			Merge( hor[nw ^ 1][j - 1], hor[nw][j - 1], tmp );
			rep( k, 0, ( int ) tmp.size() - 1 ) ++ tmp[k].first;
			Merge( tmp, { Color( 0, C[i][j] ) }, hor[nw][j] );

			Merge( ver[nw ^ 1][j - 1], ver[nw ^ 1][j], tmp );
			rep( k, 0, ( int ) tmp.size() - 1 ) ++ tmp[k].first;
			Merge( tmp, { Color( 0, C[i][j] ) }, ver[nw][j] );

			Merge( hor[nw][j], ver[nw][j], tmp );
			if( ( int ) tmp.size() == Q + 1 ) res = MIN( MIN( i, j ), tmp[Q].first );
			else res = MIN( i, j ); ans[res] ++;
		}
    }
    per( i, N, 1 ) ans[i] += ans[i + 1];
    rep( i, 1, N ) write( ans[i] ), putchar( '\n' );
	return 0;
}
