#include <iostream>
#include <string>
#include <cstdlib>

int numOfIndices(int i, int rows)
{
	if (i <= rows/2) return i+1;
	else return rows - i;
}

int max(int x, int y)
{
	return x>y ? x : y;
}

int main()
{
	int board[100][50];
	
	
	int rows = 0;
	// read the board
	bool first_row = false;
	bool last_row = false;
	while (!last_row) {
		std::string buf;
		std::cin >> buf;
		if (buf == "\n") break;
		
		int offset = 0;
		int index = 0;
		while(true) {
			int pos = buf.find(',', offset);
			if ( pos == std::string::npos ) {
				std::string str_num = buf.substr(offset);
				board[rows][index] = std::atoi(str_num.c_str());
				break;
			}
			else {
				std::string str_num = buf.substr(offset, pos - offset);
				board[rows][index] = std::atoi(str_num.c_str());
				offset = pos + 1;
				index++;
			}
		}
		if (index == 0) {
			if (!first_row) {
				first_row = true;
			} else if (!last_row) {
				last_row = true;
			}
		}
		rows++;
	}
	
	// DP
	int DP[100][50];
	for (int i=0; i<100; i++) {
		for (int j=0; j<50; j++) DP[i][j] = -1;
	}
	
	DP[0][0] = board[0][0];
	for (int i=1; i<rows; i++) {
		for (int j=0; j<numOfIndices(i,rows); j++) {
			if (i<=rows/2) {
				if (i>0) DP[i][j] = max(DP[i-1][j-1], DP[i-1][j]) + board[i][j];
				else DP[i][j] = DP[i-1][j] + board[i][j];
			}
			else {
				DP[i][j] = max(DP[i-1][j], DP[i-1][j+1]) + board[i][j];
			}
		}
	}
	
	//std::cout << std::endl;
	//for (int i=0; i<rows; i++) {
	//	for (int j=0; j<numOfIndices(i,rows); j++) {
	//		std::cout << DP[i][j] << " ";
	//	}
	//	std::cout << std::endl;
	//}
	
	std::cout << DP[rows-1][0] << std::endl;
	
	return 0;
}

