N = gets.to_i V = gets.split.map(&:to_i) $dp = {} def f(v ,i) $dp[i] ||= if i < 2 V[i] else [V[i] + f(v, i-2), f(v, i-1)].max end end p f(0, N-1)