#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

class Node{
public:
	int value;
	int max_val;

	Node() : value(-1), max_val(-1){
		return;
	}
	~Node(){
		return;
	}
};

int main(int argc, char **argv){
	std::string buf;
	std::vector<std::vector<Node> > vec;


#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		std::vector<Node> cur_vec;
		std::istringstream stream(buf);
		while(std::getline(stream, buf, ',')){
			Node n;
			n.value = std::stoi(buf);
			cur_vec.push_back(n);
		}
		vec.push_back(cur_vec);
	}

	vec[0][0].max_val = vec[0][0].value;
	for(int i = 1; i < vec.size(); i++){
		if(i <= vec.size() / 2){
			vec[i][0].max_val = vec[i - 1][0].max_val + vec[i][0].value;
			for(int j = 1; j < vec[i].size() - 1; j++){
				vec[i][j].max_val = std::max(vec[i - 1][j - 1].max_val, vec[i - 1][j].max_val) + vec[i][j].value;
			}
			vec[i].back().max_val = vec[i - 1].back().max_val + vec[i].back().value;
		}
		else{
			for(int j = 0; j < vec[i].size(); j++){
				vec[i][j].max_val = std::max(vec[i - 1][j].max_val, vec[i - 1][j + 1].max_val) + vec[i][j].value;
			}
		}
	}

	std::cout << vec.back().back().max_val << std::endl;
 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}
