/* ????????????????????????????????????????????? */
#include <stdio.h>

/* ?????°???????????? */
typedef	void			VD;
typedef	signed char		I1;
typedef unsigned char 	U1;
typedef	signed short	I2;
typedef unsigned short 	U2;
typedef	signed long		I4;
typedef unsigned long 	U4;

/* ?????°?????? */
#define MAXOFNUM_ROW 	99					/* ?????°????????§??? */
#define MAXOFSUM_COLUMN	(MAXOFNUM_ROW+1)/2	/* ?????°????????§??? */

/* ??°?????????????????° */
U1 mu1InputNum[MAXOFNUM_ROW][MAXOFSUM_COLUMN];	/* ??\??????????????°??????????´????????????? */

/* 
??¢??°??????u1ReadData
???????????\???????????????????????????????????°???????????? 
?????°???
?????????
????????????U1 ??\?????????????????°
*/
U1 u1ReadData();

/*
??¢??°??????u2SearchMax
???????????¨????????????????????§?????§???????????????
?????°???
????¬¬1?????°????????°
????????????U2 ?????§???
*/
U2 u2SearchMax(U1 u1NumOfRow);

/*
??¢??°??????
?????????2????????°??????????????§????????°????????????
?????°???
????¬¬1?????°?????°???1
????¬¬2?????°?????°???2
????????????U2 ??§??????????????°???
*/
U2 u2JudjeBigNum(U2 u2Num1,U2 u2Num2);

U4 main(void)
{
	U1 u1NumOfRow;						/* ?????????????????° */
	U2 u2MaxOfSum;						/* ???????????§??? */
	
	u1NumOfRow = u1ReadData();				/* ??????1 ??\??????????????????????????? */
	u2MaxOfSum = u2SearchMax(u1NumOfRow);	/* ??????2 ?????§????????¢??? */
	printf("%d\n",u2MaxOfSum);				/* ??????3 ?????§????????¨????????? */
        return(0);
}

U1 u1ReadData()
{
	U1 u1NumOfRow;		/* ?????????????????° */
	U1 u1NumOfColumn;	/* ?????????????????° */
	U1 u1TmpChar;		/* ','????????????'\n'???????´????????????° */
	I1 i1ReturnScanf;	/* scanf??¢??°???????????????????´????????????° */
	
	U1 u1OnlyNumCnt;
	
	u1NumOfRow = 0;
	u1NumOfColumn = 0;
	u1OnlyNumCnt = 0;
	
	while(u1OnlyNumCnt != 2){
		scanf("%d%c",&mu1InputNum[u1NumOfRow][u1NumOfColumn],&u1TmpChar);
		if(u1TmpChar == ','){
			u1NumOfColumn++;
			u1TmpChar = 0;
		}
		else{
			if(u1NumOfColumn == 0){
				u1OnlyNumCnt++;
			}
			u1NumOfRow++;
			u1NumOfColumn = 0;
		}
	}
	return u1NumOfRow;
}


U2 u2SearchMax(U1 u1NumOfRow)
{
	U2 mu2work[MAXOFNUM_ROW][MAXOFSUM_COLUMN];	/* ?¨???????????????????????´????????????? */
	U1 u1RowCnt;		/* ?????°???????????? */
	U1 u1ColumnCnt;		/* ?????°???????????? */
	U1 u1HalfNumOfRow;	/* ?????°????????? */
	U2 u2Num1;			/* ?¨?????????????????´???????????????°??????????´????????????° */
	U2 u2Num2;			/* ?¨?????????????????´???????????????°??????????´????????????° */
	
	u1HalfNumOfRow = u1NumOfRow/2+1;
	
	/* ??\?????????????????????mu2work?????????????????? */
	for(u1RowCnt = 0; u1RowCnt < u1NumOfRow; u1RowCnt++){
		for(u1ColumnCnt = 0; u1ColumnCnt <= u1RowCnt; u1ColumnCnt++){
			if(u1RowCnt >= u1HalfNumOfRow){
				if(u1ColumnCnt >= u1HalfNumOfRow*2-(u1RowCnt+1)){
					break;
				}
			}
			mu2work[u1RowCnt][u1ColumnCnt] = mu1InputNum[u1RowCnt][u1ColumnCnt];
		}
	}
	
	for(u1RowCnt = 1; u1RowCnt < u1NumOfRow; u1RowCnt++){
		for(u1ColumnCnt = 0; u1ColumnCnt <= u1RowCnt; u1ColumnCnt++){
			/* ????????¢?????¨???????´???°????¨????????????´??? */
			if(u1RowCnt < u1HalfNumOfRow){				
				if(u1ColumnCnt == 0){
					mu2work[u1RowCnt][u1ColumnCnt] = mu1InputNum[u1RowCnt][u1ColumnCnt]+mu2work[u1RowCnt-1][0];
				}
				else if(u1ColumnCnt == u1RowCnt){
					mu2work[u1RowCnt][u1ColumnCnt] = mu1InputNum[u1RowCnt][u1ColumnCnt]+mu2work[u1RowCnt-1][u1RowCnt-1];
				}
				else{
					u2Num1 = mu2work[u1RowCnt-1][u1ColumnCnt-1];
					u2Num2 = mu2work[u1RowCnt-1][u1ColumnCnt];
					mu2work[u1RowCnt][u1ColumnCnt] = mu1InputNum[u1RowCnt][u1ColumnCnt]+u2JudjeBigNum(u2Num1,u2Num2);
				}
			}
			/* ????????¢?????¨???????´???°????¨????????????´??? */
			else{
				if(u1ColumnCnt >= u1HalfNumOfRow*2-(u1RowCnt+1)){
					break;
				}
				u2Num1 = mu2work[u1RowCnt-1][u1ColumnCnt];
				u2Num2 = mu2work[u1RowCnt-1][u1ColumnCnt+1];
				mu2work[u1RowCnt][u1ColumnCnt] = mu1InputNum[u1RowCnt][u1ColumnCnt]+u2JudjeBigNum(u2Num1,u2Num2);
			}
		}
	}
	return mu2work[u1NumOfRow-1][0];
}

U2 u2JudjeBigNum(U2 u2Num1,U2 u2Num2)
{
	U2 u2Rtn;	/* ????????????????´????????????° */
	
	if(u2Num1 >= u2Num2){
		u2Rtn = u2Num1;
	}else{
		u2Rtn = u2Num2;
	}	
	return u2Rtn;
}

Measured memory_bytes: 612