# @param {Integer[]} nums
# @return {Integer}
def rob(nums)
    @buffer = {}
    dp(nums)
end

def dp(nums)
  return 0 if nums.empty?
  
  @buffer[nums.size] ||= [
    dp(nums[0...-1]), 
    nums.last + dp(nums[0...-2])
  ].max
end