#include<bits/stdc++.h>
using namespace std;

const int maxn = 2e6 + 5;
#define int long long

int n, m, k, ok[maxn];
vector<vector<int>> pre;
pair<int, int> dd[maxn];

struct node{
    int i, j, u, v;
    node() {
        i = j = 1e9;
        u = v = 0;
    }
};

node val[maxn];

int get(int i, int j, int u, int v) {
    if(i > u || j > v) return 0;
    return pre[u][v] - pre[u][j - 1]
         - pre[i - 1][v] + pre[i - 1][j - 1];
}

bool okk(int x, int i, int j, int u, int v) {
    int fi = dd[x].first;
    int se = dd[x].second;

    if(fi < i || fi > u || se < j || se > v)
        return false;

    return true;
}

signed main () {
    //freopen("hcn.inp", "r", stdin);
    //freopen("hcn.out", "w", stdout);

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

    cin >> n >> m >> k;

    vector<vector<int>> a;
    a.resize(n + 1);
    pre.resize(n + 1);

    for(int i = 0; i <= n; i++)
        a[i].resize(m + 1),
        pre[i].resize(m + 1);

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {

            cin >> a[i][j];

            int x = a[i][j];

            pre[i][j] = pre[i - 1][j]
                      + pre[i][j - 1]
                      - pre[i - 1][j - 1];

            if(!ok[x]) {
                pre[i][j]++;
                ok[x] = 1;
                dd[x] = {i, j};
            }

            val[x].i = min(val[x].i, i);
            val[x].j = min(val[x].j, j);
            val[x].u = max(val[x].u, i);
            val[x].v = max(val[x].v, j);
        }
    }

    for(int i = 1; i <= k; i++)
        ok[i] = 0;

    for(int num = 1; num <= k; num++) {

        int i = val[num].i;
        int j = val[num].j;
        int u = val[num].u;
        int v = val[num].v;

        int ans = get(i + 1, j + 1, u - 1, v - 1);

        int ii = dd[num].first;
        int jj = dd[num].second;

        if(ii >= i + 1 && ii <= u - 1 &&
           jj >= j + 1 && jj <= v - 1)
            ans--;

        ok[num] = 1;

        // Trường hợp không có interior
        if(i + 1 > u - 1 || j + 1 > v - 1) {

            vector<int> P;

            for(int hang = i; hang <= u; hang++) {
                for(int cot = j; cot <= v; cot++) {

                    if(!ok[a[hang][cot]]) {
                        ans++;
                        ok[a[hang][cot]] = 1;
                        P.push_back(a[hang][cot]);
                    }
                }
            }

            cout << ans << " ";

            for(auto x : P)
                ok[x] = 0;

            ok[num] = 0;

            continue;
        }

        vector<int> P;

        // hang(i)
        for(int cot = j + 1; cot <= v - 1; cot++) {

            int x = a[i][cot];

            if(!ok[x] && !okk(x, i + 1, j + 1, u - 1, v - 1)) {
                ans++;
                ok[x] = 1;
                P.push_back(x);
                continue;
            }

            if(!ok[x] &&
               (x != a[i + 1][cot] || i + 1 >= u)) {

                ans++;
                ok[x] = 1;
                P.push_back(x);
            }
        }

        // hang(u)
        for(int cot = j + 1; cot <= v - 1; cot++) {

            int x = a[u][cot];

            if(!ok[x] && !okk(x, i + 1, j + 1, u - 1, v - 1)) {
                ans++;
                ok[x] = 1;
                P.push_back(x);
                continue;
            }

            if(!ok[x] &&
               (x != a[u - 1][cot] || u - 1 <= i)) {

                ans++;
                ok[x] = 1;
                P.push_back(x);
            }
        }

        // cot(j)
        for(int hang = i + 1; hang <= u - 1; hang++) {

            int x = a[hang][j];

            if(!ok[x] && !okk(x, i + 1, j + 1, u - 1, v - 1)) {
                ans++;
                ok[x] = 1;
                P.push_back(x);
                continue;
            }

            if(!ok[x] &&
               (x != a[hang][j + 1] || j + 1 >= v)) {

                ans++;
                ok[x] = 1;
                P.push_back(x);
            }
        }

        // cot(v)
        for(int hang = i + 1; hang <= u - 1; hang++) {

            int x = a[hang][v];

            if(!ok[x] && !okk(x, i + 1, j + 1, u - 1, v - 1)) {
                ans++;
                ok[x] = 1;
                P.push_back(x);
                continue;
            }

            if(!ok[x] &&
               (x != a[hang][v - 1] || v - 1 <= j)) {

                ans++;
                ok[x] = 1;
                P.push_back(x);
            }
        }

        // 4 góc
        for(auto hang : {i, u}) {
            for(auto cot : {j, v}) {

                if(!ok[a[hang][cot]]) {
                    ans++;
                    P.push_back(a[hang][cot]);
                    ok[a[hang][cot]] = 1;
                }
            }
        }

        cout << ans << ' ';

        for(auto x : P)
            ok[x] = 0;

        ok[num] = 0;
    }
}
