#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
using namespace std;

int index(char c){
	return c - '0';
}

int get_num(string num){
	int c = 0;
	int n = 1;
	for(string::reverse_iterator riter = num.rbegin();
		riter != num.rend(); riter++)
	{
		c += n * index(*riter);
		n = n * 10;
	}
	return c;
}

int main(){
	string s;
	int nums[50];
	vector<string> vs;
	vector<vector<int> > area;
	while(getline(cin, s)) vs.push_back(s);
	int n = vs.size();
	for(vector<string>::iterator iter = vs.begin();
		iter != vs.end(); iter++)
	{
		vector<int> vi;
		for(string::iterator siter = (*iter).begin();
			siter != (*iter).end(); siter++)
		{
			string num;
			while(siter != (*iter).end() && isdigit(*siter)) num.push_back(*(siter++));
			vi.push_back(get_num(num));
			if(siter == (*iter).end()) break;
		}
		area.push_back(vi);
	}

	for(int k = 0; k < 50; k++){
		nums[k] = 0;
	}
	nums[0] = area[0][0];
	int i = 1;
	while(i < n / 2){
		nums[i] = nums[i - 1] + area[i][i];
		for(int j = i - 1; j > 0; j--){
			nums[j] = max(nums[j], nums[j-1]) + area[i][j];
		}
		nums[0] = nums[0] + area[i][0];
		i++;
	}
	while(i < n){
		for(int j = 0; j < n - i;j++){
			nums[j] = max(nums[j], nums[j+1]) + area[i][j];
		}
		i++;
	}
	cout << nums[0] << endl;
	return 0;
}