def inp(m=0) a=gets.chomp.split(" ").map(&:to_i);(a.size<2)? (m==0)? a[0]:a:a end def copy(a) Marshal.load(Marshal.dump(a)) end def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end def scount(a,b) a.each{|n|b[n]+=1} end n = inp a = inp max = Array.new(1001){Array.new(2,0)} 0.upto(n-1) do |d| if(max[d][0] > 1) max[d+1][0] = [max[d][0],max[d][1]].max max[d+1][1] = [(max[d][0]+a[d]),max[d][1]].max elsif(max[d][1] > 1) max[d+1][0] = [max[d][0],max[d][1]].max max[d+1][0] = [(max[d][0]+a[d]),max[d][1]].max else max[d+1][1] = a[d] end end p max[n][1]