#include #include int a[53][53]; int lin[53][53], col[53][53]; int n; int main() { //freopen ("a.in", "r", stdin); scanf ("%d", &n); int i, j; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) scanf ("%d ", &a[i][j]); for (i = 1; i <= n; ++i) for (j = 1; j <= n;++j) lin[i][j] = lin[i][j - 1] + a[i][j]; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) col[j][i] = col[j][i - 1] + a[i][j]; int x1, y1, x2, y2, best = -0x3f3f3f3f; int s = 0; for (x1 = 1; x1 <= n; ++x1) for (y1 = 1; y1 <= n; ++y1) for (x2 = x1; x2 <= n; ++x2) for (y2 = y1; y2 <= n; ++y2) { s = col[y1][x2] - col[y1][x1 - 1]; s += col[y2][x2] - col[y2][x1 - 1]; s += lin[x1][y2] - lin[x1][y1 - 1]; s += lin[x2][y2] - lin[x2][y1 - 1]; s -= a[x1][y1]; s -= a[x1][y2]; s -= a[x2][y1]; s -= a[x2][y2]; //printf ("%d %d %d %d: %d\n", x1, y1 ,x2, y2, s); if (x1 == x2 && y1 == y2) s = a[x1][y1]; if (x1 == x2 && y1 != y2) { s = lin[x1][y2] - lin[x1][y1 - 1]; } if (y1 == y2 && x1 != x2) { s = col[y1][x2] - col[y1][x1 - 1]; } if (s > best) best = s; } printf ("%d\n", best); }