//
// Created by watemus on 15.03.2021.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FF first
#define SS second

using ll = long long;
using ld = long double;

//#define int ll

template<typename T>
using vec = std::vector<T>;

template<typename T>
using uset = std::unordered_set<T>;

template<typename T1, typename T2>
using umap = std::unordered_map<T1, T2>;

constexpr ll INFL = 1000000000000000069;
constexpr int INFI = 1000000069;
const ld PI = acos(-1);

#ifdef LOCAL
std::mt19937 rnd(69);
#else
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
#endif

vec<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

#ifdef LOCAL
#else-
#endif

const int N = 1510;

int a[N][N];

int n, q;

using cols = vec<pair<int, int>>;

cols closest[N][N];

int used[N][N];

int was[N * N];

int when = 0;

cols merge(cols &ls, cols &rs) {
  when++;
  cols res;
  res.reserve(2 * q + 2);
  int jr = 0;
  int jl = 0;
  while (jl < ls.size() && jr < rs.size()) {
    if (was[ls[jl].first] == when) {
      jl++;
    } else if (was[rs[jr].first] == when) {
      jr++;
    } else if (ls[jl].second < rs[jr].second) {
      was[ls[jl].first] = when;
      res.push_back(ls[jl]);
      jl++;
    } else {
      was[rs[jr].first] = when;
      res.push_back(rs[jr]);
      jr++;
    }
  }
  while (jl < ls.size()) {
    if (was[ls[jl].first] != when) {
      res.push_back(ls[jl]);
      was[ls[jl].first] = when;
    }
    jl++;
  }
  while (jr < rs.size()) {
    if (was[rs[jr].first] != when) {
      res.push_back(rs[jr]);
      was[rs[jr].first] = when;
    }
    jr++;
  }
  while (res.size() > q + 1) {
    res.pop_back();
  }
  while (res.size() < q + 1) {
    res.emplace_back(N * N - 2, INFI);
  }
  return res;
}

struct Min_q {
  vec<cols> st1, st2;
  vec<cols> mn1, mn2;
  void push(cols &el) {
    st1.push_back(el);
    if (mn1.empty()) {
      mn1.push_back(el);
    } else {
      mn1.push_back(merge(el, mn1.back()));
    }
  }
  void move() {
    if (st2.empty()) {
      while (!st1.empty()) {
        if (mn2.empty()) {
          mn2.push_back(st1.back());
        } else {
          mn2.push_back(merge(mn2.back(), st1.back()));
        }
        st2.push_back(st1.back());
        st1.pop_back();
        mn1.pop_back();
      }
    }
  }
  int get() {
    if (st1.empty() && st2.empty())
      return INFI;
    if (st1.empty()) {
      return mn2.back().back().second;
    }
    if (st2.empty()) {
      return mn1.back().back().second;
    }
    return merge(mn1.back(), mn2.back()).back().second;
  }
  void pop() {
    move();
    st2.pop_back();
    mn2.pop_back();
  }
};

void run() {
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    closest[i][n - 1] = {{ a[i][n - 1], n - 1 }};
    for (int j = n - 2; j >= 0; j--) {
      closest[i][j] = {{ a[i][j], j }};
      for (auto [who, where] : closest[i][j + 1]) {
        if (who == a[i][j]) continue;
        closest[i][j].emplace_back(who, where);
      }
      while (closest[i][j].size() > q + 1) {
        closest[i][j].pop_back();
      }
      while (closest[i][j].size() < q + 1) {
        closest[i][j].emplace_back(N * N - 2, INFI);
      }
    }
  }
  vec<int> ans(n + 1);
  for (int i = 0; i < n; i++) {
    int l = 0;
    int r = 0;
    Min_q qq;
    int sz = 0;
    while (l < n) {
      while (i + sz < n && r < n && qq.get() - i >= r - l) {
        qq.push(closest[r][i]);
        sz++;
        r++;
      }
      if ( qq.get() - i >= r - l) {
        ans[max(1, r - l)]++;
      } else {
        ans[max(1, r - l - 1)]++;
      }
      qq.pop();
      l++;
      sz--;
    }
  }
  int ansik = n * n;
  for (int i = 0; i < n; i++) {
    ansik -= ans[i];
    cout << ansik << '\n';
  }
}
signed main() {
#ifdef LOCAL
  std::freopen("input.txt", "r", stdin);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    run();
  }
  return 0;
}


