@rh,@ans=[],0
while gets
  @rh<<$_.split(",").map(&:to_i)
end
@max=@rh.size-1
def rec(lnum,idx,sum)
  sum+=@rh[lnum][idx]
  if lnum+1==@max
    @ans=sum+@rh[lnum+1][0] if @ans<sum+@rh[lnum+1][0]
  elsif lnum+1<@max/2
    rec(lnum+1,idx,sum) if !@rh[lnum+1][idx].nil?
    rec(lnum+1,idx+1,sum) if !@rh[lnum+1][idx+1].nil?
  else
    rec(lnum+1,idx,sum) if !@rh[lnum+1][idx].nil?
    rec(lnum+1,idx-1,sum) if !@rh[lnum+1][idx-1].nil? and idx>0
  end
  return @ans
end
p rec(0,0,0)