#include <iostream>
#include <string>
#include <algorithm>

std::string str;
int input[10][10], memo[10][10], hoge[10];

void makes(){
    std::string tmp = "";
    int cnt = 0;
    for(int i = 0; i < str.size(); i++){
        if(str[i] == ','){
            hoge[cnt] = std::atoi(tmp.c_str());
            cnt++;

            tmp = "";
            continue;
        }

        tmp += str[i];
    }
    hoge[cnt] = std::atoi(tmp.c_str());
    for(int i = cnt + 1; i < 10; i++){
        hoge[i] = 0;
    }
}

int main(){
    int u = 0;
    for(int i = 0; i < 9; i++){
        getline(std::cin, str);

        makes();
        if(i > 4) u++;
        for(int j = 0; j < 10; j++){
            input[i][j + u] = hoge[j];
        }
    }

    memo[0][0] = input[0][0];
    for(int i = 0; i < 10; i++){
        for(int j = 0; j <= i; j++){
            memo[i + 1][j] = std::max(memo[i + 1][j], memo[i][j] + input[i + 1][j]);
            memo[i + 1][j + 1] = std::max(memo[i + 1][j + 1], memo[i][j] + input[i + 1][j + 1]);
        }
    }

    int ans = 0;
    for(int i = 0; i < 10; i++){
        if(ans < memo[9][i]) ans = memo[9][i];
    }

    std::cout << ans << std::endl;

    return 0;
}