max = [gets.to_i]
size = 0
readlines.map(&:chomp).each{|line|
  arr = line.split(",").map(&:to_i)
  old_max = max.clone
  max = []
  if size < arr.size
    arr.size.times{|i|
      if i > 0
        max[i] = old_max[i-1,2].max + arr[i]
      else
        max[i] = old_max[i] + arr[i]
      end
    }
    size = arr.size
  else
    arr.size.times{|i|
      max[i] = old_max[i,2].max + arr[i]
    }
    size = arr.size
  end
}
puts max