#include <bits/stdc++.h>
using namespace std;
long long n, mat1[1005][1005],s[1005],dp[1005][1005],mini,maxi;
int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    cin>>n;
    for(int i = 1; i <= n; i++){
            cin>>s[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin>>mat1[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            mini = min(dp[i-1][j], dp[i][j-1]);
            maxi = max(dp[i-1][j], dp[i][j-1]);
            if(mini == 0) dp[i][j] += maxi + mat1[i][j];
            else dp[i][j] += mini + mat1[i][j];

        }
    }
    cout<<dp[n][n]<< endl;
return 0;
}