/*

* 숫자삼각형

*/

#include <stdio.h>

#include <unistd.h>




int main()

{

//ios::sync_with_stdio(0);


short n, row, col;

int   mat[501][501] = {0};

int   max = 0;


char inputs[1000];

char* ptr;

char* end;


ptr = inputs;

end = inputs + read(0, inputs, 1000);

int sign = 1;

if (*ptr == '-') sign = -1, ptr++;

for (n = 0; *ptr++ >= '0'; )

n = n * 10 + (ptr[-1] - '0');


for (row = 0; row < n; ++row)

for (col = 0; col <= row; ++col)

{

ptr = inputs;

end = inputs + read(0, inputs, 1000);


sign = 1;

if (*ptr == '-') sign = -1, ptr++;

for (mat[row][col] = 0; *ptr++ >= '0'; )

mat[row][col] = mat[row][col] * 10 + (ptr[-1] - '0');

}


for (row = 1; row < n; ++row)

{

mat[row][0] += mat[row - 1][0];


for (col = 1; col <= row; ++col)

mat[row][col] += mat[row - 1][col - 1] > mat[row - 1][col] ? mat[row - 1][col - 1] : mat[row - 1][col]; // left vs right

}


for (col = 0; col < n+1; ++col)

if (mat[n-1][col] > max)

max = mat[n-1][col];


printf("%d", max);


return 1;

}



요거 시간요류 뜨던뎅..