#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	char str[256];
	while(scanf("%s", str) != EOF){
		int dp[128] = {0};
		bool increasing = true;
		int num = 0;
		do{
			int tmp[128];
			int tmp_size = 0;

			sscanf(str, "%d,", &tmp[0]);
			++tmp_size;
			rep(i, strlen(str)){
				if(str[i] == ','){
					sscanf(str+i+1, "%d,", &tmp[tmp_size]);
					++tmp_size;
				}
			}

			if(tmp_size < num)
				increasing = false;
			num = tmp_size;

			rep(i, num){
				if(increasing)
					tmp[i] += max(dp[i], i ? dp[i-1] : 0);
				else
					tmp[i] += max(dp[i], dp[i+1]);
			}

			rep(i, num){
				dp[i] = tmp[i];
			}
			if(!increasing && num == 1)
				break;
		}while(scanf("%s", str) != EOF);
		printf("%d\n", dp[0]);
	}
	return 0;
}