Direct solution, Dynamic Programming, O(n^2)
Intuition\nUse DP.\n\n# Approach\nUse DP. At first create a dictionary to keep the intermediate results:\n\nvar dic = new Dictionary<(int index0, int index1), i
# Intuition\nUse DP.\n\n# Approach\nUse DP. At first create a dictionary to keep the intermediate results:\n```\nvar dic = new Dictionary<(int index0, int index1), int>();\n```\nThe key in this dictionary is a tuple `(int index0, int index1)`, where `index0` and `index1` are the first and the last considered indexes in array `nums`.\nAdd a method for DP:\n```\nprivate int MaxOperations((int index0, int index1) key, Dictionary<(int index0, int index1), int>  dic, int sum, int[] nums)\n```\nIn this method\n- `(int index0, int index1) key` is the key for the dictionary\n- `Dictionary<(int index0, int index1), int> dic` is the dictionary to keep the intermediate results\n- `int sum` is the sum of 2 items\n- `int[] nums` is the initial array\nCall this method recursively.\n\n# Complexity\n- Time complexity:\n$$O(n^2)$$\n\n- Space complexity:\n$$O(n^2)$$\n\n# Code\n```\npublic class Solution {\n    public int MaxOperations(int[] nums) {\n        var dic = new Dictionary<(int index0, int index1), int>();\n        var sum = nums[0] + nums[1];\n        var rs0 = 1 + MaxOperations((2, nums.Length - 1), dic, sum, nums);\n        sum = nums[0] + nums[nums.Length - 1];\n        var rs1 = 1 + MaxOperations((1, nums.Length - 2), dic, sum, nums);\n        sum = nums[nums.Length - 2] + nums[nums.Length - 1];\n        var rs2 = 1 + MaxOperations((0, nums.Length - 3), dic, sum, nums);\n        var rs = Math.Max(Math.Max(rs0, rs1), rs2);\n        return rs;\n    }\n    private int MaxOperations((int index0, int index1) key, Dictionary<(int index0, int index1), int>  dic, int sum, int[] nums)\n    {\n        if (key.index1 <= key.index0) return 0;\n        if (dic.ContainsKey(key)) return dic[key];\n        var rs = 0;\n        if (nums[key.index0] + nums[key.index0 + 1] == sum)\n        {\n            rs = Math.Max(rs, 1 + MaxOperations((key.index0 + 2, key.index1), dic, sum, nums));\n        }\n        if (nums[key.index0] + nums[key.index1] == sum)\n        {\n            rs = Math.Max(rs, 1 + MaxOperations((key.index0 + 1, key.index1 - 1), dic, sum, nums));\n        }\n        if (nums[key.index1 - 1] + nums[key.index1] == sum)\n        {\n            rs = Math.Max(rs, 1 + MaxOperations((key.index0, key.index1 - 2), dic, sum, nums));\n        }\n        if (!dic.ContainsKey(key)) dic.Add(key, rs);\n        return rs;\n    }\n}\n```
['Dynamic Programming', 'C#']