def inp(m=1) 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(0) a = inp max = Array.new(1001){Array.new(2,0)} n.times do |d| if(max[d][0] > 1) cop = [max[d][0],max[d][1]].max max[d+1][1] = [(max[d][0]+a[d]),max[d][1]].max max[d+1][0] = cop elsif(max[d][1] > 1) cop = [max[d][0],max[d][1]].max max[d+1][1] = [(max[d][0]+a[d]),max[d][1]].max max[d+1][0] = cop else max[d+1][1] = a[d] end end p max[n][1]