#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >>n;

    int** data = new int*[n];
    int** xflat = new int*[n];
    int** yflat = new int*[n];
    map<int,int> xlength;
    map<int,int> ylength;

    for (int i=0; i<n; i++) {
        data[i] = new int[n];
        xflat[i] = new int[n];
        yflat[i] = new int[n];
    }

    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cin >>data[i][j];
            xflat[i][j] = 0;
            yflat[i][j] = 0;
        }
    }

    //fill x
    int flats = 0;
    for (int i=0; i<n; i++) {
        int len = 1;
        int lev = -1;
        for (int j=0; j<n; j++) {
            if (data[i][j] != lev) {
                flats++;
                lev = data[i][j];
                len = 1;
            } else {
                xflat[i][j] = flats;
                len++;
            }
            xflat[i][j] = flats;
            xlength[flats] = len;
        }
    }

    //fill y
    flats = 0;
    for (int j=0; j<n; j++) {
        int len = 1;
        int lev = -1;
        for (int i=0; i<n; i++) {
            if (data[i][j] != lev) {
                flats++;
                lev = data[i][j];
                len = 1;
            } else {
                yflat[i][j] = flats;
                len++;
            }
            yflat[i][j] = flats;
            ylength[flats] = len;
        }
    }
    
    int best = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            int sum = xlength[xflat[i][j]] + ylength[yflat[i][j]];
            if (sum > best) {
                best = sum;
            }
        }
    }
    cout <<best<<endl;
}