#include <iostream>
using namespace std;
const int N = 505;
int q[N][N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= i; ++j) {
cin >> q[i][j];
}
}
for (int i = n - 2; ~i; --i) {
for (int j = 0; j <= i; ++j) {
q[i][j] += max(q[i+1][j], q[i+1][j+1]);
}
}
cout << q[0][0] << endl;
return 0;
}