Python simple DP
Score is set by first operation.  Just take max of all 3 possibilities.  DP simply takes the score (which doesn\'t change) and the first and last index. \n\nCom
Score is set by first operation.  Just take max of all 3 possibilities.  DP simply takes the score (which doesn\'t change) and the first and last index. \n\nComplexity and space are both theoreticaly O(n^2) but it does finish in time, note max length is 2000\n```\nclass Solution:\n    def maxOperations(self, nums: List[int]) -> int:\n        \n        @cache\n        def dp(score, first, last):\n            if last<=first: return 0\n            ret = 0\n            if nums[first]+nums[first+1]==score: ret = max(ret, 1+dp(score,first+2,last))\n            if nums[first]+nums[last]==score:    ret = max(ret, 1+dp(score,first+1,last-1))\n            if nums[last]+nums[last-1]==score:   ret = max(ret, 1+dp(score,first,last-2))\n            return ret\n        \n        \n        return 1+max( dp(nums[0]+nums[1],2,len(nums)-1) , \n                      dp(nums[0]+nums[-1],1,len(nums)-2) , \n                      dp(nums[-1]+nums[-2],0,len(nums)-3) )\n\t\t```
[]