#include <iostream>
#include <algorithm>
using namespace std;
int tri[501][501];
int dp[501][501];
int N;
int solution(int deep, int index)
{
if (deep == N - 1) return tri[deep][index]; //맨 밑에 있는 요소에 접근했을 때
if (!dp[deep][index]) // 대각선 왼쪽과 오른쪽의 값을 비교 후 더 큰 값을 현재 위치의 값을 더한 결과를 dp에 저장
dp[deep][index] = max(solution(deep + 1, index), solution(deep + 1, index + 1)) + tri[deep][index];
return dp[deep][index]; //dp의 값이 있거나 이미 처리가 된 경우
}
int main(void)
{
cin >> N;
for (int i = 0; i < N; i++)
for (int j = 0; j < i + 1; j++)
cin >> tri[i][j];
cout << solution(0, 0);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCB0cmlbNTAxXVs1MDFdOwppbnQgZHBbNTAxXVs1MDFdOwppbnQgTjsKCmludCBzb2x1dGlvbihpbnQgZGVlcCwgaW50IGluZGV4KQp7CglpZiAoZGVlcCA9PSBOIC0gMSkgcmV0dXJuIHRyaVtkZWVwXVtpbmRleF07CQkvL+unqCDrsJHsl5Ag7J6I64qUIOyalOyGjOyXkCDsoJHqt7ztlojsnYQg65WMCglpZiAoIWRwW2RlZXBdW2luZGV4XSkJLy8g64yA6rCB7ISgIOyZvOyqveqzvCDsmKTrpbjsqr3snZgg6rCS7J2EIOu5hOq1kCDtm4Qg642UIO2BsCDqsJLsnYQg7ZiE7J6sIOychOy5mOydmCDqsJLsnYQg642U7ZWcIOqysOqzvOulvCBkcOyXkCDsoIDsnqUKCQlkcFtkZWVwXVtpbmRleF0gPSBtYXgoc29sdXRpb24oZGVlcCArIDEsIGluZGV4KSwgc29sdXRpb24oZGVlcCArIDEsIGluZGV4ICsgMSkpICsgdHJpW2RlZXBdW2luZGV4XTsKCXJldHVybiBkcFtkZWVwXVtpbmRleF07CQkvL2Rw7J2YIOqwkuydtCDsnojqsbDrgpgg7J2066+4IOyymOumrOqwgCDrkJwg6rK97JqwCn0KCmludCBtYWluKHZvaWQpCnsKCWNpbiA+PiBOOwoKCWZvciAoaW50IGkgPSAwOyBpIDwgTjsgaSsrKQoJCWZvciAoaW50IGogPSAwOyBqIDwgaSArIDE7IGorKykKCQkJY2luID4+IHRyaVtpXVtqXTsKCgljb3V0IDw8IHNvbHV0aW9uKDAsIDApOwoJcmV0dXJuIDA7Cn0=