#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int str_to_int(string str, int a[100]){
	int num = 0;
	int index = 0;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == ','){
			a[index] = num;
			index++;
			num = 0;
		}else{
			num = num * 10 + (str[i] - '0');
		}
	}
	a[index] = num;
	index++;
	for(int i = index; i < 100; i++){
		a[i] = 0;
	}
	return index;
}

int main(){
	
	string str;
	int a[1000];
	int data[1000];
	
	for(int i = 0; i < 100; i++){
		a[0] = 0;
		data[i] = 0;
	}
	
	int pre_length = 0;
	
	while(true){
		cin >> str;
		if(cin.eof()){
			break;
		}
		int cur_length = str_to_int(str, a);
		if(pre_length > cur_length){
			for(int i = 0; i < 99; i++){
				a[i] = a[i] + max(data[i], data[i + 1]);
				//cout << a[i] << " ";
			}
			//cout << endl;
			for(int i = 0; i < 99; i++){
				data[i] = a[i];
			}
			data[99] = 0;
		}else{
			a[0] = a[0] + data[0];
			//cout << a[0] << " ";
			for(int i = 1; i < 100; i++){
				a[i] = a[i] + max(data[i], data[i - 1]);
				//cout << a[i] << " ";
			}
			//cout << endl;
			data[0] = a[0];
			for(int i = 1; i < 100; i++){
				data[i] = a[i];
			}
		}
		pre_length = cur_length;
		for(int i = 0; i < 10; i++){
			//cout << data[i] << " ";
		}
		//cout << endl;
	}
	
	cout << a[0] << endl;
	
	return 0;
}