package Week1;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5 求左斜下或者右斜下相加和最大
*/
//动态规划
public class F_Triangle {
static int N;
static int dp[][]=new int[N+1][N+1];
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("Solution.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
dp=new int[N+1][N+1];
for (int i = 1; i <= N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 1; j <= i; j++) {
dp[i][j]=Integer.parseInt(st.nextToken());
}
}
for (int i = N-1; i > 0; i--) {
for (int j = 1; j <= i; j++) {
if(i+1<=N && j+1<=N) {
dp[i][j] += Math.max(dp[i+1][j], dp[i+1][j+1]);
}
}
}
System.out.println(dp[1][1]);
}
}