#include #define NMax 55 int n; int a[NMax][NMax]; int up[NMax][NMax], st[NMax][NMax]; int sum(int x1, int y1, int x2, int y2) { int ret = 0; ret += st[x1][y2] - st[x1][y1-1]; if (x2 > x1) { ret += st[x2][y2] - st[x2][y1-1]; } if (x2 - x1 > 1) { ret += up[x2-1][y1] - up[x1][y1]; if (y2 > y1) { ret += up[x2-1][y2] - up[x1][y2]; } } return ret; } int main() { //freopen("m.in", "rt", stdin); scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &a[i][j]); up[i][j] = up[i-1][j] + a[i][j]; st[i][j] = st[i][j-1] + a[i][j]; } } int maxx = a[1][1]; for (int x1 = 1; x1 <= n; x1++) { for (int y1 = 1; y1 <= n; y1++) { for (int x2 = x1; x2 <= n; x2++) { //for (int y2 = y1; y2 <= n; y2++) { int y2 = y1 + x2 - x1; if (y2 > 0 && y2 <= n) { int ssum = sum(x1, y1, x2, y2); if (ssum > maxx) { maxx = ssum; } } } } } printf("%d\n", maxx); return 0; }