require 'pp' n = gets.to_i v = gets.strip.split.map(&:to_i) if n === 1 puts v[0] exit end 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]