#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

#define MAX(A,B) ((A) > (B)? (A): (B))

int data[100][50] = {0};
int table[100][50] = {0};

int main() {
	int size = 0;
	char str[200];
	while (gets(str) != NULL) {
		for (int i = 0, count = 0, sum = 0, len = strlen(str); i <= len; i++) {
			if (str[i] == ',' || str[i] == '\0') {
				data[size][count++] = sum;
				sum = 0;
			} else {
				sum = str[i++] - '0';
				for (int j = i; '0' <= str[i] && str[i] <= '9'; i++)
					sum = sum*10 + (str[i]-'0');
				--i;
			}
		}
		++size;
	}
	table[0][0] = data[0][0];
	for (int i = 1; i < size; i++) {
		for (int j = 0, side = (i >= size/2+1? size-i: i+1); j < side; j++) {
			if (i == side-1) {
				if (j == 0)
					table[i][j] = table[i-1][0] + data[i][j];
				else if (j == side-1)
					table[i][j] = table[i-1][j-1] + data[i][j];
				else
					table[i][j] = MAX(table[i-1][j-1], table[i-1][j]) + data[i][j];
			} else {
				table[i][j] = MAX(table[i-1][j], table[i-1][j+1]) + data[i][j];
			}
		}
	}
	cout << table[size-1][0] << endl;
	return 0;
}