def main():
    n = int(input())
    data = [list(map(int,input().strip().split())) for i in range(0, n)]
    xflat = [[0]*n for i in range(0, n)]
    yflat = [[0]*n for i in range(0, n)]
    xlength = {}
    ylength = {}
    # fill x
    flats = 0;
    for i in range(0, n):
        len = 1;
        lev = -1;
        for j in range(0, n): 
            if data[i][j] != lev:
                flats += 1
                lev = data[i][j]
                len = 1
            else:
                xflat[i][j] = flats;
                len += 1
            xflat[i][j] = flats
            xlength[flats] = len
    # fill y
    flats = 0;
    for j in range(0, n):
        len = 1;
        lev = -1;
        for i in range(0, n): 
            if data[i][j] != lev:
                flats += 1
                lev = data[i][j]
                len = 1
            else:
                yflat[i][j] = flats;
                len += 1
            yflat[i][j] = flats
            ylength[flats] = len
    best = 0;
    for i in range(0, n): 
        for j in range(0, n): 
            sum = xlength[xflat[i][j]] + ylength[yflat[i][j]]
            if sum > best:
                best = sum;
    print(best)

if __name__ == '__main__': 
    main()