#include <iostream>
#include <algorithm>
int a[501][501], dp[501][501];
int main() {
int n;
std::cin >> n;
for (int i = 0; i<n; i++) {
for (int j = 0; j <= i; j++) {
std::cin >> a[i][j];
}
}
dp[0][0] = a[0][0];
for (int i = 1; i<n; i++) {
dp[i][0] = dp[i - 1][0] + a[i][0];
for (int j = 1; j<i; j++) {
dp[i][j] = std::max(dp[i - 1][j - 1], dp[i - 1][j]) + a[i][j];
}
dp[i][i] = dp[i - 1][i - 1] + a[i][i];
}
int max = 0;
for (int i = 0; i<n; i++) {
if (max<dp[n - 1][i]) max = dp[n - 1][i];
}
std::cout << max;
return 0;
}