import java.util.Scanner;
public class DigitalTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[][] array = new int[n][];
for (int i = 0; i < n; i++) {
array[i] = new int[i + 1];
for (int j = 0; j < i + 1; j++) {
array[i][j] = input.nextInt();
}
}
int sum = 0;
for(int row=n-2;row>=0;row--){
for(int colum=0;colum<row+1;colum++){
array[row][colum]=Math.max(array[row][colum]+array[row+1][colum], array[row][colum]+array[row+1][colum+1]);
}
}
System.out.println(array[0][0]);
}
}
public class DigitalTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[][] array = new int[n][];
for (int i = 0; i < n; i++) {
array[i] = new int[i + 1];
for (int j = 0; j < i + 1; j++) {
array[i][j] = input.nextInt();
}
}
int sum = 0;
for(int row=n-2;row>=0;row--){
for(int colum=0;colum<row+1;colum++){
array[row][colum]=Math.max(array[row][colum]+array[row+1][colum], array[row][colum]+array[row+1][colum+1]);
}
}
System.out.println(array[0][0]);
}
}