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