#include <iostream>
#include <string>

using namespace std;

int pow(int x, int n) {
  int ans = 1;
  for(int i = 0; i < n; i++) {
    ans *= x;
  }
  return ans;
}
int charToInt(char c) {
  return (int)c - (int)'0';
}

int strToInt(string str) {
  int ans = 0;
  for(int i = 0; i < str.length(); i++) {
    ans += charToInt(str[i]) * pow(10, (int)str.length()-i-1);
  }
  return ans;
}

int main() {
  string str;
  int l = 1;
  string temp;
  int data[100][50];
  while(getline(cin, str)) {
    if(l == 1) {
      for(int i = 0; i < 100; i++) {
	for(int j = 0; j < 50; j++) {
	  data[i][j] = -1;
	}
      }
    }
    int t = 0;
    int count = 0;
    int s = 0;
    for(int i = 0; i <= str.length(); i++) {
      if(str[i] == ',' || i == str.length()) {
	count++;
	data[l-1][t++] = strToInt(str.substr(s, i-s));
	s = i+1;
      }
    }
    l++;
  }
  l -= 1;
  int w = l/2+1;
  int value[l][w];
  for(int i = 0; i < l; i++) {
    for(int j = 0; j < w; j++) {
      value[i][j] = -1;
    }
  }
  value[0][0] = data[0][0];
  for(int i = 1; i < l; i++) {
    for(int j = 0; j < w; j++) {
      if(data[i][j] == -1) break;
      for(int k = 0; k < 2; k++) {
	int nx, ny;
	ny = i-1;
	if(i <= l/2) {
	  switch(k) {
	  case 0:
	    nx = j-1;
	    break;
	  case 1:
	    nx = j;
	    break;
	  }
	} else {
	  switch(k) {
	  case 0:
	    nx = j;
	    break;
	  case 1:
	    nx = j+1;
	    break;
	  }
	}
	if(nx < 0) continue;
	if(nx >= 50) continue;
	if(ny < 0) continue;
	if(ny >= 100) continue;
	if(data[ny][nx] == -1) continue;
	
	int newValue = data[i][j] + value[ny][nx];
	if(newValue > value[i][j]) value[i][j] = newValue;
      }
    }
  }
  
  cout << value[l-1][0] << endl;

  return 0;
}