N=gets.to_i V=gets.split.map(&:to_i) if N==1 puts V[0] exit end if N==2 puts [V[0],V[1]].max exit end DP=Array.new(N+1,0) DP[1],DP[2]=V[0],V[1] for i in 3..N do DP[i]=[DP[i-2],DP[i-3]].max+V[i-1] end puts [DP[N],DP[N-1]].max