#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<vector<int>> v(11, vector<int>(7, -1));
    char c;
    for (int i=1; i<=9; ++i) {
        for (int j=1, l=min(i,10-i); j<=l; ++j) {
            if (1 < j) cin >> c;
            cin >> v[i][j];
        }
    }
    vector<vector<int>> dp(11, vector<int>(7, 0));
    for (int i=1; i<=9; ++i) {
        for (int j=1, l=min(i,10-i); j<=l; ++j) {
            if (i < 10-i) {
                dp[i][j] = v[i][j] + max(dp[i-1][j], dp[i-1][j-1]);
            } else {
                dp[i][j] = v[i][j] + max(dp[i-1][j], dp[i-1][j+1]);
            }
        }
    }
    cout << dp[9][1] << endl;
    return 0;
}