#include<cstdio>#include<algorithm>#include<iostream>usingnamespacestd;inta[350][350];intd[350][350];intN;intmain(){scanf("%d",&N);inti,j;for(i=0;i<N;++i){for(j=0;j<i+1;++j){scanf("%d",&a[i][j]);}}d[0][0]=a[0][0];for(i=0;i<N-1;++i){for(j=0;j<=i;++j){// Note here the memoization technique that maximizes values for overlapping paths
d[i+1][j+1]=max(d[i+1][j+1],d[i][j]+a[i+1][j+1]);d[i+1][j]=max(d[i+1][j],d[i][j]+a[i+1][j]);}}cout<<*max_element(d[N-1],d[N-1]+N)<<endl;return0;}