array=[]
while s=gets
    array<<s.split(",").map(&:to_i)
end
sum=[]
sum[0]=[array[0][0]]
for i in 1..8 do
    sum[i]=[]
    if i<=4
        for j in 0..i
            x=0;y=0
            x=sum[i-1][j-1] if (j-1>=0)
            y=sum[i-1][j] if (j<i)
            sum[i][j]=([x,y].max)+array[i][j]
        end
    else
        for j in 0..8-i do
            x=sum[i-1][j+1]
            y=sum[i-1][j]
            sum[i][j]=([x,y].max)+array[i][j]
        end
    end
end

puts sum[8]