require 'pp' n = gets.to_i v = gets.strip.split.map{|e| e.to_i} dp = {} dp[0] = v[0] dp[1] = [v[0], v[1]].max (2..n - 1).each do |i| dp[i] = [dp[i-1], dp[i-2] + v[i]].max end puts dp[n - 1]