#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <climits>
#define ONLINE_JUDGE1
using namespace std;

int N, _max;
int A[51][51];

int solve(int x, int y);

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif
	int i, j;
	cin >> N;
	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			cin >> A[i][j];
		}
	}
	_max = A[0][0];
	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			_max = max(solve(i, j), _max);
		}
	}
	cout << _max;
#ifndef ONLINE_JUDGE
	while (1);
#endif
}

int solve(int x, int y) {
	int i, j, nx, ny, ok1;
	int s, saux;
	saux = A[x][y];
	nx = x + 1;
	ny = y + 1;
	while (nx < N && ny < N) {
		if (A[nx][ny] == A[x][y]) {
			s = 0; ok1 = 0;
			for (i = x; i <= nx && ok1 == 0; ++i) {
				if (A[i][y] == A[x][y]) s += A[x][y];
				else {
					s = 0; 
					ok1 = 1;
					break;
				}
				if (A[i][ny] == A[x][y]) s += A[x][y];
				else {
					s = 0; 
					ok1 = 1;
					break;
				}
			}
			
			for (j = y + 1; j < ny && ok1 == 0; ++j) {
				if (A[x][j] == A[x][y]) s += A[x][y];
				else {
					s = 0; 
					ok1 = 1;
					break;
				}
				if (A[nx][j] == A[x][y]) s += A[x][y];
				else {
					s = 0; 
					ok1 = 1;
					break;
				}
			}

			if (ok1 == 0) {
				saux = max(saux, s);
			}

		}
		++nx;
		++ny;
	}
	return saux;
}