def f(path)
  path = rotate(path)
  path[0][1..-1].size.times{|x|path[0][x + 1] += path[0][x]}
  for y in 1...path.size
    path[y][0] += path[y - 1][0]
    for x in 1...path[y].size
      path[y][x] += [path[y - 1][x], path[y][x - 1]].max
    end
  end
  return path[-1][-1]
end
def rotate(path)
  square = Array.new(path.size / 2 + 1){Array.new(path.size / 2 + 1)}
  path[0...path.size / 2].each_with_index{|row, idx|
    row.each_with_index{|n, i|
      square[idx - i][i] = n
    }
  }
  path[path.size / 2..-1].each_with_index{|row, idx|
    row.each_with_index{|n, i|
      square[path.size / 2 - i][idx + i] = n
    }
  }
  return square
end
def main(input = STDIN)
  path = []
  while arg = input.gets
    path << arg.split(",").map(&:to_i)
  end
  puts f(path)
end
main