#include<bits/stdc++.h>
using namespace std;
const int len = 5;
int data[len][len];

int dp[len+1][len+1];
void solve() {
    memset(dp, 0, sizeof(dp));
    for(int r = 0; r < len; r++) {
        for(int c = 0; c < len; c++) {
            dp[r+1][c+1] = max(dp[r+1][c], dp[r][c+1]); //select
            dp[r+1][c+1] += data[r][c]; //add
        }
    }
    printf("%d\n", dp[len][len]);
}

void input() {
    scanf("%d", &data[0][0]);
    scanf("%d,%d", &data[1][0], &data[0][1]);
    scanf("%d,%d,%d", &data[2][0], &data[1][1], &data[0][2]);
    scanf("%d,%d,%d,%d", &data[3][0], &data[2][1], &data[1][2], &data[0][3]);
    scanf("%d,%d,%d,%d,%d", &data[4][0], &data[3][1], &data[2][2], &data[1][3], &data[0][4]);
    scanf("%d,%d,%d,%d", &data[4][1], &data[3][2], &data[2][3], &data[1][4]);
    scanf("%d,%d,%d", &data[4][2], &data[3][3], &data[2][4]);
    scanf("%d,%d", &data[4][3], &data[3][4]);
    scanf("%d", &data[4][4]);
}

void print() {
    for(int r = 0; r <= len; r++) {
        for(int c = 0; c <= len; c++) {
            cout << dp[r][c];
            if(c == len) putchar('\n');
            else putchar(' ');
        }
    }
}

int main(void) {
    input();
    solve();
    return(0);
}