N = gets.to_i V = gets.split.map(&:to_i) def f(i) @dp ||= {} @dp[i] ||= if i >= N 0 else [V[i] + f(i + 2), f(i + 1)].max end end ans = f(0) puts ans