#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>

using namespace std;

struct TwoMax {
    int opt1 = -1;
    int cnt1 = 0;
    int opt2 = -1;
    int cnt2 = 0;

    void add(int a, int x) {
        if (opt1 == a) {
            cnt1 = x;
        }
        if (opt2 == a) {
            cnt2 = x;
        }

        if (opt1 == a || opt2 == a) {
            if (cnt1 < cnt2) {
                swap(opt1, opt2);
                swap(cnt1, cnt2);
            }
            return;
        }

        if (cnt1 < x) {
            opt2 = opt1;
            cnt2 = cnt1;
            opt1 = a;
            cnt1 = x;
        } else if (cnt2 < x) {
            opt2 = a;
            cnt2 = x;
        }
    }
};

struct SetTwoMax {
    set <pair <int, int>> s;

    void add(int a, int was, int x) {
        if (was) s.erase({was, a});
        s.insert({x, a});
    } 

    pair <int, int> top1() {
        if (!s.empty()) return *s.rbegin();
        return {0, -1};
    }

    pair <int, int> top2() {
        if (s.size() > 1) return *(next(s.rbegin()));
        return {0, -1};
    }
};

inline void solve() {
    int n;
    cin >> n;
    vector <vector <int>> a(n, vector <int> (n));
    vector <int> all;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
            all.push_back(a[i][j]);
        }
    }

    sort(all.begin(), all.end());
    all.resize(unique(all.begin(), all.end()) - all.begin());
    int cnt_diff = all.size();

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            a[i][j] = lower_bound(all.begin(), all.end(), a[i][j]) - all.begin();
        }
    }

    vector <vector <int>> ans(n, vector <int> (n));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            vector <array <int, 2>> cnt(cnt_diff, {0, 0});
            array <SetTwoMax, 2> flex;

            for (int x = 0; x <= i; ++x) {
                for (int y = 0; y <= j; ++y) {
                    int was = cnt[a[x][y]][(x + y) & 1];
                    flex[(x + y) & 1].add(a[x][y], was, ++cnt[a[x][y]][(x + y) & 1]);
                }
            }

            auto opt1 = flex[0].top1();
            auto opt2 = flex[1].top1();

            if (opt1.second != opt2.second) {
                ans[i][j] = max(ans[i][j], opt1.first + opt2.first);
                continue;
            }

            auto opt3 = flex[0].top2();
            auto opt4 = flex[1].top2();

            if (opt1.second != opt4.second) ans[i][j] = max(ans[i][j], opt1.first + opt4.first);
            if (opt2.second != opt3.second) ans[i][j] = max(ans[i][j], opt2.first + opt3.first);
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << (i + 1) * (j + 1) - ans[i][j] << " ";
        }
        cout << "\n";
    }
};

signed main() {
    if (1) {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    }

    solve();
}