ls = STDIN.map{|l| l.split(',').map(&:to_i)}
ls.map!.with_index{|l, i| (0...i-(ls.size/2)).to_a.map{nil} + l + (0...(ls.size/2)-i).to_a.map{nil}}

dp = Array.new(ls.size+1).map{Array.new}
m = 0
(0...ls.size).each do |n|
  ls[n].each_with_index do |v, i|
    unless v.nil?
      dp[n][i] = [(n-1>=0&&!dp[n-1][i].nil?) ? dp[n-1][i] : 0, (n-1>=0&&i-1>=0) ? dp[n-1][i-1] : 0].max + ls[n][i] 
      m = dp[n][i] if dp[n][i] > m
    end
  end
end
p m