#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n, a[N][N], dp[4][N][N];
int ans = -2e9;
int max_item_sum(vector <vector <int>> V){
n = V.size();
for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) a[i][j] = V[i - 1][j - 1];
for (int i = 1; i <= n; ++ i){
for (int j = n; j >= 1; -- j){
dp[1][i][j] = max(dp[0][i - 1][j], dp[0][i][j + 1]) + a[i][j];
}
}
for (int i = n; i >= 1; -- i){
for (int j = 1; j <= n; ++ j){
dp[2][i][j] = max(dp[1][i + 1][j], dp[1][i][j - 1]) + a[i][j];
}
}
for (int i = 1; i <= n; ++ i){
for (int j = 1; j <= n; ++ j){
dp[0][i][j] = max(dp[0][i][j - 1], dp[0][i - 1][j]) + a[i][j];
}
}
for (int i = n; i >= 1; -- i){
for (int j = n; j >= 1; -- j){
dp[3][i][j] = max(dp[3][i + 1][j], dp[3][i][j + 1]) + a[i][j];
}
}
for (int i = 1; i <= n; ++ i){
int pre = -2e9;
for (int j = 1; j <= n; ++ j){
pre = max(pre, dp[0][i - 1][j] + dp[2][i + 1][j]) + a[i][j];
ans = max(ans, pre + dp[1][i - 1][j] + dp[3][i + 1][j]);
}
}
for (int j = 1; j <= n; ++ j){
int pre = -2e9;
for (int i = 1; i <= n; ++ i){
pre = max(pre, dp[0][i][j - 1] + dp[1][i][j + 1]) + a[i][j];
ans = max(ans, pre + dp[2][i][j - 1] + dp[3][i][j + 1]);
}
}
return ans;
}