#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
using namespace std;

#define SIZE(x) int((x).size())
#define REP(i,c) for(auto &i : c)
#define pb push_back
#define eb emplace_back
typedef long long i64;
typedef unsigned long long u64;
const double EPS = 1e-12;
const int INF = 999999999;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

const int MAXN=1500;

int n,m;
int a[MAXN][MAXN];
int f[MAXN][MAXN];

 // colors in square (i,j) ... (i+f[i]][j]-1, j+f[i][j-1]), order max(x-i,y-i)
VPII sq[2][MAXN];
int cur;

bool seen[MAXN*MAXN+1];

int ans[MAXN+1];

void Solve() {
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++) {
            scanf("%d",&a[i][j]);
        }

    fill(ans+1,ans+(n+1),0);
    cur=0;
    for(int i=n-1;i>=0;i--) {
        int pre=cur;
        cur=cur^1;
        for(int j=n-1;j>=0;j--) {
            sq[cur][j]={{0,a[i][j]}};
            if(i==n-1 || j==n-1) {
                f[i][j]=1;
                ans[f[i][j]]++;
                continue;
            }

            seen[a[i][j]]=1;
            VI ps={0,0,0};
            vector<const VPII*> vs={&sq[cur][j+1],&sq[pre][j],&sq[pre][j+1]};
            while(SIZE(sq[cur][j])<=m) {
                int md=INF;
                int mi=-1;
                for(int i=0;i<3;i++) {
                    const VPII& v=*vs[i];
                    if(ps[i]==SIZE(v)) continue;
                    if(v[ps[i]].first<md) {
                        md=v[ps[i]].first;
                        mi=i;
                    }
                }
                if(mi<0) break;
                const PII &u=(*vs[mi])[ps[mi]++];
                if(!seen[u.second]) {
                    seen[u.second]=1;
                    sq[cur][j].eb(u.first+1,u.second);
                }
            }
            REP(p,sq[cur][j]) seen[p.second]=0;

            f[i][j]=min(n-i,n-j);
            if(SIZE(sq[cur][j])>m) f[i][j]=min(f[i][j],sq[cur][j][m].first);
            ans[f[i][j]]++;
        }
    }

    for(int i=n-1;i>=1;i--) ans[i]+=ans[i+1];
    for(int i=1;i<=n;i++) printf("%d\n",ans[i]);

}

int main() {
    Solve();

    return 0;
}
