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

using namespace std;

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

    // Input
    while (cin >> s) {
        cerr << s << endl;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == ',')
                continue;
            rhombus.push_back((int)(s[i] - '0'));
            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 - 1; 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;
}