a = $<.map{|s| s.split(",").map(&:to_i)}
(1..a.size-1).each{|i|
    (0..a[i].size-1).each{|j|
        if a[i-1].size < a[i].size
            a[i][j] = [a[i-1][j] || 0, j > 0 ? a[i-1][j-1] : 0].max + a[i][j]
        else
            a[i][j] = [a[i-1][j], a[i-1][j+1]].max + a[i][j]
        end
    }
}
p a[-1][0]