a,b=0,0 gets;$<.map{a,b=_1.split.map{|i|[a+i=i.to_i,b<1?0:b+i*2].max}} p a