#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <deque>
#include <set>
#include <climits>

#define rep_(v, f, l) for (int v = (f); v < (l); ++v)
#define rep(v, n) rep_(v, 0, n)

using namespace std;

typedef long long int lint;

template<typename T> inline bool in(T& x){ return cin >> x; }
template<typename T> inline T in(){T x; cin >> x; return x; }

int main()
{
    vector<vector<int> > tri;
    string line;
    while (cin >> line){
        vector<int> a;
        int s = 0;
        rep(i, line.size()){
            if (line[i] >= '0' && line[i] <= '9'){
                s *= 10;
                s += line[i] - '0';
            }
            else {
                a.push_back(s);
                s = 0;
            }
        }
        a.push_back(s);
        tri.push_back(a);
    }

    vector<vector<int> > max_tri = tri;
    rep(i, tri.size() - 1){
        rep(j, tri[i].size()){
            if (i < tri.size() / 2){
                max_tri[i + 1][j] = max(max_tri[i + 1][j], max_tri[i][j] + tri[i + 1][j]);
                max_tri[i + 1][j + 1] = max(max_tri[i + 1][j + 1], max_tri[i][j] + tri[i + 1][j + 1]);
            }
            else {
                if (j > 0) max_tri[i + 1][j - 1] = max(max_tri[i + 1][j - 1], max_tri[i][j] + tri[i + 1][j - 1]);
                if (j < tri[i].size() - 1) max_tri[i + 1][j] = max(max_tri[i + 1][j], max_tri[i][j] + tri[i + 1][j]);
            }
        }
    }
    printf("%d\n", max_tri[tri.size() - 1][0]);
	return (0);
}