#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main() {
  int a[100][51], b[100][51] = {0};
  char s[100][100];

  int i;
  while (scanf("%s", s[i]) != EOF) {
    i++;
  }
  int n = i;
  for (i = 1; i <= n; i++) {
    for (int j = 0; s[i - 1][j] != '\0'; j++) {
      if (j % 2 == 0) a[i][j / 2] = s[i - 1][j] - '0';
    }
  }

  for (i = 1; i <= n; i++) {
    int t;
    if (i <= n / 2 + 1) t = i;
    else t = (n / 2 + 1) - (i - (n / 2 + 1));
    for (int j = 0; j < t; j++) {
      if (i <= n / 2 + 1) {
	if (j == 0) b[i][j] = a[i][j] + b[i - 1][j];
	else b[i][j] = a[i][j] + max(b[i - 1][j - 1], b[i - 1][j]);
      } else {
	b[i][j] = a[i][j] + max(b[i - 1][j], b[i - 1][j + 1]);
      }
    }
  }
  cout << b[n][0] << endl;
  
  return 0;
}