#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    string s;
    int num = 0;
    vector<int> rhombus;

    // Input
    while (cin >> s) {
        for (int i = 0; i < s.size(); i++) {
            int n = s[i++] - '0';
            while ('0' <= s[i] && s[i] <= '9') 
                n = n * 10 + (s[i++] - '0');

            rhombus.push_back(n);
            num++;
        }
    }

    int index = 1;
    for (int i = 2; i * i <= num; i++) {
        rhombus[index] += rhombus[index - i + 1];
        index++;
        for (int j = 1; j <= i - 2; j++) {
            rhombus[index] += max(rhombus[index - i], rhombus[index - i + 1]);
            index++;
        }
        rhombus[index] += rhombus[index - i];
        index++;
    }
    for (int i = sqrt(num) - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            rhombus[index] += max(rhombus[index - i - 1], rhombus[index - i]);
            index++;
        }
    }

    cout << rhombus[num - 1] << endl;

    return 0;
}