N = gets.to_i V = gets.split.map(&:to_i) $dp = Hash.new 0 $dp[0] = V[0] (1...N).each{|i| $dp[i] = [$dp[i - 3], $dp[i - 2]].max + V[i] } p $dp[N-1]