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

using namespace std;

int main()
{
    int n = 0;
    int colors = 1;

    map<int, int> repaint;
    repaint[0] = 0;
    vector<vector<int>> a;

    cin >> n;
    a.resize(n, vector<int>(n));
     for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
        {
            int color;
            cin >> color;
            ++color;
            if (repaint.find(color) == repaint.end())
                repaint[color] = colors++;
            a[i][j] = repaint[color];
        }
    for (int i = 0; i < n; ++i)
    {
        vector<int>cnt[2];
        cnt[0].resize(colors);
        cnt[1].resize(colors);
        int mx[2][2] = {{0, 0}, {0, 0}};
        for (int j = 0; j < n; ++j)
        {
            for (int k = 0; k <= i; ++k)
            {
                int parity = (k + j) % 2;
                int color = a[k][j];
                cnt[parity][color]++;
                int & max1_color = mx[parity][0];
                int & max2_color = mx[parity][1];
                if (cnt[parity][color] > cnt[parity][max1_color] && color != max1_color)
                {
                    max2_color = max1_color;
                    max1_color = color;
                }
                else if (cnt[parity][color] > cnt[parity][max2_color] && color != max1_color && color != max2_color)
                {
                    max2_color = color;
                }
            }
            int s = max(cnt[0][mx[0][0]], cnt[1][mx[1][0]]);
            if (mx[0][0] != mx[1][1])
                s = max(s, cnt[0][mx[0][0]] + cnt[1][mx[1][1]]);
            if (mx[0][1] != mx[1][0])
                s = max(s, cnt[0][mx[0][1]] + cnt[1][mx[1][0]]);
            if (mx[0][0] != mx[1][0])
                s = max(s, cnt[0][mx[0][0]] + cnt[1][mx[1][0]]);
            cout << (i + 1) * (j + 1) - s << " ";
        }
        cout << endl;
    }
}