import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	auto pre = readln.chomp.split(",").map!(to!int).array;
  foreach (line; stdin.byLine) {
    auto now = line.chomp.split(",").map!(to!int).array;
    auto tmp = new int[](now.length);

    if (pre.length < now.length) {
      foreach (i; 0..pre.length) {
        tmp[i] = max(tmp[i], pre[i] + now[i]);
        tmp[i+1] = max(tmp[i+1], pre[i] + now[i+1]);
      }
    } else {
      foreach (i; 0..now.length) {
        tmp[i] = max(max(tmp[i], pre[i] + now[i]), pre[i+1] + now[i]);
      }
    }
    pre = tmp;
  }
  pre[0].writeln;
}