def printGraph graph
  graph.each do |d|
    p d
  end
end

def isTurn before, size
  before > size
end

def createGraph
  graph = Array.new

  before = -1
  while input = $stdin.gets do
    buf = Array.new
    n = input.chomp.split(",").map(&:to_i)
    (0...n.size).each do |j|
      l = ((t = isTurn(before,n.size)) && j == 0)? nil : ((t)? j - 1 : j)
      r = ((t = isTurn(before,n.size)) && j == n.size - 1)? nil : ((t)? j : j + 1)
      buf << [n[j], l, r , -1]
    end
    before = n.size
    graph << buf
  end

  #中央の行を更新
  line = graph[graph.size / 2]
  line.each do |d|
    d[1] -= 1
    d[2] -= 1
  end
  line[0][1] = nil
  line[line.size - 1][2] = nil
  graph
end

def solve graph
  max = 0
  stack = Array.new
  stack.push([0, 0, 0])

  while ! stack.empty? do
    y, x, sum = stack.pop
    sum += graph[y][x][0]
    if graph[y][x][3] < sum
      graph[y][x][3] = sum
      stack.push([y + 1, graph[y][x][1], sum]) if graph[y][x][1]
      stack.push([y + 1, graph[y][x][2], sum]) if graph[y][x][2]
      unless graph[y][x][1] || graph[y][x][2]
        max = sum if max < sum
      end
    end
  end
  max
end

p solve(createGraph)