c++ solution
\nclass Solution {\npublic:\n    int n;\n    int dp[2005][2005];\n    int find(vector<int>&nums,int sum,int i,int j)\n    {\n        if(i>=j) return 0;\n       
```\nclass Solution {\npublic:\n    int n;\n    int dp[2005][2005];\n    int find(vector<int>&nums,int sum,int i,int j)\n    {\n        if(i>=j) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int ans=0;\n        if(nums[i]+nums[i+1]==sum)\n        {\n            ans=max(ans,1+find(nums,sum,i+2,j));\n        }\n        if(nums[i]+nums[j]==sum)\n        {\n            ans=max(ans,1+find(nums,sum,i+1,j-1));\n        }\n        if(nums[j]+nums[j-1]==sum)\n        {\n            ans=max(ans,1+find(nums,sum,i,j-2));\n        }\n        return dp[i][j] = ans;\n    }\n    int maxOperations(vector<int>& nums) {\n        n=nums.size();\n        memset(dp,-1,sizeof(dp));\n        int firstOperation=find(nums,nums[0]+nums[1],2,n-1);\n        memset(dp,-1,sizeof(dp));\n        int secondOperation=find(nums,nums[n-1]+nums[n-2],0,n-3);\n        memset(dp,-1,sizeof(dp));\n        int thirdOperation=find(nums,nums[0]+nums[n-1],1,n-2);\n        return 1+max({firstOperation,secondOperation,thirdOperation});\n    }\n};\n```
['C', 'C++']